RechargeChannel.php 4.4 KB

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