Car.php
2.3 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
<?php
namespace app\api\model;
use think\Model;
class Car extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
public function getCreatetimeAttr($value)
{
return date('Y-m-d',$value);
}
public function getImageAttr($value)
{
return cdnurl($value);
}
public function selectPageData($where,$page,$limit,$lang){
if ($lang == 'ch') $field = 'c.id car_id,c.createtime,cou.ch_name country_name,c.number,c.type,g.id goods_id,g.ch_name name,g.image,g.goods_price,g.group_price,g.vip_price,g.is_vip_price,g.is_group';
else $field = 'c.id car_id,c.createtime,cou.en_name country_name,c.number,c.type,g.id goods_id,g.en_name name,g.image,g.goods_price,g.group_price,g.vip_price,g.is_vip_price,g.is_group';
$total =$this->alias('c')
->where($where)
->count();
$list = $this->alias('c')
->join('fa_goods g','c.goods_id=g.id')
->join('fa_country cou','cou.id=g.country_id')
->where($where)
->field($field)
->page($page,$limit)
->select();
return ['total' => $total, 'list' => $list];
}
public function getCarMoney($where){
$goodsId = $this->where($where)->where(['type'=>1])->column('id');
$goodsList = $this->alias('c')
->join('fa_goods g','c.goods_id=g.id')
->where(['c.id'=>['in',$goodsId]])
->field('g.id,goods_price*number goods_price,g.vip_price*number vip_price,g.is_vip_price,g.ch_name,g.en_name,g.image,c.number')
->select();
$integralGoodsId = $this->where($where)->where(['type'=>2])->column('id');
$integralGoodsList = $this->alias('c')
->join('fa_integral_goods g','c.goods_id=g.id')
->where(['c.id'=>['in',$integralGoodsId]])
->field('g.id,goods_price*number goods_price,c.number,integral*number integral,g.ch_name,g.en_name,g.image')
->select();
$list = array_merge($goodsList,$integralGoodsList);
foreach ($list as $k => $v){
if (!empty($v['is_vip_price'])) $list[$k]['type'] = 1;
else $list[$k]['type'] = 2;
}
return $list;
}
}