1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace app\cxinv\model;
- use app\user\model\TaxCategory;
- use think\Model;
- use think\model\concern\SoftDelete;
- class FinancialProducts extends Base
- {
- use SoftDelete;
- protected $schema = [
- 'id' =>'bigint',
- 'skuCode' =>'varchar',
- 'goodName' =>'varchar',
- 'inv_good_name' =>'varchar',
- 'seller_code' =>'varchar',
- 'seller_name' =>'varchar',
- 'buyer_code' =>'varchar',
- 'buyer_name' =>'varchar',
- 'good_type' =>'varchar',
- 'good_source' =>'tinyint',
- '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',
- 'basic_status' =>'tinyint',
- 'is_combind' =>'tinyint',
- '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);
- }
- }
- }
|