BetService.php 47 KB

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