BetService.php 47 KB

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