1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace app\common\model;
- use think\Model;
- // 购物车
- class ShoppingTrolley extends Model
- {
- /**
- * 验证商品某规格是否已加入购物车
- */
- public static function checkTrolley($user_id,$goods_id,$spec_id)
- {
- return self::where(['user_id'=>$user_id,'goods_id'=>$goods_id,'spec_id'=>$spec_id])->value('id');
- }
- public function goodsSpec()
- {
- return $this->belongsTo('StoreGoodsItem','spec_id')->field('id,goods_id,goods_spec,goods_no,spec_title,cover,is_deleted,original_price,sell_price');
- }
- public function goodsInfo()
- {
- return $this->belongsTo('StoreGoods','goods_id')->field('id,name,cover');
- }
- //获取购物车列表
- public static function getTrolleyList($where)
- {
- $list = static::field('t.id,t.goods_id,t.spec_id,t.goods_no,t.num,goods_spec')
- ->alias('t')
- ->leftJoin('StoreGoodsItem i','i.id = t.spec_id')
- ->where($where)->order('t.id desc')->select()->toArray();
- array_walk($list,function (&$v){
- $v['goods_spec'] = str_replace(['::',';;'],[':',';'],$v['goods_spec']);
- });
- return $list;
- }
- }
|