BetService.php 50 KB

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