|
@@ -89,29 +89,35 @@ class GoodZx extends Base{
|
|
|
$good_tax->out_tax = $param['out_tax'];
|
|
|
$good_tax->cgd_tax_id = $param['cgd_tax_id'];
|
|
|
$good_tax->cgd_tax = $param['cgd_tax'];
|
|
|
- $good_tax->createrid=$this->uid;
|
|
|
- $good_tax->creater=$this->uname;
|
|
|
+ $good_tax->createrid=$good_tax->createrid??$this->uid;
|
|
|
+ $good_tax->creater=$good_tax->creater??$this->uname;
|
|
|
$this->model->startTrans();
|
|
|
try{
|
|
|
$save=$good_tax->save();
|
|
|
if($save==false) throw new \Exception("添加失败");
|
|
|
if($param['isToSale']==1){
|
|
|
$sale = \app\admin\model\Sale::where("good_code","=",$param['spuCode'])->findOrEmpty();
|
|
|
- if($sale->isEmpty()) return error("咨询销售单不存在");
|
|
|
- $sale->updatetime=date('Y-m-d H:i:s');
|
|
|
- $sale->save();
|
|
|
- if($sale->save()==false) throw new \Exception("同步销售单失败");
|
|
|
+ if(!$sale->isEmpty()){
|
|
|
+ $sale->updatetime=date('Y-m-d H:i:s');
|
|
|
+ $sale->save();
|
|
|
+ if($sale->save()==false) throw new \Exception('同步销售单失败');
|
|
|
+ }
|
|
|
OrderTax::where(["spuCode"=>$param['spuCode'],"code"=>$sale->orderCode])->delete();
|
|
|
OrderCategory::where(["spuCode"=>$param['spuCode']])->whereNotLike("code","CG%")
|
|
|
->save(["cat_code"=>"","cat_name"=>"","merge_code"=>"","tax"=>"","short_name"=>"","inv_good_name"=>""]);
|
|
|
}
|
|
|
if($param['isToCgd']==1){
|
|
|
$cgd = \app\admin\model\PurcheaseOrder::where("spuCode","=",$param['spuCode'])->findOrEmpty();
|
|
|
- if($cgd->isEmpty()) return error("咨询采购单不存在");
|
|
|
- $cgd->updatetime=date('Y-m-d H:i:s');
|
|
|
- if($cgd->save()==false) throw new \Exception("同步采购单失败");
|
|
|
- OrderTax::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->delete();
|
|
|
- OrderCategory::where(["spuCode"=>$param['spuCode'],'code'=>$cgd->cgdNo])->save(["cat_code"=>"","cat_name"=>"","merge_code"=>"","tax"=>"","short_name"=>"","inv_good_name"=>""]);
|
|
|
+ if(!$cgd->isEmpty()) {
|
|
|
+ $cgd->updatetime=date('Y-m-d H:i:s');
|
|
|
+ if($cgd->save()==false) throw new \Exception('同步采购单失败');
|
|
|
+ OrderTax::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->delete();
|
|
|
+ OrderCategory::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->save(['cat_code'=>'','cat_name'=>'','merge_code'=>'','tax'=>'','short_name'=>'','inv_good_name'=>'']);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ OrderTax::where(['spuCode'=>$param['spuCode']])->whereNotLike('code','CG%')->delete();
|
|
|
+ OrderCategory::where(['spuCode'=>$param['spuCode']])->whereNotLike('code','CG%')->save(['cat_code'=>'','cat_name'=>'','merge_code'=>'','tax'=>'','short_name'=>'','inv_good_name'=>'']);
|
|
|
+ }
|
|
|
}
|
|
|
if($param['isToGood']==1){
|
|
|
$good->updatetime=date('Y-m-d H:i:s');
|
|
@@ -121,9 +127,9 @@ class GoodZx extends Base{
|
|
|
$this->model->commit();
|
|
|
}catch (\Exception $e){
|
|
|
$this->model->rollback();
|
|
|
- return error("添加失败");
|
|
|
+ return error($e->getMessage());
|
|
|
}
|
|
|
- return success("添加成功");
|
|
|
+ return success("更新成功");
|
|
|
}
|
|
|
|
|
|
public function info(){
|