BetService.php 46 KB

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