BetService.php 46 KB

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