ShoppingTrolley.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. // 购物车
  5. class ShoppingTrolley extends Model
  6. {
  7. /**
  8. * 验证商品某规格是否已加入购物车
  9. */
  10. public static function checkTrolley($user_id,$goods_id,$spec_id)
  11. {
  12. return self::where(['user_id'=>$user_id,'goods_id'=>$goods_id,'spec_id'=>$spec_id])->value('id');
  13. }
  14. public function goodsSpec()
  15. {
  16. return $this->belongsTo('StoreGoodsItem','spec_id')->field('id,goods_id,goods_spec,goods_no,spec_title,cover,is_deleted,original_price,sell_price');
  17. }
  18. public function goodsInfo()
  19. {
  20. return $this->belongsTo('StoreGoods','goods_id')->field('id,name,cover');
  21. }
  22. //获取购物车列表
  23. public static function getTrolleyList($where)
  24. {
  25. $list = static::field('t.id,t.goods_id,t.spec_id,t.goods_no,t.num,goods_spec')
  26. ->alias('t')
  27. ->leftJoin('StoreGoodsItem i','i.id = t.spec_id')
  28. ->where($where)->order('t.id desc')->select()->toArray();
  29. array_walk($list,function (&$v){
  30. $v['goods_spec'] = str_replace(['::',';;'],[':',';'],$v['goods_spec']);
  31. });
  32. return $list;
  33. }
  34. }