BetService.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. <?php
  2. namespace App\Services;
  3. use App\Constants\StepStatus;
  4. use App\Constants\Util;
  5. use App\Models\Message;
  6. use App\Models\PcIssue;
  7. use App\Models\Rebate;
  8. use App\Models\User;
  9. use App\Models\Bet;
  10. use App\Models\Config;
  11. use Illuminate\Support\Facades\App;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Cache;
  14. use App\Jobs\SendTelegramMessageJob;
  15. use App\Jobs\SendTelegramGroupMessageJob;
  16. use Exception;
  17. use Illuminate\Support\Facades\Log;
  18. use Telegram\Bot\Api;
  19. use Telegram\Bot\Exceptions\TelegramSDKException;
  20. use App\Services\ActivityRewardService;
  21. /**
  22. * 投注
  23. */
  24. class BetService extends BaseService
  25. {
  26. /**
  27. * @param Api $telegram
  28. * @param $data
  29. * @param $chatId
  30. * @param $firstName
  31. * @param $messageId
  32. * @param $callbackId
  33. * @return void
  34. * @throws TelegramSDKException
  35. */
  36. public static function init(Api $telegram, $data, $chatId, $firstName, $messageId, $callbackId): void
  37. {
  38. switch ($data) {
  39. case "todayExchangeRate@@rate": // 今日汇率
  40. BetService::todayExchangeRate($chatId);
  41. break;
  42. case "betsAlert":// 近期注单弹窗
  43. Cache::put('message_id_bet_record_' . $chatId, 0, 600);
  44. $alertText = BetService::recentlyRecord($chatId);
  45. BetService::alertNotice($callbackId, $alertText);
  46. break;
  47. case "promotionalActivityAlert":
  48. // 删除个人缓存
  49. Util::delCache($chatId);
  50. $returnMsg = ActivityRewardService::promotionalActivity($chatId);
  51. $telegram->sendMessage($returnMsg);
  52. break;
  53. default:
  54. //选择投注记录
  55. $pattern = "/^betRecordType@@\d+$/";
  56. if (preg_match($pattern, $data)) {
  57. $type = preg_replace('/^betRecordType@@/', '', $data);
  58. Cache::put('message_id_bet_record_' . $chatId, intval($type), 600);
  59. $telegram->deleteMessage([
  60. 'chat_id' => $chatId,
  61. 'message_id' => $messageId,
  62. ]);
  63. $returnMsg = BetService::record($chatId);
  64. $telegram->sendMessage($returnMsg);
  65. }
  66. //近期注单,下一页
  67. $pattern = "/^betRecordNextPage@@\d+$/";
  68. if (preg_match($pattern, $data)) {
  69. $page = preg_replace('/^betRecordNextPage@@/', '', $data);
  70. $page = intval($page);
  71. $res = BetService::record($chatId, $messageId, $page);
  72. $telegram->editMessageText($res);
  73. }
  74. break;
  75. }
  76. }
  77. public static function onMessage($chatId, $text, $messageId, $stepStatus): ?array
  78. {
  79. switch ($stepStatus) {
  80. default:
  81. $res = null;
  82. break;
  83. }
  84. return $res;
  85. }
  86. public static $OTHER_BET_1 = [
  87. '大',
  88. '小',
  89. '单',
  90. '双',
  91. ];
  92. public static $OTHER_BET_2 = [
  93. '大单',
  94. '大双',
  95. '小单',
  96. '小双',
  97. ];
  98. /**
  99. * @description: 模型
  100. * @return {string}
  101. */
  102. public static function model(): string
  103. {
  104. return Bet::class;
  105. }
  106. /**
  107. * @description: 枚举
  108. * @return {*}
  109. */
  110. public static function enum(): string
  111. {
  112. return '';
  113. }
  114. public static function getWhere(array $search = []): array
  115. {
  116. $where = [];
  117. if (isset($search['issue_no']) && !empty($search['issue_no'])) {
  118. $where[] = ['issue_no', '=', $search['issue_no']];
  119. }
  120. if (isset($search['member_id']) && !empty($search['member_id'])) {
  121. $where[] = ['member_id', '=', $search['member_id']];
  122. }
  123. if (isset($search['keywords']) && !empty($search['keywords'])) {
  124. $where[] = ['keywords', '=', $search['keywords']];
  125. }
  126. if (isset($search['issue_id']) && !empty($search['issue_id'])) {
  127. $where[] = ['issue_id', '=', $search['issue_id']];
  128. }
  129. if (isset($search['id']) && !empty($search['id'])) {
  130. $where[] = ['id', '=', $search['id']];
  131. }
  132. if (isset($search['user_id']) && !empty($search['user_id'])) {
  133. $where[] = ['user_id', '=', $search['user_id']];
  134. }
  135. if (isset($search['start_time']) && !empty($search['start_time'])) {
  136. $where[] = ['created_at', '>=', "{$search['start_time']} 00:00:00"];
  137. $where[] = ['created_at', '<=', "{$search['end_time']} 23:59:59"];
  138. }
  139. if (isset($search['is_winner']) && $search['is_winner'] != '') {
  140. $where[] = ['status', '=', 2];
  141. if ($search['is_winner'] == 1) {
  142. $where[] = ['profit', '>', 0];
  143. } else {
  144. $where[] = ['profit', '<=', 0];
  145. }
  146. } else {
  147. if (isset($search['status']) && $search['status'] != '') {
  148. $where[] = ['status', '=', $search['status']];
  149. }
  150. }
  151. return $where;
  152. }
  153. /**
  154. * @description: 查询单条数据
  155. * @param array $search
  156. * @return \App\Models\Coin|null
  157. */
  158. public static function findOne(array $search): ?Bet
  159. {
  160. return self::model()::where(self::getWhere($search))->first();
  161. }
  162. /**
  163. * @description: 查询所有数据
  164. * @param array $search
  165. * @return \Illuminate\Database\Eloquent\Collection
  166. */
  167. public static function findAll(array $search = [])
  168. {
  169. return self::model()::where(self::getWhere($search))->get();
  170. }
  171. /**
  172. * @description: 分页查询
  173. * @param array $search
  174. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  175. */
  176. public static function paginate(array $search = [])
  177. {
  178. $limit = isset($search['limit']) ? $search['limit'] : 15;
  179. $query = self::model()::where(self::getWhere($search))
  180. ->with(['user']);
  181. if (isset($search['username']) && !empty($search['username'])) {
  182. $username = $search['username'];
  183. $query = $query->whereHas('user', function ($query) use ($username) {
  184. $query->where('username', $username);
  185. });
  186. }
  187. $query->orderBy('id', 'desc');
  188. $paginator = $query->paginate($limit);
  189. return ['total' => $paginator->total(), 'data' => $paginator->items()];
  190. }
  191. /**
  192. * @description: 投注操作
  193. * @param string $memberId
  194. * @param string $input
  195. * @param int $messageId
  196. * @return array
  197. */
  198. public static function bet(string $memberId, string $input, int $messageId = 0): array
  199. {
  200. $msg = [];
  201. $msg['chat_id'] = $memberId;
  202. // 分解投注的内容
  203. $betResult = GameplayRuleService::bettingRuleVerify($input);
  204. $serviceAccount = Config::where('field', 'service_customer')->first()->val;
  205. $maintenanceSwitch = Config::where('field', 'maintenance_switch')->first()->val;
  206. if ($maintenanceSwitch != 0) {
  207. $text = lang("系统维护中") . "\n";
  208. $text .= lang("任何疑问都可以联系唯一客服") . ":@{$serviceAccount}";
  209. $msg['text'] = $text;
  210. if ($messageId) {
  211. $msg['reply_to_message_id'] = $messageId;
  212. }
  213. return $msg;
  214. }
  215. //是否封号
  216. $isBanned = UserService::getIsBanned($memberId);
  217. if ($isBanned) {
  218. $text = lang("账号异常") . "\n";
  219. $text .= lang("任何疑问都可以联系唯一客服") . ":@{$serviceAccount}";
  220. $msg['text'] = $text;
  221. if ($messageId) {
  222. $msg['reply_to_message_id'] = $messageId;
  223. }
  224. return $msg;
  225. }
  226. if ($betResult == null) {
  227. $text = lang("消息格式错误!") . "\n";
  228. $text .= lang("任何疑问都可以联系唯一客服") . ":@{$serviceAccount}";
  229. $msg['text'] = $text;
  230. if ($messageId) {
  231. $msg['reply_to_message_id'] = $messageId;
  232. }
  233. return $msg;
  234. }
  235. DB::beginTransaction();
  236. try {
  237. $text = lang('下注期数') . ":{issue_no}\n";
  238. $text .= lang("下注内容") . "\n";
  239. $text .= "--------\n";
  240. $success = false;
  241. $sumAmount = 0;
  242. $errText = $groupText = "";
  243. foreach ($betResult as $index => $item) {
  244. $keywords = $item['rule'];
  245. $amount = $item['amount'];
  246. $error = $issueNo = "";
  247. $b = static::singleNote($memberId, $keywords, $amount, $issueNo, $text, $error, $groupText, $index);
  248. if ($b) {
  249. $sumAmount += $amount;
  250. $text = str_replace("{issue_no}", $issueNo, $text);
  251. $success = true;
  252. $text .= "\n";
  253. } else {
  254. $errText .= $error;
  255. $errText .= "\n";
  256. }
  257. }
  258. if (!$success) {
  259. $msg['text'] = $errText;
  260. if ($messageId) {
  261. $msg['reply_to_message_id'] = $messageId;
  262. }
  263. } else {
  264. $sumAmount = number_format($sumAmount, 2);
  265. $text .= "--------\n";
  266. $text .= lang("合计金额") . ":{$sumAmount}\n";
  267. $text .= lang("下注成功");
  268. $msg['text'] = $text;
  269. $msg['text'] .= "\n";
  270. if (!empty($errText)) {
  271. $msg['text'] .= "------------------------\n";
  272. $msg['text'] .= $errText;
  273. }
  274. $groupText .= "\n--------\n";
  275. self::asyncBettingGroupNotice($groupText, self::getOperateButton()); // 异步群通知
  276. }
  277. DB::commit();
  278. } catch (Exception $e) {
  279. DB::rollBack();
  280. Log::error('错误信息', [
  281. 'message' => $e->getMessage(),
  282. 'file' => $e->getFile(),
  283. 'line' => $e->getLine(),
  284. 'trace' => $e->getTraceAsString()
  285. ]);
  286. $msg['text'] = "投注失败,请联系管理员";
  287. if ($messageId) {
  288. $msg['reply_to_message_id'] = $messageId;
  289. }
  290. }
  291. return $msg;
  292. }
  293. private static function singleNote($memberId, $keywords, $amount, &$issueNo, &$text, &$errText, &$groupText, $index): bool
  294. {
  295. $errText .= "【{$keywords}{$amount}】\n";
  296. //客服号
  297. $serviceAccount = Config::where('field', 'service_customer')->first()->val;
  298. $gameplayRuleInfo = GameplayRuleService::getGameplayRules($keywords);
  299. if ($gameplayRuleInfo == null) {
  300. $errText .= lang("玩法未配置!") . "\n";
  301. $errText .= lang("任何疑问都可以联系唯一财务") . ":@{$serviceAccount}";
  302. return false;
  303. }
  304. if ($gameplayRuleInfo['odds'] <= 0) {
  305. $errText .= lang("赔率为0 庄家通吃 禁止投注!") . "\n";
  306. $errText .= lang("任何疑问都可以联系唯一财务") . ":@{$serviceAccount}";
  307. return false;
  308. }
  309. // 期数验证
  310. $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
  311. if ($pc28Switch == 1) {
  312. $issueInfo = PcIssue::where('status', PcIssue::STATUS_BETTING)->orderBy('id', 'desc')->first();
  313. } else {
  314. $issueInfo = IssueService::model()::where('status', IssueService::model()::STATUS_BETTING)->orderBy('id', 'desc')->first();
  315. }
  316. if (empty($issueInfo)) {
  317. if ($pc28Switch == 1) {
  318. $issueCloseInfo = PcIssue::where('status', PcIssue::STATUS_CLOSE)->orderBy('id', 'desc')->first();
  319. } else {
  320. $issueCloseInfo = IssueService::model()::where('status', IssueService::model()::STATUS_CLOSE)->orderBy('id', 'desc')->first();
  321. }
  322. if (empty($issueCloseInfo)) {
  323. $errText .= lang("暂无可下注期数,本次下注无效!");
  324. return false;
  325. } else {
  326. $errText .= lang("封盘中,本次下注无效!");
  327. return false;
  328. }
  329. }
  330. if (!is_numeric($amount) || $amount <= 0) {
  331. $errText .= lang("投注金额格式不正确!");
  332. $errText .= lang("任何疑问都可以联系唯一财务") . ":@{$serviceAccount}";
  333. return false;
  334. }
  335. $now_date = date('Y-m-d H:i:s', time() + 30); // 提前30秒
  336. if ($issueInfo['end_time'] < $now_date) {
  337. $errText .= lang("封盘中,本次下注无效!");
  338. return false;
  339. }
  340. // 投注限制校验
  341. if ($amount < $gameplayRuleInfo['mininum']) {
  342. $errText .= lang("下注失败,最小金额限制") . "{$gameplayRuleInfo['mininum']}\n";
  343. return false;
  344. }
  345. // 投注限制校验
  346. if ($amount > $gameplayRuleInfo['maxinum']) {
  347. $errText .= lang("下注失败,最大金额限制") . "{$gameplayRuleInfo['maxinum']}\n";
  348. return false;
  349. }
  350. // 获取用户余额
  351. $walletInfo = WalletService::findOne(['member_id' => $memberId]);
  352. $balance = $walletInfo['available_balance'];
  353. // 余额计算
  354. if ($balance < $amount) {
  355. $errText .= lang("余额不足,本次下注无效!\n");
  356. return false;
  357. }
  358. $userInfo = UserService::findOne(['member_id' => $memberId]);
  359. $betInfo = self::findOne(['member_id' => $memberId, 'issue_no' => $issueInfo->issue_no, 'keywords' => $keywords]); // 相同下注
  360. if ($betInfo) {
  361. $betInfo->amount = $betInfo->amount + $amount;
  362. $bet_id = $betInfo->id;
  363. $betInfo->save();
  364. } else {
  365. $data = [];
  366. $data['amount'] = $amount; // 分数
  367. $data['keywords'] = $keywords; // 玩法
  368. $data['member_id'] = $memberId;
  369. $data['user_id'] = $userInfo->id;
  370. $data['issue_no'] = $issueInfo->issue_no;
  371. $data['issue_id'] = $issueInfo->id;
  372. $data['odds'] = $gameplayRuleInfo['odds'];
  373. $newBet = self::model()::create($data);
  374. $bet_id = $newBet->id;
  375. }
  376. WalletService::updateBalance($memberId, -$amount);
  377. BalanceLogService::addLog($memberId, -$amount, $balance, ($balance - $amount), '投注', $bet_id, '');
  378. //记录投注金额
  379. $rebate = Rebate::addOrUpdate([
  380. 'member_id' => $memberId,
  381. 'betting_amount' => $amount,
  382. 'first_name' => $userInfo->first_name,
  383. 'username' => $userInfo->username,
  384. ]);
  385. $odds = floatval($gameplayRuleInfo['odds']);
  386. $issueNo = $issueInfo->issue_no;
  387. $text .= "{$keywords} {$amount} ({$odds}" . lang('倍率') . ")";
  388. $lastStr = self::hideMiddleDigits($userInfo->member_id, 4);
  389. $lang = App::getLocale();
  390. $group_language = Config::where('field', 'group_language')->first()->val;
  391. App::setLocale($group_language);
  392. if ($index === 0) {
  393. $groupText .= lang("第") . "{$issueNo}" . lang("期") . "\n";
  394. $groupText .= lang("开奖时间") . ":" . date("H:i:s", strtotime($issueInfo['end_time'])) . "\n";
  395. $groupText .= lang('投注截止') . ":" . date("H:i:s", (strtotime($issueInfo['end_time'])) - 30) . "\n";;
  396. $groupText .= lang("成功") . "\n";
  397. $groupText .= lang('玩家') . ": 【{$lastStr}】 \n";
  398. }
  399. $groupText .= "{$keywords} {$amount} ({$odds}" . lang("倍率") . ") \n";
  400. App::setLocale($lang);
  401. return true;
  402. }
  403. //随机虚拟下注
  404. public static function randomVirtualBetting($maxPeople = 1): void
  405. {
  406. $maxPeople = intval($maxPeople);
  407. $maxPeople = max($maxPeople, 1);
  408. $maxPeople = min($maxPeople, 20);
  409. $num = rand(1, $maxPeople);
  410. for ($i = 0; $i < $num; $i++) {
  411. static::fakeBet(4);
  412. }
  413. }
  414. // 模拟下注
  415. private static function fakeBet($betNumber = 1): void
  416. {
  417. $noRule = ['0操', '27操'];
  418. // 防止一开就虚拟投注
  419. $cache = Cache::get('new_issue_no');
  420. if ($cache) {
  421. echo "防止一开就虚拟投注\n";
  422. return;
  423. }
  424. //系统维护
  425. $maintenanceSwitch = Config::where('field', 'maintenance_switch')->first()->val;
  426. if ($maintenanceSwitch != 0) {
  427. echo "系统维护中\n";
  428. return;
  429. }
  430. //后台是否开启虚拟投注
  431. $betFake = Config::where('field', 'bet_fake')->first()->val;
  432. if ($betFake != 1) {
  433. echo "未开启虚拟投注\n";
  434. return;
  435. }
  436. // 期数验证
  437. $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
  438. if ($pc28Switch == 1) {
  439. $issueInfo = PcIssue::where('status', PcIssue::STATUS_BETTING)->orderBy('id', 'desc')->first();
  440. } else {
  441. $issueInfo = IssueService::model()::where('status', IssueService::model()::STATUS_BETTING)->orderBy('id', 'desc')->first();
  442. }
  443. if ($issueInfo) {
  444. $betFakeRandAmount = Config::where('field', 'bet_fake_rand_amount')->first()->val;
  445. $betFakeRandAmount = explode(',', $betFakeRandAmount);
  446. $betMini = $betFakeRandAmount[0] ?? 10;
  447. $betMax = $betFakeRandAmount[1] ?? 10000;
  448. $now_date = date('Y-m-d H:i:s', time() + 38); // 提前45秒
  449. if ($issueInfo['end_time'] > $now_date) {
  450. $fake_bet_list = Cache::get('fake_bet_' . $issueInfo->issue_no, []);
  451. $gameplayRuleList = GameplayRuleService::model()::where('odds', '>', 0)->get();
  452. $gameplayRuleList = $gameplayRuleList->toArray();
  453. $member_id = self::generateRandomNumber(10);
  454. $betTimes = rand(1, $betNumber); // 每次下注次数
  455. Cache::add("封盘后下注单数_{$issueInfo->issue_no}", rand(3, 5), 4);
  456. $lastStr = self::hideMiddleDigits($member_id, 4);
  457. $lang = App::getLocale();
  458. $group_language = Config::where('field', 'group_language')->first()->val;
  459. $first_name = self::generateRandomString(6);
  460. App::setLocale($group_language);
  461. $groupText = lang("第") . "{$issueInfo->issue_no}" . lang("期") . "\n";
  462. $groupText .= lang("开奖时间") . ":" . date("H:i:s", strtotime($issueInfo['end_time'])) . "\n";
  463. $groupText .= lang('投注截止') . ":" . date("H:i:s", (strtotime($issueInfo['end_time'])) - 30) . "\n";;
  464. $groupText .= lang("成功") . "\n";
  465. $groupText .= lang('玩家') . ": 【{$lastStr}】 \n";
  466. App::setLocale($lang);
  467. $haveBet = false;
  468. for ($i = 0; $i < $betTimes; $i++) {
  469. if (strtotime($issueInfo['end_time']) - time() < IssueService::COUNTDOWN_TO_CLOSING_THE_MARKET) {
  470. $fake_bet_count = Cache::get("fake_bet_count_{$issueInfo->issue_no}", 0);
  471. $cc = Cache::get("封盘后下注单数_{$issueInfo->issue_no}");
  472. if ($fake_bet_count >= $cc) return;
  473. }
  474. $randKey = array_rand($gameplayRuleList, 1);
  475. $gameplayRuleInfo = $gameplayRuleList[$randKey] ?? [];
  476. if ($gameplayRuleInfo) {
  477. if (in_array($gameplayRuleInfo['keywords'], $noRule)) {
  478. return;
  479. }
  480. if ($gameplayRuleInfo['maxinum'] < $betMax) {
  481. $betMax = $gameplayRuleInfo['maxinum'];
  482. }
  483. if ($gameplayRuleInfo['mininum'] > $betMini) {
  484. $betMini = $gameplayRuleInfo['mininum'];
  485. }
  486. $amount = rand($betMini, $betMax);
  487. $amount = floor($amount / 10) * 10;
  488. $input = $gameplayRuleInfo['keywords'] . ' ' . $amount;
  489. // $amount = number_format($amount,2);
  490. $item = [];
  491. $item['keywords'] = $gameplayRuleInfo['keywords'];
  492. $item['odds'] = floatval($gameplayRuleInfo['odds']);
  493. $item['amount'] = $amount;
  494. $item['first_name'] = $first_name;
  495. $item['member_id'] = $member_id;
  496. $item['profit'] = 0;
  497. // $input = $item['keywords'] . $item['amount'];
  498. $fake_bet_list[] = $item;
  499. $lang = App::getLocale();
  500. $group_language = Config::where('field', 'group_language')->first()->val;
  501. $first_name = self::generateRandomString(6);
  502. App::setLocale($group_language);
  503. $groupText .= "{$input} (" . $item['odds'] . lang("倍率") . ") \n";
  504. $haveBet = true;
  505. App::setLocale($lang);
  506. if (strtotime($issueInfo['end_time']) - strtotime($now_date) < 22) {
  507. $fake_bet_count = Cache::get("fake_bet_count_{$issueInfo->issue_no}", 0);
  508. Cache::put("fake_bet_count_{$issueInfo->issue_no}", $fake_bet_count + 1, 500);
  509. }
  510. }
  511. }
  512. if ($haveBet) {
  513. $groupText .= "\n-------- \n";
  514. $inlineButton = self::getOperateButton();
  515. // 群通知 暂停2秒再发送,避免同时发送多个消息而超过 Telegram 的频率限制
  516. self::asyncBettingGroupNotice($groupText, $inlineButton); // 异步群通知
  517. sleep(2);
  518. }
  519. Cache::put('fake_bet_' . $issueInfo->issue_no, $fake_bet_list, 500);
  520. }
  521. }
  522. }
  523. /**
  524. * @description: 当期下注
  525. * @param {*} $memberId
  526. * @return {*}
  527. */
  528. public static function currentBet($memberId)
  529. {
  530. $msg['chat_id'] = $memberId;
  531. // 期数验证
  532. $issueInfo = IssueService::model()::where('status', IssueService::model()::STATUS_BETTING)->orderBy('id', 'desc')->first();
  533. $issue_no = '';
  534. if (!empty($issueInfo)) {
  535. $issue_no = $issueInfo->issue_no;
  536. } else {
  537. $issueCloseInfo = IssueService::model()::where('status', IssueService::model()::STATUS_CLOSE)->orderBy('id', 'desc')->first();
  538. if (empty($issueCloseInfo)) {
  539. $issue_no = $issueCloseInfo->issue_no;
  540. }
  541. }
  542. if ($issue_no) {
  543. $text = lang("期数") . " {$issue_no} \n";
  544. // $text .= "\n";
  545. // $text .= "----------\n";
  546. $list = self::findAll(['member_id' => $memberId, 'issue_no' => $issue_no]);
  547. $list = $list->toArray();
  548. if (empty($list)) {
  549. $text .= lang("本期暂未下注") . "! \n";
  550. } else {
  551. $keywords = implode(',', array_column($list, 'keywords'));
  552. $amounts = implode(',', array_column($list, 'amount'));
  553. $text .= lang("下注类型") . ":[" . $keywords . "] \n";
  554. $text .= lang("下注金额") . ":" . $amounts . " \n";
  555. $text .= lang("下注总额") . ":" . array_sum(array_column($list, 'amount')) . " \n";
  556. $text .= lang("开奖状态") . ":" . lang("等待开奖") . " \n";
  557. }
  558. // foreach ($list->toArray() as $k => $v) {
  559. // $text .= "{$v['keywords']}{$v['amount']} \n";
  560. // }
  561. // $text .= "\n";
  562. // $text .= "----------\n";
  563. $msg['text'] = $text;
  564. } else {
  565. $msg['text'] = lang("当前没有开放的投注期数") . "! \n";
  566. }
  567. return $msg;
  568. }
  569. /**
  570. * @description: 近期投注
  571. * @param {*} $memberId
  572. * @return {*}
  573. */
  574. public static function recentlyRecord($memberId, $page = 1, $limit = 5)
  575. {
  576. $list = self::model()::where('member_id', $memberId)->whereIn('status', [self::model()::STATUS_STAY, self::model()::STATUS_SETTLED])->orderBy('id', 'desc')->forPage($page, $limit)->get();
  577. // $text = "```\n";
  578. $text = "";
  579. $text .= "期数--内容--盈亏 \n";
  580. foreach ($list->toArray() as $k => $v) {
  581. $profit = $v['profit'] - $v['amount'];
  582. // $text .= $v['issue_no']." ".$v['keywords']." ".$v['amount']." ".$v['profit']."\n";
  583. $item = $v['issue_no'] . "==" . $v['keywords'] . rtrim(rtrim(number_format($v['amount'], 2, '.', ''), '0'), '.') . "==" . rtrim(rtrim(number_format($profit, 2, '.', ''), '0'), '.') . "\n";
  584. $text .= $item;
  585. }
  586. // $text .= "```\n";
  587. return $text;
  588. }
  589. /**
  590. * @description: 投注记录
  591. * @param {*} $memberId
  592. * @param {*} $page
  593. * @param {*} $limit
  594. * @return {*}
  595. */
  596. public static function record($memberId, $messageId = null, $page = 1, $limit = 5)
  597. {
  598. $type = Cache::get('message_id_bet_record_' . $memberId, 0);
  599. if ($type == 0) {
  600. $type = '';
  601. }
  602. $msg['chat_id'] = $memberId;
  603. $list = self::model()::where('member_id', $memberId)->whereIn('status', [self::model()::STATUS_STAY, self::model()::STATUS_SETTLED])->where(self::getWhere(['is_winner' => $type]))->orderBy('id', 'desc')->forPage($page, $limit)->get();
  604. $count = self::model()::where('member_id', $memberId)->whereIn('status', [self::model()::STATUS_STAY, self::model()::STATUS_SETTLED])->where(self::getWhere(['is_winner' => $type]))->count();
  605. $keyboard = [];
  606. $total_amount = BalanceLogService::model()::where('member_id', $memberId)->where('change_type', '中奖')->sum('amount');
  607. $total_amount = number_format($total_amount, 2);
  608. $text = lang("历史注单") . " \n";
  609. $text .= lang("中奖总派彩") . ":{$total_amount} \n";
  610. foreach ($list as $k => $v) {
  611. if ($v->status == self::model()::STATUS_SETTLED) {
  612. $phase = $v->profit - $v->amount;
  613. } else {
  614. $phase = lang('待开奖');
  615. }
  616. $text .= "-------------------------------------\n";
  617. $text .= lang("期数") . ":{$v->issue_no} \n";
  618. $text .= lang("内容") . ":{$v->keywords} \n";
  619. $text .= lang("金额") . ":{$v->amount} \n";
  620. $text .= lang("盈亏") . ":{$phase} \n";
  621. }
  622. $msg['text'] = $text;
  623. $keyboard[] = [
  624. ['text' => lang("全部"), 'callback_data' => "betRecordType@@0"],
  625. ['text' => lang("盈利"), 'callback_data' => "betRecordType@@1"],
  626. ['text' => lang("亏损"), 'callback_data' => "betRecordType@@2"]
  627. ];
  628. if ($page > 1) {
  629. $keyboard[] = [
  630. ['text' => "👆" . lang("上一页"), 'callback_data' => "betRecordNextPage@@" . ($page - 1)]
  631. ];
  632. }
  633. $allPage = ceil($count / $limit);
  634. if ($allPage > $page) {
  635. if ($page > 1) {
  636. $keyboard[count($keyboard) - 1][] = ['text' => "👇" . lang("下一页"), 'callback_data' => "betRecordNextPage@@" . ($page + 1)];
  637. } else {
  638. $keyboard[] = [
  639. ['text' => "👇" . lang("下一页"), 'callback_data' => "betRecordNextPage@@" . ($page + 1)]
  640. ];
  641. }
  642. }
  643. if ($messageId) {
  644. $msg['message_id'] = $messageId;
  645. }
  646. if ($keyboard) {
  647. $msg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
  648. }
  649. return $msg;
  650. }
  651. /**
  652. * @description: 开奖失败退回投注的
  653. * @param {*} $issue_no
  654. * @return {*}
  655. */
  656. public static function betFail($issue_no)
  657. {
  658. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  659. foreach ($list->toArray() as $k => $v) {
  660. $profit = $v['amount'];
  661. WalletService::updateBalance($v['member_id'], $profit);
  662. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  663. $balance = $walletInfo['available_balance'];
  664. BalanceLogService::addLog($v['member_id'], $profit, ($balance - $profit), $balance, '投注退分', $v['id'], '');
  665. $text = $issue_no . "期开奖失败 \n";
  666. $text .= "投注类型:{$v['keywords']} \n";
  667. $text .= "投注金额:{$v['amount']} \n";
  668. $text .= "投注的资金已退回您的钱包 \n";
  669. self::asyncSendMessage($v['member_id'], $text);
  670. $item = [];
  671. $iem['status'] = self::model()::STATUS_SETTLED;
  672. self::model()::where('id', $v['id'])->update($item);
  673. }
  674. }
  675. /**
  676. * @description: 中奖结算
  677. * @param {*} $issue_no
  678. * @param {*} $awards
  679. * @return {*}
  680. */
  681. public static function betSettled($issue_no, $awards)
  682. {
  683. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  684. // 大小单双的
  685. $otherSum = self::model()::where('issue_no', $issue_no)->where('status', self::model()::STATUS_STAY)->whereIn('keywords', ['大', '小', '单', '双'])->sum('amount');
  686. $fakeOpenData = self::fakeLotteryDraw($issue_no, $awards, 0);
  687. $keywordsList = $fakeOpenData['keywordsList'];
  688. $fakeOtherSum = $fakeOpenData['sum'];
  689. $sum = $otherSum + $fakeOtherSum;
  690. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  691. $betNoticeNum = explode(',', $betNoticeNum);
  692. $betNoticeMini = $betNoticeNum[0] ?? 26;
  693. $betNoticeMax = $betNoticeNum[1] ?? 38;
  694. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  695. $realNoticeNum = ceil($noticeNum / 2);
  696. $openList = [];
  697. $memberList = [];
  698. $bet_num = 0;
  699. foreach ($list->toArray() as $k => $v) {
  700. if (isset($keywordsList[$v['keywords']])) {
  701. $keywordsList[$v['keywords']] += $v['amount'];
  702. } else {
  703. $keywordsList[$v['keywords']] = $v['amount'];
  704. }
  705. // $userInfo = UserService::findAll(['member_id' => $v['member_id']]);
  706. // $lastStr = self::getLastChar($userInfo->first_name, 1);
  707. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  708. $item = [];
  709. $item['id'] = $v['id'];
  710. $item['status'] = self::model()::STATUS_SETTLED;
  711. if (in_array($v['keywords'], $awards)) {
  712. $amount = $v['amount'];
  713. $odds = $v['odds'];
  714. // 玩 大单 小单 大双 小双 :如果开出13和14 总注小于10000 1.5赔率含本,大于等于10000退本金。
  715. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  716. // 13 14特殊处理倍率
  717. if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  718. if ($sum < 10000) {
  719. $odds = 1.5;
  720. } else {
  721. $odds = 1;
  722. }
  723. }
  724. }
  725. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  726. if ($profit > 1000000) {
  727. $profit = 1000000; // 单注最高奖金1000000
  728. }
  729. $item['profit'] = $profit;
  730. // $yl = $profit - $amount;
  731. $yl = bcsub($profit, $amount, 2); // 盈利
  732. $rebate = Rebate::updateProfit([
  733. 'member_id' => $v['member_id'],
  734. 'profit' => $yl,
  735. ]);
  736. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  737. RebateService::updateEffectiveBettingAmount($rebate, $v['amount']);
  738. ActivityUserService::updateBettingAmount($v['member_id'],$v['amount']);
  739. }
  740. $memberList[$v['member_id']][] = [
  741. 'member_id' => $v['member_id'],
  742. 'keywords' => $v['keywords'],
  743. 'amount' => $v['amount'],
  744. 'profit' => $profit,
  745. 'yl' => $yl,
  746. ];
  747. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  748. $balance = $walletInfo['available_balance'];
  749. WalletService::updateBalance($v['member_id'], $profit);
  750. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], "盈利:{$yl}");
  751. if (isset($openList[$v['member_id']])) {
  752. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  753. $openList[$v['member_id']]['amount'] += $v['amount'];
  754. $openList[$v['member_id']]['profit'] += $profit;
  755. $openList[$v['member_id']]['lastStr'] = $lastStr;
  756. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  757. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  758. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  759. } else {
  760. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  761. $openList[$v['member_id']]['amount'] = $v['amount'];
  762. $openList[$v['member_id']]['profit'] = $profit;
  763. $openList[$v['member_id']]['lastStr'] = $lastStr;
  764. $openList[$v['member_id']]['openKeywords'] = [];
  765. $openList[$v['member_id']]['keywords'] = [];
  766. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  767. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  768. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  769. $openList[$v['member_id']]['is_send'] = true;
  770. }
  771. } //
  772. else {
  773. $rebate = Rebate::updateProfit([
  774. 'member_id' => $v['member_id'],
  775. 'profit' => ($v['amount'] * -1),
  776. ]);
  777. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  778. RebateService::updateEffectiveBettingAmount($rebate, $v['amount']);
  779. ActivityUserService::updateBettingAmount($v['member_id'],$v['amount']);
  780. }
  781. $profit = 0;
  782. // 玩 大单 小单 大双 小双 :如果开出13和14 总注小于10000 1.5赔率含本,大于等于10000退本金。
  783. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  784. $amount = $v['amount'];
  785. $odds = 0;
  786. // 13 14特殊处理倍率
  787. if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  788. if ($sum < 10000) {
  789. $odds = 1.5;
  790. } else {
  791. $odds = 1;
  792. }
  793. }
  794. // if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  795. // $odds = 1;
  796. // }
  797. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  798. if ($profit > 1000000) {
  799. $profit = 1000000; // 单注最高奖金1000000
  800. }
  801. $item['profit'] = $profit;
  802. $yl = bcsub($profit, $amount, 2); // 盈利
  803. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  804. $balance = $walletInfo['available_balance'];
  805. WalletService::updateBalance($v['member_id'], $profit);
  806. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], "盈利:{$yl}");
  807. }
  808. if (isset($openList[$v['member_id']])) {
  809. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  810. $openList[$v['member_id']]['amount'] += $v['amount'];
  811. $openList[$v['member_id']]['profit'] += $profit;
  812. $openList[$v['member_id']]['lastStr'] = $lastStr;
  813. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  814. } else {
  815. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  816. $openList[$v['member_id']]['amount'] = $v['amount'];
  817. $openList[$v['member_id']]['profit'] = $profit;
  818. $openList[$v['member_id']]['lastStr'] = $lastStr;
  819. $openList[$v['member_id']]['openKeywords'] = [];
  820. $openList[$v['member_id']]['keywords'] = [];
  821. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  822. $openList[$v['member_id']]['win_amount'] = 0;
  823. $openList[$v['member_id']]['is_send'] = true;
  824. }
  825. }
  826. self::model()::where('id', $v['id'])->update($item);
  827. }
  828. $openList = array_merge($openList, $fakeOpenData['list']);
  829. self::lotteryNotice($openList, $issue_no, $keywordsList);
  830. }
  831. // 虚拟开奖
  832. public static function fakeLotteryDraw($issue_no, $awards, $rand_num = 30)
  833. {
  834. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  835. $text = "";
  836. $keywordsList = [];
  837. $fakeOtherSum = 0;
  838. $openList = [];
  839. foreach ($fake_bet_list as $k => $v) {
  840. if (in_array($v['keywords'], ['大', '小', '单', '双'])) {
  841. $fakeOtherSum += $v['amount'];
  842. }
  843. if (isset($keywordsList[$v['keywords']])) {
  844. $keywordsList[$v['keywords']] += $v['amount'];
  845. } else {
  846. $keywordsList[$v['keywords']] = $v['amount'];
  847. }
  848. // $lastStr = self::getLastChar($v['first_name'], 1);
  849. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  850. if (in_array($v['keywords'], $awards)) {
  851. $amount = $v['amount'];
  852. $odds = $v['odds'];
  853. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  854. if ($profit > 880000) {
  855. $profit = 880000; // 单注最高奖金880000
  856. }
  857. $item['profit'] = $profit;
  858. // $v['amount'] = number_format($amount,2);
  859. if (isset($openList[$v['member_id']])) {
  860. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  861. $openList[$v['member_id']]['amount'] += $v['amount'];
  862. $openList[$v['member_id']]['profit'] += $profit;
  863. $openList[$v['member_id']]['lastStr'] = $lastStr;
  864. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  865. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  866. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  867. } else {
  868. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  869. $openList[$v['member_id']]['amount'] = $v['amount'];
  870. $openList[$v['member_id']]['profit'] = $profit;
  871. $openList[$v['member_id']]['lastStr'] = $lastStr;
  872. $openList[$v['member_id']]['openKeywords'] = [];
  873. $openList[$v['member_id']]['keywords'] = [];
  874. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  875. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  876. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  877. $openList[$v['member_id']]['is_send'] = false;
  878. }
  879. } else {
  880. if (isset($openList[$v['member_id']])) {
  881. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  882. $openList[$v['member_id']]['amount'] += $v['amount'];
  883. $openList[$v['member_id']]['lastStr'] = $lastStr;
  884. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  885. } else {
  886. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  887. $openList[$v['member_id']]['amount'] = $v['amount'];
  888. $openList[$v['member_id']]['profit'] = 0;
  889. $openList[$v['member_id']]['lastStr'] = $lastStr;
  890. $openList[$v['member_id']]['openKeywords'] = [];
  891. $openList[$v['member_id']]['keywords'] = [];
  892. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  893. $openList[$v['member_id']]['win_amount'] = 0;
  894. $openList[$v['member_id']]['is_send'] = false;
  895. }
  896. }
  897. }
  898. return ['sum' => $fakeOtherSum, 'list' => $openList, 'keywordsList' => $keywordsList];
  899. }
  900. // 开奖通知
  901. public static function lotteryNotice($openList, $issue_no, $keywordsList = [])
  902. {
  903. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  904. $betNoticeNum = explode(',', $betNoticeNum);
  905. $betNoticeMini = $betNoticeNum[0] ?? 26;
  906. $betNoticeMax = $betNoticeNum[1] ?? 38;
  907. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  908. // shuffle($openList);
  909. // Log::error('lotteryNotice openList', $openList);
  910. $lang = App::getLocale();
  911. $group_language = Config::where('field', 'group_language')->first()->val;
  912. App::setLocale($group_language);
  913. $text = "{$issue_no} " . lang("期开奖结果");
  914. $text .= "\n-----" . lang("本期开奖账单") . "----- \n";
  915. App::setLocale($lang);
  916. foreach ($openList as $k => $v) {
  917. $amount = number_format($v['amount'], 2);
  918. $v['win_amount'] = number_format($v['win_amount'], 2);
  919. $profit = number_format($v['profit'], 2);
  920. $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  921. if (empty($v['openKeywords'])) {
  922. $openKeyword = '-';
  923. } else {
  924. $openKeyword = implode(',', $v['openKeywords']);
  925. }
  926. if (($k + 1) <= $noticeNum) {
  927. $lang = App::getLocale();
  928. $group_language = Config::where('field', 'group_language')->first()->val;
  929. App::setLocale($group_language);
  930. $text .= lang("用户ID") . ":{$v['lastStr']} \n";
  931. $text .= lang("下注类型") . ":[" . implode(',', $v['keywords']) . "] \n";
  932. $text .= lang('中奖类型') . ":[" . $openKeyword . "] \n";
  933. $text .= lang('投注金额') . ":{$amount} \n";
  934. $text .= lang('中奖金额') . ":{$v['win_amount']} \n";
  935. $text .= lang('派彩金额') . ":{$profit} \n";
  936. $text .= lang("盈亏金额") . ":{$yl} \n";
  937. $text .= "-------------------------------- \n";
  938. App::setLocale($lang);
  939. }
  940. if ($v['is_send']) {
  941. $language = User::where('member_id', $v['member_id'])->first()->language;
  942. $wallet = WalletService::findOne(['member_id' => $v['member_id']]);
  943. App::setLocale($language);
  944. $text2 = lang("{issue_no}期开奖结果");
  945. $text2 = str_replace("{issue_no}", $issue_no, $text2);
  946. $text2 .= "\n";
  947. $text2 .= lang('下注类型') . ":[" . implode(',', $v['keywords']) . "] \n";
  948. $text2 .= lang('中奖类型') . ":[" . $openKeyword . "] \n";
  949. $text2 .= lang('投注金额') . ":{$amount} \n";
  950. $text2 .= lang('中奖金额') . ":{$v['win_amount']} \n";
  951. $text2 .= lang('派彩金额') . ":{$profit} \n";
  952. $text2 .= lang("盈亏金额") . ":{$yl} \n";
  953. $balance = floatval($wallet->available_balance);
  954. $text2 .= "----------------\n";
  955. $text2 .= "当前余额:{$balance} \n";
  956. $keyboard = [];
  957. $keyboard[] = [
  958. ['text' => lang("开奖历史"), 'callback_data' => "showLotteryHistory@@" . $issue_no]
  959. ];
  960. // self::sendMessage($v['member_id'],$text2,$keyboard);
  961. SendTelegramMessageJob::dispatch($v['member_id'], $text2, $keyboard);
  962. }
  963. }
  964. $inlineButton = self::getOperateButton();
  965. // 群通知
  966. $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
  967. if (($pc28Switch == 0 && is_numeric($issue_no)) || $pc28Switch == 1 && !is_numeric($issue_no)) {
  968. SendTelegramGroupMessageJob::dispatch($text, $inlineButton, '', false, '--------------------------------');
  969. }
  970. }
  971. /**
  972. * @description: 统计投注情况通知
  973. * @param {*} $issue_no
  974. * @return {*}
  975. */
  976. public static function statNotice($issue_no)
  977. {
  978. $keywordsList = [];
  979. // 虚拟投注情况
  980. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  981. foreach ($fake_bet_list as $k => $v) {
  982. if (isset($keywordsList[$v['keywords']])) {
  983. $keywordsList[$v['keywords']] += $v['amount'];
  984. } else {
  985. $keywordsList[$v['keywords']] = $v['amount'];
  986. }
  987. }
  988. // 真实投注
  989. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  990. foreach ($list->toArray() as $k => $v) {
  991. if (isset($keywordsList[$v['keywords']])) {
  992. $keywordsList[$v['keywords']] += $v['amount'];
  993. } else {
  994. $keywordsList[$v['keywords']] = $v['amount'];
  995. }
  996. }
  997. $lang = App::getLocale();
  998. $group_language = Config::where('field', 'group_language')->first()->val;
  999. App::setLocale($group_language);
  1000. $text3 = "📝 {$issue_no}" . lang('期投注统计') . " \n";
  1001. $text3 .= lang("玩法") . " " . lang("总投") . " \n";
  1002. App::setLocale($lang);
  1003. if ($keywordsList) {
  1004. uksort($keywordsList, 'custom_sort');
  1005. // ksort($keywordsList);
  1006. foreach ($keywordsList as $k => $v) {
  1007. $text3 .= "{$k} {$v} \n";
  1008. }
  1009. }
  1010. $inlineButton = self::getOperateButton();
  1011. // 投注统计的消息不发了
  1012. // SendTelegramGroupMessageJob::dispatch($text3, $inlineButton, '');
  1013. }
  1014. public static function todayExchangeRate($chatId)
  1015. {
  1016. $exchangeRate = Config::where('field', 'exchange_rate_rmb')->first()->val;
  1017. $text = lang("今日汇率") . ":1USDT = {$exchangeRate} RMB \n";
  1018. // $botMsg = [
  1019. // 'chat_id' => "@{$chatId}",
  1020. // 'text' => $text
  1021. // ];
  1022. self::sendMessage($chatId, $text);
  1023. // return $botMsg;
  1024. }
  1025. }