BetService.php 47 KB

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