From be9d9522dd97f0d5aa7bcc119f311093e2a09252 Mon Sep 17 00:00:00 2001 From: "ZLW-PC\\Administrator" <374861669@qq.com> Date: Wed, 29 Nov 2017 17:31:35 +0800 Subject: [PATCH] order detail --- app/Common/Helper.php | 29 +++++++ app/Common/ReturnData.php | 6 +- app/Http/Controllers/Api/OrderController.php | 4 +- .../Controllers/Weixin/OrderController.php | 25 +++++- .../Controllers/Weixin/UserController.php | 2 +- app/Http/Model/BaseModel.php | 1 - app/Http/Model/Order.php | 75 +++++++++++++----- app/Http/Model/Region.php | 21 +---- .../views/weixin/goods/goodsDetail.blade.php | 1 - .../views/weixin/order/orderDetail.blade.php | 67 ++++++++++++++++ .../views/weixin/order/orderList.blade.php | 77 ++++++++----------- routes/web.php | 1 + 12 files changed, 217 insertions(+), 92 deletions(-) create mode 100644 resources/views/weixin/order/orderDetail.blade.php diff --git a/app/Common/Helper.php b/app/Common/Helper.php index aee723e..bbbc1b0 100644 --- a/app/Common/Helper.php +++ b/app/Common/Helper.php @@ -219,6 +219,25 @@ class Helper return false; } + /** + * 检查是否是POST请求 + */ + public static function isPostRequest() + { + if($_SERVER['REQUEST_METHOD'] == 'POST') return true; + if($_POST) return true; + + return false; + } + + /** + * 是否是GET提交的 + */ + public static function isGetRequest() + { + return $_SERVER['REQUEST_METHOD'] == 'GET' ? true : false; + } + /** * 301跳转。 * Header 301 Moved Permanently. @@ -286,4 +305,14 @@ class Helper return false; } + + //判断是不是https + public static function isHttpsRequest() + { + if((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) return true; + + if($_SERVER['SERVER_PORT'] == 443) return true; + + return false; + } } \ No newline at end of file diff --git a/app/Common/ReturnData.php b/app/Common/ReturnData.php index 2380144..93c07cd 100644 --- a/app/Common/ReturnData.php +++ b/app/Common/ReturnData.php @@ -97,7 +97,7 @@ class ReturnData //验证码 8801 =>'验证码无效', ); - + public static function create($code, $data = null, $msg = '') { if (empty($msg) && isset(self::$codeTexts[$code])) @@ -107,7 +107,7 @@ class ReturnData return array('code' => $code, 'msg' => $msg, 'data' => $data); } - + public static function success($data = null, $msg = '') { if (empty($msg) && isset(self::$codeTexts[self::SUCCESS])) @@ -117,7 +117,7 @@ class ReturnData return array('code' => self::SUCCESS, 'msg' => $msg, 'data' => $data); } - + public static function error($code, $data = null, $msg = '') { if (empty($msg) && isset(self::$codeTexts[$code])) diff --git a/app/Http/Controllers/Api/OrderController.php b/app/Http/Controllers/Api/OrderController.php index 75f283c..2cb2213 100644 --- a/app/Http/Controllers/Api/OrderController.php +++ b/app/Http/Controllers/Api/OrderController.php @@ -30,13 +30,15 @@ class OrderController extends CommonController //参数 $data['user_id'] = Token::$uid; $data['order_id'] = $request->input('order_id',''); + if($request->input('order_status','') != ''){$data['order_status'] = $request->input('order_status');} + if($request->input('pay_status','') != ''){$data['pay_status'] = $request->input('pay_status');} if($data['order_id']=='') { return ReturnData::create(ReturnData::PARAMS_ERROR); } - return Order::getUnpaidOrder($data); + return Order::getOne($data); } //生成订单 diff --git a/app/Http/Controllers/Weixin/OrderController.php b/app/Http/Controllers/Weixin/OrderController.php index f340c6e..ba6dd80 100644 --- a/app/Http/Controllers/Weixin/OrderController.php +++ b/app/Http/Controllers/Weixin/OrderController.php @@ -55,6 +55,23 @@ class OrderController extends CommonController return view('weixin.order.orderList', $data); } + + //订单详情 + public function orderDetail(Request $request) + { + $id = $request->input('id',''); + + $postdata = array( + 'order_id' => $id, + 'access_token' => $_SESSION['weixin_user_info']['access_token'] + ); + $url = env('APP_API_URL')."/order_detail"; + $res = curl_request($url,$postdata,'GET'); + $data['post'] = $res['data']; + if(empty($data['post'])){$this->error_jump('订单不存在');} + + return view('weixin.order.orderDetail', $data); + } //订单支付 public function pay($id) @@ -62,6 +79,8 @@ class OrderController extends CommonController //获取订单详情 $postdata = array( 'order_id' => $id, //要支付的订单id + 'order_status' => 0, + 'pay_status' => 0, 'access_token' => $_SESSION['weixin_user_info']['access_token'] ); $url = env('APP_API_URL')."/order_detail"; @@ -69,7 +88,7 @@ class OrderController extends CommonController $data['order_detail'] = $res['data']; $data['order_id'] = $id; - /* if(!$res['code']!=0){$this->error_jump('订单不存在或已过期');} */ + if($res['code']!=0 || empty($data['order_detail'])){$this->error_jump('订单不存在或已过期');} //获取会员信息 $postdata = array( @@ -126,6 +145,8 @@ class OrderController extends CommonController //获取订单详情 $postdata = array( 'order_id' => $order_id, //要支付的订单id + 'order_status' => 0, + 'pay_status' => 0, 'access_token' => $_SESSION['weixin_user_info']['access_token'] ); $url = env('APP_API_URL')."/order_detail"; @@ -133,7 +154,7 @@ class OrderController extends CommonController $data['order_detail'] = $res['data']; $data['order_id'] = $order_id; - if(!$res['code']!=0){$this->error_jump('订单不存在或已过期');} + if($res['code']!=0){$this->error_jump('订单不存在或已过期');} //微信支付-start require_once(resource_path('org/wxpay/WxPayConfig.php')); // 导入微信配置类 diff --git a/app/Http/Controllers/Weixin/UserController.php b/app/Http/Controllers/Weixin/UserController.php index c2795de..1f0b189 100644 --- a/app/Http/Controllers/Weixin/UserController.php +++ b/app/Http/Controllers/Weixin/UserController.php @@ -379,7 +379,7 @@ class UserController extends CommonController { $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; $callback_url = $http_type . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; //回调地址,当前页面 - //-------生成唯一随机串防CSRF攻击 + //生成唯一随机串防CSRF攻击 $state = md5(uniqid(rand(), true)); $_SESSION['weixin_oauth']['state'] = $state; //存到SESSION $authorize_url = $wechat_auth->get_authorize_url($callback_url, $state); diff --git a/app/Http/Model/BaseModel.php b/app/Http/Model/BaseModel.php index 8862d4a..000c9ce 100644 --- a/app/Http/Model/BaseModel.php +++ b/app/Http/Model/BaseModel.php @@ -1,6 +1,5 @@ 0) { - $res['list'] = $model->skip($offset)->take($limit)->get(); + $order_list = $model->skip($offset)->take($limit)->get(); - if($res['list']) + if($order_list) { - foreach($res['list'] as $k=>$v) + foreach($order_list as $k=>$v) { + $order_list[$k]['order_status_text'] = self::getOrderStatusText($v); + $order_goods = OrderGoods::where(array('order_id'=>$v['id']))->get(); - $res[$k]['goods_list'] = $order_goods; + $order_list[$k]['goods_list'] = $order_goods; } } + + $res['list'] = $order_list; } return ReturnData::create(ReturnData::SUCCESS,$res); } - public static function getOne($where) + public static function getOne(array $param) { - $goods = self::where($where)->first(); + extract($param); + + $where['id'] = $order_id; + $where['user_id'] = $user_id; + + if(isset($order_status)){$where['order_status'] = $order_status;} + if(isset($pay_status)){$where['pay_status'] = $pay_status;} + + $res = self::where($where)->first(); + + if(!$res) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + $res['order_status_text'] = self::getOrderStatusText($res); - return $goods; + $res['province_name'] = Region::getRegionName($res['province']); + $res['city_name'] = Region::getRegionName($res['city']); + $res['district_name'] = Region::getRegionName($res['district']); + + $order_goods = OrderGoods::where(array('order_id'=>$res['id']))->get(); + $res['goods_list'] = $order_goods; + + return ReturnData::create(ReturnData::SUCCESS,$res); } //生成订单 @@ -96,7 +122,7 @@ class Order extends BaseModel //获取订单商品列表 $cartCheckoutGoods = Cart::cartCheckoutGoodsList(array('ids'=>$cartids,'user_id'=>$user_id)); $order_goods = $cartCheckoutGoods['data']; - if(!$order_goods['list']){return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'订单商品不存在');} + if(empty($order_goods['list'])){return ReturnData::create(ReturnData::SYSTEM_FAIL,null,'订单商品不存在');} //获取收货地址 $user_address = UserAddress::getOne($user_id,$default_address_id); @@ -213,18 +239,31 @@ class Order extends BaseModel return true; } - //获取未支付的订单详情 - public static function getUnpaidOrder(array $param) + //获取订单状态文字,1待付款,2待发货,3待收货,4待评价(确认收货,交易成功),5退款/售后 + public static function getOrderStatusText($where) { - extract($param); - - $res = self::where(array('id'=>$order_id,'order_status'=>0,'pay_status'=>0,'user_id'=>$user_id))->select('id', 'order_sn', 'user_id', 'add_time', 'order_amount')->first(); - - if(!$res) + $res = ''; + if($where['order_status'] == 0 && $where['pay_status'] ==0) { - return ReturnData::create(ReturnData::SYSTEM_FAIL,null,''); + $res = '待付款'; + } + elseif($where['order_status'] == 0 && $where['shipping_status'] == 0 && $where['pay_status'] == 1) + { + $res = '待发货'; + } + elseif($where['order_status'] == 0 && $where['refund_status'] == 0 && $where['shipping_status'] == 1 && $where['pay_status'] == 1) + { + $res = '待收货'; + } + elseif($where['order_status'] == 3 && $where['refund_status'] == 0 && $where['shipping_status'] == 2 && $where['is_comment'] == 0) + { + $res = '交易成功'; + } + elseif($where['order_status'] == 3 && $where['refund_status'] == 1) + { + $res = '售后'; } - return ReturnData::create(ReturnData::SUCCESS,$res); + return $res; } } \ No newline at end of file diff --git a/app/Http/Model/Region.php b/app/Http/Model/Region.php index 043078a..d204286 100644 --- a/app/Http/Model/Region.php +++ b/app/Http/Model/Region.php @@ -1,9 +1,6 @@ value('name'); - if (!empty($res)) - { - return $res; - } - - return ''; + return self::where('id', $id)->value('name'); } public static function getList($parent_id=86) @@ -31,12 +22,6 @@ class Region extends BaseModel public static function getOne($id) { - $res = self::where('id', $id)->first(); - if (!empty($res)) - { - return $res; - } - - return false; + return self::where('id', $id)->first(); } } \ No newline at end of file diff --git a/resources/views/weixin/goods/goodsDetail.blade.php b/resources/views/weixin/goods/goodsDetail.blade.php index dc4e89c..80b39c3 100644 --- a/resources/views/weixin/goods/goodsDetail.blade.php +++ b/resources/views/weixin/goods/goodsDetail.blade.php @@ -57,7 +57,6 @@ var swiper = new Swiper('.swiper-container', { 门店有售 -
diff --git a/resources/views/weixin/order/orderDetail.blade.php b/resources/views/weixin/order/orderDetail.blade.php new file mode 100644 index 0000000..8dfb260 --- /dev/null +++ b/resources/views/weixin/order/orderDetail.blade.php @@ -0,0 +1,67 @@ + +订单详情 + + + + +
+
返回
+
订单详情
+ +
+ +@include('weixin.common.headerNav') + +
+

+

+ +
+ + + +
+
订单商品
+ + +

合计: ¥ (含运费:¥)

+ +
+ + + +
+

创建时间:

+

订单编号:

+
+ + +@include('weixin.common.footer') + \ No newline at end of file diff --git a/resources/views/weixin/order/orderList.blade.php b/resources/views/weixin/order/orderList.blade.php index fc3d5ac..4ad1795 100644 --- a/resources/views/weixin/order/orderList.blade.php +++ b/resources/views/weixin/order/orderList.blade.php @@ -2,7 +2,7 @@ 我的订单 - +
返回
我的订单
@@ -10,56 +10,39 @@
@include('weixin.common.headerNav') +$value){ ?> +
+ +
单号:
+
    +$v){ ?> +
  • + +

    x

    +
  • + +
+
-
-
- -
-

您的订单已成功生成,选择您想用的支付方式进行支付。

-
-

订单编号:

-

应付金额:¥

-
-
-

选择支付方式付款

-
- -
-

- -
- -
-

- -
-
-
-
- 确认支付 -
- 您可以在 我的订单 中查看或取消您的订单。
- 如果您现在不方便支付,可以随后到 我的订单完成支付,我们会在48小时内为您保留未支付的订单。 -
+

合计: ¥ (含运费:¥)

+
-
-
- + - @include('weixin.common.footer') \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 4fff23b..86a330d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -103,6 +103,7 @@ Route::group(['prefix' => 'weixin', 'namespace' => 'Weixin', 'middleware' => ['w Route::get('/order_pay/{id}', 'OrderController@pay')->name('weixin_order_pay'); //订单支付 Route::post('/order_dopay', 'OrderController@dopay')->name('weixin_order_dopay'); //订单支付 Route::get('/order_list', 'OrderController@orderList')->name('weixin_order_list'); //全部订单列表 + Route::get('/order_detail', 'OrderController@orderDetail')->name('weixin_order_detail'); //订单详情 Route::get('/order_wxpay', 'OrderController@orderWxpay')->name('weixin_order_wxpay'); //订单微信支付 Route::get('/order_yuepay', 'OrderController@orderYuepay')->name('weixin_order_yuepay'); //订单余额支付 //收货地址