BetService.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  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. // A couponed slip refunds only what the member paid for all its numbers, and the coupon comes back.
  679. if (!empty($v['coupon_id']) || bccomp((string) ($v['coupon_discount'] ?? 0), '0', 2) > 0) {
  680. $profit = PromotionCouponService::paid($v['total_amount'], $v['coupon_discount'] ?? 0);
  681. PromotionCouponService::release('lhc_order', (int) $v['id']);
  682. }
  683. WalletService::updateBalance($v['member_id'], $profit);
  684. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  685. $balance = $walletInfo['available_balance'];
  686. BalanceLogService::addLog($v['member_id'], $profit, ($balance - $profit), $balance, '投注退分', $v['id'], '');
  687. $text = $issue_no . "期开奖失败 \n";
  688. $text .= "投注类型:{$v['number']} \n";
  689. $text .= "投注金额:{$v['amount']} \n";
  690. $text .= "投注的资金已退回您的钱包 \n";
  691. self::asyncSendMessage($v['member_id'], $text);
  692. $item = [];
  693. $item['lottery_status'] = self::model()::STATUS_LOSS;
  694. self::model()::where('id', $v['id'])->update($item);
  695. //下注项状态更新为未中奖
  696. LhcOrderItem::where('ordernum', $v['ordernum'])->update(['lottery_status' => self::model()::STATUS_LOSS]);
  697. \App\Services\Reporting\ReportContext::lotterySettled((int) $v['id']);
  698. AdminRealtime::record('lhc_order', $v['id']);
  699. }
  700. }
  701. /**
  702. * @description: 中奖结算
  703. * @param {*} $issue_no
  704. * @param {*} $awards
  705. * @return {*}
  706. */
  707. public static function betSettled($issue_no, $awards)
  708. {
  709. $list = self::findAll(['issue' => $issue_no, 'lottery_status' => self::model()::STATUS_STAY]);
  710. // 大小单双的
  711. $otherSum = self::model()::leftJoin('lhc_order_item', 'lhc_order_item.ordernum', '=', 'lhc_order.ordernum')
  712. ->whereIn('lhc_order.type', [5, 6])
  713. ->where('lhc_order.issue', $issue_no)
  714. ->where('lhc_order.lottery_status', self::model()::STATUS_STAY)
  715. ->whereIn('lhc_order_item.number', ['大', '小', '单', '双'])
  716. ->sum('lhc_order.total_amount');
  717. $fakeOpenData = self::fakeLotteryDraw($issue_no, $awards, 0);
  718. $keywordsList = $fakeOpenData['keywordsList'];
  719. $fakeOtherSum = $fakeOpenData['sum'];
  720. $sum = $otherSum + $fakeOtherSum;
  721. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  722. $betNoticeNum = explode(',', $betNoticeNum);
  723. $betNoticeMini = max(1, (int)($betNoticeNum[0] ?? 26));
  724. $betNoticeMax = max($betNoticeMini, (int)($betNoticeNum[1] ?? 38));
  725. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  726. $openList = [];
  727. $memberList = [];
  728. foreach ($list as $k => $settlementOrder) {
  729. $v = $settlementOrder->toArray();
  730. $order_item = LhcOrderItem::where('ordernum', $v['ordernum'])->get()->toArray();
  731. $total_amount = 0;
  732. $rebateDate = EffectiveBet::newYorkDate($settlementOrder->getRawOriginal('created_at'));
  733. foreach($order_item as $value) {
  734. $number = $value['number'];
  735. // Payout uses the full stake; net result and effective bet use what the member paid after the coupon.
  736. $paid = PromotionCouponService::paid($v['amount'], $value['coupon_discount'] ?? 0);
  737. if (isset($keywordsList[$number])) {
  738. $keywordsList[$number] += $v['amount'];
  739. } else {
  740. $keywordsList[$number] = $v['amount'];
  741. }
  742. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  743. $item = [];
  744. $item['id'] = $value['id'];
  745. $item['lottery_status'] = self::model()::STATUS_LOSS;//未中奖
  746. $item['profit_and_loss'] = bcsub('0', $paid, 2);
  747. if (in_array($number, $awards)) {
  748. $amount = $v['amount'];
  749. $odds = $v['odds'];
  750. //玩 大单 小单 大双 小双 :如果开出13和14 总注小于10000 1.5赔率含本,大于等于10000退本金。
  751. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  752. // 13 14特殊处理倍率
  753. if (in_array($number, self::$OTHER_BET_2)) {
  754. if ($sum < 10000) {
  755. $odds = 1.5;
  756. } else {
  757. $odds = 1;
  758. }
  759. }
  760. }
  761. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  762. if ($profit > 1000000) {
  763. $profit = 1000000; // 单注最高奖金1000000
  764. }
  765. $item['lottery_status'] = self::model()::STATUS_WIN;//中奖
  766. $item['win_amount'] = $profit;
  767. $total_amount += $profit;
  768. $yl = bcsub($profit, $paid, 2); // 盈利
  769. $item['profit_and_loss'] = $yl;
  770. $rebate = Rebate::updateProfit([
  771. 'member_id' => $v['member_id'],
  772. 'profit' => $yl,
  773. 'date' => $rebateDate,
  774. ]);
  775. RebateService::updateEffectiveBettingAmount($rebate, EffectiveBet::amount($paid, $yl));
  776. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  777. ActivityUserService::updateBettingAmount($v['member_id'], $paid);
  778. }
  779. $memberList[$v['member_id']][] = [
  780. 'member_id' => $v['member_id'],
  781. 'keywords' => $number,
  782. 'amount' => $v['amount'],
  783. 'profit' => $profit,
  784. 'yl' => $yl,
  785. ];
  786. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  787. $balance = $walletInfo['available_balance'];
  788. WalletService::updateBalance($v['member_id'], $profit);
  789. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], "盈利:{$yl}");
  790. if (isset($openList[$v['member_id']])) {
  791. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  792. $openList[$v['member_id']]['amount'] += $v['amount'];
  793. $openList[$v['member_id']]['profit'] += $profit;
  794. $openList[$v['member_id']]['lastStr'] = $lastStr;
  795. $openList[$v['member_id']]['openKeywords'][] = $number . "({$odds}" . lang("倍率") . ")";
  796. $openList[$v['member_id']]['keywords'][] = $number;
  797. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  798. } else {
  799. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  800. $openList[$v['member_id']]['amount'] = $v['amount'];
  801. $openList[$v['member_id']]['profit'] = $profit;
  802. $openList[$v['member_id']]['lastStr'] = $lastStr;
  803. $openList[$v['member_id']]['openKeywords'] = [];
  804. $openList[$v['member_id']]['keywords'] = [];
  805. $openList[$v['member_id']]['openKeywords'][] = $number . "({$odds}" . lang("倍率") . ")";
  806. $openList[$v['member_id']]['keywords'][] = $number;
  807. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  808. $openList[$v['member_id']]['is_send'] = true;
  809. }
  810. } else {
  811. $rebate = Rebate::updateProfit([
  812. 'member_id' => $v['member_id'],
  813. 'profit' => bcsub('0', $paid, 2),
  814. 'date' => $rebateDate,
  815. ]);
  816. RebateService::updateEffectiveBettingAmount($rebate, EffectiveBet::amount($paid, bcsub('0', $paid, 2)));
  817. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  818. ActivityUserService::updateBettingAmount($v['member_id'], $paid);
  819. }
  820. // 未命中的组合不应用 13/14 特殊赔率。
  821. $profit = 0;
  822. if (isset($openList[$v['member_id']])) {
  823. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  824. $openList[$v['member_id']]['amount'] += $v['amount'];
  825. $openList[$v['member_id']]['profit'] += $profit;
  826. $openList[$v['member_id']]['lastStr'] = $lastStr;
  827. $openList[$v['member_id']]['keywords'][] = $number;
  828. } else {
  829. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  830. $openList[$v['member_id']]['amount'] = $v['amount'];
  831. $openList[$v['member_id']]['profit'] = $profit;
  832. $openList[$v['member_id']]['lastStr'] = $lastStr;
  833. $openList[$v['member_id']]['openKeywords'] = [];
  834. $openList[$v['member_id']]['keywords'] = [];
  835. $openList[$v['member_id']]['keywords'][] = $number;
  836. $openList[$v['member_id']]['win_amount'] = 0;
  837. $openList[$v['member_id']]['is_send'] = true;
  838. }
  839. }
  840. LhcOrderItem::where('id', $value['id'])->update($item);
  841. }
  842. if ($total_amount > 0) {
  843. LhcOrder::where("id", $v['id'])->update(['lottery_status' => '2', 'win_amount' => $total_amount]);
  844. } else {
  845. LhcOrder::where("id", $v['id'])->update(['lottery_status' => '1', 'win_amount' => 0]);
  846. }
  847. \App\Services\Reporting\ReportContext::lotterySettled((int) $v['id']);
  848. AdminRealtime::record('lhc_order', $v['id']);
  849. }
  850. $openList = array_merge($openList, $fakeOpenData['list']);
  851. self::lotteryNotice($openList, $issue_no, $keywordsList);
  852. }
  853. // 虚拟开奖
  854. public static function fakeLotteryDraw($issue_no, $awards, $rand_num = 30)
  855. {
  856. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  857. $text = "";
  858. $keywordsList = [];
  859. $fakeOtherSum = 0;
  860. $openList = [];
  861. foreach ($fake_bet_list as $k => $v) {
  862. if (in_array($v['keywords'], ['大', '小', '单', '双'])) {
  863. $fakeOtherSum += $v['amount'];
  864. }
  865. if (isset($keywordsList[$v['keywords']])) {
  866. $keywordsList[$v['keywords']] += $v['amount'];
  867. } else {
  868. $keywordsList[$v['keywords']] = $v['amount'];
  869. }
  870. // $lastStr = self::getLastChar($v['first_name'], 1);
  871. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  872. if (in_array($v['keywords'], $awards)) {
  873. $amount = $v['amount'];
  874. $odds = $v['odds'];
  875. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  876. if ($profit > 880000) {
  877. $profit = 880000; // 单注最高奖金880000
  878. }
  879. $item['profit'] = $profit;
  880. // $v['amount'] = number_format($amount,2);
  881. if (isset($openList[$v['member_id']])) {
  882. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  883. $openList[$v['member_id']]['amount'] += $v['amount'];
  884. $openList[$v['member_id']]['profit'] += $profit;
  885. $openList[$v['member_id']]['lastStr'] = $lastStr;
  886. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  887. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  888. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  889. } else {
  890. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  891. $openList[$v['member_id']]['amount'] = $v['amount'];
  892. $openList[$v['member_id']]['profit'] = $profit;
  893. $openList[$v['member_id']]['lastStr'] = $lastStr;
  894. $openList[$v['member_id']]['openKeywords'] = [];
  895. $openList[$v['member_id']]['keywords'] = [];
  896. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'] . "({$odds}" . lang("倍率") . ")";
  897. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  898. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  899. $openList[$v['member_id']]['is_send'] = false;
  900. }
  901. } else {
  902. if (isset($openList[$v['member_id']])) {
  903. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  904. $openList[$v['member_id']]['amount'] += $v['amount'];
  905. $openList[$v['member_id']]['lastStr'] = $lastStr;
  906. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  907. } else {
  908. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  909. $openList[$v['member_id']]['amount'] = $v['amount'];
  910. $openList[$v['member_id']]['profit'] = 0;
  911. $openList[$v['member_id']]['lastStr'] = $lastStr;
  912. $openList[$v['member_id']]['openKeywords'] = [];
  913. $openList[$v['member_id']]['keywords'] = [];
  914. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  915. $openList[$v['member_id']]['win_amount'] = 0;
  916. $openList[$v['member_id']]['is_send'] = false;
  917. }
  918. }
  919. }
  920. return ['sum' => $fakeOtherSum, 'list' => $openList, 'keywordsList' => $keywordsList];
  921. }
  922. // 开奖通知
  923. public static function lotteryNotice($openList, $issue_no, $keywordsList = [])
  924. {
  925. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  926. $betNoticeNum = explode(',', $betNoticeNum);
  927. $betNoticeMini = max(1, (int)($betNoticeNum[0] ?? 26));
  928. $betNoticeMax = max($betNoticeMini, (int)($betNoticeNum[1] ?? 38));
  929. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  930. // shuffle($openList);
  931. // Log::error('lotteryNotice openList', $openList);
  932. $lang = App::getLocale();
  933. $group_language = Config::where('field', 'group_language')->first()->val;
  934. App::setLocale($group_language);
  935. $text = "{$issue_no} " . lang("期开奖结果");
  936. $text .= "\n-----" . lang("本期开奖账单") . "----- \n";
  937. App::setLocale($lang);
  938. $noticeIndex = 0;
  939. $noticeRows = 0;
  940. foreach ($openList as $v) {
  941. $noticeIndex++;
  942. $amount = number_format($v['amount'], 2);
  943. $v['win_amount'] = number_format($v['win_amount'], 2);
  944. $profit = number_format($v['profit'], 2);
  945. $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  946. if (empty($v['openKeywords'])) {
  947. $openKeyword = '-';
  948. } else {
  949. $openKeyword = implode(',', $v['openKeywords']);
  950. }
  951. if ($noticeIndex <= $noticeNum) {
  952. $noticeRows++;
  953. $lang = App::getLocale();
  954. $group_language = Config::where('field', 'group_language')->first()->val;
  955. App::setLocale($group_language);
  956. $text .= lang("用户ID") . ":{$v['lastStr']} \n";
  957. $text .= lang("下注类型") . ":[" . implode(',', $v['keywords']) . "] \n";
  958. $text .= lang('中奖类型') . ":[" . $openKeyword . "] \n";
  959. $text .= lang('投注金额') . ":{$amount} \n";
  960. $text .= lang('中奖金额') . ":{$v['win_amount']} \n";
  961. $text .= lang('派彩金额') . ":{$profit} \n";
  962. $text .= lang("盈亏金额") . ":{$yl} \n";
  963. $text .= "-------------------------------- \n";
  964. App::setLocale($lang);
  965. }
  966. //根据环境变量配置是否发送电报
  967. if ($v['is_send'] && env('SEND_TELEGRAM')) {
  968. $language = User::where('member_id', $v['member_id'])->first()->language;
  969. $wallet = WalletService::findOne(['member_id' => $v['member_id']]);
  970. App::setLocale($language);
  971. $text2 = lang("{issue_no}期开奖结果");
  972. $text2 = str_replace("{issue_no}", $issue_no, $text2);
  973. $text2 .= "\n";
  974. $text2 .= lang('下注类型') . ":[" . implode(',', $v['keywords']) . "] \n";
  975. $text2 .= lang('中奖类型') . ":[" . $openKeyword . "] \n";
  976. $text2 .= lang('投注金额') . ":{$amount} \n";
  977. $text2 .= lang('中奖金额') . ":{$v['win_amount']} \n";
  978. $text2 .= lang('派彩金额') . ":{$profit} \n";
  979. $text2 .= lang("盈亏金额") . ":{$yl} \n";
  980. $balance = floatval($wallet->available_balance);
  981. $text2 .= "----------------\n";
  982. $text2 .= "当前余额:{$balance} \n";
  983. $keyboard = [];
  984. $keyboard[] = [
  985. ['text' => lang("开奖历史"), 'callback_data' => "showLotteryHistory@@" . $issue_no]
  986. ];
  987. // self::sendMessage($v['member_id'],$text2,$keyboard);
  988. SendTelegramMessageJob::dispatch($v['member_id'], $text2, $keyboard)->afterCommit();
  989. }
  990. }
  991. $inlineButton = self::getOperateButton();
  992. //根据环境变量配置是否发送电报
  993. if (env('SEND_TELEGRAM')) {
  994. // 群通知
  995. $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
  996. if (($pc28Switch == 0 && is_numeric($issue_no)) || $pc28Switch == 1 && !is_numeric($issue_no)) {
  997. Log::channel('issue')->info('结算列表群通知入队', [
  998. 'issue_no' => $issue_no,
  999. 'pc28_switch' => $pc28Switch,
  1000. 'text_length' => strlen($text),
  1001. 'open_list_count' => count($openList),
  1002. 'notice_num' => $noticeNum,
  1003. 'notice_rows' => $noticeRows,
  1004. ]);
  1005. SendTelegramGroupMessageJob::dispatch($text, $inlineButton, '', false, '--------------------------------', [
  1006. 'message_type' => 'settlement_list',
  1007. 'issue_no' => $issue_no,
  1008. 'open_list_count' => count($openList),
  1009. 'notice_rows' => $noticeRows,
  1010. ])->afterCommit();
  1011. } else {
  1012. Log::channel('issue')->info('结算列表群通知跳过', [
  1013. 'issue_no' => $issue_no,
  1014. 'pc28_switch' => $pc28Switch,
  1015. 'reason' => 'pc28_switch_not_match_issue_type',
  1016. ]);
  1017. }
  1018. } else {
  1019. Log::channel('issue')->info('结算列表群通知跳过', [
  1020. 'issue_no' => $issue_no,
  1021. 'reason' => 'send_telegram_disabled',
  1022. ]);
  1023. }
  1024. }
  1025. /**
  1026. * @description: 统计投注情况通知
  1027. * @param {*} $issue_no
  1028. * @return {*}
  1029. */
  1030. public static function statNotice($issue_no)
  1031. {
  1032. $keywordsList = [];
  1033. // 虚拟投注情况
  1034. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  1035. foreach ($fake_bet_list as $k => $v) {
  1036. if (isset($keywordsList[$v['keywords']])) {
  1037. $keywordsList[$v['keywords']] += $v['amount'];
  1038. } else {
  1039. $keywordsList[$v['keywords']] = $v['amount'];
  1040. }
  1041. }
  1042. // 真实投注
  1043. $list = self::findAll(['issue_no' => $issue_no]);
  1044. foreach ($list->toArray() as $k => $v) {
  1045. if (isset($keywordsList[$v['keywords']])) {
  1046. $keywordsList[$v['keywords']] += $v['amount'];
  1047. } else {
  1048. $keywordsList[$v['keywords']] = $v['amount'];
  1049. }
  1050. }
  1051. $lang = App::getLocale();
  1052. $group_language = Config::where('field', 'group_language')->first()->val;
  1053. App::setLocale($group_language);
  1054. $text3 = "📝 {$issue_no}" . lang('期投注统计') . " \n";
  1055. $text3 .= lang("玩法") . " " . lang("总投") . " \n";
  1056. App::setLocale($lang);
  1057. if ($keywordsList) {
  1058. uksort($keywordsList, 'custom_sort');
  1059. // ksort($keywordsList);
  1060. foreach ($keywordsList as $k => $v) {
  1061. $text3 .= "{$k} {$v} \n";
  1062. }
  1063. }
  1064. $inlineButton = self::getOperateButton();
  1065. // 投注统计的消息不发了
  1066. // SendTelegramGroupMessageJob::dispatch($text3, $inlineButton, '');
  1067. }
  1068. public static function todayExchangeRate($chatId)
  1069. {
  1070. $exchangeRate = Config::where('field', 'exchange_rate_rmb')->first()->val;
  1071. $text = lang("今日汇率") . ":1USDT = {$exchangeRate} RMB \n";
  1072. // $botMsg = [
  1073. // 'chat_id' => "@{$chatId}",
  1074. // 'text' => $text
  1075. // ];
  1076. self::sendMessage($chatId, $text);
  1077. // return $botMsg;
  1078. }
  1079. }