BetService.php 47 KB

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