Adjust.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\cxinv\controller;
  3. use app\cxinv\model\FinancialTz;
  4. use app\cxinv\model\TzProduct;
  5. use think\App;
  6. class Adjust extends Base
  7. {
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. $this->model = new FinancialTz();
  12. }
  13. public function list()
  14. {
  15. $params = $this->request->param(["goodNo"=>"","goodType"=>"","status"=>"","start"=>"","end"=>"",'seller_code'=>"",
  16. "page"=>1,"size"=>15],"post","trim");
  17. $where=[];
  18. if($params['goodNo']!='') $where[]=['Manager.goodNo','like','%'.$params['goodNo'].'%'];
  19. if($params['goodType']!='') $where[]=['Manager.goodType','=',$params['goodType']];
  20. if($params['status']!='') $where[]=['financial_tz.status','=',$params['status']];
  21. if($params['start']!='') $where[]=['financial_tz.create_time','>=',startTime($params['start'])];
  22. if($params['end']!='') $where[]=['financial_tz.create_time','<=',startTime($params['end'])];
  23. if($params['seller_code']!='') $where[]=['Manager.seller_code','=',$params['seller_code']];
  24. $list = $this->model
  25. ->with(["ProductTz"=>["Product"]])
  26. ->withJoin("Manager", "LEFT")
  27. ->where($where)
  28. ->order("financial_tz.id", "desc")
  29. ->paginate(['page'=>$params['page'],'list_rows'=>$params['size']]);
  30. return success("获取成功",["list"=>$list->items(),"total"=>$list->total()]);
  31. }
  32. public function info()
  33. {
  34. $ids = $this->request->param("id","0","int");
  35. if($ids==0) return error("参数错误");
  36. $info = $this->model
  37. ->with(["ProductTz"=>["Product"],"Manager"=>['ProductRela'=>['Product']]])
  38. ->findOrEmpty($ids);
  39. if($info->isEmpty()) return error("信息不存在");
  40. return success("获取成功",$info);
  41. }
  42. public function status()
  43. {
  44. $params = $this->request->param(["id","status","idArr"=>[],"checkFee"=>"","isAddCheck"=>0],"post","trim");
  45. $validate = $this->validate($params,[
  46. 'id|计提单ID'=>'require|number',
  47. 'status|状态'=>'require|number|in:1,2,3,4',
  48. 'idArr|关联商品id'=>'requireIf:status,2|array',
  49. 'checkFee|调整金额'=>'requireIf:status,2|float',
  50. 'isAddCheck|是否添加至调整单'=>'number|in:0,1',
  51. ]);
  52. if($validate!==true) return error($validate);
  53. $info = $this->model->findOrEmpty($params['id']);
  54. if($info->isEmpty()) return error("计提单信息不存在");
  55. if($info->status==2) return error("已审核,无法修改");
  56. if($params['status']==2 && !empty($params['idArr'])){
  57. foreach ($params['idArr'] as $k=>$v){
  58. $vali=$this->validate($v,[
  59. 'id|商品id'=>'require|number',
  60. 'num|数量'=>'require|float',
  61. 'subunit_price|不含税单价'=>'require|float',
  62. 'unit_price|含税单价'=>'require|float',
  63. ]);
  64. if($vali!==true) return error($vali);
  65. $params['idArr'][$k]['ktCode']=$info->ktCode;
  66. $params['idArr'][$k]['type']=2;
  67. $params['idArr'][$k]['checkUid']=$this->uid;
  68. $params['idArr'][$k]['checkUname']=$this->uname;
  69. $params['idArr'][$k]['product_id']=$v['id'];
  70. unset($params['idArr'][$k]['id']);
  71. }
  72. }
  73. $info->status=$params['status'];
  74. $info->check_fee=$params['checkFee'];
  75. $info->is_checkOrder=$params['isAddCheck'];
  76. $info->checkUid=$this->uid;
  77. $info->checkUname=$this->uname;
  78. $this->model->startTrans();
  79. try{
  80. $save=$info->save();
  81. if($save===false) throw new \Exception("保存失败");
  82. if($params['status']==2 && !empty($params['idArr'])){
  83. $key=(new TzProduct)->saveAll($params['idArr']);
  84. if($key->isEmpty()) throw new \Exception("保存商品信息失败");
  85. }
  86. $this->model->commit();
  87. }catch (\Exception $e){
  88. $this->model->rollback();
  89. return error($e->getMessage());
  90. }
  91. return success("操作成功");
  92. }
  93. }