BetService.php 49 KB

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