BetService.php 48 KB

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