BetService.php 49 KB

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