| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Http\Controllers\Controller;
- use App\Models\RechargeChannel as RechargeChannelModel;
- use App\Models\RechargeChannelGroup;
- use Exception;
- use App\Constants\HttpStatus;
- class RechargeChannel extends Controller
- {
- //获取充值方式
- public function getChannel()
- {
- $data_type = request()->input('data_type', 1);
- $channel = RechargeChannelModel::getChannel($data_type);
- return $this->success(['total' => count($channel), 'data' => $channel]);
- }
- /**
- * 充值通道组合列表
- */
- public function groupList()
- {
- try {
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 15);
- $query = new RechargeChannelGroup();
- $count = $query->count();
- $list = $query
- ->forPage($page, $limit)
- ->get();
- foreach($list as &$item) {
- $item->rechargeTypes = $item['recharge_type'] ? RechargeChannelModel::getChannel(1, $item['recharge_type']) : [];
- $item->withdrawTypes = $item['withdraw_type'] ? RechargeChannelModel::getChannel(2, $item['withdraw_type']) : [];
- $item->activityTypes = $item['activity_type'] ? RechargeChannelModel::getChannel(3, $item['activity_type']) : [];
- }
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
- }
- return $this->success(['total' => $count, 'data' => $list]);
- }
- /**
- * 充值通道组合管理更新
- */
- public function updateGroup()
- {
- try {
- $params = request()->validate([
- 'id' => ['nullable','integer'],
- 'name' => ['required','string'],
- 'recharge_type' => ['required','array'],
- 'withdraw_type' => ['required','array'],
- 'activity_type' => ['nullable','array'],
- ]);
- foreach (['recharge_type' => 1, 'withdraw_type' => 2, 'activity_type' => 3] as $field => $dataType) {
- $types = array_values(array_unique(array_filter(array_map('strval', $params[$field] ?? []))));
- if ($types) {
- $existingCount = RechargeChannelModel::query()->where('data_type', $dataType)
- ->whereIn('type', $types)->distinct()->count('type');
- if ($existingCount !== count($types)) throw new Exception("{$field} 包含不存在的通道类型");
- }
- $params[$field] = $types;
- }
-
- if (empty($params['id'])) {
- RechargeChannelGroup::create($params);
- } else {
- $info = RechargeChannelGroup::where('id', $params['id'])->first();
- if (!$info) throw new Exception('数据不存在');
- $info->update($params);
- $info->save();
- }
-
- return $this->success();
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
- }
- }
- /**
- * 充值通道管理列表
- */
- public function list()
- {
- try {
- $params = request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1'],
- 'data_type' => ['nullable', 'string'],
- 'type' => ['nullable', 'string'],
- 'from' => ['nullable', 'integer'],
- 'key' => ['nullable', 'string'],
- 'name' => ['nullable', 'string'],
- ]);
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 15);
- $query = new RechargeChannelModel();
- if (!empty($params['data_type'])) {
- $query = $query->where('data_type', $params['data_type']);
- }
- if (!empty($params['type'])) {
- $query = $query->where('type', $params['type']);
- }
- if (isset($params['from'])) {
- $query = $query->where('from', $params['from']);
- }
- if (!empty($params['key'])) {
- $query = $query->where('key', $params['key']);
- }
- if (!empty($params['name'])) {
- $query = $query->where('name', 'like', '%'.$params['name'].'%');
- }
- $count = $query->count();
- $list = $query
- ->forPage($page, $limit)
- ->orderBy('sort', 'asc')
- ->get();
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
- }
- return $this->success(['total' => $count, 'data' => $list]);
- }
- /**
- * 充值通道管理更新
- */
- public function update()
- {
- try {
- $params = request()->validate([
- 'id' => ['nullable','integer'],
- 'from' => ['nullable','integer'],
- 'key' => ['nullable','string','max:100'],
- 'name' => ['nullable','string','max:100'],
- 'data_type' => ['required','integer','in:1,2,3'],
- 'type' => ['required','string','max:100'],
- 'rate' => ['required','numeric','min:0'],
- 'min' => ['nullable','numeric','min:0'],
- 'max' => ['nullable','numeric','gte:min'],
- 'fixed' => ['nullable','string'],
- 'status' => ['nullable','integer','in:0,1'],
- 'sort' => ['nullable','integer','min:0'],
- ]);
- if (empty($params['id'])) {
- RechargeChannelModel::create($params);
- } else {
- $info = RechargeChannelModel::where('id', $params['id'])->first();
- if (!$info) throw new Exception('数据不存在');
- $info->update($params);
- $info->save();
- }
-
- return $this->success();
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
- }
- }
- }
|