RechargeChannel.php 4.6 KB

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