BetService.php 47 KB

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