| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Http\Controllers\Controller;
- use App\Models\JisuLottery as JisuLotteryModel;
- use Exception;
- use App\Constants\HttpStatus;
- class JisuLottery extends Controller
- {
- /**
- * 开奖管理列表
- */
- public function list()
- {
- try {
- $params = request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1'],
- 'type' => ['nullable', 'integer', 'min:1'],
- 'status' => ['nullable', 'integer', 'min:1'],
- 'is_settlement' => ['nullable', 'integer'],
- 'issue' => ['nullable', 'string'],
- 'open_code' => ['nullable', 'string'],
- 'start_time' => ['nullable', 'string'],
- 'end_time' => ['nullable', 'string'],
- ]);
- $page = request()->input('page', 1);
- $limit = request()->input('limit', 15);
- $query = new JisuLotteryModel();
- if (!empty($params['type'])) {
- $query = $query->where('type', $params['type']);
- }
- if (!empty($params['status'])) {
- $query = $query->where('status', $params['status']);
- }
- if (isset($params['is_settlement'])) {
- $query = $query->where('is_settlement', $params['is_settlement']);
- }
- if (!empty($params['issue'])) {
- $query = $query->where('issue', $params['issue']);
- }
- if (!empty($params['open_code'])) {
- $query = $query->where('open_code', $params['open_code']);
- }
- if (!empty($params['start_time'])) {
- $query = $query->where('open_time', '>=', strtotime($params['start_time'].' 00:00:00'));
- }
- if (!empty($params['end_time'])) {
- $query = $query->where('open_time', '<', strtotime($params['end_time'].' 23:59:59'));
- }
- $count = $query->count();
- $list = $query
- ->forPage($page, $limit)
- ->orderByDesc('open_time')
- ->get();
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
- }
- return $this->success(['total' => $count, 'data' => $list]);
- }
-
- //设置预开奖号码
- public function setAdvanceCode()
- {
- try {
- $params = request()->validate([
- 'id' => ['required','integer'],
- 'advance_code' => ['required','array'],
- ]);
- $id = $params['id'];
- // if (count($params['advance_code']) != 7) {
- // throw new Exception('开奖号码必须是7个数');
- // }
- $info = JisuLotteryModel::where('id', $id)->first();
- if (!$info) throw new Exception('数据不存在');
- if (!empty($info->open_code)) {
- throw new Exception('已开奖');
- }
- if (!empty($info->advance_code)) {
- throw new Exception('已设置');
- }
- if ($info->type == 2) {
- if (count($params['advance_code']) != 5) {
- throw new Exception('开奖号码必须是5个数');
- }
- } else {
- if (count($params['advance_code']) != 10) {
- throw new Exception('开奖号码必须是10个数');
- }
- }
- $info->advance_code = implode(",",$params['advance_code']);
- $info->save();
- return $this->success();
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
- }
- }
- }
|