|
@@ -982,4 +982,39 @@ class Orders extends Api{
|
|
|
return json_send(['code'=>'error','msg'=>'取消失败','data'=>['error'=>$th->getMessage().$th->getLine()]]);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单详情 /api/orders/create
|
|
|
+ *
|
|
|
+ * @pamam int $id 订单ID
|
|
|
+ *
|
|
|
+ * */
|
|
|
+ public function get_detail( Request $request, Model $Model,OrdersProduct $OrdersProduct,Business $Business,OrdersAddr $OrdersAddr){
|
|
|
+ // 验证参数
|
|
|
+ $request->scene('get_detail')->validate();
|
|
|
+ // 接受参数
|
|
|
+ $id = request('id',0);
|
|
|
+ // 查询数据
|
|
|
+ $order = $Model->query()->find($id,['id','pay_total','status','price_total','coupon_total','business_id','pay_total','weizan_orderid','insert_time']);
|
|
|
+ // 查询不到订单
|
|
|
+ if( !$order ) return json_send(['code'=>'error','msg'=>'订单不存在']);
|
|
|
+ // 数据转换
|
|
|
+ $order = $order->toArray();
|
|
|
+ // id转编号
|
|
|
+ $order['insert_time'] = date('Y-m-d H:i:s',$order['insert_time']);
|
|
|
+ $order['business_name'] = (string) $Business->getOne($order['business_id'],'name');
|
|
|
+ $order['order_code'] = $Model->idToCode($order['id']);
|
|
|
+ $order['state'] = $Model->getState($order['status'],'state');
|
|
|
+ // 查询子订单数据
|
|
|
+ $order['order_items'] = $OrdersProduct->query()->where([['order_id','=',$id]])->select(['id as item_id','order_id','product_id','buy_num','pay_total','is_rebate','sku_attr_names as product_spec','product_name','product_thumb'])->get()->toArray();
|
|
|
+ // 处理缩略图
|
|
|
+ foreach ($order['order_items'] as $key => $value) {
|
|
|
+ $value['product_thumb'] = $value['product_thumb'] ? path_compat($value['product_thumb']) : '';
|
|
|
+ $order['order_items'][$key] = $value;
|
|
|
+ }
|
|
|
+ // 地址
|
|
|
+ $order['order_addr'] = $OrdersAddr->query()->where([['order_id','=',$id]])->first(['contact_area','contact_school','contact_grade','contact_class','contact_name','contact_phone']);
|
|
|
+ // 加载模板
|
|
|
+ return json_send(['code'=>'success','msg'=>'获取成功','data'=>$order]);
|
|
|
+ }
|
|
|
}
|