BetService.php 48 KB

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