RechargeChannel.php 5.3 KB

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