BetService.php 49 KB

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