BetService.php 48 KB

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