RechargeChannel.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\RechargeChannel as RechargeChannelModel;
  5. use App\Models\RechargeChannelGroup;
  6. use Exception;
  7. use App\Constants\HttpStatus;
  8. class RechargeChannel extends Controller
  9. {
  10. //获取充值方式
  11. public function getChannel()
  12. {
  13. $channel = RechargeChannelModel::getChannel(1);
  14. return $this->success(['total' => count($channel), 'data' => $channel]);
  15. }
  16. /**
  17. * 充值通道组合列表
  18. */
  19. public function groupList()
  20. {
  21. try {
  22. $page = request()->input('page', 1);
  23. $limit = request()->input('limit', 15);
  24. $query = new RechargeChannelGroup();
  25. $count = $query->count();
  26. $list = $query
  27. ->forPage($page, $limit)
  28. ->get();
  29. foreach($list as &$item) {
  30. $item->rechargeType = RechargeChannelModel::getChannel(1, $item['recharge_type']);
  31. $item->withdrawType = RechargeChannelModel::getChannel(2, $item['withdraw_type']);
  32. $item->activityType = RechargeChannelModel::getChannel(3, $item['activity_type']);
  33. }
  34. } catch (Exception $e) {
  35. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  36. }
  37. return $this->success(['total' => $count, 'data' => $list]);
  38. }
  39. /**
  40. * 充值通道组合管理更新
  41. */
  42. public function updateGroup()
  43. {
  44. try {
  45. $params = request()->validate([
  46. 'id' => ['nullable','integer'],
  47. 'name' => ['required','string'],
  48. 'recharge_type' => ['required','array'],
  49. 'withdraw_type' => ['required','array'],
  50. 'activity_type' => ['nullable','array'],
  51. ]);
  52. $params['type'] = implode(',', $params['type']);
  53. if (empty($params['id'])) {
  54. RechargeChannelGroup::create($params);
  55. } else {
  56. $info = RechargeChannelGroup::where('id', $params['id'])->first();
  57. if (!$info) throw new Exception('数据不存在');
  58. $info->update($params);
  59. $info->save();
  60. }
  61. return $this->success();
  62. } catch (Exception $e) {
  63. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  64. }
  65. }
  66. /**
  67. * 充值通道管理列表
  68. */
  69. public function list()
  70. {
  71. try {
  72. $params = request()->validate([
  73. 'page' => ['nullable', 'integer', 'min:1'],
  74. 'limit' => ['nullable', 'integer', 'min:1'],
  75. 'data_type' => ['nullable', 'string'],
  76. 'type' => ['nullable', 'string'],
  77. 'from' => ['nullable', 'integer'],
  78. 'key' => ['nullable', 'string'],
  79. 'name' => ['nullable', 'string'],
  80. ]);
  81. $page = request()->input('page', 1);
  82. $limit = request()->input('limit', 15);
  83. $query = new RechargeChannelModel();
  84. if (!empty($params['data_type'])) {
  85. $query = $query->where('data_type', $params['data_type']);
  86. }
  87. if (!empty($params['type'])) {
  88. $query = $query->where('type', $params['type']);
  89. }
  90. if (isset($params['from'])) {
  91. $query = $query->where('from', $params['from']);
  92. }
  93. if (!empty($params['key'])) {
  94. $query = $query->where('key', $params['key']);
  95. }
  96. if (!empty($params['name'])) {
  97. $query = $query->where('name', 'like', '%'.$params['name'].'%');
  98. }
  99. $count = $query->count();
  100. $list = $query
  101. ->forPage($page, $limit)
  102. ->orderBy('sort', 'asc')
  103. ->get();
  104. } catch (Exception $e) {
  105. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  106. }
  107. return $this->success(['total' => $count, 'data' => $list]);
  108. }
  109. /**
  110. * 充值通道管理更新
  111. */
  112. public function update()
  113. {
  114. try {
  115. $params = request()->validate([
  116. 'id' => ['nullable','integer'],
  117. 'from' => ['nullable','integer'],
  118. 'key' => ['nullable','string'],
  119. 'name' => ['nullable','string'],
  120. 'data_type' => ['required','string'],
  121. 'type' => ['required','string'],
  122. 'rate' => ['required','numeric'],
  123. 'min' => ['nullable','integer'],
  124. 'max' => ['nullable','integer'],
  125. 'fixed' => ['nullable','string'],
  126. 'status' => ['nullable','integer'],
  127. 'sort' => ['nullable','integer'],
  128. ]);
  129. if (empty($params['id'])) {
  130. RechargeChannelModel::create($params);
  131. } else {
  132. $info = RechargeChannelModel::where('id', $params['id'])->first();
  133. if (!$info) throw new Exception('数据不存在');
  134. $info->update($params);
  135. $info->save();
  136. }
  137. return $this->success();
  138. } catch (Exception $e) {
  139. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  140. }
  141. }
  142. }