repository = $repository; if (!systemConfig('svip_switch_status')) throw new ValidateException('付费会员未开启'); } /** * TODO 会员卡类型列表 * @param GroupRepository $groupRepository * @param GroupDataRepository $groupDataRepository * @return \think\response\Json * @author Qinii * @day 2022/11/7 */ public function getTypeLst(GroupRepository $groupRepository,GroupDataRepository $groupDataRepository) { $group_id = $groupRepository->getSearch(['group_key' => 'svip_pay'])->value('group_id'); $where['group_id'] = $group_id; $where['status'] = 1; $list = $groupDataRepository->getSearch($where)->field('group_data_id,value,sort,status')->order('sort DESC')->select(); if ($this->request->isLogin() && $this->request->userInfo()->is_svip != -1) { foreach ($list as $item) { if ($item['value']['svip_type'] != 1) $res[] = $item; } } $list = $res ?? $list; $def = []; if ($list && isset($list[0])) { $def = $list[0] ? (['group_data_id' => $list[0]['group_data_id']] + $list[0]['value']) : []; } return app('json')->success(['def' => $def, 'list' => $list]); } /** * TODO 购买会员 * @param $id * @param GroupDataRepository $groupDataRepository * @param ServeOrderRepository $serveOrderRepository * @return \think\response\Json|void * @author Qinii * @day 2022/11/7 */ public function createOrder($id, GroupDataRepository $groupDataRepository, UserOrderRepository $userOrderRepository) { $params = $this->request->params(['pay_type','return_url','bind_mer_id','bind_staff_id']); if (!in_array($params['pay_type'], ['weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr'], true)) return app('json')->fail('请选择正确的支付方式'); $res = $groupDataRepository->getWhere(['group_data_id' => $id, 'status' => 1]); if (!$res) return app('json')->fail('参数有误~'); if ($this->request->userInfo()->is_svip == 3) return app('json')->fail('您已经是终身会员~'); if ($this->request->userInfo()->is_svip !== -1 && $res['value']['svip_type'] == 1) return app('json')->fail('请选择其他会员类型'); $params['is_app'] = $this->request->isApp(); return $userOrderRepository->add($res,$this->request->userInfo(),$params); } /** * TODO 会员中心个人信息 * @return \think\response\Json * @author Qinii * @day 2022/11/9 */ public function svipUserInfo() { if ($this->request->isLogin()) { $user = app()->make(UserRepository::class)->getSearch([])->field('uid,nickname,avatar,is_svip,svip_endtime,svip_save_money')->find($this->request->uid()); if ($user && $user['is_svip'] == 3) $user['svip_endtime'] = date('Y-m-d H:i:s',strtotime("+100 year")); } $data['user'] = $user ?? new \stdClass(); $data['interests'] = systemConfig('svip_switch_status') ? app()->make(MemberinterestsRepository::class)->getInterestsByLevel(MemberinterestsRepository::TYPE_SVIP) : []; return app('json')->success($data); } /** * TODO 获取会员优惠券列表 * @param StoreCouponRepository $couponRepository * @return \think\response\Json * @author Qinii * @day 2022/11/17 */ public function svipCoupon(StoreCouponRepository $couponRepository) { $where['send_type'] = $couponRepository::GET_COUPON_TYPE_SVIP; $uid = $this->request->isLogin() ? $this->request->uid() : null; $data = $couponRepository->sviplist($where, $uid); return app('json')->success($data); } /** * TODO 领取会员优惠券 * @param $id * @param StoreCouponRepository $couponRepository * @return \think\response\Json * @author Qinii * @day 2022/11/17 */ public function receiveCoupon($id, StoreCouponRepository $couponRepository) { if (!$this->request->userInfo()->is_svip) return app('json')->fail('您还不是付费会员'); if (!$couponRepository->exists($id)) return app('json')->fail('优惠券不存在'); try { $couponRepository->receiveSvipCounpon($id, $this->request->uid()); } catch (\Exception $e) { return app('json')->fail('优惠券已被领完'); } return app('json')->success('领取成功'); } /** * TODO 会员专属商品 * @param SpuRepository $spuRepository * @return \think\response\Json * @author Qinii * @day 2022/11/17 */ public function svipProductList(SpuRepository $spuRepository) { [$page, $limit] = $this->getPage(); $user = $this->request->isLogin() ? $this->request->userInfo() : null; if (systemConfig('svip_product_switch') || (isset($user->is_svip) && $user->is_svip > 0)){ $where['is_gift_bag'] = 0; $where['product_type'] = 0; $where['order'] = 'star'; $where['svip'] = 1; $data = $spuRepository->getApiSearch($where, $page, $limit, $user); } return app('json')->success($data ?? ['count' => 0,'list' => []]); } /** * Common: 会员卡兑换 * Author: wu-hui * Time: 2024/03/02 18:46 * @param GroupDataRepository $groupDataRepository * @param UserOrderRepository $userOrderRepository * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function vipExchangeCode(GroupDataRepository $groupDataRepository, UserOrderRepository $userOrderRepository){ // 参数获取 $exchangeCode = $this->request->param('exchange_code', ''); if(empty($exchangeCode)) throw new ValidateException('兑换码不存在!'); $user = $this->request->userInfo(); $uid = $this->request->uid(); // 获取兑换码信息 $exchangeCodeInfo = app()->make(VipExchangeCodeRepository::class) ->getSearchModel(['exchange_code'=>$exchangeCode]) ->findOrEmpty() ->toArray(); if(empty($exchangeCodeInfo)) throw new ValidateException('兑换码不存在!'); if($exchangeCodeInfo['status'] == 0) throw new ValidateException('兑换码未激活!'); if($exchangeCodeInfo['status'] == 2) throw new ValidateException('兑换码已被使用,请勿重复使用!'); if($exchangeCodeInfo['status'] == 3) throw new ValidateException('兑换码已作废!'); // 下单并且使用 $res = $groupDataRepository->getWhere(['group_data_id' => $exchangeCodeInfo['group_data_id'], 'status' => 1]); if (!$res) throw new ValidateException('会员卡不存在!'); if ($user->is_svip == 3) throw new ValidateException('您已经是终身会员!'); if ($user->is_svip !== -1 && $res['value']['svip_type'] == 1) throw new ValidateException('兑换失败,您已开通该类型会员!'); // 模拟下单 $params['pay_type'] = 'free'; $params['return_url'] = ''; $params['is_app'] = $this->request->isApp(); $params['bind_mer_id'] = $exchangeCodeInfo['mer_id'] ?? 0; $params['bind_staff_id'] = $exchangeCodeInfo['staff_id'] ?? 0; $params['exchange_code'] = $exchangeCode; $params['exchange_code_id'] = $exchangeCodeInfo['id']; $userOrderRepository->add($res, $user, $params); // 开通成功 修改信息 UserVipExchangeCode::where('id',$exchangeCodeInfo['id']) ->update([ 'status' => 2, 'use_time' => date("Y-m-d H:i:s",time()), 'use_user_id' => $uid ]); return app('json')->success(); } }