BetService.php 50 KB

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