FinancialProducts.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\cxinv\model;
  3. use app\user\model\TaxCategory;
  4. use think\Model;
  5. use think\model\concern\SoftDelete;
  6. class FinancialProducts extends Base
  7. {
  8. use SoftDelete;
  9. //设置字段信息
  10. protected $schema = [
  11. 'id' =>'bigint',//
  12. 'skuCode' =>'varchar',//订单商品编号
  13. 'goodName' =>'varchar',//商品名称
  14. 'inv_good_name' =>'varchar',//发票商品名称
  15. 'seller_code' =>'varchar',//销售方公司编号
  16. 'seller_name' =>'varchar',//销售方公司
  17. 'buyer_code' =>'varchar',//买方公司编号
  18. 'buyer_name' =>'varchar',//买方公司
  19. 'good_type' =>'varchar',//商品类型 1 库存2非库存 3 咨询
  20. 'good_source' =>'tinyint',//来源1采销 2 非采销
  21. 'spec' =>'varchar',//规格
  22. 'good_code' =>'varchar',//商品代码
  23. 'unit' =>'varchar',//单位
  24. 'unit_price' =>'decimal',//成本税前单价
  25. 'subunit_price' =>'decimal',//成本税后单价
  26. 'unit_weight' =>'decimal',//单位重量
  27. 'spectral' =>'varchar',//分光
  28. 'inv_type' =>'varchar',//发票类型
  29. 'cat_code' =>'varchar',//进项类目
  30. 'cat_tax' =>'varchar',//税率
  31. 'status' =>'tinyint',//0禁用 1启用
  32. 'basic_status' =>'tinyint',//1 真实成本 2 预估成本
  33. 'is_combind' =>'tinyint',//组合商品 0否 1是
  34. 'apply_id' =>'int',//创建人
  35. 'apply_name' =>'varchar',//创建人
  36. 'create_time' =>'datetime',//
  37. 'update_time' =>'datetime',//
  38. 'delete_time' =>'datetime',//
  39. ];
  40. protected $createTime = "create_time";
  41. protected $updateTime = "update_time";
  42. protected $deleteTime='delete_time';
  43. public function ProductsCombind(){
  44. return $this->hasMany('ProductsCombind','parent_id','id');
  45. }
  46. public function CatInfo(){
  47. return $this->belongsTo(TaxCategory::class,'cat_code','merge_code')->bind(["cat_name","merge_code","short_name"]);
  48. }
  49. public function ProductStock(){
  50. return $this->hasOne(ProductStock::class,'product_id','id')->bind(['residue_stock','total_stock','pending_stock','combind_stock']);
  51. }
  52. public static function onAfterInsert(Model $model) : void{
  53. $stock = ProductStock::where('product_id',$model->id)->findOrEmpty();
  54. if($stock->isEmpty()){
  55. $stock_data=[
  56. 'product_id'=>$model->id,
  57. 'residue_stock'=>0,
  58. 'total_stock'=>0,
  59. 'pending_stock'=>0,
  60. ];
  61. ProductStock::create($stock_data);
  62. }
  63. }
  64. }