BetService.php 47 KB

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