Wash.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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','','trim');
  12. $data = model('address')->checkAddrCode($code,9,$this->orgId);
  13. if(!$data){
  14. HelpHander::error('二维码不正确');
  15. }
  16. HelpHander::success(['id'=>$data['id'],'title'=>$data['title']]);
  17. }
  18. public function getWashItems(){
  19. $data = (new WashingItems())->getList($this->orgId);
  20. HelpHander::success($data?$data:[]);
  21. }
  22. public function add(){
  23. $orgId=$this->orgId;
  24. $userId=$this->userId;
  25. $depId=input('depId','0');
  26. if(empty($depId)) HelpHander::error('地点不能为空');
  27. $item = input('items','');
  28. if(empty($item)) HelpHander::error('物品信息不能为空');
  29. $items = json_decode($item,true);
  30. if(!is_array($items)) HelpHander::error('物品信息格式错误');
  31. $formatItem = [];
  32. foreach ($items as $k=>$v){
  33. if(empty($v['num'])) HelpHander::error('请填写'.$v['title'].'信息数量');
  34. $formatItem[$k]['items_id'] = $v['id'];
  35. $formatItem[$k]['num'] = $v['num'];
  36. }
  37. $params['dep_id'] = $depId;
  38. $params['org_id'] = $orgId;
  39. $params['user_id'] = $userId;
  40. $params['items'] = $formatItem;
  41. $res = (new WashingRecord())->addSave($params);
  42. if(!$res){
  43. HelpHander::error((new WashingRecord())->getError());
  44. }
  45. HelpHander::success([],'添加成功');
  46. }
  47. public function getWashList(){
  48. $orgId=$this->orgId;
  49. $userId=$this->userId;
  50. $type =input('type',1);
  51. $page =input('page',1);
  52. $size =input('size',10);
  53. $data = (new WashingRecord())->getApiList($page,$size,$type,$userId,$orgId);
  54. HelpHander::success($data);
  55. }
  56. public function getWashDetail(){
  57. $id=input('id',0);
  58. if(empty($id)) HelpHander::error('参数id不能为空');
  59. $map[] = ['id','=',$id];
  60. $map[] = ['user_id','=',$this->userId];
  61. $map[] = ['del','=',0];
  62. $data = Db::name('washing_record')
  63. ->field('mode,create_time,return_time,confirm_time,sign')
  64. ->where($map)
  65. ->find();
  66. if(empty($data)) HelpHander::error('信息不存在');
  67. $item = Db::name('washing_record_item')->where('washing_record_id',$id)
  68. ->select();
  69. $items = [];
  70. foreach ($item as $k=>$v){
  71. $goods = Db::name('washing_items')
  72. ->where('id',$v['items_id'])
  73. ->find();
  74. $items[$k]['num'] = $v['num'];
  75. $items[$k]['title'] = $goods['title'];
  76. }
  77. $data['items'] = $items;
  78. $data['return_time'] = $data['return_time']?$data['return_time']:'';
  79. $data['confirm_time'] = $data['confirm_time']?$data['confirm_time']:'';
  80. $data['sign'] = $data['sign']?$data['sign']:'';
  81. $data['items'] = $items;
  82. HelpHander::success($data?$data:[]);
  83. }
  84. public function optionWash(){
  85. $id=input('id',0);
  86. $type=input('type');
  87. $sign=input('sign');
  88. if(empty($type)) HelpHander::error('参数type不能为空');
  89. if(!in_array($type,[2,3])) HelpHander::error('参数type值错误');
  90. if($type==3){
  91. if(empty($sign)) HelpHander::error('签名照片不能为空');
  92. }
  93. switch ($type){
  94. case 2:
  95. $res = (new WashingRecord())->returnWash($id,$this->orgId);
  96. break;
  97. case 3:
  98. $res = (new WashingRecord())->confirmWash($id,$this->orgId,$sign);
  99. break;
  100. }
  101. if(!$res) HelpHander::error((new WashingRecord())->getError());
  102. HelpHander::success([],'操作成功');
  103. }
  104. }