BetService.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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 > 1000000) {
  601. $profit = 1000000; // 单注最高奖金1000000
  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. $profit = 0;
  656. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  657. $amount = $v['amount'];
  658. $odds = 0;
  659. // 13 14特殊处理倍率
  660. if (in_array($v['keywords'], self::$OTHER_BET_1)) {
  661. if ($sum < 10000) {
  662. $odds = 1.5;
  663. } else {
  664. $odds = 1;
  665. }
  666. }
  667. if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  668. $odds = 1;
  669. }
  670. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  671. if ($profit > 1000000) {
  672. $profit = 1000000; // 单注最高奖金1000000
  673. }
  674. $item['profit'] = $profit;
  675. $yl = bcsub($profit, $amount, 2); // 盈利
  676. }
  677. if (isset($openList[$v['member_id']])) {
  678. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  679. $openList[$v['member_id']]['amount'] += $v['amount'];
  680. $openList[$v['member_id']]['profit'] += $profit;
  681. $openList[$v['member_id']]['lastStr'] = $lastStr;
  682. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  683. } else {
  684. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  685. $openList[$v['member_id']]['amount'] = $v['amount'];
  686. $openList[$v['member_id']]['profit'] = $profit;
  687. $openList[$v['member_id']]['lastStr'] = $lastStr;
  688. $openList[$v['member_id']]['openKeywords'] = [];
  689. $openList[$v['member_id']]['keywords'] = [];
  690. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  691. $openList[$v['member_id']]['win_amount'] = 0;
  692. $openList[$v['member_id']]['is_send'] = true;
  693. }
  694. // if ($k + 1 <= $realNoticeNum) {
  695. // // $text .= "会员下注 【" . $lastStr . "】{$v['amount']} {$v['profit']} -{$v['amount']}\n";
  696. // $bet_num++;
  697. // }
  698. // $memberList[$v['member_id']][] = [
  699. // 'member_id' => $v['member_id'],
  700. // 'amount' => $v['amount'],
  701. // 'keywords' => $v['keywords'],
  702. // 'profit' => 0,
  703. // 'yl' => '-'.$v['amount'],
  704. // ];
  705. }
  706. self::model()::where('id', $v['id'])->update($item);
  707. }
  708. // foreach($openList as $k => $v){
  709. // $amount = $v['amount'];
  710. // // if($v['profit'] >= 0){
  711. // $profit = number_format($v['profit'],2);
  712. // $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  713. // // $text .= "会员下注 【" . $v['lastStr'] . "】 {$amount} {$profit} {$yl}\n";
  714. // if(++$bet_num <= $realNoticeNum){
  715. // if(empty($v['openKeywords'])){
  716. // $openKeyword = '-';
  717. // }else{
  718. // $openKeyword = implode(',', $v['openKeywords']);
  719. // }
  720. // $text .= "用户ID:{$v['lastStr']} \n";
  721. // $text .= "下注类型:[".implode(',', $v['keywords'])."] \n";
  722. // $text .= "中奖类型:[".$openKeyword."] \n";
  723. // $text .= "投注金额:{$amount} \n";
  724. // $text .= "中奖金额:{$v['win_amount']} \n";
  725. // $text .= "派彩金额:{$profit} \n";
  726. // $text .= "盈亏金额:{$yl} \n";
  727. // $text .= "-------------------------------- \n";
  728. // }
  729. // $text2 = "{$issue_no}期开奖结果 \n";
  730. // $text2 .= "下注类型:[".implode(',', $v['keywords'])."] \n";
  731. // $text2 .= "中奖类型:[".$openKeyword."] \n";
  732. // $text2 .= "投注金额:{$amount} \n";
  733. // $text2 .= "中奖金额:{$v['win_amount']} \n";
  734. // $text2 .= "派彩金额:{$profit} \n";
  735. // $text2 .= "盈亏金额:{$yl} \n";
  736. // $keyboard = [];
  737. // $keyboard[] = [
  738. // ['text' => "开奖历史", 'callback_data' => "showLotteryHistory@@" . $issue_no]
  739. // ];
  740. // SendTelegramMessageJob::dispatch($v['member_id'],$text2,$keyboard);
  741. // // self::sendMessage($v['member_id'],$text2);
  742. // // }else{
  743. // // $text .= "会员下注 【" . $v['lastStr'] . "】 {$amount} 0 -{$amount}\n";
  744. // // }
  745. // }
  746. $inlineButton = self::getOperateButton();
  747. $rand_num = $noticeNum - $bet_num;
  748. $openList = array_merge($openList, $fakeOpenData['list']);
  749. // 群通知
  750. // self::bettingGroupNotice($text, $inlineButton, '');
  751. // SendTelegramGroupMessageJob::dispatch($text,$inlineButton,'');
  752. self::lotteryNotice($openList, $issue_no, $keywordsList);
  753. }
  754. /**
  755. * @description: 中奖结算
  756. * @param {*} $issue_no
  757. * @param {*} $awards
  758. * @return {*}
  759. */
  760. public static function betSettled2($issue_no, $awards)
  761. {
  762. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  763. $data = [];
  764. $text = $issue_no . "期开奖结果 \n";
  765. $text .= "-----本期开奖账单----- \n";
  766. // $text .=" 中奖类型 用户 投注金额 中奖金额 盈亏 \n";
  767. $text .= "\n";
  768. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  769. $betNoticeNum = explode(',', $betNoticeNum);
  770. $betNoticeMini = $betNoticeNum[0] ?? 26;
  771. $betNoticeMax = $betNoticeNum[1] ?? 38;
  772. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  773. $realNoticeNum = ceil($noticeNum / 2);
  774. $openList = [];
  775. $bet_num = 0;
  776. foreach ($list->toArray() as $k => $v) {
  777. // $userInfo = UserService::findAll(['member_id' => $v['member_id']]);
  778. // $lastStr = self::getLastChar($userInfo->first_name, 1);
  779. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  780. $item = [];
  781. $item['id'] = $v['id'];
  782. $item['status'] = self::model()::STATUS_SETTLED;
  783. if (in_array($v['keywords'], $awards)) {
  784. // $profit = $v['amount'] * $v['odds'];
  785. $amount = $v['amount'];
  786. // $amount = rtrim($amount, '0'); // 去掉右侧的 0
  787. // $amount = rtrim($amount, '.'); // 如果末尾是 . 就去掉
  788. $odds = $v['odds'];
  789. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  790. if ($profit > 880000) {
  791. $profit = 880000; // 单注最高奖金880000
  792. }
  793. $item['profit'] = $profit;
  794. // $yl = $profit - $amount;
  795. $yl = bcsub($profit, $amount, 2); // 盈利
  796. // if ($k + 1 <= $realNoticeNum) {
  797. // // $text .= "会员下注 【" . $lastStr . "】{$v['amount']} {$profit} {$yl}\n";
  798. // $bet_num++;
  799. // }
  800. // 结算
  801. // WalletService::updateBalance($v['member_id'], $profit);
  802. // $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  803. // $balance = $walletInfo['available_balance'];
  804. // BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
  805. if (isset($openList[$v['member_id']])) {
  806. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  807. $openList[$v['member_id']]['amount'] += $v['amount'];
  808. $openList[$v['member_id']]['profit'] += $profit;
  809. $openList[$v['member_id']]['lastStr'] = $lastStr;
  810. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  811. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  812. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  813. } else {
  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']]['openKeywords'] = [];
  819. $openList[$v['member_id']]['keywords'] = [];
  820. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  821. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  822. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  823. $openList[$v['member_id']]['is_send'] = true;
  824. }
  825. } else {
  826. if (isset($openList[$v['member_id']])) {
  827. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  828. $openList[$v['member_id']]['amount'] += $v['amount'];
  829. $openList[$v['member_id']]['lastStr'] = $lastStr;
  830. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  831. } else {
  832. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  833. $openList[$v['member_id']]['amount'] = $v['amount'];
  834. $openList[$v['member_id']]['profit'] = 0;
  835. $openList[$v['member_id']]['lastStr'] = $lastStr;
  836. $openList[$v['member_id']]['openKeywords'] = [];
  837. $openList[$v['member_id']]['keywords'] = [];
  838. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  839. $openList[$v['member_id']]['win_amount'] = 0;
  840. $openList[$v['member_id']]['is_send'] = true;
  841. }
  842. // if ($k + 1 <= $realNoticeNum) {
  843. // // $text .= "会员下注 【" . $lastStr . "】{$v['amount']} {$v['profit']} -{$v['amount']}\n";
  844. // $bet_num++;
  845. // }
  846. }
  847. // self::model()::where('id', $v['id'])->update($item);
  848. }
  849. // foreach($openList as $k => $v){
  850. // $amount = $v['amount'];
  851. // // if($v['profit'] >= 0){
  852. // $profit = number_format($v['profit'],2);
  853. // $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  854. // // $text .= "会员下注 【" . $v['lastStr'] . "】 {$amount} {$profit} {$yl}\n";
  855. // if(++$bet_num <= $realNoticeNum){
  856. // $text .= "用户ID:{$v['lastStr']} \n";
  857. // $text .= "下注类型:[".implode(',', $v['keywords'])."] \n";
  858. // $text .= "中奖类型:[".implode(',', $v['openKeywords'])."] \n";
  859. // $text .= "投注金额:{$amount} \n";
  860. // $text .= "中奖金额:{$v['win_amount']} \n";
  861. // $text .= "派彩金额:{$profit} \n";
  862. // $text .= "盈亏金额:{$yl} \n";
  863. // $text .= "-------------------------------- \n";
  864. // }
  865. // $text2 = "{$issue_no}期开奖结果 \n";
  866. // $text2 .= "下注类型:[".implode(',', $v['keywords'])."] \n";
  867. // $text2 .= "中奖类型:[".implode(',', $v['openKeywords'])."] \n";
  868. // $text2 .= "投注金额:{$amount} \n";
  869. // $text2 .= "中奖金额:{$v['win_amount']} \n";
  870. // $text2 .= "派彩金额:{$profit} \n";
  871. // $text2 .= "盈亏金额:{$yl} \n";
  872. // $keyboard = [];
  873. // $keyboard[] = [
  874. // ['text' => "开奖历史", 'callback_data' => "showLotteryHistory@@" . $issue_no]
  875. // ];
  876. // // SendTelegramMessageJob::dispatch($v['member_id'],$text2);
  877. // self::sendMessage($v['member_id'],$text2,$keyboard);
  878. // // }else{
  879. // // $text .= "会员下注 【" . $v['lastStr'] . "】 {$amount} 0 -{$amount}\n";
  880. // // }
  881. // }
  882. $inlineButton = self::getOperateButton();
  883. $rand_num = $noticeNum - $bet_num;
  884. $fakeOpenData = self::fakeLotteryDraw($issue_no, $awards, $rand_num);
  885. $openList = array_merge($openList, $fakeOpenData['list']);
  886. // 群通知
  887. // self::bettingGroupNotice($text, $inlineButton, '');
  888. // SendTelegramGroupMessageJob::dispatch($text,$inlineButton,'');
  889. self::lotteryNotice($openList, $issue_no);
  890. }
  891. // 虚拟开奖
  892. public static function fakeLotteryDraw($issue_no, $awards, $rand_num = 30)
  893. {
  894. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  895. $text = "";
  896. $keywordsList = [];
  897. $fakeOtherSum = 0;
  898. $openList = [];
  899. foreach ($fake_bet_list as $k => $v) {
  900. if (in_array($v['keywords'], ['大', '小', '单', '双'])) {
  901. $fakeOtherSum += $v['amount'];
  902. }
  903. if (isset($keywordsList[$v['keywords']])) {
  904. $keywordsList[$v['keywords']] += $v['amount'];
  905. } else {
  906. $keywordsList[$v['keywords']] = $v['amount'];
  907. }
  908. // $lastStr = self::getLastChar($v['first_name'], 1);
  909. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  910. if (in_array($v['keywords'], $awards)) {
  911. $amount = $v['amount'];
  912. $odds = $v['odds'];
  913. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  914. if ($profit > 880000) {
  915. $profit = 880000; // 单注最高奖金880000
  916. }
  917. $item['profit'] = $profit;
  918. // $v['amount'] = number_format($amount,2);
  919. if (isset($openList[$v['member_id']])) {
  920. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  921. $openList[$v['member_id']]['amount'] += $v['amount'];
  922. $openList[$v['member_id']]['profit'] += $profit;
  923. $openList[$v['member_id']]['lastStr'] = $lastStr;
  924. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  925. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  926. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  927. } else {
  928. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  929. $openList[$v['member_id']]['amount'] = $v['amount'];
  930. $openList[$v['member_id']]['profit'] = $profit;
  931. $openList[$v['member_id']]['lastStr'] = $lastStr;
  932. $openList[$v['member_id']]['openKeywords'] = [];
  933. $openList[$v['member_id']]['keywords'] = [];
  934. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  935. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  936. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  937. $openList[$v['member_id']]['is_send'] = false;
  938. }
  939. } else {
  940. if (isset($openList[$v['member_id']])) {
  941. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  942. $openList[$v['member_id']]['amount'] += $v['amount'];
  943. $openList[$v['member_id']]['lastStr'] = $lastStr;
  944. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  945. } else {
  946. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  947. $openList[$v['member_id']]['amount'] = $v['amount'];
  948. $openList[$v['member_id']]['profit'] = 0;
  949. $openList[$v['member_id']]['lastStr'] = $lastStr;
  950. $openList[$v['member_id']]['openKeywords'] = [];
  951. $openList[$v['member_id']]['keywords'] = [];
  952. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  953. $openList[$v['member_id']]['win_amount'] = 0;
  954. $openList[$v['member_id']]['is_send'] = false;
  955. }
  956. }
  957. }
  958. return ['sum' => $fakeOtherSum, 'list' => $openList, 'keywordsList' => $keywordsList];
  959. }
  960. // 开奖通知
  961. public static function lotteryNotice($openList, $issue_no, $keywordsList = [])
  962. {
  963. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  964. $betNoticeNum = explode(',', $betNoticeNum);
  965. $betNoticeMini = $betNoticeNum[0] ?? 26;
  966. $betNoticeMax = $betNoticeNum[1] ?? 38;
  967. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  968. // shuffle($openList);
  969. // Log::error('lotteryNotice openList', $openList);
  970. $text = "{$issue_no}期开奖结果";
  971. $text .= "\n-----本期开奖账单----- \n";
  972. foreach ($openList as $k => $v) {
  973. $amount = number_format($v['amount'], 2);
  974. $v['win_amount'] = number_format($v['win_amount'], 2);
  975. $profit = number_format($v['profit'], 2);
  976. $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  977. if (empty($v['openKeywords'])) {
  978. $openKeyword = '-';
  979. } else {
  980. $openKeyword = implode(',', $v['openKeywords']);
  981. }
  982. if (($k + 1) <= $noticeNum) {
  983. $text .= "用户ID:{$v['lastStr']} \n";
  984. $text .= "下注类型:[" . implode(',', $v['keywords']) . "] \n";
  985. $text .= "中奖类型:[" . $openKeyword . "] \n";
  986. $text .= "投注金额:{$amount} \n";
  987. $text .= "中奖金额:{$v['win_amount']} \n";
  988. $text .= "派彩金额:{$profit} \n";
  989. $text .= "盈亏金额:{$yl} \n";
  990. $text .= "-------------------------------- \n";
  991. }
  992. if ($v['is_send']) {
  993. $language = User::where('member_id', $v['member_id'])->first()->language;
  994. App::setLocale($language);
  995. $text2 = lang("{issue_no}期开奖结果");
  996. $text2 = str_replace("{issue_no}", $issue_no, $text2);
  997. $text2 .= "\n";
  998. $text2 .= lang('下注类型') . ":[" . implode(',', $v['keywords']) . "] \n";
  999. $text2 .= lang('中奖类型') . ":[" . $openKeyword . "] \n";
  1000. $text2 .= lang('投注金额') . ":{$amount} \n";
  1001. $text2 .= lang('中奖金额') . ":{$v['win_amount']} \n";
  1002. $text2 .= lang('派彩金额') . ":{$profit} \n";
  1003. $text2 .= lang("盈亏金额") . ":{$yl} \n";
  1004. $keyboard = [];
  1005. $keyboard[] = [
  1006. ['text' => lang("开奖历史"), 'callback_data' => "showLotteryHistory@@" . $issue_no]
  1007. ];
  1008. // self::sendMessage($v['member_id'],$text2,$keyboard);
  1009. SendTelegramMessageJob::dispatch($v['member_id'], $text2, $keyboard);
  1010. }
  1011. }
  1012. $inlineButton = self::getOperateButton();
  1013. // 群通知
  1014. // self::bettingGroupNotice($text, $inlineButton, '');
  1015. // Log::error('lotteryNotice Group:'.$text);
  1016. // $pos = strrpos($text, '--------------------------------');
  1017. //
  1018. // if ($pos !== false) {
  1019. // // 使用 substr_replace 来删除最后一个 "ne"
  1020. // $text = substr_replace($text, "", $pos, strlen('--------------------------------'));
  1021. // }
  1022. SendTelegramGroupMessageJob::dispatch($text, $inlineButton, '', false, '--------------------------------');
  1023. }
  1024. /**
  1025. * @description: 统计投注情况通知
  1026. * @param {*} $issue_no
  1027. * @return {*}
  1028. */
  1029. public static function statNotice($issue_no)
  1030. {
  1031. $keywordsList = [];
  1032. // 虚拟投注情况
  1033. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  1034. foreach ($fake_bet_list 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. // 真实投注
  1042. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  1043. foreach ($list->toArray() as $k => $v) {
  1044. if (isset($keywordsList[$v['keywords']])) {
  1045. $keywordsList[$v['keywords']] += $v['amount'];
  1046. } else {
  1047. $keywordsList[$v['keywords']] = $v['amount'];
  1048. }
  1049. }
  1050. $text3 = "📝 {$issue_no}期投注统计 \n";
  1051. if ($keywordsList) {
  1052. ksort($keywordsList);
  1053. foreach ($keywordsList as $k => $v) {
  1054. $text3 .= "玩法:{$k} \n";
  1055. $text3 .= "总注:{$v} \n";
  1056. $text3 .= "-------------- \n";
  1057. }
  1058. }
  1059. $inlineButton = self::getOperateButton();
  1060. SendTelegramGroupMessageJob::dispatch($text3, $inlineButton, '');
  1061. }
  1062. public static function todayExchangeRate($chatId)
  1063. {
  1064. $exchangeRate = Config::where('field', 'exchange_rate_rmb')->first()->val;
  1065. $text = lang("今日汇率") . ":1USDT = {$exchangeRate} RMB \n";
  1066. // $botMsg = [
  1067. // 'chat_id' => "@{$chatId}",
  1068. // 'text' => $text
  1069. // ];
  1070. self::sendMessage($chatId, $text);
  1071. // return $botMsg;
  1072. }
  1073. }