Goods.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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/5/6
* Time: 15:27
*/
namespace app\index\model;
use think\Model;
class Goods extends Model
{
public function getPropertyAttr($value){
$data = [];
if(!empty($value)){
$data = explode(',',$value);
}
return $data;
}
public function getThumbnailAttr($value){
return cdnurl($value);
}
public function selectData($where){
$where['g.status'] = ['eq','1'];
$data = $this
->alias('g')
->field('g.*,t.name as goodstype_name,s.name as store_name,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
->join('sto_goodstype t','t.id = g.goodstype_id')
->join('sto_store s','s.id = g.store_id')
->where($where)
->order('weigh desc')
->select();
$storeModel = new Store();
foreach($data as $key => $vo){
$store = $storeModel->findData(['id'=>$vo['store_id']]);
$data[$key]['store_is_vip'] = $store['is_vip'];
$data[$key]['store_is_svip'] = $store['is_svip'];
}
return $data;
}
public function selectPageData($where,$pageNum){
$where['g.status'] = ['eq','1'];
$data = $this
->alias('g')
->field('g.*,t.name as goodstype_name,s.name as store_name,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
->join('sto_goodstype t','t.id = g.goodstype_id')
->join('sto_store s','s.id = g.store_id')
->where($where)
->order('weigh desc')
->paginate($pageNum);
$storeModel = new Store();
foreach($data as $key => $vo){
$store = $storeModel->findData(['id'=>$vo['store_id']]);
$data[$key]['store_is_vip'] = $store['is_vip'];
$data[$key]['store_is_svip'] = $store['is_svip'];
}
return $data;
}
public function findData($where){
$data = $this
->alias('g')
->field('g.*,t.name as goodstype_name,s.lng,s.lat,s.name as store_name,s.address as store_address,s.property,s.type,s.content as store_content,s.thumbnail as store_thumbnail,s.money as store_money')
->join('sto_goodstype t','t.id = g.goodstype_id')
->join('sto_store s','s.id = g.store_id')
->where($where)
->fetchSql()
->find();
dump($data);exit;
$storeModel = new Store();
$store = $storeModel->findData(['id'=>$data['store_id']]);
$data['store_is_vip'] = $store['is_vip'];
$data['store_is_svip'] = $store['is_svip'];
return $data;
}
}