Wash.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\common\model\WashingItems;
  5. use app\common\model\WashingRecord;
  6. use app\hander\HelpHander;
  7. use think\Db;
  8. class Wash extends Base
  9. {
  10. public function getWashDep(){
  11. $code=input('code','');
  12. if(empty($code)) HelpHander::error('code不能为空');
  13. $data = get_qrcode_arr($code);
  14. if(empty($data)) HelpHander::error('地点不存在');
  15. if($data['type'] !='address'){
  16. HelpHander::error('地点不存在');
  17. }
  18. $info = Db::name('address')->where('id',$data['id'])
  19. ->field('id,title,types')
  20. ->find();
  21. $types = $info['types']?explode(',',$info['types']):[];
  22. if(!in_array(9,$types)){
  23. HelpHander::error('二维码不正确');
  24. }
  25. unset($info['types']);
  26. HelpHander::success($info?$info:[]);
  27. }
  28. public function getWashItems(){
  29. $data = (new WashingItems())->getList($this->orgId);
  30. HelpHander::success($data?$data:[]);
  31. }
  32. public function add(){
  33. $orgId=$this->orgId;
  34. $userId=$this->userId;
  35. $depId=input('depId','0');
  36. $sqImg = input('sqImg','');
  37. $sqSign = input('sqSign','');
  38. if(empty($depId)) HelpHander::error('地点不能为空');
  39. $item = input('items','');
  40. if(empty($item)) HelpHander::error('物品信息不能为空');
  41. $items = json_decode($item,true);
  42. if(!is_array($items) || empty($items)) HelpHander::error('物品信息格式错误');
  43. $formatItem = [];
  44. foreach ($items as $k=>$v){
  45. if(empty($v['num'])) HelpHander::error('请填写'.$v['title'].'信息数量');
  46. $formatItem[$k]['items_id'] = $v['id'];
  47. $formatItem[$k]['num'] = $v['num'];
  48. }
  49. // if(!$sqImg)HelpHander::error('收取图片不能为空');
  50. if(!$sqSign)HelpHander::error('收取签名不能为空');
  51. $params['dep_id'] = $depId;
  52. $params['org_id'] = $orgId;
  53. $params['user_id'] = $userId;
  54. $params['items'] = $formatItem;
  55. $params['sq_img'] = $sqImg;
  56. $params['sq_sign'] = $sqSign;
  57. $res = (new WashingRecord())->addSave($params);
  58. if(!$res){
  59. HelpHander::error((new WashingRecord())->getError());
  60. }
  61. HelpHander::success([],'添加成功');
  62. }
  63. public function getWashList(){
  64. $orgId=$this->orgId;
  65. $userId=$this->userId;
  66. $type =input('type',1);
  67. $page =input('page',1);
  68. $size =input('size',10);
  69. $data = (new WashingRecord())->getApiList($page,$size,$type,$userId,$orgId);
  70. HelpHander::success($data);
  71. }
  72. public function getWashDetail(){
  73. $id=input('id',0);
  74. if(empty($id)) HelpHander::error('参数id不能为空');
  75. $map[] = ['id','=',$id];
  76. $map[] = ['user_id','=',$this->userId];
  77. $map[] = ['del','=',0];
  78. $data = Db::name('washing_record')
  79. ->field('mode,create_time,return_time,confirm_time,sign,sq_img,sq_sign,img')
  80. ->where($map)
  81. ->find();
  82. $data['sq_img'] = $data['sq_img']?$data['sq_img']:'';
  83. $data['sq_sign'] = $data['sq_sign']?$data['sq_sign']:'';
  84. $data['img'] = $data['img']?$data['img']:'';
  85. if(empty($data)) HelpHander::error('信息不存在');
  86. $item = Db::name('washing_record_item')->where('washing_record_id',$id)
  87. ->select();
  88. $items = [];
  89. foreach ($item as $k=>$v){
  90. $goods = Db::name('washing_items')
  91. ->where('id',$v['items_id'])
  92. ->find();
  93. $items[$k]['num'] = $v['num'];
  94. $items[$k]['title'] = $goods['title'];
  95. }
  96. $data['items'] = $items;
  97. $data['return_time'] = $data['return_time']?$data['return_time']:'';
  98. $data['confirm_time'] = $data['confirm_time']?$data['confirm_time']:'';
  99. $data['sign'] = $data['sign']?$data['sign']:'';
  100. $data['items'] = $items;
  101. HelpHander::success($data?$data:[]);
  102. }
  103. public function optionWash(){
  104. $id=input('id',0);
  105. $type=input('type');
  106. $sign=input('sign');
  107. $img = input('img');
  108. if(empty($type)) HelpHander::error('参数type不能为空');
  109. if(!in_array($type,[2,3])) HelpHander::error('参数type值错误');
  110. if($type==3){
  111. // if(empty($img)) HelpHander::error('确认照片不能为空');
  112. if(empty($sign)) HelpHander::error('签名照片不能为空');
  113. }
  114. switch ($type){
  115. case 2:
  116. $res = (new WashingRecord())->returnWash($id,$this->orgId);
  117. break;
  118. case 3:
  119. $res = (new WashingRecord())->confirmWash($id,$this->orgId,$sign,$img);
  120. break;
  121. }
  122. if(!$res) HelpHander::error((new WashingRecord())->getError());
  123. HelpHander::success([],'操作成功');
  124. }
  125. }