dataLists(new RetailOrderList()); } public function order_count(){ $userId=$this->request->userId; $where=['uid'=>$userId,'paid'=>0]; $no_pay=Cashierclass::where($where)->count(); $where['paid']=1; $where['status']=0; $waiting=Cashierclass::where($where)->count(); $where['status']=1; $receiving=Cashierclass::where($where)->count(); return $this->success('ok',['no_pay'=>$no_pay,'waiting'=>$waiting,'receiving'=>$receiving]); } /** * @notes 检测零售订单 */ public function checkOrder(){ $cartId = (Array)$this->request->post('cart_id', []); $addressId = (int)$this->request->post('address_id'); $pay_type = (int)$this->request->post('pay_type'); $auth_code = $this->request->post('auth_code'); //微信支付条码 $params=$this->request->post(); $res=OrderLogic::cartIdByOrderInfo($cartId,$addressId,null,$params); if($res==false){ $msg=OrderLogic::getError(); if($msg=='购物车为空'){ return $this->data([]); } return $this->fail(OrderLogic::getError()); } return $this->data($res); } /** * @notes 创建零售订单 */ public function createOrder(){ // d(WeChatConfigService::getPayConfigByTerminal(1)); $user=User::where('id',$this->request->userId)->find(); $cartId = (Array)$this->request->post('cart_id', []); $mer_id = (Array)$this->request->post('mer_id', 0); if($mer_id<=0){ return $this->fail('自提点不能为空'); } if(count($cartId)>100){ return $this->fail('购物车商品不能超过100个'); } $addressId = (int)$this->request->post('address_id'); $pay_type = (int)$this->request->post('pay_type'); $auth_code = $this->request->post('auth_code'); //微信支付条码 $params=$this->request->post(); $order=OrderLogic::createOrder($cartId,$addressId,null,$params); if($order!=false){ if($pay_type==PayEnum::BALANCE_PAY){ $user=User::where('id',$this->request->userId)->find(); $res=RetailOrderLogic::payBalance($user,$order); if($res==true){ $res=RetailOrderLogic::paySuccess($order, ['money'=>$order['actual']]); if($res){ }else{ return $this->fail(RetailOrderLogic::getError()); } }else{ return $this->fail(RetailOrderLogic::getError()); } }elseif($pay_type==PayEnum::WECHAT_PAY){ $redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; $result = PaymentLogic::pay($pay_type,'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl); if (false === $result) { return $this->fail(PaymentLogic::getError(), $params); } return $this->success('', $result); } return $this->data(['order_id'=>$order->id]); }else{ return $this->fail(OrderLogic::getError()); } } /** * 重新支付 */ public function Repayment(){ $order_id = (int)$this->request->post('order_id'); $pay_type = (int)$this->request->post('pay_type'); $where=[ 'id'=>$order_id, 'uid'=>$this->userId, 'paid'=>0, ]; $order=Cashierclass::where($where)->find(); if($pay_type==PayEnum::BALANCE_PAY){ $user=User::where('id',$this->request->userId)->find(); $res=RetailOrderLogic::payBalance($user,$order); if($res==true){ $res=RetailOrderLogic::paySuccess($order, ['money'=>$order['actual']]); if($res){ }else{ return $this->fail(RetailOrderLogic::getError()); } }else{ return $this->fail(RetailOrderLogic::getError()); } } return $this->fail('支付失败'); } public function detail(){ $order_id = (int)$this->request->get('order_id'); $where=[ 'id'=>$order_id, 'uid'=>$this->userId, ]; $order=CashierclassLogic::detail($where); if($order){ return $this->data($order); }else{ return $this->fail('订单不存在'); } } /** * 获取用户常用购买记录 */ public function frequently_purchase(){ $params=$this->request->get(); $res=RetailOrderLogic::frequentlyPurchase($params); if($res==false){ return $this->fail(RetailOrderLogic::getError()); }else{ return $this->data($res); } } }