BetService.php 48 KB

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