BetService.php 47 KB

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