BetService.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  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. // 下注项存于 lhc_order_item;相同下注只合并到本机器人建的单项、无优惠券、未开奖的订单
  373. $betInfo = LhcOrder::where('type', $type)
  374. ->where('member_id', $memberId)
  375. ->where('issue', $issueInfo->issue_no)
  376. ->where('lottery_status', LhcOrder::STATUS_STAY)
  377. ->whereNull('coupon_id')
  378. ->whereColumn('total_amount', 'amount')
  379. ->whereIn('ordernum', LhcOrderItem::where('member_id', $memberId)->where('number', $keywords)->select('ordernum'))
  380. ->lockForUpdate()
  381. ->first(); // 相同下注
  382. if ($betInfo) {
  383. $betInfo->amount = bcadd($betInfo->amount, $amount, 2);
  384. $betInfo->total_amount = $betInfo->amount;
  385. $betInfo->save();
  386. $bet_id = $betInfo->id;
  387. } else {
  388. $ordernum = date('YmdHis') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  389. LhcOrderItem::create([
  390. 'ordernum' => $ordernum,
  391. 'member_id' => $memberId,
  392. 'number' => $keywords, // 玩法
  393. ]);
  394. $newBet = LhcOrder::create([
  395. 'type' => $type,
  396. 'issue' => $issueInfo->issue_no,
  397. 'ordernum' => $ordernum,
  398. 'member_id' => $memberId,
  399. 'odds' => $gameplayRuleInfo['odds'],
  400. 'amount' => $amount, // 分数
  401. 'total_amount' => $amount,
  402. ]);
  403. $bet_id = $newBet->id;
  404. }
  405. WalletService::updateBalance($memberId, -$amount);
  406. BalanceLogService::addLog($memberId, -$amount, $balance, ($balance - $amount), '投注', $bet_id, '');
  407. $odds = floatval($gameplayRuleInfo['odds']);
  408. $issueNo = $issueInfo->issue_no;
  409. $text .= "{$keywords} {$amount} ({$odds}" . lang('倍率') . ")";
  410. $lastStr = self::hideMiddleDigits($userInfo->member_id, 4);
  411. $lang = App::getLocale();
  412. $group_language = Config::where('field', 'group_language')->first()->val;
  413. App::setLocale($group_language);
  414. if ($index === 0) {
  415. $groupText .= lang("第") . "{$issueNo}" . lang("期") . "\n";
  416. $groupText .= lang("开奖时间") . ":" . date("H:i:s", strtotime($issueInfo['end_time'])) . "\n";
  417. $groupText .= lang('投注截止') . ":" . date("H:i:s", (strtotime($issueInfo['end_time'])) - 30) . "\n";;
  418. $groupText .= lang("成功") . "\n";
  419. $groupText .= lang('玩家') . ": 【{$lastStr}】 \n";
  420. }
  421. $groupText .= "{$keywords} {$amount} ({$odds}" . lang("倍率") . ") \n";
  422. App::setLocale($lang);
  423. return true;
  424. }
  425. //随机虚拟下注
  426. public static function randomVirtualBetting($maxPeople = 1): void
  427. {
  428. $maxPeople = intval($maxPeople);
  429. $maxPeople = max($maxPeople, 1);
  430. $maxPeople = min($maxPeople, 20);
  431. $num = rand(1, $maxPeople);
  432. for ($i = 0; $i < $num; $i++) {
  433. static::fakeBet(4);
  434. }
  435. }
  436. // 模拟下注
  437. private static function fakeBet($betNumber = 1): void
  438. {
  439. $noRule = ['0操', '27操'];
  440. // 防止一开就虚拟投注
  441. $cache = Cache::get('new_issue_no');
  442. if ($cache) {
  443. echo "防止一开就虚拟投注\n";
  444. return;
  445. }
  446. //系统维护
  447. $maintenanceSwitch = Config::where('field', 'maintenance_switch')->first()->val;
  448. if ($maintenanceSwitch != 0) {
  449. echo "系统维护中\n";
  450. return;
  451. }
  452. //后台是否开启虚拟投注
  453. $betFake = Config::where('field', 'bet_fake')->first()->val;
  454. if ($betFake != 1) {
  455. echo "未开启虚拟投注\n";
  456. return;
  457. }
  458. // 期数验证
  459. $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
  460. if ($pc28Switch == 1) {
  461. $issueInfo = PcIssue::where('status', PcIssue::STATUS_BETTING)->orderBy('id', 'desc')->first();
  462. } else {
  463. $issueInfo = IssueService::model()::where('status', IssueService::model()::STATUS_BETTING)->orderBy('id', 'desc')->first();
  464. }
  465. if ($issueInfo) {
  466. $betFakeRandAmount = Config::where('field', 'bet_fake_rand_amount')->first()->val;
  467. $betFakeRandAmount = explode(',', $betFakeRandAmount);
  468. $betMini = $betFakeRandAmount[0] ?? 10;
  469. $betMax = $betFakeRandAmount[1] ?? 10000;
  470. $now_date = date('Y-m-d H:i:s', time() + 38); // 提前45秒
  471. if ($issueInfo['end_time'] > $now_date) {
  472. $fake_bet_list = Cache::get('fake_bet_' . $issueInfo->issue_no, []);
  473. $gameplayRuleList = GameplayRuleService::model()::where('odds', '>', 0)->get();
  474. $gameplayRuleList = $gameplayRuleList->toArray();
  475. $member_id = self::generateRandomNumber(10);
  476. $betTimes = rand(1, $betNumber); // 每次下注次数
  477. Cache::add("封盘后下注单数_{$issueInfo->issue_no}", rand(3, 5), 4);
  478. $lastStr = self::hideMiddleDigits($member_id, 4);
  479. $lang = App::getLocale();
  480. $group_language = Config::where('field', 'group_language')->first()->val;
  481. $first_name = self::generateRandomString(6);
  482. App::setLocale($group_language);
  483. $groupText = lang("第") . "{$issueInfo->issue_no}" . lang("期") . "\n";
  484. $groupText .= lang("开奖时间") . ":" . date("H:i:s", strtotime($issueInfo['end_time'])) . "\n";
  485. $groupText .= lang('投注截止') . ":" . date("H:i:s", (strtotime($issueInfo['end_time'])) - 30) . "\n";;
  486. $groupText .= lang("成功") . "\n";
  487. $groupText .= lang('玩家') . ": 【{$lastStr}】 \n";
  488. App::setLocale($lang);
  489. $haveBet = false;
  490. for ($i = 0; $i < $betTimes; $i++) {
  491. if (strtotime($issueInfo['end_time']) - time() < IssueService::COUNTDOWN_TO_CLOSING_THE_MARKET) {
  492. $fake_bet_count = Cache::get("fake_bet_count_{$issueInfo->issue_no}", 0);
  493. $cc = Cache::get("封盘后下注单数_{$issueInfo->issue_no}");
  494. if ($fake_bet_count >= $cc) return;
  495. }
  496. $randKey = array_rand($gameplayRuleList, 1);
  497. $gameplayRuleInfo = $gameplayRuleList[$randKey] ?? [];
  498. if ($gameplayRuleInfo) {
  499. if (in_array($gameplayRuleInfo['keywords'], $noRule)) {
  500. return;
  501. }
  502. if ($gameplayRuleInfo['maxinum'] < $betMax) {
  503. $betMax = $gameplayRuleInfo['maxinum'];
  504. }
  505. if ($gameplayRuleInfo['mininum'] > $betMini) {
  506. $betMini = $gameplayRuleInfo['mininum'];
  507. }
  508. $amount = rand($betMini, $betMax);
  509. $amount = floor($amount / 10) * 10;
  510. $input = $gameplayRuleInfo['keywords'] . ' ' . $amount;
  511. // $amount = number_format($amount,2);
  512. $item = [];
  513. $item['keywords'] = $gameplayRuleInfo['keywords'];
  514. $item['odds'] = floatval($gameplayRuleInfo['odds']);
  515. $item['amount'] = $amount;
  516. $item['first_name'] = $first_name;
  517. $item['member_id'] = $member_id;
  518. $item['profit'] = 0;
  519. // $input = $item['keywords'] . $item['amount'];
  520. $fake_bet_list[] = $item;
  521. $lang = App::getLocale();
  522. $group_language = Config::where('field', 'group_language')->first()->val;
  523. $first_name = self::generateRandomString(6);
  524. App::setLocale($group_language);
  525. $groupText .= "{$input} (" . $item['odds'] . lang("倍率") . ") \n";
  526. $haveBet = true;
  527. App::setLocale($lang);
  528. if (strtotime($issueInfo['end_time']) - strtotime($now_date) < 22) {
  529. $fake_bet_count = Cache::get("fake_bet_count_{$issueInfo->issue_no}", 0);
  530. Cache::put("fake_bet_count_{$issueInfo->issue_no}", $fake_bet_count + 1, 500);
  531. }
  532. }
  533. }
  534. if ($haveBet) {
  535. $groupText .= "\n-------- \n";
  536. $inlineButton = self::getOperateButton();
  537. // 群通知 暂停2秒再发送,避免同时发送多个消息而超过 Telegram 的频率限制
  538. self::asyncBettingGroupNotice($groupText, $inlineButton); // 异步群通知
  539. sleep(2);
  540. }
  541. Cache::put('fake_bet_' . $issueInfo->issue_no, $fake_bet_list, 500);
  542. }
  543. }
  544. }
  545. /**
  546. * @description: 当期下注
  547. * @param {*} $memberId
  548. * @return {*}
  549. */
  550. public static function currentBet($memberId)
  551. {
  552. $msg['chat_id'] = $memberId;
  553. // 期数验证
  554. $issueInfo = IssueService::model()::where('status', IssueService::model()::STATUS_BETTING)->orderBy('id', 'desc')->first();
  555. $issue_no = '';
  556. if (!empty($issueInfo)) {
  557. $issue_no = $issueInfo->issue_no;
  558. } else {
  559. $issueCloseInfo = IssueService::model()::where('status', IssueService::model()::STATUS_CLOSE)->orderBy('id', 'desc')->first();
  560. if (empty($issueCloseInfo)) {
  561. $issue_no = $issueCloseInfo->issue_no;
  562. }
  563. }
  564. if ($issue_no) {
  565. $text = lang("期数") . " {$issue_no} \n";
  566. // $text .= "\n";
  567. // $text .= "----------\n";
  568. $list = self::model()::with('items')->whereIn('type', [5, 6])->where('member_id', $memberId)->where('issue', $issue_no)->get();
  569. $list = $list->map(fn ($v) => ['number' => $v->items->pluck('number')->implode(','), 'amount' => $v->amount])->toArray();
  570. if (empty($list)) {
  571. $text .= lang("本期暂未下注") . "! \n";
  572. } else {
  573. $keywords = implode(',', array_column($list, 'number'));
  574. $amounts = implode(',', array_column($list, 'amount'));
  575. $text .= lang("下注类型") . ":[" . $keywords . "] \n";
  576. $text .= lang("下注金额") . ":" . $amounts . " \n";
  577. $text .= lang("下注总额") . ":" . array_sum(array_column($list, 'amount')) . " \n";
  578. $text .= lang("开奖状态") . ":" . lang("等待开奖") . " \n";
  579. }
  580. // foreach ($list->toArray() as $k => $v) {
  581. // $text .= "{$v['keywords']}{$v['amount']} \n";
  582. // }
  583. // $text .= "\n";
  584. // $text .= "----------\n";
  585. $msg['text'] = $text;
  586. } else {
  587. $msg['text'] = lang("当前没有开放的投注期数") . "! \n";
  588. }
  589. return $msg;
  590. }
  591. /**
  592. * @description: 近期投注
  593. * @param {*} $memberId
  594. * @return {*}
  595. */
  596. public static function recentlyRecord($memberId, $page = 1, $limit = 5)
  597. {
  598. $list = self::model()::with('items')->whereIn('type', [5, 6])->where('member_id', $memberId)->orderBy('id', 'desc')->forPage($page, $limit)->get();
  599. // $text = "```\n";
  600. $text = "";
  601. $text .= "期数--内容--盈亏 \n";
  602. foreach ($list as $k => $v) {
  603. $v = $v->toArray() + ['number' => $v->items->pluck('number')->implode(',')];
  604. $profit = $v['win_amount'] - $v['amount'];
  605. // $text .= $v['issue_no']." ".$v['keywords']." ".$v['amount']." ".$v['profit']."\n";
  606. $item = $v['issue'] . "==" . $v['number'] . rtrim(rtrim(number_format($v['amount'], 2, '.', ''), '0'), '.') . "==" . rtrim(rtrim(number_format($profit, 2, '.', ''), '0'), '.') . "\n";
  607. $text .= $item;
  608. }
  609. // $text .= "```\n";
  610. return $text;
  611. }
  612. /**
  613. * @description: 投注记录
  614. * @param {*} $memberId
  615. * @param {*} $page
  616. * @param {*} $limit
  617. * @return {*}
  618. */
  619. public static function record($memberId, $messageId = null, $page = 1, $limit = 5)
  620. {
  621. $type = Cache::get('message_id_bet_record_' . $memberId, 0);
  622. if ($type == 0) {
  623. $type = '';
  624. }
  625. $msg['chat_id'] = $memberId;
  626. $list = self::model()::with('items')->whereIn('type', [5, 6])->where('member_id', $memberId)->orderBy('id', 'desc')->forPage($page, $limit)->get();
  627. $count = self::model()::whereIn('type', [5, 6])->where('member_id', $memberId)->count();
  628. $keyboard = [];
  629. $total_amount = BalanceLogService::model()::where('member_id', $memberId)->where('change_type', '中奖')->sum('amount');
  630. $total_amount = number_format($total_amount, 2);
  631. $text = lang("历史注单") . " \n";
  632. $text .= lang("中奖总派彩") . ":{$total_amount} \n";
  633. foreach ($list as $k => $v) {
  634. if ($v->lottery_status == self::model()::STATUS_WIN || $v->lottery_status == self::model()::STATUS_LOSS) {
  635. $phase = $v->win_amount - $v->amount;
  636. } else {
  637. $phase = lang('待开奖');
  638. }
  639. $text .= "-------------------------------------\n";
  640. $text .= lang("期数") . ":{$v->issue} \n";
  641. $text .= lang("内容") . ":" . $v->items->pluck('number')->implode(',') . " \n";
  642. $text .= lang("金额") . ":{$v->amount} \n";
  643. $text .= lang("盈亏") . ":{$phase} \n";
  644. }
  645. $msg['text'] = $text;
  646. $keyboard[] = [
  647. ['text' => lang("全部"), 'callback_data' => "betRecordType@@0"],
  648. ['text' => lang("盈利"), 'callback_data' => "betRecordType@@1"],
  649. ['text' => lang("亏损"), 'callback_data' => "betRecordType@@2"]
  650. ];
  651. if ($page > 1) {
  652. $keyboard[] = [
  653. ['text' => "👆" . lang("上一页"), 'callback_data' => "betRecordNextPage@@" . ($page - 1)]
  654. ];
  655. }
  656. $allPage = ceil($count / $limit);
  657. if ($allPage > $page) {
  658. if ($page > 1) {
  659. $keyboard[count($keyboard) - 1][] = ['text' => "👇" . lang("下一页"), 'callback_data' => "betRecordNextPage@@" . ($page + 1)];
  660. } else {
  661. $keyboard[] = [
  662. ['text' => "👇" . lang("下一页"), 'callback_data' => "betRecordNextPage@@" . ($page + 1)]
  663. ];
  664. }
  665. }
  666. if ($messageId) {
  667. $msg['message_id'] = $messageId;
  668. }
  669. if ($keyboard) {
  670. $msg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
  671. }
  672. return $msg;
  673. }
  674. /**
  675. * @description: 开奖失败退回投注的
  676. * @param {*} $issue_no
  677. * @return {*}
  678. */
  679. public static function betFail($issue_no)
  680. {
  681. $list = self::findAll(['issue' => $issue_no, 'lottery_status' => self::model()::STATUS_STAY]);
  682. foreach ($list->toArray() as $k => $v) {
  683. $profit = $v['amount'];
  684. // A couponed slip refunds only what the member paid for all its numbers, and the coupon comes back.
  685. if (!empty($v['coupon_id']) || bccomp((string) ($v['coupon_discount'] ?? 0), '0', 2) > 0) {
  686. $profit = PromotionCouponService::paid($v['total_amount'], $v['coupon_discount'] ?? 0);
  687. PromotionCouponService::release('lhc_order', (int) $v['id']);
  688. }
  689. WalletService::updateBalance($v['member_id'], $profit);
  690. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  691. $balance = $walletInfo['available_balance'];
  692. BalanceLogService::addLog($v['member_id'], $profit, ($balance - $profit), $balance, '投注退分', $v['id'], '');
  693. $text = $issue_no . "期开奖失败 \n";
  694. $text .= "投注类型:" . LhcOrderItem::where('ordernum', $v['ordernum'])->pluck('number')->implode(',') . " \n";
  695. $text .= "投注金额:{$v['amount']} \n";
  696. $text .= "投注的资金已退回您的钱包 \n";
  697. self::asyncSendMessage($v['member_id'], $text);
  698. $item = [];
  699. $item['lottery_status'] = self::model()::STATUS_LOSS;
  700. self::model()::where('id', $v['id'])->update($item);
  701. //下注项状态更新为未中奖
  702. LhcOrderItem::where('ordernum', $v['ordernum'])->update(['lottery_status' => self::model()::STATUS_LOSS]);
  703. \App\Services\Reporting\ReportContext::lotterySettled((int) $v['id']);
  704. AdminRealtime::record('lhc_order', $v['id']);
  705. }
  706. }
  707. /**
  708. * @description: 中奖结算
  709. * @param {*} $issue_no
  710. * @param {*} $awards
  711. * @return {*}
  712. */
  713. public static function betSettled($issue_no, $awards)
  714. {
  715. $list = self::findAll(['issue' => $issue_no, 'lottery_status' => self::model()::STATUS_STAY]);
  716. // 大小单双的
  717. $otherSum = self::model()::leftJoin('lhc_order_item', 'lhc_order_item.ordernum', '=', 'lhc_order.ordernum')
  718. ->whereIn('lhc_order.type', [5, 6])
  719. ->where('lhc_order.issue', $issue_no)
  720. ->where('lhc_order.lottery_status', self::model()::STATUS_STAY)
  721. ->whereIn('lhc_order_item.number', ['大', '小', '单', '双'])
  722. ->sum('lhc_order.total_amount');
  723. $fakeOpenData = self::fakeLotteryDraw($issue_no, $awards, 0);
  724. $keywordsList = $fakeOpenData['keywordsList'];
  725. $fakeOtherSum = $fakeOpenData['sum'];
  726. $sum = $otherSum + $fakeOtherSum;
  727. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  728. $betNoticeNum = explode(',', $betNoticeNum);
  729. $betNoticeMini = max(1, (int)($betNoticeNum[0] ?? 26));
  730. $betNoticeMax = max($betNoticeMini, (int)($betNoticeNum[1] ?? 38));
  731. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  732. $openList = [];
  733. $memberList = [];
  734. foreach ($list as $k => $settlementOrder) {
  735. $v = $settlementOrder->toArray();
  736. $order_item = LhcOrderItem::where('ordernum', $v['ordernum'])->get()->toArray();
  737. $total_amount = 0;
  738. foreach($order_item as $value) {
  739. $number = $value['number'];
  740. // Payout uses the full stake; net result and effective bet use what the member paid after the coupon.
  741. $paid = PromotionCouponService::paid($v['amount'], $value['coupon_discount'] ?? 0);
  742. if (isset($keywordsList[$number])) {
  743. $keywordsList[$number] += $v['amount'];
  744. } else {
  745. $keywordsList[$number] = $v['amount'];
  746. }
  747. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  748. $item = [];
  749. $item['id'] = $value['id'];
  750. $item['lottery_status'] = self::model()::STATUS_LOSS;//未中奖
  751. $item['profit_and_loss'] = bcsub('0', $paid, 2);
  752. if (in_array($number, $awards)) {
  753. $amount = $v['amount'];
  754. $odds = $v['odds'];
  755. //玩 大单 小单 大双 小双 :如果开出13和14 总注小于10000 1.5赔率含本,大于等于10000退本金。
  756. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  757. // 13 14特殊处理倍率
  758. if (in_array($number, self::$OTHER_BET_2)) {
  759. if ($sum < 10000) {
  760. $odds = 1.5;
  761. } else {
  762. $odds = 1;
  763. }
  764. }
  765. }
  766. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  767. if ($profit > 1000000) {
  768. $profit = 1000000; // 单注最高奖金1000000
  769. }
  770. $item['lottery_status'] = self::model()::STATUS_WIN;//中奖
  771. $item['win_amount'] = $profit;
  772. $total_amount += $profit;
  773. $yl = bcsub($profit, $paid, 2); // 盈利
  774. $item['profit_and_loss'] = $yl;
  775. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  776. ActivityUserService::updateBettingAmount($v['member_id'], $paid);
  777. }
  778. $memberList[$v['member_id']][] = [
  779. 'member_id' => $v['member_id'],
  780. 'keywords' => $number,
  781. 'amount' => $v['amount'],
  782. 'profit' => $profit,
  783. 'yl' => $yl,
  784. ];
  785. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  786. $balance = $walletInfo['available_balance'];
  787. WalletService::updateBalance($v['member_id'], $profit);
  788. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], "盈利:{$yl}");
  789. if (isset($openList[$v['member_id']])) {
  790. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  791. $openList[$v['member_id']]['amount'] += $v['amount'];
  792. $openList[$v['member_id']]['profit'] += $profit;
  793. $openList[$v['member_id']]['lastStr'] = $lastStr;
  794. $openList[$v['member_id']]['openKeywords'][] = $number . "({$odds}" . lang("倍率") . ")";
  795. $openList[$v['member_id']]['keywords'][] = $number;
  796. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  797. } else {
  798. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  799. $openList[$v['member_id']]['amount'] = $v['amount'];
  800. $openList[$v['member_id']]['profit'] = $profit;
  801. $openList[$v['member_id']]['lastStr'] = $lastStr;
  802. $openList[$v['member_id']]['openKeywords'] = [];
  803. $openList[$v['member_id']]['keywords'] = [];
  804. $openList[$v['member_id']]['openKeywords'][] = $number . "({$odds}" . lang("倍率") . ")";
  805. $openList[$v['member_id']]['keywords'][] = $number;
  806. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  807. $openList[$v['member_id']]['is_send'] = true;
  808. }
  809. } else {
  810. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  811. ActivityUserService::updateBettingAmount($v['member_id'], $paid);
  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'] && config('services.telegram.send_enabled', false)) {
  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 (config('services.telegram.send_enabled', false)) {
  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. }