dataLists(new RetailOrderList()); } /** * 收银机对应的采购零售订单列表 */ public function merchant_order_list() { $number = $this->request->get('number'); $page_no = $this->request->get('page_no', 1); $date = $this->request->get('date', date('Y-m-d')); if(!$this->userInfo['merchant']['mer_id']){ return $this->fail('没有权限'); } $where=[]; if($number){ $where[] = ['number', 'like', '%' . $number . '%']; } $where[] = ['merchant', '=',$this->userInfo['merchant']['mer_id']]; $where[] = ['paid', '=',1]; $res = Cashierclass::where($where)->page($page_no, 25)->whereDay('create_time', $date) ->select()->each(function($item){ $item['goods_list']=Cashierinfo::where('pid',$item['id'])->with('goodsName')->field('goods,nums,price sell')->limit(5)->select(); $item['goods_count']=count(explode(',',$item['cart_id'])); }); $data['count'] = Cashierclass::where($where)->whereDay('create_time', $date)->count(); $data['lists'] = $res?->toArray(); $data['page_no'] = $page_no; $data['page_siz'] = 15; return $this->success('ok', $data); } 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); $pay_type = (int)$this->request->post('pay_type'); $addressId = (int)$this->request->post('address_id'); $auth_code = $this->request->post('auth_code'); //微信支付条码 $params = $this->request->post(); if ($mer_id <= 0 && $pay_type!=9) { return $this->fail('自提点不能为空'); } if (count($cartId) > 100) { return $this->fail('购物车商品不能超过100个'); } if($pay_type==9){ if(empty($this->request->userInfo['merchant'])){ return $this->fail('请先绑定商户'); } $mer_id=$this->request->userInfo['merchant']['mer_id']; $params['mer_id']=$mer_id; } $order = OrderLogic::createOrder($cartId, $addressId, null, $params); if ($order != false) { switch ($pay_type) { case PayEnum::BALANCE_PAY: //余额支付 $user = User::where('id', $this->request->userId)->find(); $res = RetailOrderLogic::payBalance($user, $order); if (RetailOrderLogic::hasError()) { return $this->fail(RetailOrderLogic::getError()); } else { $res = RetailOrderLogic::paySuccess($order, ['money' => $order['actual']]); if (RetailOrderLogic::hasError()) { return $this->fail(RetailOrderLogic::getError()); } return $this->success('余额支付成功'); } break; case PayEnum::WECHAT_PAY: //微信支付 $redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; $result = PaymentLogic::pay($pay_type, 'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl); if (PaymentLogic::hasError()) { return $this->fail(PaymentLogic::getError(), $params); } return $this->success('', $result); break; case PayEnum::WECHAT_PAY_BARCODE: //微信条码支付 $result = PaymentLogic::codepay($auth_code, $order); if (PaymentLogic::hasError()) { return $this->fail(PaymentLogic::getError(), $params); } if($result['trade_state_desc']=='支付成功'){ PayNotifyLogic::handle('cashierclass', $result['out_trade_no'], $result); } return $this->success('', $result); break; default: return $this->fail('支付方式错误'); } return $this->data(['order_id' => $order->id]); } else { return $this->fail(OrderLogic::getError()); } } /** * 重新支付 */ public function Repayment() { $order_id = (int)$this->request->post('order_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(); $where = [ 'id' => $order_id, 'uid' => $this->userId, 'paid' => 0, ]; $order = Cashierclass::where($where)->find(); if(!$order) return $this->fail('订单不存在或已支付'); switch ($pay_type) { case PayEnum::BALANCE_PAY: //余额支付 $user = User::where('id', $this->request->userId)->find(); $res = RetailOrderLogic::payBalance($user, $order); if (!RetailOrderLogic::hasError()) { $res = RetailOrderLogic::paySuccess($order, ['money' => $order['actual']]); if(RetailOrderLogic::hasError()){ return $this->fail(RetailOrderLogic::getError()); } return $this->success('余额支付成功'); }else{ return $this->fail(RetailOrderLogic::getError()); } break; case PayEnum::WECHAT_PAY: //微信支付 $redirectUrl = $params['redirect'] ?? '/pages/payment/payment'; if ($addressId != $order['address_id']) { $address = UserAddress::where(['address_id' => $addressId, 'uid' => Request()->userId])->find(); if ($address) { $_order['real_name'] = $address['real_name']; $_order['user_phone'] = $address['phone']; $_order['user_address'] = $address['detail']; $_order['address_id'] = $addressId; Cashierclass::where(['id' => $order_id, 'uid' => Request()->userId])->update($_order); } } $result = PaymentLogic::pay($pay_type, 'cashierclass', $order, $this->userInfo['terminal'], $redirectUrl); if (PaymentLogic::hasError()) { return $this->fail(PaymentLogic::getError()); } return $this->success('', $result); break; case PayEnum::WECHAT_PAY_BARCODE: //微信条码支付 $result = PaymentLogic::codepay($auth_code, $order); if (PaymentLogic::hasError()) { return $this->fail(PaymentLogic::getError(), $params); } if($result['trade_state_desc']=='支付成功'){ PayNotifyLogic::handle('cashierclass', $result['out_trade_no'], $result); } return $this->success('支付成功',['order_id'=>$order['order_id']]); break; default: return $this->fail('支付方式错误'); } 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 (RetailOrderLogic::hasError()) { return $this->fail(RetailOrderLogic::getError()); } else { return $this->data($res); } } /** * 取消订单 */ public function cancel_order() { $order_id = (int)$this->request->post('order_id'); $value = (int)$this->request->post('value'); $where = [ 'id' => $order_id, 'uid' => $this->userId, 'paid' => 0, ]; $order = Cashierclass::where($where)->find(); if ($order) { $data = ['data' => $value, 'delete_time' => time()]; Cashierclass::where($where)->update($data); return $this->success('取消成功'); } return $this->fail('取消失败'); } /** * 确认收货 */ public function confirm_receipt() { $order_id = (int)$this->request->post('order_id'); $where = [ 'id' => $order_id, 'uid' => $this->userId, 'paid' => 1, 'status' => 1, ]; $order = Cashierclass::where($where)->find(); if ($order) { $data = ['status' => 2]; Cashierclass::where($where)->update($data); return $this->success('确认成功'); } return $this->fail('确认失败'); } /** * 再次购买 */ public function purchase_again() { $order_id = (int)$this->request->get('order_id'); $res = RetailOrderLogic::purchaseAgain($order_id); if ($res == false) { return $this->fail('添加失败'); } else { return $this->success('添加成功'); } } }