SellerInputRecord.php
4.01 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
<?php
namespace domain\user;
use Yii;
use domain\user\models\SellerInputRecord as SellerInputRecordModel;
use Exception;
/**
* Class SellerInputRecord
* @package domain\user
*/
class SellerInputRecord
{
/**
* 创建激活记录
* @param $item
*/
static function create($item)
{
try {
$sellerInputRecordModel = Yii::createObject(SellerInputRecordModel::className());
$sellerInputRecordModel->user_mp_id = trim($item["user_mp_id"]); // 用户编号
$sellerInputRecordModel->leave_message = trim($item['leave_message']); // 商家留言
$sellerInputRecordModel->delivery_address = trim($item['delivery_address']); // 发货地址
$sellerInputRecordModel->product_image_path = trim($item['product_image_path']); // 商品图片
$sellerInputRecordModel->product_vedio_path = trim($item['product_vedio_path']); // 商品视频
$sellerInputRecordModel->buyer_mobile = trim($item['buyer_mobile']); // 买家手机号
$sellerInputRecordModel->uuid = trim($item['uuid']); // 验证编号
$sellerInputRecordModel->extraction_code = trim($item['extraction_code']); // 提取码
$result = $sellerInputRecordModel->save();
if($result) {
// 新增用户地址
if (trim($item['delivery_address'])) {
$userAddress = UserAddress::create([
"user_id" => trim($item["user_mp_id"]),
"address" => trim($item['delivery_address']),
]);
}
$result = $sellerInputRecordModel->id;
} else {
$result = false;
}
return $result;
} catch (Exception $e) {
return false;
}
}
/**
* @param $id
* @param $item
* @return null|static
*/
static function update($id, $item)
{
$sellerInputRecordModel = SellerInputRecordModel::findOne($id);
if (empty($sellerInputRecordModel)) {
return false;
}
if (isset($item['user_mp_id']) && !empty($item['user_mp_id'])) {
$sellerInputRecordModel->user_mp_id = trim($item["user_mp_id"]); // user_mp_id
}
if (isset($item['leave_message']) && !empty($item['leave_message'])) {
$sellerInputRecordModel->leave_message = trim($item['leave_message']); // leave_message
}
if (isset($item['delivery_address']) && !empty($item['delivery_address'])) {
$sellerInputRecordModel->delivery_address = trim($item['delivery_address']); // 发货地址
}
if (isset($item['product_image_path']) && !empty($item['product_image_path'])) {
$sellerInputRecordModel->product_image_path = trim($item['product_image_path']); // 商品图片
}
if (isset($item['product_vedio_path']) && !empty($item['product_vedio_path'])) {
$sellerInputRecordModel->product_vedio_path = trim($item['product_vedio_path']); // 产品视频
}
if (isset($item['buyer_mobile']) && !empty($item['buyer_mobile'])) {
$sellerInputRecordModel->buyer_mobile = trim($item['buyer_mobile']); // 买家手机号
}
if (isset($item['extraction_code']) && !empty($item['extraction_code'])) {
$sellerInputRecordModel->extraction_code = trim($item['extraction_code']); // 提取码
}
if (isset($item['uuid']) && !empty($item['uuid'])) {
$sellerInputRecordModel->uuid = trim($item['uuid']); // 激活编号
}
$resultSave = $sellerInputRecordModel->save();
return $resultSave;
}
/**
* @param $id
* @param $item
* @return null|static
*/
public static function delete($id)
{
$sellerInputRecordModel = SellerInputRecordModel::findOne($id);
if (empty($sellerInputRecordModel)) {
return false;
}
return SellerInputRecordModel::updateAll(["is_delete" => 1], ["id" => $id]);
}
}