user = $this->getUser(); // 用户信息 } /** * 修改收货地址 */ public function addressedit() { $data = $this->postData(); if (empty($data['order_id'])) { return $this->renderError('订单id为空'); } if (empty($data['address_id'])) { return $this->renderError('收货地址为空'); } $order = OrderModel::getUserOrderDetail($data['order_id'], $this->user['user_id']); if ($order['delivery_status']['value'] == 20) { return $this->renderError('该订单已发货,不允许修改'); } $useradd =(new UserAddress)->find($data['address_id']); if ($useradd['user_id'] != $this->user['user_id']) { return $this->renderError('收货地址信息错误'); } $vall = [ 'name' => $useradd['name'], 'phone' => $useradd['phone'], 'detail' => $useradd['detail'], 'province_id'=> $useradd['province_id'], 'city_id' => $useradd['city_id'], 'region_id' => $useradd['region_id'], ]; (new OrderAddress)->where('order_id',$order['order_id'])->update($vall); $this->user->where('user_id',$this->user['user_id'])->update(['address_id'=>$data['address_id']]); return $this->renderSuccess('修改成功'); } /** * 是否有未上传信息订单 */ public function borderorder() { $where = [ ['user_id','=',$this->user['user_id']], ['is_border','=',20], ['order_status','in',"10,30"], ['pay_status','=',20], ['real_name','=',null], ]; $order_id = (new OrderModel)->where($where)->value('order_id'); if (empty($order_id)) { $data = []; }else{ $data = ['order_id'=>$order_id]; } return $this->renderSuccess('查询成功',$data); } /** * 跨境信息上传 */ public function crossborder() { $data = $this->postData(); // $data = [ // 'order_id' => 1, // 'real_name' => '葛云龙', // 'idcard' => '23018419910505303X', // 'card_front' => 'http://192.168.18.9:8009/uploads/20220408/3759c7b39b77fc40575172e864fc4489.jpg', // 'card_back' => 'http://192.168.18.9:8009/uploads/20220407/7ea9db666a9a95dd1f54e2a42e0ac3ed.png', // ]; if (empty($data['order_id'])) { return $this->renderError('订单id为空'); } if (empty($data['real_name'])) { return $this->renderError('请填写收货人真实姓名'); } $order = OrderModel::getUserOrderDetail($data['order_id'], $this->user['user_id']); if (empty($order)) { return $this->renderError('订单信息错误'); } if (!empty($order['card_front'])) { return $this->renderError('该订单信息已上传'); } if ($order['address']['name'] != $data['real_name']) { return $this->renderError('收货人姓名信息错误'); } if (empty($data['idcard'])) { return $this->renderError('请填写身份证号码'); } $regIdCard = "/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/"; if (!Validate::regex($data['idcard'],$regIdCard)){ return $this->renderError('身份证号格式错误'); return false; } if (empty($data['card_front'])) { return $this->renderError('请上传身份证正面照'); } if (empty($data['card_back'])) { return $this->renderError('请上传身份证反面照'); } $vall = [ 'real_name' => $data['real_name'], 'idcard' => $data['idcard'], 'card_front' => $data['card_front'], 'card_back' => $data['card_back'], ]; if ((new OrderModel)->where('order_id',$order['order_id'])->update($vall)) { return $this->renderSuccess('信息上传成功'); } return $this->renderError('网络错误,请稍后再试'); } /** * 我的订单列表 */ public function lists($dataType) { $data = $this->postData(); $model = new OrderModel; $list = $model->getList($this->user['user_id'], $dataType, $data); $h5_alipay = Setting::getItem(SettingEnum::H5ALIPAY)['is_open']; return $this->renderSuccess('', compact('list', 'h5_alipay')); } /** * 订单详情信息 */ public function detail($order_id) { // 订单详情 $model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']); // 剩余支付时间 if($model['pay_status']['value'] == 10 && $model['order_status']['value'] != 20 && $model['pay_end_time'] != 0){ $model['pay_end_time'] = $this->formatPayEndTime($model['pay_end_time'] - time()); }else{ $model['pay_end_time'] = ''; } // 该订单是否允许申请售后 $model['isAllowRefund'] = $model->isAllowRefund(); $h5_alipay = Setting::getItem(SettingEnum::H5ALIPAY)['is_open']; return $this->renderSuccess('', [ 'order' => $model, // 订单详情 'setting' => [ // 积分名称 'points_name' => SettingModel::getPointsName(), ], 'h5_alipay' => $h5_alipay ]); } /** * 获取物流信息 */ public function express($order_id) { // 订单信息 $order = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']); if (!$order['express_no']) { return $this->renderError('没有物流信息'); } // 获取物流信息 $model = $order['express']; $express = $model->dynamic($model['express_name'], $model['express_code'], $order['express_no']); if ($express === false) { return $this->renderError($model->getError()); } return $this->renderSuccess('', compact('express')); } /** * 取消订单 */ public function cancel($order_id) { $model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']); if ($model->cancel($this->user)) { return $this->renderSuccess('订单取消成功'); } return $this->renderError($model->getError()?:'订单取消失败'); } /** * 确认收货 */ public function receipt($order_id) { $model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']); if ($model->receipt()) { return $this->renderSuccess('收货成功'); } return $this->renderError($model->getError()?:'收货失败'); } /** * 立即支付 */ public function pay($order_id, $payType = OrderPayTypeEnum::WECHAT, $pay_source = 'wx') { // 获取订单详情 $model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']); // 订单支付事件 if (!$model->onPay($payType, $pay_source)) { return $this->renderError($model->getError() ?: '订单支付失败'); } // 构建微信支付请求 $payment = $model->onOrderPayment($this->user, $model, $payType, $pay_source); // 支付状态提醒 return $this->renderSuccess('', [ 'order_id' => $model['order_id'], // 订单id 'pay_type' => $payType, // 支付方式 'payment' => $payment // 微信支付参数 ]); } /** * 获取订单核销二维码 */ public function qrcode($order_id, $source) { // 订单详情 $order = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']); // 判断是否为待核销订单 if (!$order->checkExtractOrder($order)) { return $this->renderError($order->getError()); } $Qrcode = new ExtractService( $this->app_id, $this->user, $order_id, $source, $order['order_no'] ); return $this->renderSuccess('',[ 'qrcode' => $Qrcode->getImage(), ]); } private function formatPayEndTime($leftTime){ if($leftTime <= 0){ return ''; } $str = ''; $day = floor($leftTime/86400); $hour = floor(($leftTime - $day * 86400)/3600); $min = floor((($leftTime - $day * 86400) - $hour * 3600)/60); if ($day > 0) $str .= $day . '天'; if ($hour > 0) $str .= $hour . '小时'; if ($min > 0) $str .= $min . '分钟'; return $str; } }