BetService.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  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. if (strtotime($issueInfo['end_time']) - strtotime($now_date) < 22) {
  357. $fake_bet_count = Cache::get("fake_bet_count_{$issueInfo->issue_no}", 0);
  358. if ($fake_bet_count >= 3) return;
  359. }
  360. $randKey = array_rand($gameplayRuleList, 1);
  361. $gameplayRuleInfo = $gameplayRuleList[$randKey] ?? [];
  362. if ($gameplayRuleInfo) {
  363. if (in_array($gameplayRuleInfo['keywords'], $noRule)) {
  364. return;
  365. }
  366. if ($gameplayRuleInfo['maxinum'] < $betMax) {
  367. $betMax = $gameplayRuleInfo['maxinum'];
  368. }
  369. if ($gameplayRuleInfo['mininum'] > $betMini) {
  370. $betMini = $gameplayRuleInfo['mininum'];
  371. }
  372. $amount = rand($betMini, $betMax);
  373. $amount = floor($amount / 10) * 10;
  374. $input = $gameplayRuleInfo['keywords'] . $amount;
  375. // $amount = number_format($amount,2);
  376. $item = [];
  377. $item['keywords'] = $gameplayRuleInfo['keywords'];
  378. $item['odds'] = $gameplayRuleInfo['odds'];
  379. $item['amount'] = $amount;
  380. $item['first_name'] = self::generateRandomString(6);
  381. $item['member_id'] = $member_id;
  382. $item['profit'] = 0;
  383. // $input = $item['keywords'] . $item['amount'];
  384. $fake_bet_list[] = $item;
  385. $lastStr = self::hideMiddleDigits($item['member_id'], 4);
  386. $groupText = "";
  387. $groupText .= "会员下注 【" . $lastStr . "】 \n";
  388. $groupText .= "下注期数:{$issueInfo->issue_no} \n";
  389. $groupText .= "下注内容: \n";
  390. $groupText .= "----------- \n";
  391. $groupText .= "{$input} \n";
  392. $groupText .= "----------- \n";
  393. if (strtotime($issueInfo['end_time']) - strtotime($now_date) < 22) {
  394. $fake_bet_count = Cache::get("fake_bet_count_{$issueInfo->issue_no}", 0);
  395. Cache::put("fake_bet_count_{$issueInfo->issue_no}", $fake_bet_count + 1, 500);
  396. }
  397. $inlineButton = self::getOperateButton();
  398. // 群通知
  399. // self::bettingGroupNotice($groupText, $inlineButton); // 群通知
  400. self::asyncBettingGroupNotice($groupText, $inlineButton); // 异步群通知
  401. }
  402. }
  403. Cache::put('fake_bet_' . $issueInfo->issue_no, $fake_bet_list, 500);
  404. }
  405. }
  406. }
  407. }
  408. /**
  409. * @description: 当期下注
  410. * @param {*} $memberId
  411. * @return {*}
  412. */
  413. public static function currentBet($memberId)
  414. {
  415. $msg['chat_id'] = $memberId;
  416. // 期数验证
  417. $issueInfo = IssueService::model()::where('status', IssueService::model()::STATUS_BETTING)->orderBy('id', 'desc')->first();
  418. $issue_no = '';
  419. if (!empty($issueInfo)) {
  420. $issue_no = $issueInfo->issue_no;
  421. } else {
  422. $issueCloseInfo = IssueService::model()::where('status', IssueService::model()::STATUS_CLOSE)->orderBy('id', 'desc')->first();
  423. if (empty($issueCloseInfo)) {
  424. $issue_no = $issueCloseInfo->issue_no;
  425. }
  426. }
  427. if ($issue_no) {
  428. $text = lang("期数") . " {$issue_no} \n";
  429. // $text .= "\n";
  430. // $text .= "----------\n";
  431. $list = self::findAll(['member_id' => $memberId, 'issue_no' => $issue_no]);
  432. $list = $list->toArray();
  433. if (empty($list)) {
  434. $text .= lang("本期暂未下注") . "! \n";
  435. } else {
  436. $keywords = implode(',', array_column($list, 'keywords'));
  437. $amounts = implode(',', array_column($list, 'amount'));
  438. $text .= lang("下注类型") . ":[" . $keywords . "] \n";
  439. $text .= lang("下注金额") . ":" . $amounts . " \n";
  440. $text .= lang("下注总额") . ":" . array_sum(array_column($list, 'amount')) . " \n";
  441. $text .= lang("开奖状态") . ":" . lang("等待开奖") . " \n";
  442. }
  443. // foreach ($list->toArray() as $k => $v) {
  444. // $text .= "{$v['keywords']}{$v['amount']} \n";
  445. // }
  446. // $text .= "\n";
  447. // $text .= "----------\n";
  448. $msg['text'] = $text;
  449. } else {
  450. $msg['text'] = lang("当前没有开放的投注期数") . "! \n";
  451. }
  452. return $msg;
  453. }
  454. /**
  455. * @description: 近期投注
  456. * @param {*} $memberId
  457. * @return {*}
  458. */
  459. public static function recentlyRecord($memberId, $page = 1, $limit = 5)
  460. {
  461. $list = self::model()::where('member_id', $memberId)->whereIn('status', [self::model()::STATUS_STAY, self::model()::STATUS_SETTLED])->orderBy('id', 'desc')->forPage($page, $limit)->get();
  462. // $text = "```\n";
  463. $text = "";
  464. $text .= "期数--内容--盈亏 \n";
  465. foreach ($list->toArray() as $k => $v) {
  466. $profit = $v['profit'] - $v['amount'];
  467. // $text .= $v['issue_no']." ".$v['keywords']." ".$v['amount']." ".$v['profit']."\n";
  468. $item = $v['issue_no'] . "==" . $v['keywords'] . rtrim(rtrim(number_format($v['amount'], 2, '.', ''), '0'), '.') . "==" . rtrim(rtrim(number_format($profit, 2, '.', ''), '0'), '.') . "\n";
  469. $text .= $item;
  470. }
  471. // $text .= "```\n";
  472. return $text;
  473. }
  474. /**
  475. * @description: 投注记录
  476. * @param {*} $memberId
  477. * @param {*} $page
  478. * @param {*} $limit
  479. * @return {*}
  480. */
  481. public static function record($memberId, $messageId = null, $page = 1, $limit = 5)
  482. {
  483. $type = Cache::get('message_id_bet_record_' . $memberId, 0);
  484. if ($type == 0) {
  485. $type = '';
  486. }
  487. $msg['chat_id'] = $memberId;
  488. $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();
  489. $count = self::model()::where('member_id', $memberId)->whereIn('status', [self::model()::STATUS_STAY, self::model()::STATUS_SETTLED])->where(self::getWhere(['is_winner' => $type]))->count();
  490. $keyboard = [];
  491. $total_amount = BalanceLogService::model()::where('member_id', $memberId)->where('change_type', '中奖')->sum('amount');
  492. $total_amount = number_format($total_amount, 2);
  493. $text = lang("历史注单") . " \n";
  494. $text .= lang("中奖总派彩") . ":{$total_amount} \n";
  495. foreach ($list as $k => $v) {
  496. if ($v->status == self::model()::STATUS_SETTLED) {
  497. $phase = $v->profit - $v->amount;
  498. } else {
  499. $phase = lang('待开奖');
  500. }
  501. $text .= "-------------------------------------\n";
  502. $text .= lang("期数") . ":{$v->issue_no} \n";
  503. $text .= lang("内容") . ":{$v->keywords} \n";
  504. $text .= lang("金额") . ":{$v->amount} \n";
  505. $text .= lang("盈亏") . ":{$phase} \n";
  506. }
  507. $msg['text'] = $text;
  508. $keyboard[] = [
  509. ['text' => lang("全部"), 'callback_data' => "betRecordType@@0"],
  510. ['text' => lang("盈利"), 'callback_data' => "betRecordType@@1"],
  511. ['text' => lang("亏损"), 'callback_data' => "betRecordType@@2"]
  512. ];
  513. if ($page > 1) {
  514. $keyboard[] = [
  515. ['text' => "👆" . lang("上一页"), 'callback_data' => "betRecordNextPage@@" . ($page - 1)]
  516. ];
  517. }
  518. $allPage = ceil($count / $limit);
  519. if ($allPage > $page) {
  520. if ($page > 1) {
  521. $keyboard[count($keyboard) - 1][] = ['text' => "👇" . lang("下一页"), 'callback_data' => "betRecordNextPage@@" . ($page + 1)];
  522. } else {
  523. $keyboard[] = [
  524. ['text' => "👇" . lang("下一页"), 'callback_data' => "betRecordNextPage@@" . ($page + 1)]
  525. ];
  526. }
  527. }
  528. if ($messageId) {
  529. $msg['message_id'] = $messageId;
  530. }
  531. if ($keyboard) {
  532. $msg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
  533. }
  534. return $msg;
  535. }
  536. /**
  537. * @description: 开奖失败退回投注的
  538. * @param {*} $issue_no
  539. * @return {*}
  540. */
  541. public static function betFail($issue_no)
  542. {
  543. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  544. foreach ($list->toArray() as $k => $v) {
  545. $profit = $v['amount'];
  546. WalletService::updateBalance($v['member_id'], $profit);
  547. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  548. $balance = $walletInfo['available_balance'];
  549. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
  550. $text = $issue_no . "期开奖失败 \n";
  551. $text .= "投注类型:{$v['keywords']} \n";
  552. $text .= "投注金额:{$v['amount']} \n";
  553. $text .= "投注的资金已退回您的钱包 \n";
  554. self::asyncSendMessage($v['member_id'], $text);
  555. $item = [];
  556. $iem['status'] = self::model()::STATUS_SETTLED;
  557. self::model()::where('id', $v['id'])->update($item);
  558. }
  559. }
  560. /**
  561. * @description: 中奖结算
  562. * @param {*} $issue_no
  563. * @param {*} $awards
  564. * @return {*}
  565. */
  566. public static function betSettled($issue_no, $awards)
  567. {
  568. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  569. // 大小单双的
  570. $otherSum = self::model()::where('issue_no', $issue_no)->where('status', self::model()::STATUS_STAY)->whereIn('keywords', ['大', '小', '单', '双'])->sum('amount');
  571. $fakeOpenData = self::fakeLotteryDraw($issue_no, $awards, 0);
  572. $keywordsList = $fakeOpenData['keywordsList'];
  573. $fakeOtherSum = $fakeOpenData['sum'];
  574. $sum = $otherSum + $fakeOtherSum;
  575. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  576. $betNoticeNum = explode(',', $betNoticeNum);
  577. $betNoticeMini = $betNoticeNum[0] ?? 26;
  578. $betNoticeMax = $betNoticeNum[1] ?? 38;
  579. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  580. $realNoticeNum = ceil($noticeNum / 2);
  581. $openList = [];
  582. $memberList = [];
  583. $bet_num = 0;
  584. foreach ($list->toArray() as $k => $v) {
  585. if (isset($keywordsList[$v['keywords']])) {
  586. $keywordsList[$v['keywords']] += $v['amount'];
  587. } else {
  588. $keywordsList[$v['keywords']] = $v['amount'];
  589. }
  590. // $userInfo = UserService::findAll(['member_id' => $v['member_id']]);
  591. // $lastStr = self::getLastChar($userInfo->first_name, 1);
  592. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  593. $item = [];
  594. $item['id'] = $v['id'];
  595. $item['status'] = self::model()::STATUS_SETTLED;
  596. if (in_array($v['keywords'], $awards)) {
  597. // $profit = $v['amount'] * $v['odds'];
  598. $amount = $v['amount'];
  599. // $amount = rtrim($amount, '0'); // 去掉右侧的 0
  600. // $amount = rtrim($amount, '.'); // 如果末尾是 . 就去掉
  601. $odds = $v['odds'];
  602. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  603. // 13 14特殊处理倍率
  604. if (in_array($v['keywords'], self::$OTHER_BET_1)) {
  605. if ($sum < 10000) {
  606. $odds = 1.5;
  607. } else {
  608. $odds = 1;
  609. }
  610. }
  611. if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  612. $odds = 1;
  613. }
  614. }
  615. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  616. if ($profit > 1000000) {
  617. $profit = 1000000; // 单注最高奖金1000000
  618. }
  619. $item['profit'] = $profit;
  620. // $yl = $profit - $amount;
  621. $yl = bcsub($profit, $amount, 2); // 盈利
  622. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  623. Rebate::updateProfit([
  624. 'member_id' => $v['member_id'],
  625. 'profit' => $yl,
  626. ]);
  627. }
  628. $memberList[$v['member_id']][] = [
  629. 'member_id' => $v['member_id'],
  630. 'keywords' => $v['keywords'],
  631. 'amount' => $v['amount'],
  632. 'profit' => $profit,
  633. 'yl' => $yl,
  634. ];
  635. // 结算
  636. WalletService::updateBalance($v['member_id'], $profit);
  637. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  638. $balance = $walletInfo['available_balance'];
  639. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
  640. if (isset($openList[$v['member_id']])) {
  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'][] = $v['keywords'];
  646. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  647. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  648. } else {
  649. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  650. $openList[$v['member_id']]['amount'] = $v['amount'];
  651. $openList[$v['member_id']]['profit'] = $profit;
  652. $openList[$v['member_id']]['lastStr'] = $lastStr;
  653. $openList[$v['member_id']]['openKeywords'] = [];
  654. $openList[$v['member_id']]['keywords'] = [];
  655. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  656. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  657. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  658. $openList[$v['member_id']]['is_send'] = true;
  659. }
  660. } else {
  661. if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
  662. Rebate::updateProfit([
  663. 'member_id' => $v['member_id'],
  664. 'profit' => ($v['amount'] * -1),
  665. ]);
  666. }
  667. $profit = 0;
  668. if (in_array('13操', $awards) || in_array('14操', $awards)) {
  669. $amount = $v['amount'];
  670. $odds = 0;
  671. // 13 14特殊处理倍率
  672. if (in_array($v['keywords'], self::$OTHER_BET_1)) {
  673. if ($sum < 10000) {
  674. $odds = 1.5;
  675. } else {
  676. $odds = 1;
  677. }
  678. }
  679. if (in_array($v['keywords'], self::$OTHER_BET_2)) {
  680. $odds = 1;
  681. }
  682. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  683. if ($profit > 1000000) {
  684. $profit = 1000000; // 单注最高奖金1000000
  685. }
  686. $item['profit'] = $profit;
  687. $yl = bcsub($profit, $amount, 2); // 盈利
  688. WalletService::updateBalance($v['member_id'], $profit);
  689. $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  690. $balance = $walletInfo['available_balance'];
  691. BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
  692. }
  693. if (isset($openList[$v['member_id']])) {
  694. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  695. $openList[$v['member_id']]['amount'] += $v['amount'];
  696. $openList[$v['member_id']]['profit'] += $profit;
  697. $openList[$v['member_id']]['lastStr'] = $lastStr;
  698. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  699. } else {
  700. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  701. $openList[$v['member_id']]['amount'] = $v['amount'];
  702. $openList[$v['member_id']]['profit'] = $profit;
  703. $openList[$v['member_id']]['lastStr'] = $lastStr;
  704. $openList[$v['member_id']]['openKeywords'] = [];
  705. $openList[$v['member_id']]['keywords'] = [];
  706. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  707. $openList[$v['member_id']]['win_amount'] = 0;
  708. $openList[$v['member_id']]['is_send'] = true;
  709. }
  710. }
  711. self::model()::where('id', $v['id'])->update($item);
  712. }
  713. $openList = array_merge($openList, $fakeOpenData['list']);
  714. self::lotteryNotice($openList, $issue_no, $keywordsList);
  715. }
  716. /**
  717. * @description: 中奖结算
  718. * @param {*} $issue_no
  719. * @param {*} $awards
  720. * @return {*}
  721. */
  722. public static function betSettled2($issue_no, $awards)
  723. {
  724. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  725. $data = [];
  726. $text = $issue_no . "期开奖结果 \n";
  727. $text .= "-----本期开奖账单----- \n";
  728. // $text .=" 中奖类型 用户 投注金额 中奖金额 盈亏 \n";
  729. $text .= "\n";
  730. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  731. $betNoticeNum = explode(',', $betNoticeNum);
  732. $betNoticeMini = $betNoticeNum[0] ?? 26;
  733. $betNoticeMax = $betNoticeNum[1] ?? 38;
  734. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  735. $realNoticeNum = ceil($noticeNum / 2);
  736. $openList = [];
  737. $bet_num = 0;
  738. foreach ($list->toArray() as $k => $v) {
  739. // $userInfo = UserService::findAll(['member_id' => $v['member_id']]);
  740. // $lastStr = self::getLastChar($userInfo->first_name, 1);
  741. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  742. $item = [];
  743. $item['id'] = $v['id'];
  744. $item['status'] = self::model()::STATUS_SETTLED;
  745. if (in_array($v['keywords'], $awards)) {
  746. // $profit = $v['amount'] * $v['odds'];
  747. $amount = $v['amount'];
  748. // $amount = rtrim($amount, '0'); // 去掉右侧的 0
  749. // $amount = rtrim($amount, '.'); // 如果末尾是 . 就去掉
  750. $odds = $v['odds'];
  751. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  752. if ($profit > 880000) {
  753. $profit = 880000; // 单注最高奖金880000
  754. }
  755. $item['profit'] = $profit;
  756. // $yl = $profit - $amount;
  757. $yl = bcsub($profit, $amount, 2); // 盈利
  758. // if ($k + 1 <= $realNoticeNum) {
  759. // // $text .= "会员下注 【" . $lastStr . "】{$v['amount']} {$profit} {$yl}\n";
  760. // $bet_num++;
  761. // }
  762. // 结算
  763. // WalletService::updateBalance($v['member_id'], $profit);
  764. // $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
  765. // $balance = $walletInfo['available_balance'];
  766. // BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
  767. if (isset($openList[$v['member_id']])) {
  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'][] = $v['keywords'];
  773. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  774. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  775. } else {
  776. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  777. $openList[$v['member_id']]['amount'] = $v['amount'];
  778. $openList[$v['member_id']]['profit'] = $profit;
  779. $openList[$v['member_id']]['lastStr'] = $lastStr;
  780. $openList[$v['member_id']]['openKeywords'] = [];
  781. $openList[$v['member_id']]['keywords'] = [];
  782. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  783. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  784. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  785. $openList[$v['member_id']]['is_send'] = true;
  786. }
  787. } else {
  788. if (isset($openList[$v['member_id']])) {
  789. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  790. $openList[$v['member_id']]['amount'] += $v['amount'];
  791. $openList[$v['member_id']]['lastStr'] = $lastStr;
  792. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  793. } else {
  794. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  795. $openList[$v['member_id']]['amount'] = $v['amount'];
  796. $openList[$v['member_id']]['profit'] = 0;
  797. $openList[$v['member_id']]['lastStr'] = $lastStr;
  798. $openList[$v['member_id']]['openKeywords'] = [];
  799. $openList[$v['member_id']]['keywords'] = [];
  800. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  801. $openList[$v['member_id']]['win_amount'] = 0;
  802. $openList[$v['member_id']]['is_send'] = true;
  803. }
  804. // if ($k + 1 <= $realNoticeNum) {
  805. // // $text .= "会员下注 【" . $lastStr . "】{$v['amount']} {$v['profit']} -{$v['amount']}\n";
  806. // $bet_num++;
  807. // }
  808. }
  809. // self::model()::where('id', $v['id'])->update($item);
  810. }
  811. // foreach($openList as $k => $v){
  812. // $amount = $v['amount'];
  813. // // if($v['profit'] >= 0){
  814. // $profit = number_format($v['profit'],2);
  815. // $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  816. // // $text .= "会员下注 【" . $v['lastStr'] . "】 {$amount} {$profit} {$yl}\n";
  817. // if(++$bet_num <= $realNoticeNum){
  818. // $text .= "用户ID:{$v['lastStr']} \n";
  819. // $text .= "下注类型:[".implode(',', $v['keywords'])."] \n";
  820. // $text .= "中奖类型:[".implode(',', $v['openKeywords'])."] \n";
  821. // $text .= "投注金额:{$amount} \n";
  822. // $text .= "中奖金额:{$v['win_amount']} \n";
  823. // $text .= "派彩金额:{$profit} \n";
  824. // $text .= "盈亏金额:{$yl} \n";
  825. // $text .= "-------------------------------- \n";
  826. // }
  827. // $text2 = "{$issue_no}期开奖结果 \n";
  828. // $text2 .= "下注类型:[".implode(',', $v['keywords'])."] \n";
  829. // $text2 .= "中奖类型:[".implode(',', $v['openKeywords'])."] \n";
  830. // $text2 .= "投注金额:{$amount} \n";
  831. // $text2 .= "中奖金额:{$v['win_amount']} \n";
  832. // $text2 .= "派彩金额:{$profit} \n";
  833. // $text2 .= "盈亏金额:{$yl} \n";
  834. // $keyboard = [];
  835. // $keyboard[] = [
  836. // ['text' => "开奖历史", 'callback_data' => "showLotteryHistory@@" . $issue_no]
  837. // ];
  838. // // SendTelegramMessageJob::dispatch($v['member_id'],$text2);
  839. // self::sendMessage($v['member_id'],$text2,$keyboard);
  840. // // }else{
  841. // // $text .= "会员下注 【" . $v['lastStr'] . "】 {$amount} 0 -{$amount}\n";
  842. // // }
  843. // }
  844. $inlineButton = self::getOperateButton();
  845. $rand_num = $noticeNum - $bet_num;
  846. $fakeOpenData = self::fakeLotteryDraw($issue_no, $awards, $rand_num);
  847. $openList = array_merge($openList, $fakeOpenData['list']);
  848. // 群通知
  849. // self::bettingGroupNotice($text, $inlineButton, '');
  850. // SendTelegramGroupMessageJob::dispatch($text,$inlineButton,'');
  851. self::lotteryNotice($openList, $issue_no);
  852. }
  853. // 虚拟开奖
  854. public static function fakeLotteryDraw($issue_no, $awards, $rand_num = 30)
  855. {
  856. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  857. $text = "";
  858. $keywordsList = [];
  859. $fakeOtherSum = 0;
  860. $openList = [];
  861. foreach ($fake_bet_list as $k => $v) {
  862. if (in_array($v['keywords'], ['大', '小', '单', '双'])) {
  863. $fakeOtherSum += $v['amount'];
  864. }
  865. if (isset($keywordsList[$v['keywords']])) {
  866. $keywordsList[$v['keywords']] += $v['amount'];
  867. } else {
  868. $keywordsList[$v['keywords']] = $v['amount'];
  869. }
  870. // $lastStr = self::getLastChar($v['first_name'], 1);
  871. $lastStr = self::hideMiddleDigits($v['member_id'], 4);
  872. if (in_array($v['keywords'], $awards)) {
  873. $amount = $v['amount'];
  874. $odds = $v['odds'];
  875. $profit = bcmul($amount, $odds, 2); // 保留两位小数
  876. if ($profit > 880000) {
  877. $profit = 880000; // 单注最高奖金880000
  878. }
  879. $item['profit'] = $profit;
  880. // $v['amount'] = number_format($amount,2);
  881. if (isset($openList[$v['member_id']])) {
  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'][] = $v['keywords'];
  887. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  888. $openList[$v['member_id']]['win_amount'] += $v['amount'];
  889. } else {
  890. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  891. $openList[$v['member_id']]['amount'] = $v['amount'];
  892. $openList[$v['member_id']]['profit'] = $profit;
  893. $openList[$v['member_id']]['lastStr'] = $lastStr;
  894. $openList[$v['member_id']]['openKeywords'] = [];
  895. $openList[$v['member_id']]['keywords'] = [];
  896. $openList[$v['member_id']]['openKeywords'][] = $v['keywords'];
  897. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  898. $openList[$v['member_id']]['win_amount'] = $v['amount'];
  899. $openList[$v['member_id']]['is_send'] = false;
  900. }
  901. } else {
  902. if (isset($openList[$v['member_id']])) {
  903. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  904. $openList[$v['member_id']]['amount'] += $v['amount'];
  905. $openList[$v['member_id']]['lastStr'] = $lastStr;
  906. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  907. } else {
  908. $openList[$v['member_id']]['member_id'] = $v['member_id'];
  909. $openList[$v['member_id']]['amount'] = $v['amount'];
  910. $openList[$v['member_id']]['profit'] = 0;
  911. $openList[$v['member_id']]['lastStr'] = $lastStr;
  912. $openList[$v['member_id']]['openKeywords'] = [];
  913. $openList[$v['member_id']]['keywords'] = [];
  914. $openList[$v['member_id']]['keywords'][] = $v['keywords'];
  915. $openList[$v['member_id']]['win_amount'] = 0;
  916. $openList[$v['member_id']]['is_send'] = false;
  917. }
  918. }
  919. }
  920. return ['sum' => $fakeOtherSum, 'list' => $openList, 'keywordsList' => $keywordsList];
  921. }
  922. // 开奖通知
  923. public static function lotteryNotice($openList, $issue_no, $keywordsList = [])
  924. {
  925. $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
  926. $betNoticeNum = explode(',', $betNoticeNum);
  927. $betNoticeMini = $betNoticeNum[0] ?? 26;
  928. $betNoticeMax = $betNoticeNum[1] ?? 38;
  929. $noticeNum = rand($betNoticeMini, $betNoticeMax);
  930. // shuffle($openList);
  931. // Log::error('lotteryNotice openList', $openList);
  932. $text = "{$issue_no}期开奖结果";
  933. $text .= "\n-----本期开奖账单----- \n";
  934. foreach ($openList as $k => $v) {
  935. $amount = number_format($v['amount'], 2);
  936. $v['win_amount'] = number_format($v['win_amount'], 2);
  937. $profit = number_format($v['profit'], 2);
  938. $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
  939. if (empty($v['openKeywords'])) {
  940. $openKeyword = '-';
  941. } else {
  942. $openKeyword = implode(',', $v['openKeywords']);
  943. }
  944. if (($k + 1) <= $noticeNum) {
  945. $text .= "用户ID:{$v['lastStr']} \n";
  946. $text .= "下注类型:[" . implode(',', $v['keywords']) . "] \n";
  947. $text .= "中奖类型:[" . $openKeyword . "] \n";
  948. $text .= "投注金额:{$amount} \n";
  949. $text .= "中奖金额:{$v['win_amount']} \n";
  950. $text .= "派彩金额:{$profit} \n";
  951. $text .= "盈亏金额:{$yl} \n";
  952. $text .= "-------------------------------- \n";
  953. }
  954. if ($v['is_send']) {
  955. $language = User::where('member_id', $v['member_id'])->first()->language;
  956. App::setLocale($language);
  957. $text2 = lang("{issue_no}期开奖结果");
  958. $text2 = str_replace("{issue_no}", $issue_no, $text2);
  959. $text2 .= "\n";
  960. $text2 .= lang('下注类型') . ":[" . implode(',', $v['keywords']) . "] \n";
  961. $text2 .= lang('中奖类型') . ":[" . $openKeyword . "] \n";
  962. $text2 .= lang('投注金额') . ":{$amount} \n";
  963. $text2 .= lang('中奖金额') . ":{$v['win_amount']} \n";
  964. $text2 .= lang('派彩金额') . ":{$profit} \n";
  965. $text2 .= lang("盈亏金额") . ":{$yl} \n";
  966. $keyboard = [];
  967. $keyboard[] = [
  968. ['text' => lang("开奖历史"), 'callback_data' => "showLotteryHistory@@" . $issue_no]
  969. ];
  970. // self::sendMessage($v['member_id'],$text2,$keyboard);
  971. SendTelegramMessageJob::dispatch($v['member_id'], $text2, $keyboard);
  972. }
  973. }
  974. $inlineButton = self::getOperateButton();
  975. // 群通知
  976. // self::bettingGroupNotice($text, $inlineButton, '');
  977. // Log::error('lotteryNotice Group:'.$text);
  978. // $pos = strrpos($text, '--------------------------------');
  979. //
  980. // if ($pos !== false) {
  981. // // 使用 substr_replace 来删除最后一个 "ne"
  982. // $text = substr_replace($text, "", $pos, strlen('--------------------------------'));
  983. // }
  984. SendTelegramGroupMessageJob::dispatch($text, $inlineButton, '', false, '--------------------------------');
  985. }
  986. /**
  987. * @description: 统计投注情况通知
  988. * @param {*} $issue_no
  989. * @return {*}
  990. */
  991. public static function statNotice($issue_no)
  992. {
  993. $keywordsList = [];
  994. // 虚拟投注情况
  995. $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
  996. foreach ($fake_bet_list as $k => $v) {
  997. if (isset($keywordsList[$v['keywords']])) {
  998. $keywordsList[$v['keywords']] += $v['amount'];
  999. } else {
  1000. $keywordsList[$v['keywords']] = $v['amount'];
  1001. }
  1002. }
  1003. // 真实投注
  1004. $list = self::findAll(['issue_no' => $issue_no, 'status' => self::model()::STATUS_STAY]);
  1005. foreach ($list->toArray() as $k => $v) {
  1006. if (isset($keywordsList[$v['keywords']])) {
  1007. $keywordsList[$v['keywords']] += $v['amount'];
  1008. } else {
  1009. $keywordsList[$v['keywords']] = $v['amount'];
  1010. }
  1011. }
  1012. $text3 = "📝 {$issue_no}期投注统计 \n";
  1013. if ($keywordsList) {
  1014. ksort($keywordsList);
  1015. foreach ($keywordsList as $k => $v) {
  1016. $text3 .= "玩法:{$k} \n";
  1017. $text3 .= "总注:{$v} \n";
  1018. $text3 .= "-------------- \n";
  1019. }
  1020. }
  1021. $inlineButton = self::getOperateButton();
  1022. SendTelegramGroupMessageJob::dispatch($text3, $inlineButton, '');
  1023. }
  1024. public static function todayExchangeRate($chatId)
  1025. {
  1026. $exchangeRate = Config::where('field', 'exchange_rate_rmb')->first()->val;
  1027. $text = lang("今日汇率") . ":1USDT = {$exchangeRate} RMB \n";
  1028. // $botMsg = [
  1029. // 'chat_id' => "@{$chatId}",
  1030. // 'text' => $text
  1031. // ];
  1032. self::sendMessage($chatId, $text);
  1033. // return $botMsg;
  1034. }
  1035. }