GoodZx.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodBasic;
  4. use app\admin\model\GoodPlatform;
  5. use app\admin\model\GoodTax;
  6. use app\admin\model\OrderTax;
  7. use app\cxinv\model\OrderCategory;
  8. use app\user\model\AccountItem;
  9. use think\App;
  10. class GoodZx extends Base{
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. $this->model=new \app\admin\model\GoodZixun();
  15. }
  16. public function list(){
  17. $param = $this->request->param(["spuCode"=>"","status"=>"","tax_status"=>"","order_source"=>"","orderCode"=>"",
  18. "start"=>"","end"=>"","relaComNo"=>"","good_name"=>"","supplierNo"=>"","name"=>"","page"=>"1","size"=>"10","creater"=>""],
  19. "post","trim");
  20. $where =[['is_del','=',0]] ;
  21. if($param['spuCode']!="") $where[]=['good_zixun.spuCode','like',"%".$param['spuCode']."%"];
  22. if($param['status']!="") $where[]=['good_zixun.status','=',$param['status']];
  23. if($param['tax_status']!="") $where[]=['good_tax.status','=',$param['tax_status']==0?null:$param['tax_status']];
  24. if($param['order_source']!="") $where[]=['order_source','in',$param['order_source']];
  25. if($param['orderCode']!="") $where[]=['good_zixun.spuCode','in',\app\admin\model\Sale::where("orderCode","=",$param['orderCode'])->column("good_code")];
  26. if($param['relaComNo']!="") $where[]=['good_zixun.companyNo|supplierNo','=',$param['relaComNo']];
  27. if($param['good_name']!="") $where[]=['good_name','like',"%".$param['good_name']."%"];
  28. if($param['supplierNo']!="") $where[]=['supplierNo','like',$param['supplierNo']];
  29. if($param['name']!="") $where[]=['supplierName','like',"%".$param['name']."%"];
  30. if($param['start']!="") $where[]=['good_zixun.addtime','>=',startTime($param['start'])];
  31. if($param['end']!="") $where[]=['good_zixun.addtime','<=',endTime($param['end'])];
  32. if($param['creater']!="") $where[]=['good_zixun.creater','like',"%{$param['creater']}%"];
  33. $list = $this->model->with(["brand","unit","cat","Platform","GoodTax"=>["outCategory","inCategory","cgdCategory"]])->withJoin("good_tax","left")
  34. ->where($where)->order('id desc')
  35. ->paginate(['page'=>$param['page'],'list_rows'=>$param['size']])
  36. ->each(function(&$item){
  37. $item['cat_info'] = explode("_",$item->search);
  38. $item['is_basic'] =GoodBasic::where("spuCode","=",$item['spuCode'])->value("status");
  39. $item['is_online'] = GoodPlatform::where("spuCode","=",$item['spuCode'])->findOrEmpty()->isEmpty()?0:1;
  40. $item["orderCode"] = \app\admin\model\Sale::where("good_code","=",$item['spuCode'])->value("orderCode");
  41. $account = AccountItem::with(["ItemName"])->where("account_id","=",$item['order_createrid'])->findOrEmpty();
  42. $item["order_creater_depart"] = $account["depart_name"]??"";
  43. });
  44. $list->hidden(["brand","unit","cat","good_tax","GoodTax","Platform"]);
  45. return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  46. }
  47. //添加或修改商品税目
  48. public function changeTax(){
  49. $param = $this->request->param([
  50. "spuCode"=>"",
  51. "isToSale"=>0, //是否同步结算销售单
  52. "isToCgd"=>0, //是否同步结算采购单
  53. "isToGood"=>0, //是否同步结算商品库
  54. "tax_id"=>"",
  55. "tax"=>"",
  56. "inv_good_name"=>"",
  57. "out_tax_id"=>"",
  58. "out_tax"=>"",
  59. "cgd_tax_id"=>"",
  60. "cgd_tax"=>"",
  61. ],"post","trim");
  62. $validate = $this->validate($param,[
  63. "spuCode|商品编码"=>"require",
  64. "isToSale|是否同步结算销售单"=>"number|in:0,1",
  65. "isToCgd|是否同步结算采购单"=>"number|in:0,1",
  66. "isToGood|是否同步结算商品库"=>"number|in:0,1",
  67. "tax_id|进项税目"=>"require",
  68. "tax|进项税率"=>"number",
  69. "inv_good_name|开票商品名称"=>"require",
  70. "out_tax_id|销项税目"=>"require",
  71. "out_tax|销项税率"=>"number",
  72. "cgd_tax_id|源头税目"=>"require",
  73. "cgd_tax|源头税率"=>"number",
  74. ]);
  75. if($validate!==true) return error($validate);
  76. $good= $this->model->where("spuCode","=",$param['spuCode'])->findOrEmpty();
  77. if($good->isEmpty()) return error("咨询商品不存在");
  78. $good_tax = GoodTax::where("spuCode","=",$param['spuCode'])->findOrEmpty();
  79. $good_tax->open_type=$good->open_type;
  80. $good_tax->companyNo = $good->companyNo;
  81. $good_tax->tax_id = $param['tax_id'];
  82. $good_tax->tax = $param['tax'];
  83. $good_tax->inv_good_name = $param['inv_good_name'];
  84. $good_tax->out_tax_id = $param['out_tax_id'];
  85. $good_tax->out_tax = $param['out_tax'];
  86. $good_tax->cgd_tax_id = $param['cgd_tax_id'];
  87. $good_tax->cgd_tax = $param['cgd_tax'];
  88. $good_tax->createrid=$good_tax->createrid??$this->uid;
  89. $good_tax->creater=$good_tax->creater??$this->uname;
  90. $this->model->startTrans();
  91. try{
  92. $save=$good_tax->save();
  93. if($save==false) throw new \Exception("添加失败");
  94. if($param['isToSale']==1){
  95. $sale = \app\admin\model\Sale::where("good_code","=",$param['spuCode'])->findOrEmpty();
  96. if(!$sale->isEmpty()){
  97. $sale->updatetime=date('Y-m-d H:i:s');
  98. $sale->save();
  99. if($sale->save()==false) throw new \Exception('同步销售单失败');
  100. }
  101. OrderTax::where(["spuCode"=>$param['spuCode'],"code"=>$sale->orderCode])->delete();
  102. OrderCategory::where(["spuCode"=>$param['spuCode']])->whereNotLike("code","CG%")
  103. ->save(["cat_code"=>"","cat_name"=>"","merge_code"=>"","tax"=>"","short_name"=>"","inv_good_name"=>""]);
  104. }
  105. if($param['isToCgd']==1){
  106. $cgd = \app\admin\model\PurcheaseOrder::where("spuCode","=",$param['spuCode'])->findOrEmpty();
  107. if(!$cgd->isEmpty()) {
  108. $cgd->updatetime=date('Y-m-d H:i:s');
  109. if($cgd->save()==false) throw new \Exception('同步采购单失败');
  110. OrderTax::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->delete();
  111. OrderCategory::where(['spuCode'=>$param['spuCode'],'code'=>$cgd->cgdNo])->save(['cat_code'=>'','cat_name'=>'','merge_code'=>'','tax'=>'','short_name'=>'','inv_good_name'=>'']);
  112. }else{
  113. OrderTax::where(['spuCode'=>$param['spuCode']])->whereNotLike('code','CG%')->delete();
  114. OrderCategory::where(['spuCode'=>$param['spuCode']])->whereNotLike('code','CG%')->save(['cat_code'=>'','cat_name'=>'','merge_code'=>'','tax'=>'','short_name'=>'','inv_good_name'=>'']);
  115. }
  116. }
  117. if($param['isToGood']==1){
  118. $good->updatetime=date('Y-m-d H:i:s');
  119. $sa=$good->save();
  120. if($sa==false) throw new \Exception("同步商品库失败");
  121. }
  122. $this->model->commit();
  123. }catch (\Exception $e){
  124. $this->model->rollback();
  125. return error($e->getMessage());
  126. }
  127. return success("更新成功");
  128. }
  129. public function info(){
  130. $id = $this->request->post("id","", "int");
  131. $info = $this->model->with(["brand","unit","cat","Platform","GoodTax"=>["outCategory","inCategory","cgdCategory"]])
  132. ->where("id","=",$id)->findOrEmpty();
  133. if($info->isEmpty()) return error("咨询商品不存在");
  134. $info['cat_info'] = explode("_",$info->search);
  135. $info['is_basic'] =GoodBasic::where("spuCode","=",$info['spuCode'])->value("status");
  136. $info['is_online'] = GoodPlatform::where("spuCode","=",$info['spuCode'])->findOrEmpty()->isEmpty()?0:1;
  137. $info["orderCode"] = \app\admin\model\Sale::where("good_code","=",$info['spuCode'])->value("orderCode");
  138. $account = AccountItem::with(["ItemName"])->where("account_id","=",$info['order_createrid'])->findOrEmpty();
  139. $info["order_creater_depart"] = $account["depart_name"]??"";
  140. return success("获取成功",$info);
  141. }
  142. }