Store.php
2.7 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
<?php
namespace app\admin\model\groupon\store;
use think\Model;
use traits\model\SoftDelete;
class Store extends Model
{
use SoftDelete;
// 表名
protected $name = 'groupon_store';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'status_text',
'area_text',
'user_ids',
'user_ids_list',
'images_arr',
'image'
];
public function getStatusTextAttr($value, $data)
{
return $data['status'] == '1' ? '启用中' : '禁用中';
}
public function getAreaTextAttr($value, $data)
{
$area_text = '';
if(isset($data['service_type']) && $data['service_type'] === 'area') {
$province_ids = [];
if(!empty($data['service_province_ids']) ) {
$province_ids = explode(',', $data['service_province_ids']);
}
$city_ids = [];
if(!empty($data['service_city_ids'])) {
$city_ids = explode(',', $data['service_city_ids']);
}
$area_ids = [];
if(!empty($data['service_area_ids'])) {
$area_ids = explode(',', $data['service_area_ids']);
}
$ids = array_merge($province_ids, $city_ids, $area_ids);
if(!empty($ids)) {
$areaArray = \app\admin\model\groupon\Area::where('id', 'in', $ids)->column('name');
$area_text = implode(',', $areaArray);
}
}
return $area_text;
}
public function getUserIdsAttr($value, $data)
{
$user_store = \think\Db::name('groupon_user_store')->where('store_id', $data['id'])->select();
$user_ids = array_column($user_store, 'user_id');
return $user_ids;
}
public function getUserIdsListAttr($value, $data)
{
$user_store = \think\Db::name('groupon_user_store')->where('store_id', $data['id'])->select();
$user_ids_list = [];
foreach($user_store as $us) {
$user_ids_list[] = \app\admin\model\groupon\user\User::where('id', $us['user_id'])->field('id,nickname')->find();
}
return $user_ids_list;
}
public function getImageAttr($value, $data)
{
return $this->images_arr[0] ?? '';
}
public function getImagesArrAttr($value, $data)
{
$imagesArray = [];
if (!empty($data['images'])) {
$imagesArray = explode(',', $data['images']);
return $imagesArray;
}
return $imagesArray;
}
}