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