'bigint',// 'skuCode' =>'varchar',//订单商品编号 'goodName' =>'varchar',//商品名称 'inv_good_name' =>'varchar',//发票商品名称 'seller_code' =>'varchar',//销售方公司编号 'seller_name' =>'varchar',//销售方公司 'buyer_code' =>'varchar',//买方公司编号 'buyer_name' =>'varchar',//买方公司 'good_type' =>'varchar',//商品类型 1 库存2非库存 3 咨询 'good_source' =>'tinyint',//来源1采销 2 非采销 'spec' =>'varchar',//规格 'good_code' =>'varchar',//商品代码 'unit' =>'varchar',//单位 'unit_price' =>'decimal',//成本税前单价 'subunit_price' =>'decimal',//成本税后单价 'unit_weight' =>'decimal',//单位重量 'spectral' =>'varchar',//分光 'inv_type' =>'varchar',//发票类型 'cat_code' =>'varchar',//进项类目 'cat_tax' =>'varchar',//税率 'status' =>'tinyint',//0禁用 1启用 'basic_status' =>'tinyint',//1 真实成本 2 预估成本 'is_combind' =>'tinyint',//组合商品 0否 1是 'apply_id' =>'int',//创建人 'apply_name' =>'varchar',//创建人 'create_time' =>'datetime',// 'update_time' =>'datetime',// 'delete_time' =>'datetime',// ]; protected $createTime = "create_time"; protected $updateTime = "update_time"; protected $deleteTime='delete_time'; public function ProductsCombind(){ return $this->hasMany('ProductsCombind','parent_id','id'); } public function CatInfo(){ return $this->belongsTo(TaxCategory::class,'cat_code','merge_code')->bind(["cat_name","merge_code","short_name"]); } public function ProductStock(){ return $this->hasOne(ProductStock::class,'product_id','id')->bind(['residue_stock','total_stock','pending_stock','combind_stock']); } public static function onAfterInsert(Model $model) : void{ $stock = ProductStock::where('product_id',$model->id)->findOrEmpty(); if($stock->isEmpty()){ $stock_data=[ 'product_id'=>$model->id, 'residue_stock'=>0, 'total_stock'=>0, 'pending_stock'=>0, ]; ProductStock::create($stock_data); } } }