RechargeChannel.php 4.8 KB

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