belongsTo(Unit::class,"good_unit")->bind(["unit_name"=>"unit"]); } public function brand(){ return $this->belongsTo(Brand::class,'brand_id')->bind(['brand_name']); } public function getSpecInfoAttr($v,$row){ return (new GoodSpec())->with(["spec","specinfo"])->where(["spuCode"=>$row['spuCode']])->field("spec_id,spec_value_id")->select(); } public function getCatInfoAttr($v,$row){ return made($row['cat_id']); } public function getTotalStockAttr($v,$row){ return (new GoodStock())->withJoin(['WareInfo'],"left")->where(['spuCode'=>$row['spuCode'],"wsm_type"=>[5,4]]) ->sum(Db::raw("usable_stock+wait_out_stock")); } public function getUsableStockAttr($v,$row){ return (new GoodStock())->withJoin(['WareInfo'],'left')->where(['spuCode'=>$row['spuCode'],'wsm_type'=>[5,4]]) ->sum("usable_stock"); } public function getWaitInStockAttr($v,$row){ return (new GoodStock())->withJoin(['WareInfo'],'left')->where(['spuCode'=>$row['spuCode'],'wsm_type'=>[5,4]]) ->sum('wait_in_stock'); } public function getWaitOutStockAttr($v,$row){ return (new GoodStock())->withJoin([' WareInfo'],'left')->where(['spuCode'=>$row['spuCode'],'wsm_type'=>[5,4]]) ->sum('wait_out_stock'); } }