OrderExpress.php
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace addons\shopro\model;
use think\Model;
use addons\shopro\exception\Exception;
use think\Db;
/**
* 订单包裹
*/
class OrderExpress extends Model
{
// 表名,不含前缀
protected $name = 'shopro_order_express';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $hidden = ['updatetime'];
// //列表动态隐藏字段
// protected static $list_hidden = ['content', 'params', 'images', 'service_ids'];
protected $append = [
];
public static function getList($params) {
$user = User::info();
$order_id = $params['order_id'] ?? 0;
$list = self::with(['log', 'item' => function ($query) use ($order_id) {
return $query->where('order_id', $order_id);
}])->where('user_id', $user->id)->where('order_id', $order_id)->select();
return $list;
}
public static function detail($params) {
$user = User::info();
$id = $params['id'] ?? 0;
$order_id = $params['order_id'] ?? 0;
$detail = self::with(['log', 'item' => function ($query) use ($order_id) {
return $query->where('order_id', $order_id);
}])->where('user_id', $user->id)->where('order_id', $order_id)->where('id', $id)->find();
return $detail;
}
// 根据物流单号查询物流信息
public static function getDetail($params) {
$user = User::info();
$express_no = $params['express_no'] ?? '';
$order_id = $params['order_id'] ?? 0;
$detail = self::with(['log','order'])->where('user_id', $user->id)->where('order_id', $order_id)->where('express_no', $express_no)->find();
// 差异更新物流信息
$expressLib = new \addons\shopro\library\Express();
$result = $expressLib->search([
'express_code' => $detail['express_code'],
'express_no' => $detail['express_no']
], $detail, $detail->order);
$expressLib->checkAndAddTraces($detail, $result);
return $detail;
}
/**
* 记得用的时候一定要额外加上 order_id 等于当前订单号
*/
public function item()
{
return $this->hasMany(\addons\shopro\model\OrderItem::class, 'express_no', 'express_no');
}
public function log()
{
return $this->hasMany(\addons\shopro\model\OrderExpressLog::class, 'order_express_id')->order('id', 'desc');
}
public function order()
{
return $this->belongsTo(\addons\shopro\model\Order::class, 'order_id');
}
}