123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace app\cxinv\model;
- use think\Model;
- use think\model\concern\SoftDelete;
- class FinancialTz extends Base
- {
- use SoftDelete;
- protected $schema = [
- 'id' =>'bigint',//
- 'ktCode' =>'varchar',//计提编号
- 'manager_id' =>'bigint',//出库id
- 'status' =>'tinyint',//状态 1 待审核 2 已审核 3 已驳回 4 已取消
- 'num' =>'decimal',//数量
- 'out_fee' =>'decimal',//出口金额
- 'check_fee' =>'decimal',//调整金额
- 'is_checkOrder' =>'tinyint',//是否调整单
- 'fz_date' =>'varchar',//
- '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 Manager(){
- return $this->hasOne(FinancialManager::class,'id','manager_id');
- }
- public function ProductTz(){
- return $this->hasMany(TzProduct::class,'ktCode','ktCode');
- }
- public function FinancialCheck()
- {
- return $this->hasOne(FinancialCheck::class,'code','ktCode');
- }
- public static function MakeInfo($product,$create)
- {
- foreach ($product as $k=>&$v) {
- $create['num']=bcadd($create['num'],$v['num'],8);
- $v['ktCode']=$create['ktCode'];
- $create['out_fee']=bcadd($create['out_fee'],bcmul($v['num'],$v['subunit_price'],15),15);
- }
- $kt = self::create($create);
- if($kt->isEmpty()) throw new \Exception('计提单生成失败');
- $key=(new TzProduct)->saveAll($product);
- if($key->isEmpty()) throw new \Exception('计提商品信息生成失败');
- }
- public static function onAfterUpdate(Model $model): void
- {
- $change = $model->getChangedData();
- $origin = $model->getOrigin();
- if (isset($change['status']) && $change['status'] == 2 && $origin['status'] == 1) {
- $product = TzProduct::with(['Product'=>['ProductsCombind','ProductStock']])->where(['ktCode' => $model['ktCode'], 'type' => 1])->select();
- $product->each(function ($item) use ($model) {
- if($item['is_combind']==0){
- ProductStock::AddSingleStock($item->Product, $item['num']);
- $log[] = [
- "type" => 5,
- 'order_item_id' => $model->id,
- 'product_id' => $item['product_id'],
- 'num' => $item['num'],
- "fz_date" => $model->fz_date,
- 'unit_price' => $item['unit_price'],
- 'rate' => $item->Product->cat_tax,
- 'apply_id' => $model->checkUid,
- 'apply_name' => $model->checkUname,
- ];
- }else{
- if($item->ProductsCombind->isEmpty()) throw new \Exception('子商品不存在');
- $ids=ProductStock::AddCombindStock( $item['product_id'], $item['num']);
- foreach ($ids as $id){
- $log[] = [
- "type" => 1,
- 'order_item_id' => $model->id,
- 'product_id' => $id['product_id'],
- 'num' =>$id['num'],
- "fz_date" => $model->fz_date,
- 'unit_price' => $id['unit_price'],
- 'rate' => $id['rate'],
- 'apply_id' => $model->checkUid,
- 'apply_name' => $model->checkUname,
- ];
- }
- }
- (new ProductOnlog)->saveAll($log);
- });
- if ($change['is_checkOrder'] == 1) {
- $check=[
- "checkCode"=>makeNo("CWTZ"),
- "type"=>1,
- "code"=>$model->ktCode,
- "itemid"=>$model->Manager->inv_item_id,
- "goodNo"=>$model->Manager->goodNo,
- 'goodType'=>$model->Manager->goodType,
- "goodName"=>$model->Manager->goodName,
- "spec"=>$model->Manager->inv_spec,
- "unit"=>$model->Manager->inv_unit,
- "company_code"=>$model->Manager->seller_code,
- "company_name"=>$model->Manager->seller_name,
- "num"=>0, // 出库调整金额
- "price"=>$model->Manager->inv_price,
- "subprice"=>$model->Manager->inv_subprice,
- "check_fee"=>$model->check_fee,
- "check_uid"=>$model->checkUid,
- "fz_date"=> $model->Manager->fz_date,
- "check_uname"=>$model->checkUname,
- ];
- FinancialCheck::create($check);
- }
- }
- }
- }
|