RechargeChannel.php 5.4 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. $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->rechargeTypes = $item['recharge_type'] ? RechargeChannelModel::getChannel(1, $item['recharge_type']) : [];
  32. $item->withdrawTypes = $item['withdraw_type'] ? RechargeChannelModel::getChannel(2, $item['withdraw_type']) : [];
  33. $item->activityTypes = $item['activity_type'] ? 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. 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. }