LhcLottery.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\LhcLottery as LhcLotteryModel;
  5. use Exception;
  6. use App\Constants\HttpStatus;
  7. class LhcLottery extends Controller
  8. {
  9. /**
  10. * 开奖管理列表
  11. */
  12. public function list()
  13. {
  14. try {
  15. $params = request()->validate([
  16. 'page' => ['nullable', 'integer', 'min:1'],
  17. 'limit' => ['nullable', 'integer', 'min:1'],
  18. 'type' => ['nullable', 'integer', 'min:1'],
  19. 'status' => ['nullable', 'integer', 'min:1'],
  20. 'is_settlement' => ['nullable', 'integer'],
  21. 'issue' => ['nullable', 'string'],
  22. 'open_code' => ['nullable', 'string'],
  23. 'start_time' => ['nullable', 'string'],
  24. 'end_time' => ['nullable', 'string'],
  25. ]);
  26. $page = request()->input('page', 1);
  27. $limit = request()->input('limit', 15);
  28. $query = new LhcLotteryModel();
  29. if (!empty($params['type'])) {
  30. $query = $query->where('type', $params['type']);
  31. }
  32. if (!empty($params['status'])) {
  33. $query = $query->where('status', $params['status']);
  34. }
  35. if (isset($params['is_settlement'])) {
  36. $query = $query->where('is_settlement', $params['is_settlement']);
  37. }
  38. if (!empty($params['issue'])) {
  39. $query = $query->where('issue', $params['issue']);
  40. }
  41. if (!empty($params['open_code'])) {
  42. $query = $query->where('open_code', $params['open_code']);
  43. }
  44. if (!empty($params['start_time'])) {
  45. $query = $query->where('open_time', '>=', strtotime($params['start_time'].' 00:00:00'));
  46. }
  47. if (!empty($params['end_time'])) {
  48. $query = $query->where('open_time', '<', strtotime($params['end_time'].' 23:59:59'));
  49. }
  50. $count = $query->count();
  51. $list = $query
  52. ->forPage($page, $limit)
  53. ->orderByDesc('id')
  54. ->get();
  55. } catch (Exception $e) {
  56. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  57. }
  58. return $this->success(['total' => $count, 'data' => $list]);
  59. }
  60. //设置预开奖号码
  61. public function setAdvanceCode()
  62. {
  63. try {
  64. $params = request()->validate([
  65. 'id' => ['required','integer'],
  66. 'advance_code' => ['required','array'],
  67. ]);
  68. $id = $params['id'];
  69. if (count($params['advance_code']) != 7) {
  70. throw new Exception('开奖号码必须是7个数');
  71. }
  72. $info = LhcLotteryModel::where('id', $id)->first();
  73. if (!$info) throw new Exception('数据不存在');
  74. if (!empty($info->open_code)) {
  75. throw new Exception('已开奖');
  76. }
  77. if (!empty($info->advance_code)) {
  78. throw new Exception('已设置');
  79. }
  80. $info->advance_code = implode(",",$params['advance_code']);
  81. $info->save();
  82. return $this->success();
  83. } catch (Exception $e) {
  84. return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());
  85. }
  86. }
  87. }