day(1); // $month = $otj->month(); // $week = $otj->week(); // echo 'success'; // } /** * 会员专区 */ public function memberZone(){ $userId = UserService::getCurrentLoginUserId(); $info = User::detail(['user_id'=>$userId]); $data['duration'] = 1;//年卡 $data['curr_month'] = intval(date('m'));//年卡 $data['member_expire_time'] = $info['member_expire_time']>0?date('Y-m-d',$info['member_expire_time']):''; $data['gold_rice'] = $info['gold_rice']; $data['welfare'] = MemberWelfare::currMonthWelfare($userId); return $this->renderSuccess($data); } /** * 推荐商品 * @return array|\think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function vipGoodsList(){ $model = new GoodsModel; $list = $model->getList([],15,true); foreach ($list as &$item){ $dis = MemberGoods::where(['goods_id'=>$item['goods_id'],'status'=>0]) ->field('goods_id,discount')->find(); if ($dis){ //$t = helper::bcmul($item['goods_price_min'],$dis['discount'],3); //$item['member_goods_price'] = helper::bcadd(ceil($t)/100,0,2); $item['member_goods_dis_price'] = helper::bcsub($item['goods_price_min'],$item['member_price'],2); } } return $this->renderSuccess(compact('list')); } /** * 优惠券适用商品 * @return array|\think\response\Json * @throws \think\db\exception\DbException */ public function vipCouponGoodsList(){ $couponId = $this->request->get('coupon_id'); $model = new GoodsModel; $exGoodsId = CouponGood::getExceptGoodsId($couponId,1); $params['not_goods_id_arr'] = $exGoodsId; $list = $model->getList($params,15,false); return $this->renderSuccess(compact('list')); } /** * 会员开通记录 * @return array|\think\response\Json * @throws \app\common\exception\BaseException */ public function vipOpenRecords(){ $userId = UserService::getCurrentLoginUserId(); $list = MemberCardOrder::getList($userId); return $this->renderSuccess(compact('list')); } /** * 校验会员时效 * @return array|\think\response\Json * @throws \app\common\exception\BaseException */ public function checkMemberExpire(){ $user = UserService::getCurrentLoginUser(true); if ($user['member_expire_time'] - time() > 63072000){//大于两年 $end_date = date('Y-m-d',$user['member_expire_time']).'后方可进行续费操作'; return $this->renderError('您的会员有效期天数已达上限啦~',['hint'=>$end_date]); } return $this->renderSuccess(); } /** * 会员卡详情 * @return array|\think\response\Json */ public function memberCardInfo(){ $user = UserService::getCurrentLoginUser(); $member_status = 0; $expire_at = ''; if ($user){ if ($user['member_expire_time'] == 0){ $member_status = 0;//未开通 }elseif($user['member_expire_time'] < time()){ $member_status = 1;//已过期 }else{ $member_status = 2;//生效中 $expire_at = date('Y-m-d',$user['member_expire_time']); } } $card = MemberCards::findCard(); return $this->renderSuccess(compact('card','member_status','expire_at')); } /** * 金米粒收入/支出列表 * @param string $dataType in收入 out 支出 * @return array * @throws \app\common\exception\BaseException * @throws \think\db\exception\DbException * @author: zjwhust * @Time: 2022/6/7 11:58 */ public function listGoldRice(string $dataType = GoldRice::LIST_TYPE_IN) { $user = UserService::getCurrentLoginUser(); $model = new GoldRice; $param = []; $param['userId'] = $user['user_id']; $list = $model->getList($dataType,$param); return $this->renderSuccess(compact('list')); } /** * 领取福利 * @return array|\think\response\Json * @throws \app\common\exception\BaseException */ public function drawMemberWelfare(){ $user = UserService::getCurrentLoginUser(true); if ($user['member_expire_time'] < time()){ return $this->renderError('您的会员已过期'); } $id = $this->request->get('id'); $m = new MemberWelfareDraw(); $flag = $m->drawAction($id,$user); if ($flag){ return $this->renderSuccess(); } return $this->renderError($m->getError()); } /** * 福利领取记录 * @return array|\think\response\Json * @throws \app\common\exception\BaseException * @throws \think\db\exception\DbException */ public function myWelfareRecords(){ $user = UserService::getCurrentLoginUser(true); if ($user['member_expire_time'] < time()){ return $this->renderError('您的会员已过期'); } $m = new MemberWelfareDraw(); $list = $m->welfareRecords($user->user_id); return $this->renderSuccess(compact('list')); } /** * 我领取的福利详情 * @return array|\think\response\Json * @throws \app\common\exception\BaseException */ public function myWelfareDetail(){ $user = UserService::getCurrentLoginUser(true); $id = $this->request->get('id'); $m = new MemberWelfareDraw(); $list = $m->myWelfareDetail($id); if($user['user_id']!=$list['user_id']){ return $this->renderError('不是你的福利'); } //todo 需根据第三方接口联调更新 if($list['target_type']==2){ $list['hx_qrcode_url'] = url('/api/order/getHxWelQrcode',['id'=>$list['id']], true, true)->build(); } return $this->renderSuccess(compact('list')); } /** * 用户优惠券详情 * @param int $user_coupon_id * @return array|\think\response\Json */ public function VipCouponDetail(int $user_coupon_id){ $list = UserCoupon::showDetail($user_coupon_id); return $this->renderSuccess(compact('list')); } /** * v1.4.1开通/续费会员后的会员开通礼优惠券列表弹窗 * @author: zjwhust * @Time: 2022/6/24 14:44 */ public function vipRechargeCouponList(){ $list = (new Coupon)->getMemList(); return $this->renderSuccess(compact('list')); } /** * v1.4.1是否有待领取的会员开通礼 * @author: zjwhust * @Time: 2022/6/24 15:31 */ public function isReceive(){ $user = UserService::getCurrentLoginUser(true); $count = MemberCardOrder::where('user_id',$user['user_id']) ->where('pay_status',1) ->where('order_status',30) ->where('is_del',0) ->where('is_receive',0) ->count(); return $this->renderSuccess(compact('count')); } /** * v1.4.1领取会员开通礼 * @author: zjwhust * @Time: 2022/6/24 15:34 */ public function receive(){ $user = UserService::getCurrentLoginUser(true); if($user['member_expire_time']renderError('不是会员'); } $memberOrder = MemberCardOrder::where('user_id',$user['user_id']) ->where('pay_status',1) ->where('order_status',30) ->where('is_del',0) ->where('is_receive',0) ->select(); if(!$memberOrder){ return $this->renderError('您已领取,请在优惠券卡包查看'); } Db::startTrans(); try{ $list = (new Coupon)->getMemList(); foreach ($list as $coupon){ for ($i=0;$i<$coupon['limit_receive_cnt'];$i++){ $model = new UserCoupon(); $model->receiveLogin($coupon,$user); } } //会员订单修改为已处理 MemberCardOrder::where('id',$memberOrder[0]['id'])->update(['is_receive'=>1]); Db::commit(); return $this->renderSuccess('领取成功'); }catch (Exception $e) { Db::rollback(); return $this->renderError($e->getMessage()); } } /** * 异业门店核销详情接口 * @author: zjwhust * @Time: 2022/7/21 18:08 */ public function hxWelfareDetail($id){ // $id = $this->request->get('id'); $user = UserService::getCurrentLoginUser(true); $shop = Shops::find($user['shop_id']); if(!$shop || $shop['is_virtual']!=3){ return $this->renderError('不是异业门店,不能核销'); } $m = new MemberWelfareDraw(); $list = $m->myWelfareDetail($id); if($list['deploy_type']!=2){ return $this->renderError('不是自制券码'); } return $this->renderSuccess(compact('list')); } /** * 核销异业门店核销 * @author: zjwhust * @Time: 2022/7/21 18:14 */ public function hxWelfare($id){ $user = UserService::getCurrentLoginUser(true); $shop = Shops::find($user['shop_id']); if(!$shop || $shop['is_virtual']!=3){ return $this->renderError('不是异业门店,不能核销'); } $m = new MemberWelfareDraw(); $list = $m->myWelfareDetail($id); if($list['deploy_type']!=2){ return $this->renderError('不是自制券码'); } if($list['use_end_time']renderError('已过使用有效期'); } $list->check_status = 1; $list->check_time = date('Y-m-d H:i:s'); if($list->save()){ return $this->renderSuccess('核销成功'); } return $this->renderError('核销失败'); } }