Good.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use think\App;use think\facade\Validate;
  5. class Good extends Base
  6. {
  7. protected $model=null;
  8. public function __construct(App $app) {
  9. parent::__construct($app);
  10. $this->model=new \app\admin\model\Good();
  11. }
  12. /** 商品列表
  13. * @throws \think\db\exception\DbException
  14. * @throws \think\exception\DbException
  15. */
  16. public function list(){
  17. $param=$this->request->param(["spuCode"=>"","status"=>"","good_name"=>"",'companyNo'=>'','supplierNo'=>'',
  18. 'creater'=>'','isZx'=>'',"cat_diff"=>"","tax_diff"=>"",'page'=>'1','size'=>'15'],"post","trim");
  19. $where=[];
  20. $param["spuCode"]==""?? $where[]=['spuCode','like',"%{$param['spuCode']}%"];
  21. $param["good_name"]==""?? $where[]=['good_name','like',"%{$param['good_name']}%"];
  22. $param["companyNo"]==""?? $where[]=['companyNo','like',"%{$param['companyNo']}%"];
  23. $param["supplierNo"]==""?? $where[]=['supplierNo','like',"%{$param['supplierNo']}%"];
  24. $param["creater"]==""?? $where[]=['creater','like',"%{$param['creater']}%"];
  25. $param["status"]===""?? $where[]=['status','=',$param['status']];
  26. $param["isZx"]==""?? $where[]=['isZx','=',$param['isZx']];
  27. $list= $this->model->where($where)->order("id desc")
  28. ->paginate(["page"=>$param['page'],"list_rows"=>$param["size"]]);
  29. $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  30. }
  31. //批量更新数据状态审核
  32. public function exam(){
  33. $param=$this->request->param(["list"=>[],"status"=>""],"post","trim");
  34. $valid=Validate::rule(["list|审核数据集"=>"require|array","status|状态"=>"require|number|in:1,2"]);
  35. if($valid->check($param)==false)$this->error($valid->getError());
  36. $validList=Validate::rule([
  37. 'spuCode|商品编号' => 'require|max:255',
  38. 'tax|税率' => 'require|max:4',
  39. 'cat_code|类目编号简写' => 'require|max:255',
  40. 'inv_good_name|开票商品名称' => 'require|max:255',
  41. 'inv_tag|税率标识' => 'requireIf:status,2|between:0,3',
  42. 'is_discount|是否有优惠政策' => 'requireIf:status,2|in:0,1',
  43. 'addTax|增值税管理内容' => 'max:255']);
  44. $goodUpdate=[];
  45. $catArr = \app\admin\model\InvCat::where(["cat_code"=>array_unique(array_column($param['list'],"cat_code"))])
  46. ->column('tax,merge_code,short_name', 'cat_code');
  47. foreach ($param['list'] as $item){
  48. $temp=[];
  49. $item['status'] = $param['status'];
  50. if($validList->check($item)==false) $this->error("商品{$item['spuCode']}".$validList->getError());
  51. $good=$this->model->where(["spuCode"=>$item['spuCode']])->findOrEmpty();
  52. if($good->isEmpty())$this->error("商品信息{$item['spuCode']}不存在");
  53. if(!isset($catArr[$item['cat_code']]))$this->error("商品{$item['spuCode']}所选类目不存在");
  54. $tax = $catArr[$item['cat_code']]['tax']==""?[]:explode('、', $catArr[$item['cat_code']]['tax']);
  55. if(!in_array($item['tax'],$tax))$this->error("商品{$item['spuCode']}所选税率与类目包含税率不一致");
  56. //采购端修改 只能在待财务设置税务类目状态 切该商品未参与采购付款回票对账
  57. //销售端修改 只要没参与销售回款开票结算
  58. $temp['id']=$good->id;
  59. $temp['status']=$param['status'];
  60. if($param['status']<$good->status) $this->error("商品{$item['spuCode']}当前状态".\app\admin\model\Good::$status[$good->status]."不可修改");
  61. $item['tax'] = bcdiv(str_replace('%', '', $item['tax']), "100", 2);
  62. if($param['status']==1){
  63. if($good->cgd_to_pay)$this->error("商品{$item['spuCode']}已参与采购付款回票对账");
  64. $temp["cgd_inv_cat_code"]=$catArr[$item['cat_code']]['merge_code'];
  65. $temp["cgd_inv_cat_name"]=$catArr[$item['cat_code']]['short_name'];
  66. $temp["cgd_inv_good_name"]= $item['inv_good_name'];
  67. $temp["cgd_inv_tax"]= $item['tax'];
  68. }
  69. if($param['status']==2){
  70. if($good->qrd_to_pay)$this->error("商品{$item['spuCode']}已参与销售回款开票结算");
  71. $check = CheckTax($item['is_discount'],$item['tax'],$item['inv_tag'],
  72. $item['addTax'],$message);
  73. if($check==false)$this->error("商品{$item['spuCode']}{$message}");
  74. $temp['inv_cat_code']=$catArr[$item['cat_code']]['merge_code'];
  75. $temp['inv_cat_name']=$catArr[$item['cat_code']]['short_name'];
  76. $temp['inv_good_name']= $item['inv_good_name'];
  77. $temp['inv_tax']= $item['tax'];
  78. $temp['is_discount']= $item['is_discount'];
  79. $temp['addTax']= $item['addTax'];
  80. $temp['inv_tag']= $item['inv_tag'];
  81. $temp['tax_diff']= $item['tax']==$good->cgd_inv_tax?1:2;
  82. $temp['cat_diff']= $temp['inv_cat_code']==$good->cgd_inv_cat_code?1:2;
  83. }
  84. $examinfo=$good->exam_info;
  85. $examinfo[]=['apply_name'=>$this->uname,'exam_status'=>$item['status'],"updatetime"=>date("Y-m-d H:i:s")];
  86. $temp['exam_info'] = json_encode($examinfo,JSON_UNESCAPED_UNICODE);
  87. $goodUpdate[]=$temp;
  88. }
  89. $this->model->saveAll($goodUpdate);
  90. $this->success("更新成功");
  91. }
  92. //商品信息
  93. public function info(){
  94. $param=$this->request->param(['spuCode'=>''],'post','trim');
  95. $valid=Validate::rule(['spuCode|商品成本编号'=>'require|max:255']);
  96. if($valid->check($param)==false)$this->error($valid->getError());
  97. $info = $this->model->where(["spuCode"=>$param['spuCode']])->findOrEmpty();
  98. if($info->isEmpty())$this->error("商品信息不存在");
  99. $this->success("获取成功",$info);
  100. }
  101. }