BetService.php 48 KB

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