user = $this->getUserDetail(); // 用户信息 } /** * 获取当前用户信息 */ public function detail() { // 当前用户信息 $userInfo = $this->user; //优惠券数量 $couponCount = CouponUserModel::getUserCount($userInfo['user_id']); // 订单总数 $model = new OrderModel; $orderCount = [ 'payment' => $model->getOrderClassCount('payment',$this->shop_id,$userInfo['user_id']), 'comment' => $model->getOrderClassCount('comment',$this->shop_id,$userInfo['user_id']), 'refund10' => $model->getOrderClassCount('refund10',$this->shop_id,$userInfo['user_id']) ]; return $this->renderSuccess(compact('userInfo', 'orderCount','couponCount')); } /** * 开通会员 */ public function openVip() { $model = UserModel::get($this->user_id); if ($model->openVip()) { return $this->renderMsg('开通成功'); } $error = $model->getError() ?: '开通失败'; return $this->renderError($error); } /** * 购买会员 * $type 30=微信 40=支付宝 */ public function buyVip($money,$type=30) { $order_no = order_no(); $order = [ 'mode' => 20, //消费 'type' => $type,//支付类型 'order_no' => $order_no, 'money' => $money, 'remark' => '购买会员卡', 'user_id' => $this->user['user_id'], 'shop_id' => $this->shop_id, 'applet_id' => $this->applet_id ]; Cache::set($order_no, $order,7200); //H5支付 if($this->mp == 'h5'){ //微信 if($type == 30){ $wx = new WxPay(SettingModel::getItem('wxpay',$this->applet_id)); if(!$result = $wx->h5($order_no,$money,'api/food.notify/buyvip/appletid/'.$this->applet_id,'购买会员卡')){ return $this->renderError($wx->getError()); } } //支付宝 if($type == 40){ $alipay = new AlipayPay($this->applet_id); if(!$result = $alipay->tradeWapPay($order_no,$money,'api/food.notify/alipayBuyvip/appletid/'.$this->applet_id,'h5/food/#/pages/user/index','购买会员卡')){ $this->error = $alipay->getError(); return false; } } }else{ //微信小程序支付 if($type == 30){ $wx = new WxPay(SettingModel::getItem('wxpay',$this->applet_id)); if(!$result = $wx->jsapi($order_no,$money,$this->user['open_id'],'api/food.notify/buyvip/appletid/'.$this->applet_id,'购买会员卡')){ return $this->renderError($wx->getError()); } } //支付宝小程序支付 if($type == 40){ $alipay = new AlipayPay($this->applet_id); if(!$result = $alipay->tradeCreate($order_no,$money,$this->user['open_id'],'api/food.notify/alipayBuyvip/appletid/'.$this->applet_id,'购买会员卡')){ return $this->renderError($alipay->getError()); } } } return $this->renderSuccess($result); } }