LuckLotteryServices.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\activity\lottery;
  13. use app\services\BaseServices;
  14. use app\dao\activity\lottery\LuckLotteryDao;
  15. use app\services\coupon\StoreCouponIssueServices;
  16. use app\services\product\product\StoreProductServices;
  17. use app\services\user\UserBillServices;
  18. use app\services\user\UserLabelRelationServices;
  19. use app\services\user\UserServices;
  20. use crmeb\exceptions\AdminException;
  21. use crmeb\services\CacheService;
  22. use think\exception\ValidateException;
  23. /**
  24. *
  25. * Class LuckLotteryServices
  26. * @package app\services\activity\lottery
  27. * @method getFactorLottery(int $factor = 1, string $field = '*', array $with = ['prize'], bool $is_doing = true)
  28. */
  29. class LuckLotteryServices extends BaseServices
  30. {
  31. /**
  32. * 抽奖形式,奖品数量
  33. * @var int[]
  34. */
  35. protected $lottery_type = [
  36. '1' => 8 //九宫格
  37. ];
  38. /**
  39. * 抽奖类型
  40. * @var string[]
  41. */
  42. protected $lottery_factor = [
  43. '1' => '积分',
  44. '2' => '余额',
  45. '3' => '下单支付成功',
  46. '4' => '订单评价',
  47. '5' => '关注公众号'
  48. ];
  49. /**
  50. * LuckLotteryServices constructor.
  51. * @param LuckLotteryDao $dao
  52. */
  53. public function __construct(LuckLotteryDao $dao)
  54. {
  55. $this->dao = $dao;
  56. }
  57. public function getList(array $where)
  58. {
  59. [$page, $limit] = $this->getPageValue();
  60. $where['is_del'] = 0;
  61. $list = $this->dao->getList($where, '*', ['prize'], $page, $limit);
  62. $lottery_factor = $this->lottery_factor;
  63. /** @var LuckLotteryRecordServices $luckLotteryRecordServices */
  64. $luckLotteryRecordServices = app()->make(LuckLotteryRecordServices::class);
  65. foreach ($list as &$item) {
  66. $item['lottery_type'] = $lottery_factor[$item['factor']] ?? '';
  67. $data = $luckLotteryRecordServices->getLotteryRecordData((int)$item['id']);
  68. $item['lottery_all'] = $data['all'] ?? 0;
  69. $item['lottery_people'] = $data['people'] ?? 0;
  70. $item['lottery_win'] = $data['win'] ?? 0;
  71. if ($item['status']) {
  72. if ($item['start_time'] == 0 && $item['end_time'] == 0) {
  73. $item['lottery_status'] = '进行中';
  74. } else {
  75. if ($item['start_time'] > time())
  76. $item['lottery_status'] = '未开始';
  77. else if ($item['end_time'] < time())
  78. $item['lottery_status'] = '已结束';
  79. else if ($item['end_time'] > time() && $item['start_time'] < time()) {
  80. $item['lottery_status'] = '进行中';
  81. }
  82. }
  83. } else $item['lottery_status'] = '已结束';
  84. $item['start_time'] = $item['start_time'] ? date('Y-m-d H:i:s', $item['start_time']) : '';
  85. $item['end_time'] = $item['end_time'] ? date('Y-m-d H:i:s', $item['end_time']) : '';
  86. }
  87. $count = $this->dao->count($where);
  88. return compact('list', 'count');
  89. }
  90. /**
  91. * 获取抽奖详情
  92. * @param int $id
  93. * @return array|\think\Model
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\DbException
  96. * @throws \think\db\exception\ModelNotFoundException
  97. */
  98. public function getlotteryInfo(int $id)
  99. {
  100. $lottery = $this->dao->getLottery($id, '*', ['prize']);
  101. if (!$lottery) {
  102. throw new ValidateException('活动不存在或已删除');
  103. }
  104. $lottery = $lottery->toArray();
  105. if (isset($lottery['prize']) && $lottery['prize']) {
  106. $products = $coupons = [];
  107. $product_ids = array_unique(array_column($lottery['prize'], 'product_id'));
  108. $coupon_ids = array_unique(array_column($lottery['prize'], 'coupon_id'));
  109. /** @var StoreProductServices $productServices */
  110. $productServices = app()->make(StoreProductServices::class);
  111. $products = $productServices->getColumn([['id', 'in', $product_ids]], 'id,store_name,image', 'id');
  112. /** @var StoreCouponIssueServices $couponServices */
  113. $couponServices = app()->make(StoreCouponIssueServices::class);
  114. $coupons = $couponServices->getColumn([['id', 'in', $coupon_ids]], 'id,coupon_title', 'id');
  115. foreach ($lottery['prize'] as &$prize) {
  116. $prize['coupon_title'] = $prize['goods_image'] = '';
  117. if ($prize['type'] == 6) {
  118. $prize['goods_image'] = $products[$prize['product_id']]['image'] ?? '';
  119. }
  120. if ($prize['type'] == 5) {
  121. $prize['coupon_title'] = $coupons[$prize['coupon_id']]['coupon_title'] ?? '';
  122. }
  123. }
  124. }
  125. return $lottery;
  126. }
  127. /**
  128. * 添加抽奖活动以及奖品
  129. * @param array $data
  130. * @return mixed
  131. */
  132. public function add(array $data)
  133. {
  134. $prizes = $data['prize'];
  135. $prize_num = $this->lottery_type[1];
  136. if (count($prizes) != $prize_num) {
  137. throw new ValidateException('请选择' . $prize_num . '个奖品');
  138. }
  139. unset($data['prize']);
  140. return $this->transaction(function () use ($data, $prizes) {
  141. $time = time();
  142. $data['add_time'] = $time;
  143. if (!$lottery = $this->dao->save($data)) {
  144. throw new ValidateException('添加抽奖活动失败');
  145. }
  146. if ($data['status']) {
  147. $this->setStatus((int)$lottery->id, $data['status']);
  148. }
  149. /** @var LuckPrizeServices $luckPrizeServices */
  150. $luckPrizeServices = app()->make(LuckPrizeServices::class);
  151. $data = [];
  152. $sort = 1;
  153. foreach ($prizes as $prize) {
  154. $prize = $luckPrizeServices->checkPrizeData($prize);
  155. $prize['lottery_id'] = $lottery->id;
  156. unset($prize['id']);
  157. $prize['add_time'] = $time;
  158. $prize['sort'] = $sort;
  159. $data[] = $prize;
  160. $sort++;
  161. }
  162. if (!$luckPrizeServices->saveAll($data)) {
  163. throw new ValidateException('添加抽奖奖品失败');
  164. }
  165. return true;
  166. });
  167. }
  168. /**
  169. * 修改抽奖活动以及奖品
  170. * @param int $id
  171. * @param array $data
  172. * @return mixed
  173. * @throws \think\db\exception\DataNotFoundException
  174. * @throws \think\db\exception\DbException
  175. * @throws \think\db\exception\ModelNotFoundException
  176. */
  177. public function edit(int $id, array $data)
  178. {
  179. $lottery = $this->dao->getLottery($id);
  180. if (!$lottery) {
  181. throw new ValidateException('抽奖活动不存在');
  182. }
  183. if ($lottery['status'] && (($lottery['start_time'] == 0 && $lottery['end_time'] == 0) || ($lottery['start_time'] <= time() && $lottery['end_time'] >= time()))) {
  184. throw new ValidateException('活动正在进行中,暂不支持编辑');
  185. }
  186. $newPrizes = $data['prize'];
  187. unset($data['prize'], $data['id']);
  188. $prize_num = $this->lottery_type[1];
  189. if (count($newPrizes) != $prize_num) {
  190. throw new ValidateException('请选择' . $prize_num . '个奖品');
  191. }
  192. /** @var LuckPrizeServices $luckPrizeServices */
  193. $luckPrizeServices = app()->make(LuckPrizeServices::class);
  194. $prizes = $luckPrizeServices->getLotteryPrizeList($id);
  195. return $this->transaction(function () use ($id, $lottery, $data, $newPrizes, $prizes, $luckPrizeServices) {
  196. $updateIds = array_column($newPrizes, 'id');
  197. $oldIds = array_column($prizes, 'id');
  198. $delIds = array_merge(array_diff($oldIds, $updateIds));
  199. $insert = [];
  200. $time = time();
  201. $sort = 1;
  202. foreach ($newPrizes as $prize) {
  203. $prize = $luckPrizeServices->checkPrizeData($prize);
  204. $prize['sort'] = $sort;
  205. if (isset($prize['id']) && $prize['id']) {
  206. if (!$prize['lottery_id']) {
  207. throw new ValidateException('缺少活动ID');
  208. }
  209. if (!$luckPrizeServices->update($prize['id'], $prize, 'id')) {
  210. throw new ValidateException('修改奖品失败');
  211. }
  212. } else {
  213. unset($prize['id']);
  214. $prize['lottery_id'] = $id;
  215. $prize['add_time'] = $time;
  216. $prize['sort'] = $sort;
  217. $insert[] = $prize;
  218. }
  219. $sort++;
  220. }
  221. if ($insert) {
  222. if (!$luckPrizeServices->saveAll($insert)) {
  223. throw new ValidateException('新增奖品失败');
  224. }
  225. }
  226. if ($delIds) {
  227. if (!$luckPrizeServices->update([['id', 'in', $delIds]], ['is_del' => 1])) {
  228. throw new ValidateException('删除奖品失败');
  229. }
  230. }
  231. if (!$this->dao->update($id, $data)) {
  232. throw new ValidateException('修改失败');
  233. }
  234. //上架
  235. if (!$lottery['status'] && $data['status']) {
  236. $this->setStatus($id, $data['status']);
  237. }
  238. return true;
  239. });
  240. }
  241. /**
  242. * 获取用户某个抽奖活动剩余抽奖次数
  243. * @param int $uid
  244. * @param int $lottery_id
  245. * @param array $userInfo
  246. * @param array $lottery
  247. * @return false|float|int|mixed
  248. * @throws \Psr\SimpleCache\InvalidArgumentException
  249. * @throws \think\db\exception\DataNotFoundException
  250. * @throws \think\db\exception\DbException
  251. * @throws \think\db\exception\ModelNotFoundException
  252. */
  253. public function getLotteryNum(int $uid, int $lottery_id, array $userInfo = [], array $lottery = [])
  254. {
  255. /** @var UserServices $userServices */
  256. $userServices = app()->make(UserServices::class);
  257. if (!$userInfo) {
  258. $userInfo = $userServices->getUserInfo($uid);
  259. }
  260. if (!$userInfo) {
  261. throw new ValidateException('用户不存在');
  262. }
  263. if (!$lottery) {
  264. $lottery = $this->dao->getLottery($lottery_id, '*', [], true);
  265. }
  266. if (!$lottery) {
  267. throw new ValidateException('该活动已经下架,请持续关注');
  268. }
  269. //抽奖类型:1:积分2:余额3:下单支付成功4:订单评价5:拉新人
  270. switch ($lottery['factor']) {
  271. case 1:
  272. return $userInfo['integral'] > 0 && $lottery['factor_num'] > 0 ? floor($userInfo['integral'] / $lottery['factor_num']) : 0;
  273. break;
  274. case 2:
  275. return $userInfo['now_money'] > 0 && $lottery['factor_num'] > 0 ? floor($userInfo['now_money'] / $lottery['factor_num']) : 0;
  276. break;
  277. case 3:
  278. return $this->getCacheLotteryNum($uid, 'order');
  279. break;
  280. case 4:
  281. return $this->getCacheLotteryNum($uid, 'comment');
  282. break;
  283. case 5:
  284. return $userInfo['spread_lottery'] ?? 0;
  285. break;
  286. default:
  287. throw new ValidateException('暂未有该类型活动');
  288. break;
  289. }
  290. }
  291. /**
  292. * 验证用户抽奖资格(用户等级、付费会员、用户标签)
  293. * @param int $uid
  294. * @param int $lottery_id
  295. * @param array $userInfo
  296. * @param array $lottery
  297. * @return bool
  298. * @throws \think\db\exception\DataNotFoundException
  299. * @throws \think\db\exception\DbException
  300. * @throws \think\db\exception\ModelNotFoundException
  301. */
  302. public function checkoutUserAuth(int $uid, int $lottery_id, array $userInfo = [], array $lottery = [])
  303. {
  304. if (!$userInfo) {
  305. /** @var UserServices $userServices */
  306. $userServices = app()->make(UserServices::class);
  307. $userInfo = $userServices->getUserInfo($uid);
  308. }
  309. if (!$userInfo) {
  310. throw new ValidateException('用户不存在');
  311. }
  312. if (!$lottery) {
  313. $lottery = $this->dao->getLottery($lottery_id, '*', [], true);
  314. }
  315. if (!$lottery) {
  316. throw new ValidateException('该活动已经下架,请持续关注');
  317. }
  318. //部分用户参与
  319. if ($lottery['attends_user'] == 2) {
  320. //用户等级
  321. if ($lottery['user_level'] && !in_array($userInfo['level'], $lottery['user_level'])) {
  322. throw new ValidateException('您暂时无法参与该活动');
  323. }
  324. //用户标签
  325. if ($lottery['user_label']) {
  326. /** @var UserLabelRelationServices $userlableRelation */
  327. $userlableRelation = app()->make(UserLabelRelationServices::class);
  328. $user_labels = $userlableRelation->getUserLabels($uid);
  329. if (!array_intersect($lottery['user_label'], $user_labels)) {
  330. throw new ValidateException('您暂时无法参与该活动');
  331. }
  332. }
  333. //是否是付费会员
  334. if ($lottery['is_svip'] != -1) {
  335. if (($lottery['is_svip'] == 1 && $userInfo['is_money_level'] <= 0) || ($lottery['is_svip'] == 0 && $userInfo['is_money_level'] > 0)) {
  336. throw new ValidateException('您暂时无法参与该活动');
  337. }
  338. }
  339. }
  340. return true;
  341. }
  342. /**
  343. * 抽奖
  344. * @param int $uid
  345. * @param int $lottery_id
  346. */
  347. public function luckLottery(int $uid, int $lottery_id)
  348. {
  349. /** @var UserServices $userServices */
  350. $userServices = app()->make(UserServices::class);
  351. $userInfo = $userServices->getUserInfo($uid);
  352. if (!$userInfo) {
  353. throw new ValidateException('用户不存在');
  354. }
  355. $lottery = $this->dao->getLottery($lottery_id, '*', [], true);
  356. if (!$lottery) {
  357. throw new ValidateException('该活动已经下架,请持续关注');
  358. }
  359. $userInfo = $userInfo->toArray();
  360. $lottery = $lottery->toArray();
  361. //验证用户身份
  362. $this->checkoutUserAuth($uid, $lottery_id, $userInfo, $lottery);
  363. /** @var LuckPrizeServices $lotteryPrizeServices */
  364. $lotteryPrizeServices = app()->make(LuckPrizeServices::class);
  365. $lotteryPrize = $lotteryPrizeServices->getPrizeList($lottery_id);
  366. if (!$lotteryPrize) {
  367. throw new ValidateException('该活动状态有误,请联系管理员');
  368. }
  369. if ($this->getLotteryNum($uid, $lottery_id, $userInfo, $lottery) < 1) {
  370. //抽奖类型:1:积分2:余额3:下单支付成功4:订单评价5:拉新人
  371. switch ($lottery['factor']) {
  372. case 1:
  373. throw new ValidateException('积分不足,没有更多抽奖次数');
  374. break;
  375. case 2:
  376. throw new ValidateException('余额不足,没有更多抽奖次数');
  377. break;
  378. case 3:
  379. throw new ValidateException('购买商品之后获得更多抽奖次数');
  380. break;
  381. case 4:
  382. throw new ValidateException('订单完成评价之后获得更多抽奖次数');
  383. break;
  384. case 5:
  385. throw new ValidateException('邀请更多好友获取抽奖次数');
  386. break;
  387. default:
  388. throw new ValidateException('暂未有该类型活动');
  389. break;
  390. }
  391. }
  392. return $this->transaction(function () use ($uid, $lotteryPrize, $userInfo, $lottery) {
  393. /** @var LuckPrizeServices $luckPrizeServices */
  394. $luckPrizeServices = app()->make(LuckPrizeServices::class);
  395. //随机抽奖
  396. $prize = $luckPrizeServices->getLuckPrize($lotteryPrize);
  397. if (!$prize) {
  398. throw new ValidateException('该活动状态有误,请联系管理员');
  399. }
  400. //中奖扣除积分、余额
  401. $this->lotteryFactor($uid, $userInfo, $lottery);
  402. //中奖减少奖品数量
  403. $luckPrizeServices->decPrizeNum($prize['id'], $prize);
  404. /** @var LuckLotteryRecordServices $lotteryRecordServices */
  405. $lotteryRecordServices = app()->make(LuckLotteryRecordServices::class);
  406. //中奖写入记录
  407. $record = $lotteryRecordServices->insertPrizeRecord($uid, $prize, $userInfo);
  408. //不是站内商品直接领奖
  409. if ($prize['type'] != 6) {
  410. $lotteryRecordServices->receivePrize($uid, (int)$record->id);
  411. }
  412. $prize['lottery_record_id'] = $record->id;
  413. return $prize;
  414. });
  415. }
  416. /**
  417. * 抽奖消耗扣除用户积分、余额等
  418. * @param int $uid
  419. * @param array $userInfo
  420. * @param array $lottery
  421. * @return bool
  422. * @throws \Psr\SimpleCache\InvalidArgumentException
  423. */
  424. public function lotteryFactor(int $uid, array $userInfo, array $lottery)
  425. {
  426. if (!$userInfo || !$lottery) {
  427. return true;
  428. }
  429. //抽奖类型:1:积分2:余额3:下单支付成功4:订单评价5:拉新人
  430. switch ($lottery['factor']) {
  431. case 1:
  432. if ($userInfo['integral'] > $lottery['factor_num']) {
  433. $integral = bcsub((string)$userInfo['integral'], (string)$lottery['factor_num'], 0);
  434. } else {
  435. $integral = 0;
  436. }
  437. /** @var UserServices $userServices */
  438. $userServices = app()->make(UserServices::class);
  439. /** @var UserBillServices $userBillServices */
  440. $userBillServices = app()->make(UserBillServices::class);
  441. $userBillServices->income('lottery_use_integral', $uid, $lottery['factor_num'], $userInfo['integral'], $lottery['id']);
  442. if (!$userServices->update($uid, ['integral' => $integral], 'uid')) {
  443. throw new ValidateException('抽奖扣除用户积分失败');
  444. }
  445. break;
  446. case 2:
  447. if ($userInfo['now_money'] > $lottery['factor_num']) {
  448. $now_money = bcsub((string)$userInfo['now_money'], (string)$lottery['factor_num'], 2);
  449. } else {
  450. $now_money = 0;
  451. }
  452. /** @var UserServices $userServices */
  453. $userServices = app()->make(UserServices::class);
  454. /** @var UserBillServices $userBillServices */
  455. $userBillServices = app()->make(UserBillServices::class);
  456. $userBillServices->income('lottery_use_money', $uid, $lottery['factor_num'], $userInfo['now_money'], $lottery['id']);
  457. if (!$userServices->update($uid, ['now_money' => $now_money], 'uid')) {
  458. throw new ValidateException('抽奖扣除用户积分失败');
  459. }
  460. break;
  461. case 3:
  462. case 4:
  463. //销毁抽奖次数缓存
  464. $this->delCacheLotteryNum($uid, $lottery['factor'] == 3 ? 'order' : 'comment');
  465. break;
  466. case 5:
  467. /** @var UserServices $userServices */
  468. $userServices = app()->make(UserServices::class);
  469. $spread_lottery = 0;
  470. if ($userInfo['spread_lottery'] > 1) {
  471. $spread_lottery = $userInfo['spread_lottery'] - 1;
  472. }
  473. if (!$userServices->update($uid, ['spread_lottery' => $spread_lottery], 'uid')) {
  474. throw new ValidateException('抽奖扣除用户推广获取抽奖次数失败');
  475. }
  476. break;
  477. default:
  478. throw new ValidateException('暂未有该类型活动');
  479. break;
  480. }
  481. return true;
  482. }
  483. /**
  484. * 删除
  485. * @param int $id
  486. * @return bool
  487. * @throws \think\db\exception\DataNotFoundException
  488. * @throws \think\db\exception\DbException
  489. * @throws \think\db\exception\ModelNotFoundException
  490. */
  491. public function delLottery(int $id)
  492. {
  493. if ($lottery = $this->dao->getLottery($id)) {
  494. if (!$this->dao->update(['id' => $id], ['is_del' => 1])) {
  495. throw new AdminException('删除失败,请稍候重试');
  496. }
  497. }
  498. return true;
  499. }
  500. /**
  501. * 设置抽奖活动状态
  502. * @param int $id
  503. * @param $status
  504. * @return false|mixed
  505. * @throws \think\db\exception\DataNotFoundException
  506. * @throws \think\db\exception\DbException
  507. * @throws \think\db\exception\ModelNotFoundException
  508. */
  509. public function setStatus(int $id, $status)
  510. {
  511. if (!$id) return false;
  512. $lottery = $this->dao->getLottery($id, 'id,factor');
  513. if (!$lottery) {
  514. return false;
  515. }
  516. //每一种抽奖类型只有一个上架
  517. if ($status) {
  518. $this->dao->update(['factor' => $lottery['factor']], ['status' => 0]);
  519. }
  520. return $this->dao->update($id, ['status' => $status], 'id');
  521. }
  522. /**
  523. * 下单支付、评论缓存抽奖次数
  524. * @param int $uid
  525. * @param string $type
  526. * @return bool
  527. * @throws \Psr\SimpleCache\InvalidArgumentException
  528. */
  529. public function setCacheLotteryNum(int $uid, string $type = 'order')
  530. {
  531. $factor = $type == 'order' ? 3 : 4;
  532. $lottery = $this->dao->getFactorLottery($factor, 'id,factor_num');
  533. if (!$lottery || !$lottery['factor_num']) {
  534. return true;
  535. }
  536. $key = 'user_' . $type . '_luck_lottery_' . $uid;
  537. $cache = CacheService::redisHandler();
  538. return $cache->set($key, $lottery['factor_num'], 120);
  539. }
  540. /**
  541. * 取出下单支付、评论得到的抽奖此处
  542. * @param int $uid
  543. * @param string $type
  544. * @return int|mixed
  545. * @throws \Psr\SimpleCache\InvalidArgumentException
  546. */
  547. public function getCacheLotteryNum(int $uid, string $type = 'order')
  548. {
  549. $key = 'user_' . $type . '_luck_lottery_' . $uid;
  550. $num = CacheService::redisHandler()->get($key);
  551. return empty($num) ? 0 : $num;
  552. }
  553. /**
  554. * 抽奖之后销毁缓存
  555. * @param int $uid
  556. * @param string $type
  557. * @return bool
  558. * @throws \Psr\SimpleCache\InvalidArgumentException
  559. */
  560. public function delCacheLotteryNum(int $uid, string $type = 'order')
  561. {
  562. $key = 'user_' . $type . '_luck_lottery_' . $uid;
  563. $num = $this->getCacheLotteryNum($uid, $type);
  564. $cache = CacheService::redisHandler();
  565. if ($num > 1) {
  566. $cache->set($key, $num - 1, 120);
  567. } else {
  568. $cache->delete($key);
  569. }
  570. return true;
  571. }
  572. }