BetService.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  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. //笔笔返改为隔天统一返,不在每次结算的时候返了
  729. // if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  730. // RebateService::BibiReturn($rebate, $v['amount']);
  731. // }
  732. $memberList[$v['member_id']][] = [
  733. 'member_id' => $v['member_id'],
  734. 'keywords' => $v['keywords'],
  735. 'amount' => $v['amount'],
  736. 'profit' => $profit,
  737. 'yl' => $yl,
  738. ];
  739. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  740. $balance = $walletInfo['available_balance'];
  741. WalletService::updateBalance($v['member_id'], $profit);
  742. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], "盈利:{$yl}");
  743. if (isset($openList[$v['member_id']])) {
  744. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  745. $openList[$v['member_id']]['amount'] += $v['amount'];
  746. $openList[$v['member_id']]['profit'] += $profit;
  747. $openList[$v['member_id']]['lastStr'] = $lastStr;
  748. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  749. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  750. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  751. } else {
  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'] = [];
  757. $openList[$v['member_id']]['keywords'] = [];
  758. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  759. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  760. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  761. $openList[$v['member_id']]['is_send'] = true;
  762. }
  763. } //
  764. else {
  765. $rebate = Rebate::updateProfit([
  766. 'member_id' => $v['member_id'],
  767. 'profit' => ($v['amount'] * -1),
  768. ]);
  769. //笔笔返改为隔天统一返,不在每次结算的时候返了
  770. // if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  771. // RebateService::BibiReturn($rebate, $v['amount']);
  772. // }
  773. $profit = 0;
  774. // 玩 大单 小单 大双 小双 :如果开出13和14 总注小于10000 1.5赔率含本,大于等于10000退本金。
  775. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  776. $amount = $v['amount'];
  777. $odds = 0;
  778. // 13 14特殊处理倍率
  779. if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  780. if ($sum < 10000) {
  781. $odds = 1.5;
  782. } else {
  783. $odds = 1;
  784. }
  785. }
  786. // if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  787. // $odds = 1;
  788. // }
  789. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  790. if ($profit > 1000000) {
  791. $profit = 1000000; // 单注最高奖金1000000
  792. }
  793. $item['profit'] = $profit;
  794. $yl = bcsub($profit, $amount, 2); // 盈利
  795. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  796. $balance = $walletInfo['available_balance'];
  797. WalletService::updateBalance($v['member_id'], $profit);
  798. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], "盈利:{$yl}");
  799. }
  800. if (isset($openList[$v['member_id']])) {
  801. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  802. $openList[$v['member_id']]['amount'] += $v['amount'];
  803. $openList[$v['member_id']]['profit'] += $profit;
  804. $openList[$v['member_id']]['lastStr'] = $lastStr;
  805. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  806. } else {
  807. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  808. $openList[$v['member_id']]['amount'] = $v['amount'];
  809. $openList[$v['member_id']]['profit'] = $profit;
  810. $openList[$v['member_id']]['lastStr'] = $lastStr;
  811. $openList[$v['member_id']]['openKeywords'] = [];
  812. $openList[$v['member_id']]['keywords'] = [];
  813. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  814. $openList[$v['member_id']]['win_amount'] = 0;
  815. $openList[$v['member_id']]['is_send'] = true;
  816. }
  817. }
  818. self::model()::where('id', $v['id'])->update($item);
  819. }
  820. $openList = array_merge($openList, $fakeOpenData['list']);
  821. self::lotteryNotice($openList, $issue_no, $keywordsList);
  822. }
  823. // 虚拟开奖
  824. public static function fakeLotteryDraw($issue_no, $awards, $rand_num = 30)
  825. {
  826. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  827. $text = "";
  828. $keywordsList = [];
  829. $fakeOtherSum = 0;
  830. $openList = [];
  831. foreach ($fake_bet_list as $k => $v) {
  832. if (in_array($v['keywords'], ['大', '小', '单', '双'])) {
  833. $fakeOtherSum += $v['amount'];
  834. }
  835. if (isset($keywordsList[$v['keywords']])) {
  836. $keywordsList[$v['keywords']] += $v['amount'];
  837. } else {
  838. $keywordsList[$v['keywords']] = $v['amount'];
  839. }
  840. // $lastStr = self::getLastChar($v['first_name'], 1);
  841. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  842. if (in_array($v['keywords'], $awards)) {
  843. $amount = $v['amount'];
  844. $odds = $v['odds'];
  845. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  846. if ($profit > 880000) {
  847. $profit = 880000; // 单注最高奖金880000
  848. }
  849. $item['profit'] = $profit;
  850. // $v['amount'] = number_format($amount,2);
  851. if (isset($openList[$v['member_id']])) {
  852. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  853. $openList[$v['member_id']]['amount'] += $v['amount'];
  854. $openList[$v['member_id']]['profit'] += $profit;
  855. $openList[$v['member_id']]['lastStr'] = $lastStr;
  856. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  857. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  858. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  859. } else {
  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'] = [];
  865. $openList[$v['member_id']]['keywords'] = [];
  866. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  867. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  868. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  869. $openList[$v['member_id']]['is_send'] = false;
  870. }
  871. } else {
  872. if (isset($openList[$v['member_id']])) {
  873. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  874. $openList[$v['member_id']]['amount'] += $v['amount'];
  875. $openList[$v['member_id']]['lastStr'] = $lastStr;
  876. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  877. } else {
  878. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  879. $openList[$v['member_id']]['amount'] = $v['amount'];
  880. $openList[$v['member_id']]['profit'] = 0;
  881. $openList[$v['member_id']]['lastStr'] = $lastStr;
  882. $openList[$v['member_id']]['openKeywords'] = [];
  883. $openList[$v['member_id']]['keywords'] = [];
  884. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  885. $openList[$v['member_id']]['win_amount'] = 0;
  886. $openList[$v['member_id']]['is_send'] = false;
  887. }
  888. }
  889. }
  890. return ['sum' => $fakeOtherSum, 'list' => $openList, 'keywordsList' => $keywordsList];
  891. }
  892. // 开奖通知
  893. public static function lotteryNotice($openList, $issue_no, $keywordsList = [])
  894. {
  895. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  896. $betNoticeNum = explode(',', $betNoticeNum);
  897. $betNoticeMini = $betNoticeNum[0] ?? 26;
  898. $betNoticeMax = $betNoticeNum[1] ?? 38;
  899. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  900. // shuffle($openList);
  901. // Log::error('lotteryNotice openList', $openList);
  902. $lang = App::getLocale();
  903. $group_language = Config::where('field', 'group_language')->first()->val;
  904. App::setLocale($group_language);
  905. $text = "{$issue_no} " . lang("期开奖结果");
  906. $text .= "\n-----" . lang("本期开奖账单") . "----- \n";
  907. App::setLocale($lang);
  908. foreach ($openList as $k => $v) {
  909. $amount = number_format($v['amount'], 2);
  910. $v['win_amount'] = number_format($v['win_amount'], 2);
  911. $profit = number_format($v['profit'], 2);
  912. $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  913. if (empty($v['openKeywords'])) {
  914. $openKeyword = '-';
  915. } else {
  916. $openKeyword = implode(',', $v['openKeywords']);
  917. }
  918. if (($k + 1) <= $noticeNum) {
  919. $lang = App::getLocale();
  920. $group_language = Config::where('field', 'group_language')->first()->val;
  921. App::setLocale($group_language);
  922. $text .= lang("用户ID") . ":{$v['lastStr']} \n";
  923. $text .= lang("下注类型") . ":[" . implode(',', $v['keywords']) . "] \n";
  924. $text .= lang('中奖类型') . ":[" . $openKeyword . "] \n";
  925. $text .= lang('投注金额') . ":{$amount} \n";
  926. $text .= lang('中奖金额') . ":{$v['win_amount']} \n";
  927. $text .= lang('派彩金额') . ":{$profit} \n";
  928. $text .= lang("盈亏金额") . ":{$yl} \n";
  929. $text .= "-------------------------------- \n";
  930. App::setLocale($lang);
  931. }
  932. if ($v['is_send']) {
  933. $language = User::where('member_id', $v['member_id'])->first()->language;
  934. $wallet = WalletService::findOne(['member_id' => $v['member_id']]);
  935. App::setLocale($language);
  936. $text2 = lang("{issue_no}期开奖结果");
  937. $text2 = str_replace("{issue_no}", $issue_no, $text2);
  938. $text2 .= "\n";
  939. $text2 .= lang('下注类型') . ":[" . implode(',', $v['keywords']) . "] \n";
  940. $text2 .= lang('中奖类型') . ":[" . $openKeyword . "] \n";
  941. $text2 .= lang('投注金额') . ":{$amount} \n";
  942. $text2 .= lang('中奖金额') . ":{$v['win_amount']} \n";
  943. $text2 .= lang('派彩金额') . ":{$profit} \n";
  944. $text2 .= lang("盈亏金额") . ":{$yl} \n";
  945. $balance = floatval($wallet->available_balance);
  946. $text2 .= "----------------\n";
  947. $text2 .= "当前余额:{$balance} \n";
  948. $keyboard = [];
  949. $keyboard[] = [
  950. ['text' => lang("开奖历史"), 'callback_data' => "showLotteryHistory@@" . $issue_no]
  951. ];
  952. // self::sendMessage($v['member_id'],$text2,$keyboard);
  953. SendTelegramMessageJob::dispatch($v['member_id'], $text2, $keyboard);
  954. }
  955. }
  956. $inlineButton = self::getOperateButton();
  957. // 群通知
  958. $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
  959. if (($pc28Switch == 0 && is_numeric($issue_no)) || $pc28Switch == 1 && !is_numeric($issue_no)) {
  960. SendTelegramGroupMessageJob::dispatch($text, $inlineButton, '', false, '--------------------------------');
  961. }
  962. }
  963. /**
  964. * @description: 统计投注情况通知
  965. * @param {*} $issue_no
  966. * @return {*}
  967. */
  968. public static function statNotice($issue_no)
  969. {
  970. $keywordsList = [];
  971. // 虚拟投注情况
  972. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  973. foreach ($fake_bet_list as $k => $v) {
  974. if (isset($keywordsList[$v['keywords']])) {
  975. $keywordsList[$v['keywords']] += $v['amount'];
  976. } else {
  977. $keywordsList[$v['keywords']] = $v['amount'];
  978. }
  979. }
  980. // 真实投注
  981. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  982. foreach ($list->toArray() as $k => $v) {
  983. if (isset($keywordsList[$v['keywords']])) {
  984. $keywordsList[$v['keywords']] += $v['amount'];
  985. } else {
  986. $keywordsList[$v['keywords']] = $v['amount'];
  987. }
  988. }
  989. $lang = App::getLocale();
  990. $group_language = Config::where('field', 'group_language')->first()->val;
  991. App::setLocale($group_language);
  992. $text3 = "📝 {$issue_no}" . lang('期投注统计') . " \n";
  993. $text3 .= lang("玩法") . " " . lang("总投") . " \n";
  994. App::setLocale($lang);
  995. if ($keywordsList) {
  996. uksort($keywordsList, 'custom_sort');
  997. // ksort($keywordsList);
  998. foreach ($keywordsList as $k => $v) {
  999. $text3 .= "{$k} {$v} \n";
  1000. }
  1001. }
  1002. $inlineButton = self::getOperateButton();
  1003. // 投注统计的消息不发了
  1004. // SendTelegramGroupMessageJob::dispatch($text3, $inlineButton, '');
  1005. }
  1006. public static function todayExchangeRate($chatId)
  1007. {
  1008. $exchangeRate = Config::where('field', 'exchange_rate_rmb')->first()->val;
  1009. $text = lang("今日汇率") . ":1USDT = {$exchangeRate} RMB \n";
  1010. // $botMsg = [
  1011. // 'chat_id' => "@{$chatId}",
  1012. // 'text' => $text
  1013. // ];
  1014. self::sendMessage($chatId, $text);
  1015. // return $botMsg;
  1016. }
  1017. }