commit | author | age
|
90c639
|
1 |
<?php |
Z |
2 |
|
|
3 |
namespace app\models; |
|
4 |
|
|
5 |
/** |
|
6 |
* This is the model class for table "order_send_template". |
|
7 |
* |
|
8 |
* @property int $id |
|
9 |
* @property int $mall_id |
|
10 |
* @property int $mch_id |
|
11 |
* @property string $name 发货单名称 |
|
12 |
* @property string $cover_pic 缩略图 |
|
13 |
* @property string $params 模板参数 |
|
14 |
* @property int $is_default 是否为默认模板0.否|1.是 |
|
15 |
* @property string $created_at |
|
16 |
* @property string $updated_at |
|
17 |
* @property string $deleted_at |
|
18 |
* @property int $is_delete |
|
19 |
*/ |
|
20 |
class OrderSendTemplate extends ModelActiveRecord |
|
21 |
{ |
|
22 |
/** |
|
23 |
* {@inheritdoc} |
|
24 |
*/ |
|
25 |
public static function tableName() |
|
26 |
{ |
|
27 |
return '{{%order_send_template}}'; |
|
28 |
} |
|
29 |
|
|
30 |
/** |
|
31 |
* {@inheritdoc} |
|
32 |
*/ |
|
33 |
public function rules() |
|
34 |
{ |
|
35 |
return [ |
|
36 |
[['mall_id', 'params', 'created_at', 'updated_at', 'deleted_at'], 'required'], |
|
37 |
[['mall_id', 'mch_id', 'is_default', 'is_delete'], 'integer'], |
|
38 |
[['params'], 'string'], |
|
39 |
[['created_at', 'updated_at', 'deleted_at'], 'safe'], |
|
40 |
[['name'], 'string', 'max' => 60], |
|
41 |
[['cover_pic'], 'string', 'max' => 255], |
|
42 |
]; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* {@inheritdoc} |
|
47 |
*/ |
|
48 |
public function attributeLabels() |
|
49 |
{ |
|
50 |
return [ |
|
51 |
'id' => 'ID', |
|
52 |
'mall_id' => 'Mall ID', |
|
53 |
'mch_id' => 'Mch ID', |
|
54 |
'name' => '发货单名称', |
|
55 |
'cover_pic' => '缩略图', |
|
56 |
'params' => '模板参数', |
|
57 |
'is_default' => '是否为默认模板0.否|1.是', |
|
58 |
'created_at' => 'Created At', |
|
59 |
'updated_at' => 'Updated At', |
|
60 |
'deleted_at' => 'Deleted At', |
|
61 |
'is_delete' => 'Is Delete', |
|
62 |
]; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* @param OrderSendTemplate $template |
|
67 |
* @return array |
|
68 |
*/ |
|
69 |
public function getNewData($template, $defaultParams = []) |
|
70 |
{ |
|
71 |
$newTemplate = []; |
|
72 |
$newTemplate['id'] = $template->id; |
|
73 |
$newTemplate['name'] = $template->name; |
|
74 |
$newTemplate['cover_pic'] = $template->cover_pic; |
|
75 |
$newTemplate['is_default'] = $template->is_default; |
|
76 |
// 补充上新加的默认值 |
|
77 |
$params = json_decode($template->params, true); |
|
78 |
foreach ($defaultParams as $key => $value) { |
|
79 |
if (!isset($params[$key])) { |
|
80 |
$params[$key] = $value; |
|
81 |
} |
|
82 |
} |
|
83 |
$newTemplate['params'] = $params; |
|
84 |
|
|
85 |
return $newTemplate; |
|
86 |
} |
|
87 |
} |