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