ActivityRewardService.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace App\Services;
  3. use App\Constants\HttpStatus;
  4. use App\Constants\Util;
  5. use App\Models\ActivityReward;
  6. use App\Models\Config;
  7. use App\Models\Role;
  8. use App\Models\UserSession;
  9. use App\Models\User;
  10. use Exception;
  11. class ActivityRewardService extends BaseService
  12. {
  13. public static string $MODEL = ActivityReward::class;
  14. /**
  15. * @description: 查询单条数据
  16. * @param array $search
  17. * @return ActivityReward|null
  18. */
  19. public static function findOne(array $search): ActivityReward|null
  20. {
  21. return static::$MODEL::where(static::getWhere($search))->first();
  22. }
  23. public static function getWhere(array $search = []): array
  24. {
  25. $where = [];
  26. if (isset($search['id']) && !empty($search['id'])) {
  27. $where[] = ['id', '=', $search['id']];
  28. }
  29. if (isset($search['status']) && $search['status'] != '') {
  30. $where[] = ['status', '=', $search['status']];
  31. }
  32. if (isset($search['type']) && $search['type'] != '') {
  33. $where[] = ['type', '=', $search['type']];
  34. }
  35. if (isset($search['title']) && !empty($search['title'])) {
  36. $where[] = ['title', 'like', "%{$search['title']}%"];
  37. }
  38. if (isset($search['start_time']) && !empty($search['start_time'])) {
  39. if (is_array($search['start_time'])) {
  40. if (count($search['start_time']) == 2) {
  41. $where[] = ['start_time', $search['start_time'][0], $search['start_time'][1]];
  42. } else {
  43. $where[] = ['start_time', '=', $search['start_time'][0]];
  44. }
  45. } else {
  46. $where[] = ['start_time', '=', $search['start_time']];
  47. }
  48. }
  49. if (isset($search['end_time']) && !empty($search['end_time'])) {
  50. if (is_array($search['end_time'])) {
  51. if (count($search['end_time']) == 2) {
  52. $where[] = ['end_time', $search['end_time'][0], $search['end_time'][1]];
  53. } else {
  54. $where[] = ['end_time', '=', $search['end_time'][0]];
  55. }
  56. } else {
  57. $where[] = ['end_time', '=', $search['end_time']];
  58. }
  59. }
  60. return $where;
  61. }
  62. public static function deleteAll(array $search = []): bool
  63. {
  64. $count = static::$MODEL::where(static::getWhere($search))->delete();
  65. if ($count < 1) throw new Exception('删除失败', HttpStatus::CUSTOM_ERROR);
  66. return true;
  67. }
  68. /**
  69. * Update or create
  70. * @param array $params
  71. * @return bool
  72. * @throws Exception
  73. */
  74. public static function submit(array $params = []): bool
  75. {
  76. if (isset($params['start_time']))
  77. $params['start_time'] = strtotime($params['start_time']);
  78. if (isset($params['end_time']))
  79. $params['end_time'] = strtotime($params['end_time']);
  80. if (isset($params['detail_image']))
  81. $params['detail_image'] = Util::replacePartInUrl($params['detail_image']);
  82. if (!empty($params['id'])) {
  83. $info = static::findOne(['id' => $params['id']]);
  84. if (!$info) throw new Exception("操作失败", HttpStatus::CUSTOM_ERROR);
  85. $info->update($params);
  86. } else {
  87. static::$MODEL::create($params);
  88. }
  89. return true;
  90. }
  91. public static function promotionalActivity($chatId): array
  92. {
  93. $keyboard = [];
  94. $url = Config::where('field','activity_home_url')->first()->val;
  95. $url.="?member_id=".$chatId;
  96. $keyboard[] = [
  97. ['text'=>'活动首页','url'=>$url]
  98. ];
  99. $msg = [];
  100. $msg['chat_id'] = $chatId;
  101. $msg['text'] = "点击下方按钮进入活动首页";
  102. $msg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
  103. return $msg;
  104. }
  105. //F1bet娱乐更多玩法(足球首页)
  106. public static function footballUrl($chatId): array
  107. {
  108. $token = UserSession::setToken($chatId);
  109. $is_bind = User::where('member_id', $chatId)->value('account') ? 1 : 0;
  110. $keyboard = [];
  111. $url = Config::where('field','football_home_url ')->first()->val;
  112. $url.="?token=".$token."&is_bind=".$is_bind;
  113. $keyboard[] = [
  114. ['text'=>'F1bet娱乐首页','url'=>$url]
  115. ];
  116. $msg = [];
  117. $msg['chat_id'] = $chatId;
  118. $msg['text'] = "点击下方按钮进入F1bet娱乐首页";
  119. $msg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
  120. return $msg;
  121. }
  122. }