|
@@ -0,0 +1,51 @@
|
|
|
+<?php
|
|
|
+declare (strict_types = 1);
|
|
|
+
|
|
|
+namespace app\report\model;
|
|
|
+
|
|
|
+use think\facade\Db;use think\Model;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @mixin \think\Model
|
|
|
+ */
|
|
|
+class GoodBasic extends Model
|
|
|
+{
|
|
|
+ protected $append=["spec_info","cat_info","usable_stock","total_stock","wait_in_stock","wait_out_stock","child"];
|
|
|
+
|
|
|
+ public function unit(){
|
|
|
+ return $this->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');
|
|
|
+ }
|
|
|
+}
|