BetService.php 47 KB

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