Adjust.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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',"page","size"],"post","trim");
  16. $where=[];
  17. if($params['goodNo']!='') $where[]=['Manager.goodNo','like','%'.$params['goodNo'].'%'];
  18. if($params['goodType']!='') $where[]=['Manager.goodType','=',$params['goodType']];
  19. if($params['status']!='') $where[]=['financial_tz.status','=',$params['status']];
  20. if($params['start']!='') $where[]=['financial_tz.create_time','>=',startTime($params['start'])];
  21. if($params['end']!='') $where[]=['financial_tz.create_time','<=',startTime($params['end'])];
  22. if($params['seller_code']!='') $where[]=['Manager.seller_code','=',$params['seller_code']];
  23. $list = $this->model
  24. ->with(["ProductTz"=>["ManagerProduct"]])
  25. ->withJoin("Manager", "LEFT")
  26. ->where($where)
  27. ->order("financial_tz.id", "desc")
  28. ->paginate(['page'=>$params['page'],'list_rows'=>$params['size']]);
  29. return success("获取成功",["list"=>$list->items(),"total"=>$list->total()]);
  30. }
  31. public function info()
  32. {
  33. $ids = $this->request->param("id","0","int");
  34. if($ids==0) return error("参数错误");
  35. $info = $this->model
  36. ->with(["ProductTz"=>["ManagerProduct"],"Manager"])
  37. ->findOrEmpty($ids);
  38. if($info->isEmpty()) return error("信息不存在");
  39. return success("获取成功",$info);
  40. }
  41. public function status()
  42. {
  43. $params = $this->request->param(["id","status","idArr"=>[],"checkFee"=>"","isAddCheck"=>0],"post","trim");
  44. $validate = $this->validate($params,[
  45. 'id|计提单ID'=>'require|number',
  46. 'status|状态'=>'require|number|in:1,2,3,4',
  47. 'idArr|关联商品id'=>'requireIf:status,2|array',
  48. 'checkFee|调整金额'=>'requireIf:status,2|float',
  49. 'isAddCheck|是否添加至调整单'=>'number|in:0,1',
  50. ]);
  51. if($validate!==true) return error($validate);
  52. $info = $this->model->findOrEmpty($params['id']);
  53. if($info->isEmpty()) return error("计提单信息不存在");
  54. if($params['status']==2 && !empty($params['idArr'])){
  55. foreach ($params['idArr'] as $k=>$v){
  56. $vali=$this->validate($v,[
  57. 'id|商品id'=>'require|number',
  58. 'num|数量'=>'require|float',
  59. 'unit_price|单价'=>'require|float',
  60. ]);
  61. if($vali!==true) return error($vali);
  62. $params['idArr'][$k]['ktCode']=$info->ktCode;
  63. $params['idArr'][$k]['type']=2;
  64. $params['idArr'][$k]['checkUid']=$this->uid;
  65. $params['idArr'][$k]['checkUname']=$this->uname;
  66. }
  67. }
  68. $info->status=$params['status'];
  69. $info->check_fee=$params['checkFee'];
  70. $info->is_checkOrder=$params['isAddCheck'];
  71. $info->checkUid=$this->uid;
  72. $info->checkUname=$this->uname;
  73. $this->model->startTrans();
  74. try{
  75. $save=$info->save();
  76. if($save===false) throw new \Exception("保存失败");
  77. if($params['status']==2 && !empty($params['idArr'])){
  78. $key=(new TzProduct)->saveAll($params['idArr']);
  79. if($key->isEmpty()) throw new \Exception("保存商品信息失败");
  80. }
  81. }catch (\Exception $e){
  82. $this->model->rollback();
  83. return error($e->getMessage());
  84. }
  85. }
  86. }