BetService.php 48 KB

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