|
@@ -2,6 +2,7 @@
|
|
|
namespace app\cxinv\model;
|
|
|
|
|
|
use app\user\model\TaxCategory;
|
|
|
+use think\Model;
|
|
|
use think\model\concern\SoftDelete;
|
|
|
class FinancialProducts extends Base
|
|
|
{
|
|
@@ -51,4 +52,17 @@ class FinancialProducts extends Base
|
|
|
public function ProductStock(){
|
|
|
return $this->hasOne(ProductStock::class,'product_id','id')->bind(['residue_stock','total_stock','pending_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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|