OrderItem.php
5.9 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
namespace app\admin\model\groupon\order;
use think\Model;
use traits\model\SoftDelete;
use addons\groupon\library\traits\model\order\OrderItemStatus;
class OrderItem extends Model
{
use OrderItemStatus, SoftDelete;
// 表名
protected $name = 'groupon_order_item';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'dispatch_status_text',
'comment_status_text',
'activity_type_text',
'refund_status_text',
'status_code',
'status_name',
'status_desc',
'btns',
'ext_arr'
];
// 发货状态
const DISPATCH_STATUS_NOSEND = 0; // 未发货
const DISPATCH_STATUS_READY = 1; // 已备货
const DISPATCH_STATUS_ARRIVE = 2; // 已到货
const DISPATCH_STATUS_GETED = 3; // 已提货
// 退款状态
const REFUND_STATUS_NOREFUND = 0; // 退款状态 未申请
const REFUND_STATUS_ING = 1; // 申请中 // 不需要申请(状态不会出现)
const REFUND_STATUS_OK = 2; // 已同意
const REFUND_STATUS_FINISH = 3; // 退款完成
// 评价状态
const COMMENT_STATUS_NO = 0; // 待评价
const COMMENT_STATUS_OK = 1; // 已评价
public function getExtArrAttr($value, $data)
{
return (isset($data['ext']) && $data['ext']) ? json_decode($data['ext'], true) : [];
}
public function getDispatchStatusList()
{
return ['0' => __('Dispatch_status 0'), '1' => __('Dispatch_status 1'), '2' => __('Dispatch_status 2'), '3' => __('Dispatch_status 3')];
}
public function getCommentStatusList()
{
return ['0' => __('Comment_status 0'), '1' => __('Comment_status 1')];
}
public function getRefundStatusList()
{
return ['0' => __('Refund_status 0'), '1' => __('Refund_status 1'), '2' => __('Refund_status 2'), '3' => __('Refund_status 3')];
}
public function getDispatchStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['dispatch_status']) ? $data['dispatch_status'] : '');
$list = $this->getDispatchStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getActivityTypeList()
{
return ['seckill' => __('Activity_type seckill'), 'groupon' => __('Activity_type groupon')];
}
public function getActivityTypeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['activity_type']) ? $data['activity_type'] : '');
$list = $this->getActivityTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getCommentStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['comment_status']) ? $data['comment_status'] : '');
$list = $this->getCommentStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getRefundStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['refund_status']) ? $data['refund_status'] : '');
$list = $this->getRefundStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getStatus($data, $type)
{
$btns = [];
$status_name = '';
$status_desc = '';
$status_code = $this->status_code;
$item_code = 'null'; // 有售后的时候,第二状态
if (strpos($status_code, '|') !== false) {
$codes = explode('|', $status_code);
$status_code = $codes[0] ?? 'null';
$item_code = $codes[1] ?? 'null';
}
switch ($status_code) {
case 'null':
case 'cancel':
case 'invalid':
case 'nopay':
// 未支付的返回空
break;
case 'nosend':
$status_name = '待备货';
$status_desc = '请尽快安排备货';
$btns[] = 'refund'; // 退款
break;
case 'noarrive':
$status_name = '已备货';
$status_desc = '平台已备货,等待自提点签收';
$btns[] = 'refund'; // 退款
break;
case 'noget':
$status_name = '待取货';
$status_desc = '商品已到达指定自提点,等待用户取货';
$btns[] = 'refund'; // 售后
break;
case 'nocomment':
$status_name = '待评价';
$status_desc = '等待买家评价';
$btns[] = 'refund'; // 退款
break;
case 'commented':
$status_name = '已评价';
$status_desc = '订单已评价';
$btns[] = 'refund'; // 退款
break;
case 'refund_finish':
$status_name = '退款完成';
$status_desc = '订单退款完成';
break;
case 'refund_ing': // 不需要申请退款(状态不会出现)
$status_name = '退款处理中';
$status_desc = '退款处理中';
$btns[] = 'refund'; // 退款
break;
}
return $type == 'status_name' ? $status_name : ($type == 'btns' ? $btns : $status_desc);
}
// 商家配送, 到店自提的门店
public function store()
{
return $this->belongsTo(\app\admin\model\groupon\store\Store::class, 'store_id');
}
public function order()
{
return $this->belongsTo(\app\admin\model\groupon\order\Order::class, 'order_id');
}
}