12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace app\cxinv\model;
- use app\cxinv\model\Base;
- use think\Model;
- class TzProduct extends Base
- {
- protected $schema = [
- 'id' =>'bigint',//
- 'ktCode' =>'varchar',//调整id
- 'type' =>'tinyint',//1元数据 2调整数据
- 'product_id' =>'bigint',//商品id
- 'num' =>'decimal',//影响数量
- 'unit_price' =>'decimal',//单价
- 'create_time' =>'datetime',//
- 'update_time' =>'datetime',//
- ];
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- public function Product(){
- return $this->hasOne(FinancialProducts::class,'id','product_id');
- }
- public function Adjust(){
- return $this->hasOne(FinancialTz::class,'ktCode','ktCode');
- }
- public static function onAfterInsert(Model $model): void
- {
- if($model['type']==2){
- try{
- $adjust=$model->Adjust;
- ProductStock::OutStock($model['product_id'],$model['num']);
- $log = [
- "type" => 2,
- 'order_item_id' => $adjust->manager_id,
- 'product_id' => $model['product_id'],
- 'num' => $model['num'],
- "fz_date" => $adjust->Manager->fz_date,
- 'unit_price' =>$model['unit_price'],
- 'rate' => $model->Product->cat_tax,
- 'apply_id' => $model->checkUid,
- 'apply_name' => $model->checkUname,
- ];
- (new ProductOnlog)->save($log);
- }catch (\Exception $e){
- throw new \Exception($e->getMessage());
- }
- }
- }
- }
|