hasOne(ShopGoods::class,'id','goods_id'); } public static function getStateDisplayMap() { return [ self::STATE_CHECKED => self::STATE_CHECKED_STRING, self::STATE_NOT_CHECKED => self::STATE_NOT_CHECKED_STRING ]; } public static function getGoodsCount($where){ return static::where($where)->sum('number'); } public static function getGoodsAmountCount($where){ $cartData = static::where($where)->get(); $goodsTotalPrice = 0.00; if($cartData){ foreach($cartData as $item){ $goodsTotalPrice = PriceCalculate($goodsTotalPrice,'+',PriceCalculate($item['retail_price'],'*',$item['number'])); } } return $goodsTotalPrice; } // 获取选中的商品 public static function getCheckedGoodsList($uid){ $where['uid'] = $uid; $where['checked'] = self::STATE_CHECKED; return static::with('shop_goods')->where($where)->get(); } }