Apply.php
3.5 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
<?php
namespace addons\groupon\model\store;
use think\Model;
use addons\groupon\model\User;
use addons\groupon\model\Area;
use addons\groupon\exception\Exception;
/**
* 门店申请
*/
class Apply extends Model
{
// 表名,不含前缀
protected $name = 'groupon_store_apply';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $hidden = [];
protected $append = [
'status_name',
'images_original'
];
/**
* 门店申请详情
*
* @return object
*/
public static function info() {
$user = User::info();
// 查询审核未通过的或者驳回的门店申请信息
$apply = self::where('user_id', $user->id)->where('status', 'in', [-1, 0])->find();
return $apply;
}
/**
* 门店申请
*/
public static function apply($params) {
$user = User::info();
extract($params);
$area = Area::get($area_id);
$city = Area::get($area->pid);
$province = Area::get($city->pid);
$apply = self::info();
// if ($apply['status'] == 1) {
// new Exception('您的申请已通过,不需重复申请');
// }
$data['user_id'] = $user->id;
$data['name'] = $name;
$data['images'] = join(',', $images);
$data['realname'] = $realname;
$data['phone'] = $phone;
$data['province_name'] = $province->name;
$data['city_name'] = $city->name;
$data['area_name'] = $area->name;
$data['province_id'] = $province->id;
$data['city_id'] = $city->id;
$data['area_id'] = $area->id;
$data['address'] = $address;
$data['latitude'] = $latitude;
$data['longitude'] = $longitude;
// $data['openhours'] = $openhours;
// $data['openweeks'] = $openweeks;
$data['status'] = 0;
if ($apply) {
$data['apply_num'] = $apply->apply_num + 1;
$apply->save($data);
} else {
$data['apply_num'] = 1;
$apply = new self();
$apply->save($data);
}
return $apply;
}
/* -------------------------- 访问器 ------------------------ */
public function getStatusNameAttr($value, $data) {
switch($data['status']) {
case -1:
$status_name = '已拒绝';
break;
case 0:
$status_name = '待审核';
break;
case 1:
$status_name = '已通过';
break;
default :
$status_name = '';
}
return $status_name;
}
public function getImagesAttr($value, $data)
{
$imagesArray = [];
if (!empty($value)) {
$imagesArray = explode(',', $value);
foreach ($imagesArray as &$v) {
$v = cdnurl($v, true);
}
}
return $imagesArray;
}
public function getImagesOriginalAttr($value, $data)
{
$imagesArray = [];
if (!empty($data['images'])) {
$imagesArray = explode(',', $data['images']);
}
return $imagesArray;
}
/* -------------------------- 模型关联 ------------------------ */
/* -------------------------- 模型关联 ------------------------ */
}