修改API的物流显示模块
This commit is contained in:
parent
4355ab04ec
commit
5c4a04a042
@ -530,12 +530,25 @@ class Order extends Api
|
||||
* @author suny
|
||||
* @date 2021/7/13 6:12 下午
|
||||
*/
|
||||
// public function orderTraces()
|
||||
// {
|
||||
// $order_id = $this->request->get('id');
|
||||
// $tips = '参数错误';
|
||||
// if ($order_id) {
|
||||
// $traces = OrderLogic::orderTraces($order_id, $this->user_id);
|
||||
// if ($traces) {
|
||||
// return JsonServer::success('获取成功', $traces);
|
||||
// }
|
||||
// $tips = '暂无物流信息';
|
||||
// }
|
||||
// return JsonServer::error($tips);
|
||||
// }
|
||||
public function orderTraces()
|
||||
{
|
||||
$order_id = $this->request->get('id');
|
||||
$id = $this->request->get('id');
|
||||
$tips = '参数错误';
|
||||
if ($order_id) {
|
||||
$traces = OrderLogic::orderTraces($order_id, $this->user_id);
|
||||
if ($id) {
|
||||
$traces = OrderLogic::getExpress($id, $this->user_id);
|
||||
if ($traces) {
|
||||
return JsonServer::success('获取成功', $traces);
|
||||
}
|
||||
|
||||
@ -3398,4 +3398,135 @@ class OrderLogic extends Logic
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getExpress($id, $user_id)
|
||||
{
|
||||
$order_delivery = Delivery::where(['id' => $id])->field('order_id, invoice_no,shipping_name,shipping_id,mobile')->find();
|
||||
|
||||
$order = new Order();
|
||||
$order = $order->alias('o')
|
||||
->join('order_goods og', 'o.id = og.order_id')
|
||||
->join('goods g', 'g.id = og.goods_id')
|
||||
->where(['o.id' => $order_delivery['order_id'], 'o.user_id' => $user_id, 'pay_status' => OrderEnum::ORDER_STATUS_DELIVERY, 'o.del' => 0])
|
||||
->field('o.id,o.delivery_id,order_status,total_num,og.image,o.consignee,o.mobile,o.province,o.city,o.district,o.address,pay_time,confirm_take_time,o.shipping_status,shipping_time')
|
||||
->append(['delivery_address'])
|
||||
->find();
|
||||
|
||||
//初始化数据
|
||||
$order_tips = '已下单';
|
||||
$order_traces = [];
|
||||
$traces = [];//物流轨迹
|
||||
$shipment = [//发货
|
||||
'title' => '已发货',
|
||||
'tips' => '',
|
||||
'time' => '',
|
||||
];
|
||||
$finish = [//交易完成
|
||||
'title' => '交易完成',
|
||||
'tips' => '',
|
||||
'time' => '',
|
||||
];
|
||||
|
||||
if ($order) {
|
||||
$express = ConfigServer::get('express', 'way');
|
||||
|
||||
//已发货
|
||||
if ($express && $order['shipping_status']) {
|
||||
$result = Kd100Logic::expressDetail($id);
|
||||
if (!isset($result) || (time() > $result['sel_time'])) {
|
||||
$key = ConfigServer::get($express, 'appkey');
|
||||
$app = ConfigServer::get($express, 'appsecret');
|
||||
//获取物流配置
|
||||
if ($app && $key) {
|
||||
//快递配置设置为快递鸟时
|
||||
if ($express === 'kdniao') {
|
||||
$expressage = (new Kdniao($app, $key, Env::get('app.app_debug', 'true')));
|
||||
$shipping_field = 'codebird';
|
||||
} else {
|
||||
$expressage = (new Kd100($app, $key, Env::get('app.app_debug', 'true')));
|
||||
$shipping_field = 'code100';
|
||||
}
|
||||
//快递编码
|
||||
$shipping_code = Db::name('express')->where(['id' => $order_delivery['shipping_id']])->value($shipping_field);
|
||||
//获取物流轨迹
|
||||
if ($shipping_code === 'SF' && $express === 'kdniao') {
|
||||
$expressage->logistics($shipping_code, $order_delivery['invoice_no'], substr($order_delivery['mobile'],-4));
|
||||
}else {
|
||||
$phone = '';
|
||||
if ($shipping_code === 'shunfeng') {
|
||||
$phone = $order['mobile'];
|
||||
}
|
||||
|
||||
$expressage->logistics($shipping_code, $order_delivery['invoice_no'], $phone);
|
||||
}
|
||||
|
||||
$traces = $expressage->logisticsFormat();
|
||||
//获取不到物流轨迹时
|
||||
if ($traces == false) {
|
||||
$error = $expressage->getError();
|
||||
$error = json_decode($error,true);
|
||||
if ($express === 'kdniao') {
|
||||
if($error['Success'] == false){
|
||||
$traces[] = [$error['Reason']];
|
||||
}
|
||||
} else {
|
||||
if($error['result'] == false){
|
||||
$traces[] = [$error['message']];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($traces as &$item) {
|
||||
$item = array_values(array_unique($item));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$traces = json_decode($result['data'], true);
|
||||
foreach ($traces as &$item) {
|
||||
$item = array_values(array_unique($item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//待收货
|
||||
if ($order['order_status'] == 2) {
|
||||
$shipment['tips'] = '商品已出库';
|
||||
$shipment['time'] = date('Y-m-d H:i:s', $order['shipping_time']);
|
||||
}
|
||||
//确认收货
|
||||
if ($order['order_status'] == 3) {
|
||||
$order_tips = '交易完成';
|
||||
$finish['tips'] = '订单交易完成';
|
||||
$finish['time'] = $order['confirm_take_time'] ? date('Y-m-d H:i:s', $order['confirm_take_time']) : $order['confirm_take_time'];
|
||||
}
|
||||
//数据合并
|
||||
$order_traces = [
|
||||
'order' => [
|
||||
'tips' => $order_tips,
|
||||
'image' => UrlServer::getFileUrl($order['image']),
|
||||
'count' => $order['total_num'],
|
||||
'invoice_no' => $order_delivery['invoice_no'],
|
||||
'shipping_name' => empty($order_delivery['shipping_name']) ? '-' : $order_delivery['shipping_name'],
|
||||
],
|
||||
'take' => [
|
||||
'contacts' => $order['consignee'],
|
||||
'mobile' => $order['mobile'],
|
||||
'address' => $order['delivery_address'],
|
||||
],
|
||||
'finish' => $finish,
|
||||
'delivery' => [
|
||||
'title' => '运输中',
|
||||
'traces' => $traces
|
||||
],
|
||||
'shipment' => $shipment,
|
||||
'buy' => [
|
||||
'title' => '已下单',
|
||||
'tips' => '订单提交成功',
|
||||
'time' => date('Y-m-d H:i:s', $order['pay_time'])
|
||||
],
|
||||
];
|
||||
return $order_traces;
|
||||
}
|
||||
|
||||
return $order_traces;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user