TzProduct.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\cxinv\model;
  3. use app\cxinv\model\Base;
  4. use think\Model;
  5. class TzProduct extends Base
  6. {
  7. protected $schema = [
  8. 'id' =>'bigint',//
  9. 'ktCode' =>'varchar',//调整id
  10. 'type' =>'tinyint',//1元数据 2调整数据
  11. 'product_id' =>'bigint',//商品id
  12. 'num' =>'decimal',//影响数量
  13. 'unit_price' =>'decimal',//单价
  14. 'create_time' =>'datetime',//
  15. 'update_time' =>'datetime',//
  16. ];
  17. protected $createTime = 'create_time';
  18. protected $updateTime = 'update_time';
  19. public function Product(){
  20. return $this->hasOne(FinancialProducts::class,'id','product_id');
  21. }
  22. public function Adjust(){
  23. return $this->hasOne(FinancialTz::class,'ktCode','ktCode');
  24. }
  25. public static function onAfterInsert(Model $model): void
  26. {
  27. if($model['type']==2){
  28. try{
  29. $adjust=$model->Adjust;
  30. ProductStock::OutStock($model['product_id'],$model['num']);
  31. $log = [
  32. "type" => 2,
  33. 'order_item_id' => $adjust->manager_id,
  34. 'product_id' => $model['product_id'],
  35. 'num' => $model['num'],
  36. "fz_date" => $adjust->Manager->fz_date,
  37. 'unit_price' =>$model['unit_price'],
  38. 'rate' => $model->Product->cat_tax,
  39. 'apply_id' => $model->checkUid,
  40. 'apply_name' => $model->checkUname,
  41. ];
  42. (new ProductOnlog)->save($log);
  43. }catch (\Exception $e){
  44. throw new \Exception($e->getMessage());
  45. }
  46. }
  47. }
  48. }