BetService.php 49 KB

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