BetService.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  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 randomVirtualBetting($maxPeople = 1): void
  321. {
  322. $maxPeople = intval($maxPeople);
  323. $maxPeople = max($maxPeople, 1);
  324. $maxPeople = min($maxPeople, 20);
  325. $num = rand(1, $maxPeople);
  326. for ($i = 0; $i < $num; $i++) {
  327. static::fakeBet();
  328. }
  329. }
  330. // 模拟下注
  331. private static function fakeBet()
  332. {
  333. $noRule = ['0操', '27操'];
  334. // 防止一开就虚拟投注
  335. $cache = Cache::get('new_issue_no');
  336. if ($cache) {
  337. return;
  338. }
  339. $maintenanceSwitch = Config::where('field', 'maintenance_switch')->first()->val;
  340. if ($maintenanceSwitch != 0) {
  341. return;
  342. }
  343. $betFake = Config::where('field', 'bet_fake')->first()->val;
  344. if ($betFake) {
  345. // 期数验证
  346. $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
  347. if ($pc28Switch == 1) {
  348. $issueInfo = PcIssue::where('status', PcIssue::STATUS_BETTING)->orderBy('id', 'desc')->first();
  349. } else {
  350. $issueInfo = IssueService::model()::where('status', IssueService::model()::STATUS_BETTING)->orderBy('id', 'desc')->first();
  351. }
  352. if ($issueInfo) {
  353. $betFakeRandAmount = Config::where('field', 'bet_fake_rand_amount')->first()->val;
  354. $betFakeRandAmount = explode(',', $betFakeRandAmount);
  355. $betMini = $betFakeRandAmount[0] ?? 10;
  356. $betMax = $betFakeRandAmount[1] ?? 10000;
  357. $now_date = date('Y-m-d H:i:s', time() + 38); // 提前45秒
  358. if ($issueInfo['end_time'] > $now_date) {
  359. $fake_bet_list = Cache::get('fake_bet_' . $issueInfo->issue_no, []);
  360. $gameplayRuleList = GameplayRuleService::model()::where('odds', '>', 0)->get();
  361. $gameplayRuleList = $gameplayRuleList->toArray();
  362. $member_id = self::generateRandomNumber(10);
  363. $betTimes = rand(1, 4); // 每次下注次数
  364. for ($i = 0; $i < $betTimes; $i++) {
  365. if (strtotime($issueInfo['end_time']) - strtotime($now_date) < 22) {
  366. $fake_bet_count = Cache::get("fake_bet_count_{$issueInfo->issue_no}", 0);
  367. if ($fake_bet_count >= 3) return;
  368. }
  369. $randKey = array_rand($gameplayRuleList, 1);
  370. $gameplayRuleInfo = $gameplayRuleList[$randKey] ?? [];
  371. if ($gameplayRuleInfo) {
  372. if (in_array($gameplayRuleInfo['keywords'], $noRule)) {
  373. return;
  374. }
  375. if ($gameplayRuleInfo['maxinum'] < $betMax) {
  376. $betMax = $gameplayRuleInfo['maxinum'];
  377. }
  378. if ($gameplayRuleInfo['mininum'] > $betMini) {
  379. $betMini = $gameplayRuleInfo['mininum'];
  380. }
  381. $amount = rand($betMini, $betMax);
  382. $amount = floor($amount / 10) * 10;
  383. $input = $gameplayRuleInfo['keywords'] . $amount;
  384. // $amount = number_format($amount,2);
  385. $item = [];
  386. $item['keywords'] = $gameplayRuleInfo['keywords'];
  387. $item['odds'] = $gameplayRuleInfo['odds'];
  388. $item['amount'] = $amount;
  389. $item['first_name'] = self::generateRandomString(6);
  390. $item['member_id'] = $member_id;
  391. $item['profit'] = 0;
  392. // $input = $item['keywords'] . $item['amount'];
  393. $fake_bet_list[] = $item;
  394. $lastStr = self::hideMiddleDigits($item['member_id'], 4);
  395. $groupText = "会员下注 【" . $lastStr . "】 \n";
  396. $groupText .= "下注期数:{$issueInfo->issue_no} \n";
  397. $groupText .= "下注内容: \n";
  398. $groupText .= "----------- \n";
  399. $groupText .= "{$input} \n";
  400. $groupText .= "----------- \n";
  401. if (strtotime($issueInfo['end_time']) - strtotime($now_date) < 22) {
  402. $fake_bet_count = Cache::get("fake_bet_count_{$issueInfo->issue_no}", 0);
  403. Cache::put("fake_bet_count_{$issueInfo->issue_no}", $fake_bet_count + 1, 500);
  404. }
  405. $inlineButton = self::getOperateButton();
  406. // 群通知
  407. // self::bettingGroupNotice($groupText, $inlineButton); // 群通知
  408. self::asyncBettingGroupNotice($groupText, $inlineButton); // 异步群通知
  409. }
  410. }
  411. Cache::put('fake_bet_' . $issueInfo->issue_no, $fake_bet_list, 500);
  412. }
  413. }
  414. }
  415. }
  416. /**
  417. * @description: 当期下注
  418. * @param {*} $memberId
  419. * @return {*}
  420. */
  421. public static function currentBet($memberId)
  422. {
  423. $msg['chat_id'] = $memberId;
  424. // 期数验证
  425. $issueInfo = IssueService::model()::where('status', IssueService::model()::STATUS_BETTING)->orderBy('id', 'desc')->first();
  426. $issue_no = '';
  427. if (!empty($issueInfo)) {
  428. $issue_no = $issueInfo->issue_no;
  429. } else {
  430. $issueCloseInfo = IssueService::model()::where('status', IssueService::model()::STATUS_CLOSE)->orderBy('id', 'desc')->first();
  431. if (empty($issueCloseInfo)) {
  432. $issue_no = $issueCloseInfo->issue_no;
  433. }
  434. }
  435. if ($issue_no) {
  436. $text = lang("期数") . " {$issue_no} \n";
  437. // $text .= "\n";
  438. // $text .= "----------\n";
  439. $list = self::findAll(['member_id' => $memberId, 'issue_no' => $issue_no]);
  440. $list = $list->toArray();
  441. if (empty($list)) {
  442. $text .= lang("本期暂未下注") . "! \n";
  443. } else {
  444. $keywords = implode(',', array_column($list, 'keywords'));
  445. $amounts = implode(',', array_column($list, 'amount'));
  446. $text .= lang("下注类型") . ":[" . $keywords . "] \n";
  447. $text .= lang("下注金额") . ":" . $amounts . " \n";
  448. $text .= lang("下注总额") . ":" . array_sum(array_column($list, 'amount')) . " \n";
  449. $text .= lang("开奖状态") . ":" . lang("等待开奖") . " \n";
  450. }
  451. // foreach ($list->toArray() as $k => $v) {
  452. // $text .= "{$v['keywords']}{$v['amount']} \n";
  453. // }
  454. // $text .= "\n";
  455. // $text .= "----------\n";
  456. $msg['text'] = $text;
  457. } else {
  458. $msg['text'] = lang("当前没有开放的投注期数") . "! \n";
  459. }
  460. return $msg;
  461. }
  462. /**
  463. * @description: 近期投注
  464. * @param {*} $memberId
  465. * @return {*}
  466. */
  467. public static function recentlyRecord($memberId, $page = 1, $limit = 5)
  468. {
  469. $list = self::model()::where('member_id', $memberId)->whereIn('status', [self::model()::STATUS_STAY, self::model()::STATUS_SETTLED])->orderBy('id', 'desc')->forPage($page, $limit)->get();
  470. // $text = "```\n";
  471. $text = "";
  472. $text .= "期数--内容--盈亏 \n";
  473. foreach ($list->toArray() as $k => $v) {
  474. $profit = $v['profit'] - $v['amount'];
  475. // $text .= $v['issue_no']." ".$v['keywords']." ".$v['amount']." ".$v['profit']."\n";
  476. $item = $v['issue_no'] . "==" . $v['keywords'] . rtrim(rtrim(number_format($v['amount'], 2, '.', ''), '0'), '.') . "==" . rtrim(rtrim(number_format($profit, 2, '.', ''), '0'), '.') . "\n";
  477. $text .= $item;
  478. }
  479. // $text .= "```\n";
  480. return $text;
  481. }
  482. /**
  483. * @description: 投注记录
  484. * @param {*} $memberId
  485. * @param {*} $page
  486. * @param {*} $limit
  487. * @return {*}
  488. */
  489. public static function record($memberId, $messageId = null, $page = 1, $limit = 5)
  490. {
  491. $type = Cache::get('message_id_bet_record_' . $memberId, 0);
  492. if ($type == 0) {
  493. $type = '';
  494. }
  495. $msg['chat_id'] = $memberId;
  496. $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();
  497. $count = self::model()::where('member_id', $memberId)->whereIn('status', [self::model()::STATUS_STAY, self::model()::STATUS_SETTLED])->where(self::getWhere(['is_winner' => $type]))->count();
  498. $keyboard = [];
  499. $total_amount = BalanceLogService::model()::where('member_id', $memberId)->where('change_type', '中奖')->sum('amount');
  500. $total_amount = number_format($total_amount, 2);
  501. $text = lang("历史注单") . " \n";
  502. $text .= lang("中奖总派彩") . ":{$total_amount} \n";
  503. foreach ($list as $k => $v) {
  504. if ($v->status == self::model()::STATUS_SETTLED) {
  505. $phase = $v->profit - $v->amount;
  506. } else {
  507. $phase = lang('待开奖');
  508. }
  509. $text .= "-------------------------------------\n";
  510. $text .= lang("期数") . ":{$v->issue_no} \n";
  511. $text .= lang("内容") . ":{$v->keywords} \n";
  512. $text .= lang("金额") . ":{$v->amount} \n";
  513. $text .= lang("盈亏") . ":{$phase} \n";
  514. }
  515. $msg['text'] = $text;
  516. $keyboard[] = [
  517. ['text' => lang("全部"), 'callback_data' => "betRecordType@@0"],
  518. ['text' => lang("盈利"), 'callback_data' => "betRecordType@@1"],
  519. ['text' => lang("亏损"), 'callback_data' => "betRecordType@@2"]
  520. ];
  521. if ($page > 1) {
  522. $keyboard[] = [
  523. ['text' => "👆" . lang("上一页"), 'callback_data' => "betRecordNextPage@@" . ($page - 1)]
  524. ];
  525. }
  526. $allPage = ceil($count / $limit);
  527. if ($allPage > $page) {
  528. if ($page > 1) {
  529. $keyboard[count($keyboard) - 1][] = ['text' => "👇" . lang("下一页"), 'callback_data' => "betRecordNextPage@@" . ($page + 1)];
  530. } else {
  531. $keyboard[] = [
  532. ['text' => "👇" . lang("下一页"), 'callback_data' => "betRecordNextPage@@" . ($page + 1)]
  533. ];
  534. }
  535. }
  536. if ($messageId) {
  537. $msg['message_id'] = $messageId;
  538. }
  539. if ($keyboard) {
  540. $msg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
  541. }
  542. return $msg;
  543. }
  544. /**
  545. * @description: 开奖失败退回投注的
  546. * @param {*} $issue_no
  547. * @return {*}
  548. */
  549. public static function betFail($issue_no)
  550. {
  551. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  552. foreach ($list->toArray() as $k => $v) {
  553. $profit = $v['amount'];
  554. WalletService::updateBalance($v['member_id'], $profit);
  555. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  556. $balance = $walletInfo['available_balance'];
  557. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
  558. $text = $issue_no . "期开奖失败 \n";
  559. $text .= "投注类型:{$v['keywords']} \n";
  560. $text .= "投注金额:{$v['amount']} \n";
  561. $text .= "投注的资金已退回您的钱包 \n";
  562. self::asyncSendMessage($v['member_id'], $text);
  563. $item = [];
  564. $iem['status'] = self::model()::STATUS_SETTLED;
  565. self::model()::where('id', $v['id'])->update($item);
  566. }
  567. }
  568. /**
  569. * @description: 中奖结算
  570. * @param {*} $issue_no
  571. * @param {*} $awards
  572. * @return {*}
  573. */
  574. public static function betSettled($issue_no, $awards)
  575. {
  576. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  577. // 大小单双的
  578. $otherSum = self::model()::where('issue_no', $issue_no)->where('status', self::model()::STATUS_STAY)->whereIn('keywords', ['大', '小', '单', '双'])->sum('amount');
  579. $fakeOpenData = self::fakeLotteryDraw($issue_no, $awards, 0);
  580. $keywordsList = $fakeOpenData['keywordsList'];
  581. $fakeOtherSum = $fakeOpenData['sum'];
  582. $sum = $otherSum + $fakeOtherSum;
  583. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  584. $betNoticeNum = explode(',', $betNoticeNum);
  585. $betNoticeMini = $betNoticeNum[0] ?? 26;
  586. $betNoticeMax = $betNoticeNum[1] ?? 38;
  587. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  588. $realNoticeNum = ceil($noticeNum / 2);
  589. $openList = [];
  590. $memberList = [];
  591. $bet_num = 0;
  592. foreach ($list->toArray() as $k => $v) {
  593. if (isset($keywordsList[$v['keywords']])) {
  594. $keywordsList[$v['keywords']] += $v['amount'];
  595. } else {
  596. $keywordsList[$v['keywords']] = $v['amount'];
  597. }
  598. // $userInfo = UserService::findAll(['member_id' => $v['member_id']]);
  599. // $lastStr = self::getLastChar($userInfo->first_name, 1);
  600. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  601. $item = [];
  602. $item['id'] = $v['id'];
  603. $item['status'] = self::model()::STATUS_SETTLED;
  604. if (in_array($v['keywords'], $awards)) {
  605. // $profit = $v['amount'] * $v['odds'];
  606. $amount = $v['amount'];
  607. // $amount = rtrim($amount, '0'); // 去掉右侧的 0
  608. // $amount = rtrim($amount, '.'); // 如果末尾是 . 就去掉
  609. $odds = $v['odds'];
  610. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  611. // 13 14特殊处理倍率
  612. if (in_array($v['keywords'], self::$OTHER_BET_1)) {
  613. if ($sum < 10000) {
  614. $odds = 1.5;
  615. } else {
  616. $odds = 1;
  617. }
  618. }
  619. if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  620. $odds = 1;
  621. }
  622. }
  623. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  624. if ($profit > 1000000) {
  625. $profit = 1000000; // 单注最高奖金1000000
  626. }
  627. $item['profit'] = $profit;
  628. // $yl = $profit - $amount;
  629. $yl = bcsub($profit, $amount, 2); // 盈利
  630. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  631. Rebate::updateProfit([
  632. 'member_id' => $v['member_id'],
  633. 'profit' => $yl,
  634. ]);
  635. }
  636. $memberList[$v['member_id']][] = [
  637. 'member_id' => $v['member_id'],
  638. 'keywords' => $v['keywords'],
  639. 'amount' => $v['amount'],
  640. 'profit' => $profit,
  641. 'yl' => $yl,
  642. ];
  643. // 结算
  644. WalletService::updateBalance($v['member_id'], $profit);
  645. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  646. $balance = $walletInfo['available_balance'];
  647. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
  648. if (isset($openList[$v['member_id']])) {
  649. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  650. $openList[$v['member_id']]['amount'] += $v['amount'];
  651. $openList[$v['member_id']]['profit'] += $profit;
  652. $openList[$v['member_id']]['lastStr'] = $lastStr;
  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. } else {
  657. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  658. $openList[$v['member_id']]['amount'] = $v['amount'];
  659. $openList[$v['member_id']]['profit'] = $profit;
  660. $openList[$v['member_id']]['lastStr'] = $lastStr;
  661. $openList[$v['member_id']]['openKeywords'] = [];
  662. $openList[$v['member_id']]['keywords'] = [];
  663. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  664. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  665. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  666. $openList[$v['member_id']]['is_send'] = true;
  667. }
  668. } else {
  669. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  670. Rebate::updateProfit([
  671. 'member_id' => $v['member_id'],
  672. 'profit' => ($v['amount'] * -1),
  673. ]);
  674. }
  675. $profit = 0;
  676. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  677. $amount = $v['amount'];
  678. $odds = 0;
  679. // 13 14特殊处理倍率
  680. if (in_array($v['keywords'], self::$OTHER_BET_1)) {
  681. if ($sum < 10000) {
  682. $odds = 1.5;
  683. } else {
  684. $odds = 1;
  685. }
  686. }
  687. if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  688. $odds = 1;
  689. }
  690. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  691. if ($profit > 1000000) {
  692. $profit = 1000000; // 单注最高奖金1000000
  693. }
  694. $item['profit'] = $profit;
  695. $yl = bcsub($profit, $amount, 2); // 盈利
  696. WalletService::updateBalance($v['member_id'], $profit);
  697. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  698. $balance = $walletInfo['available_balance'];
  699. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
  700. }
  701. if (isset($openList[$v['member_id']])) {
  702. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  703. $openList[$v['member_id']]['amount'] += $v['amount'];
  704. $openList[$v['member_id']]['profit'] += $profit;
  705. $openList[$v['member_id']]['lastStr'] = $lastStr;
  706. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  707. } else {
  708. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  709. $openList[$v['member_id']]['amount'] = $v['amount'];
  710. $openList[$v['member_id']]['profit'] = $profit;
  711. $openList[$v['member_id']]['lastStr'] = $lastStr;
  712. $openList[$v['member_id']]['openKeywords'] = [];
  713. $openList[$v['member_id']]['keywords'] = [];
  714. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  715. $openList[$v['member_id']]['win_amount'] = 0;
  716. $openList[$v['member_id']]['is_send'] = true;
  717. }
  718. }
  719. self::model()::where('id', $v['id'])->update($item);
  720. }
  721. $openList = array_merge($openList, $fakeOpenData['list']);
  722. self::lotteryNotice($openList, $issue_no, $keywordsList);
  723. }
  724. /**
  725. * @description: 中奖结算
  726. * @param {*} $issue_no
  727. * @param {*} $awards
  728. * @return {*}
  729. */
  730. public static function betSettled2($issue_no, $awards)
  731. {
  732. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  733. $data = [];
  734. $text = $issue_no . "期开奖结果 \n";
  735. $text .= "-----本期开奖账单----- \n";
  736. // $text .=" 中奖类型 用户 投注金额 中奖金额 盈亏 \n";
  737. $text .= "\n";
  738. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  739. $betNoticeNum = explode(',', $betNoticeNum);
  740. $betNoticeMini = $betNoticeNum[0] ?? 26;
  741. $betNoticeMax = $betNoticeNum[1] ?? 38;
  742. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  743. $realNoticeNum = ceil($noticeNum / 2);
  744. $openList = [];
  745. $bet_num = 0;
  746. foreach ($list->toArray() as $k => $v) {
  747. // $userInfo = UserService::findAll(['member_id' => $v['member_id']]);
  748. // $lastStr = self::getLastChar($userInfo->first_name, 1);
  749. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  750. $item = [];
  751. $item['id'] = $v['id'];
  752. $item['status'] = self::model()::STATUS_SETTLED;
  753. if (in_array($v['keywords'], $awards)) {
  754. // $profit = $v['amount'] * $v['odds'];
  755. $amount = $v['amount'];
  756. // $amount = rtrim($amount, '0'); // 去掉右侧的 0
  757. // $amount = rtrim($amount, '.'); // 如果末尾是 . 就去掉
  758. $odds = $v['odds'];
  759. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  760. if ($profit > 880000) {
  761. $profit = 880000; // 单注最高奖金880000
  762. }
  763. $item['profit'] = $profit;
  764. // $yl = $profit - $amount;
  765. $yl = bcsub($profit, $amount, 2); // 盈利
  766. // if ($k + 1 <= $realNoticeNum) {
  767. // // $text .= "会员下注 【" . $lastStr . "】{$v['amount']} {$profit} {$yl}\n";
  768. // $bet_num++;
  769. // }
  770. // 结算
  771. // WalletService::updateBalance($v['member_id'], $profit);
  772. // $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  773. // $balance = $walletInfo['available_balance'];
  774. // BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
  775. if (isset($openList[$v['member_id']])) {
  776. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  777. $openList[$v['member_id']]['amount'] += $v['amount'];
  778. $openList[$v['member_id']]['profit'] += $profit;
  779. $openList[$v['member_id']]['lastStr'] = $lastStr;
  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. } else {
  784. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  785. $openList[$v['member_id']]['amount'] = $v['amount'];
  786. $openList[$v['member_id']]['profit'] = $profit;
  787. $openList[$v['member_id']]['lastStr'] = $lastStr;
  788. $openList[$v['member_id']]['openKeywords'] = [];
  789. $openList[$v['member_id']]['keywords'] = [];
  790. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  791. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  792. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  793. $openList[$v['member_id']]['is_send'] = true;
  794. }
  795. } else {
  796. if (isset($openList[$v['member_id']])) {
  797. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  798. $openList[$v['member_id']]['amount'] += $v['amount'];
  799. $openList[$v['member_id']]['lastStr'] = $lastStr;
  800. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  801. } else {
  802. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  803. $openList[$v['member_id']]['amount'] = $v['amount'];
  804. $openList[$v['member_id']]['profit'] = 0;
  805. $openList[$v['member_id']]['lastStr'] = $lastStr;
  806. $openList[$v['member_id']]['openKeywords'] = [];
  807. $openList[$v['member_id']]['keywords'] = [];
  808. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  809. $openList[$v['member_id']]['win_amount'] = 0;
  810. $openList[$v['member_id']]['is_send'] = true;
  811. }
  812. // if ($k + 1 <= $realNoticeNum) {
  813. // // $text .= "会员下注 【" . $lastStr . "】{$v['amount']} {$v['profit']} -{$v['amount']}\n";
  814. // $bet_num++;
  815. // }
  816. }
  817. // self::model()::where('id', $v['id'])->update($item);
  818. }
  819. // foreach($openList as $k => $v){
  820. // $amount = $v['amount'];
  821. // // if($v['profit'] >= 0){
  822. // $profit = number_format($v['profit'],2);
  823. // $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  824. // // $text .= "会员下注 【" . $v['lastStr'] . "】 {$amount} {$profit} {$yl}\n";
  825. // if(++$bet_num <= $realNoticeNum){
  826. // $text .= "用户ID:{$v['lastStr']} \n";
  827. // $text .= "下注类型:[".implode(',', $v['keywords'])."] \n";
  828. // $text .= "中奖类型:[".implode(',', $v['openKeywords'])."] \n";
  829. // $text .= "投注金额:{$amount} \n";
  830. // $text .= "中奖金额:{$v['win_amount']} \n";
  831. // $text .= "派彩金额:{$profit} \n";
  832. // $text .= "盈亏金额:{$yl} \n";
  833. // $text .= "-------------------------------- \n";
  834. // }
  835. // $text2 = "{$issue_no}期开奖结果 \n";
  836. // $text2 .= "下注类型:[".implode(',', $v['keywords'])."] \n";
  837. // $text2 .= "中奖类型:[".implode(',', $v['openKeywords'])."] \n";
  838. // $text2 .= "投注金额:{$amount} \n";
  839. // $text2 .= "中奖金额:{$v['win_amount']} \n";
  840. // $text2 .= "派彩金额:{$profit} \n";
  841. // $text2 .= "盈亏金额:{$yl} \n";
  842. // $keyboard = [];
  843. // $keyboard[] = [
  844. // ['text' => "开奖历史", 'callback_data' => "showLotteryHistory@@" . $issue_no]
  845. // ];
  846. // // SendTelegramMessageJob::dispatch($v['member_id'],$text2);
  847. // self::sendMessage($v['member_id'],$text2,$keyboard);
  848. // // }else{
  849. // // $text .= "会员下注 【" . $v['lastStr'] . "】 {$amount} 0 -{$amount}\n";
  850. // // }
  851. // }
  852. $inlineButton = self::getOperateButton();
  853. $rand_num = $noticeNum - $bet_num;
  854. $fakeOpenData = self::fakeLotteryDraw($issue_no, $awards, $rand_num);
  855. $openList = array_merge($openList, $fakeOpenData['list']);
  856. // 群通知
  857. // self::bettingGroupNotice($text, $inlineButton, '');
  858. // SendTelegramGroupMessageJob::dispatch($text,$inlineButton,'');
  859. self::lotteryNotice($openList, $issue_no);
  860. }
  861. // 虚拟开奖
  862. public static function fakeLotteryDraw($issue_no, $awards, $rand_num = 30)
  863. {
  864. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  865. $text = "";
  866. $keywordsList = [];
  867. $fakeOtherSum = 0;
  868. $openList = [];
  869. foreach ($fake_bet_list as $k => $v) {
  870. if (in_array($v['keywords'], ['大', '小', '单', '双'])) {
  871. $fakeOtherSum += $v['amount'];
  872. }
  873. if (isset($keywordsList[$v['keywords']])) {
  874. $keywordsList[$v['keywords']] += $v['amount'];
  875. } else {
  876. $keywordsList[$v['keywords']] = $v['amount'];
  877. }
  878. // $lastStr = self::getLastChar($v['first_name'], 1);
  879. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  880. if (in_array($v['keywords'], $awards)) {
  881. $amount = $v['amount'];
  882. $odds = $v['odds'];
  883. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  884. if ($profit > 880000) {
  885. $profit = 880000; // 单注最高奖金880000
  886. }
  887. $item['profit'] = $profit;
  888. // $v['amount'] = number_format($amount,2);
  889. if (isset($openList[$v['member_id']])) {
  890. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  891. $openList[$v['member_id']]['amount'] += $v['amount'];
  892. $openList[$v['member_id']]['profit'] += $profit;
  893. $openList[$v['member_id']]['lastStr'] = $lastStr;
  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. } else {
  898. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  899. $openList[$v['member_id']]['amount'] = $v['amount'];
  900. $openList[$v['member_id']]['profit'] = $profit;
  901. $openList[$v['member_id']]['lastStr'] = $lastStr;
  902. $openList[$v['member_id']]['openKeywords'] = [];
  903. $openList[$v['member_id']]['keywords'] = [];
  904. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  905. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  906. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  907. $openList[$v['member_id']]['is_send'] = false;
  908. }
  909. } else {
  910. if (isset($openList[$v['member_id']])) {
  911. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  912. $openList[$v['member_id']]['amount'] += $v['amount'];
  913. $openList[$v['member_id']]['lastStr'] = $lastStr;
  914. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  915. } else {
  916. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  917. $openList[$v['member_id']]['amount'] = $v['amount'];
  918. $openList[$v['member_id']]['profit'] = 0;
  919. $openList[$v['member_id']]['lastStr'] = $lastStr;
  920. $openList[$v['member_id']]['openKeywords'] = [];
  921. $openList[$v['member_id']]['keywords'] = [];
  922. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  923. $openList[$v['member_id']]['win_amount'] = 0;
  924. $openList[$v['member_id']]['is_send'] = false;
  925. }
  926. }
  927. }
  928. return ['sum' => $fakeOtherSum, 'list' => $openList, 'keywordsList' => $keywordsList];
  929. }
  930. // 开奖通知
  931. public static function lotteryNotice($openList, $issue_no, $keywordsList = [])
  932. {
  933. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  934. $betNoticeNum = explode(',', $betNoticeNum);
  935. $betNoticeMini = $betNoticeNum[0] ?? 26;
  936. $betNoticeMax = $betNoticeNum[1] ?? 38;
  937. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  938. // shuffle($openList);
  939. // Log::error('lotteryNotice openList', $openList);
  940. $text = "{$issue_no}期开奖结果";
  941. $text .= "\n-----本期开奖账单----- \n";
  942. foreach ($openList as $k => $v) {
  943. $amount = number_format($v['amount'], 2);
  944. $v['win_amount'] = number_format($v['win_amount'], 2);
  945. $profit = number_format($v['profit'], 2);
  946. $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  947. if (empty($v['openKeywords'])) {
  948. $openKeyword = '-';
  949. } else {
  950. $openKeyword = implode(',', $v['openKeywords']);
  951. }
  952. if (($k + 1) <= $noticeNum) {
  953. $text .= "用户ID:{$v['lastStr']} \n";
  954. $text .= "下注类型:[" . implode(',', $v['keywords']) . "] \n";
  955. $text .= "中奖类型:[" . $openKeyword . "] \n";
  956. $text .= "投注金额:{$amount} \n";
  957. $text .= "中奖金额:{$v['win_amount']} \n";
  958. $text .= "派彩金额:{$profit} \n";
  959. $text .= "盈亏金额:{$yl} \n";
  960. $text .= "-------------------------------- \n";
  961. }
  962. if ($v['is_send']) {
  963. $language = User::where('member_id', $v['member_id'])->first()->language;
  964. App::setLocale($language);
  965. $text2 = lang("{issue_no}期开奖结果");
  966. $text2 = str_replace("{issue_no}", $issue_no, $text2);
  967. $text2 .= "\n";
  968. $text2 .= lang('下注类型') . ":[" . implode(',', $v['keywords']) . "] \n";
  969. $text2 .= lang('中奖类型') . ":[" . $openKeyword . "] \n";
  970. $text2 .= lang('投注金额') . ":{$amount} \n";
  971. $text2 .= lang('中奖金额') . ":{$v['win_amount']} \n";
  972. $text2 .= lang('派彩金额') . ":{$profit} \n";
  973. $text2 .= lang("盈亏金额") . ":{$yl} \n";
  974. $keyboard = [];
  975. $keyboard[] = [
  976. ['text' => lang("开奖历史"), 'callback_data' => "showLotteryHistory@@" . $issue_no]
  977. ];
  978. // self::sendMessage($v['member_id'],$text2,$keyboard);
  979. SendTelegramMessageJob::dispatch($v['member_id'], $text2, $keyboard);
  980. }
  981. }
  982. $inlineButton = self::getOperateButton();
  983. // 群通知
  984. // self::bettingGroupNotice($text, $inlineButton, '');
  985. // Log::error('lotteryNotice Group:'.$text);
  986. // $pos = strrpos($text, '--------------------------------');
  987. //
  988. // if ($pos !== false) {
  989. // // 使用 substr_replace 来删除最后一个 "ne"
  990. // $text = substr_replace($text, "", $pos, strlen('--------------------------------'));
  991. // }
  992. SendTelegramGroupMessageJob::dispatch($text, $inlineButton, '', false, '--------------------------------');
  993. }
  994. /**
  995. * @description: 统计投注情况通知
  996. * @param {*} $issue_no
  997. * @return {*}
  998. */
  999. public static function statNotice($issue_no)
  1000. {
  1001. $keywordsList = [];
  1002. // 虚拟投注情况
  1003. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  1004. foreach ($fake_bet_list as $k => $v) {
  1005. if (isset($keywordsList[$v['keywords']])) {
  1006. $keywordsList[$v['keywords']] += $v['amount'];
  1007. } else {
  1008. $keywordsList[$v['keywords']] = $v['amount'];
  1009. }
  1010. }
  1011. // 真实投注
  1012. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  1013. foreach ($list->toArray() as $k => $v) {
  1014. if (isset($keywordsList[$v['keywords']])) {
  1015. $keywordsList[$v['keywords']] += $v['amount'];
  1016. } else {
  1017. $keywordsList[$v['keywords']] = $v['amount'];
  1018. }
  1019. }
  1020. $text3 = "📝 {$issue_no}期投注统计 \n";
  1021. $text3 .= "玩法 总投 \n";
  1022. if ($keywordsList) {
  1023. ksort($keywordsList);
  1024. foreach ($keywordsList as $k => $v) {
  1025. $text3 .= "{$k} {$v} \n";
  1026. // $text3 .= "玩法:{$k} \n";
  1027. // $text3 .= "总注:{$v} \n";
  1028. // $text3 .= "-------------- \n";
  1029. }
  1030. }
  1031. $inlineButton = self::getOperateButton();
  1032. SendTelegramGroupMessageJob::dispatch($text3, $inlineButton, '');
  1033. }
  1034. public static function todayExchangeRate($chatId)
  1035. {
  1036. $exchangeRate = Config::where('field', 'exchange_rate_rmb')->first()->val;
  1037. $text = lang("今日汇率") . ":1USDT = {$exchangeRate} RMB \n";
  1038. // $botMsg = [
  1039. // 'chat_id' => "@{$chatId}",
  1040. // 'text' => $text
  1041. // ];
  1042. self::sendMessage($chatId, $text);
  1043. // return $botMsg;
  1044. }
  1045. }