Adjust.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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"])
  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($params['status']==2 && !empty($params['idArr'])){
  56. foreach ($params['idArr'] as $k=>$v){
  57. $vali=$this->validate($v,[
  58. 'id|商品id'=>'require|number',
  59. 'num|数量'=>'require|float',
  60. 'subunit_price|不含税单价'=>'require|float',
  61. 'unit_price|含税单价'=>'require|float',
  62. ]);
  63. if($vali!==true) return error($vali);
  64. $params['idArr'][$k]['ktCode']=$info->ktCode;
  65. $params['idArr'][$k]['type']=2;
  66. $params['idArr'][$k]['checkUid']=$this->uid;
  67. $params['idArr'][$k]['checkUname']=$this->uname;
  68. }
  69. }
  70. $info->status=$params['status'];
  71. $info->check_fee=$params['checkFee'];
  72. $info->is_checkOrder=$params['isAddCheck'];
  73. $info->checkUid=$this->uid;
  74. $info->checkUname=$this->uname;
  75. $this->model->startTrans();
  76. try{
  77. $save=$info->save();
  78. if($save===false) throw new \Exception("保存失败");
  79. if($params['status']==2 && !empty($params['idArr'])){
  80. $key=(new TzProduct)->saveAll($params['idArr']);
  81. if($key->isEmpty()) throw new \Exception("保存商品信息失败");
  82. }
  83. $this->model->commit();
  84. }catch (\Exception $e){
  85. $this->model->rollback();
  86. return error($e->getMessage());
  87. }
  88. return success("操作成功");
  89. }
  90. }