123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace app\api\controller\v1;
- use app\api\controller\Base;
- use app\common\model\WashingItems;
- use app\common\model\WashingRecord;
- use app\hander\HelpHander;
- use think\Db;
- class Wash extends Base
- {
- public function getWashDep(){
- $code=input('code','');
- if(empty($code)) HelpHander::error('code不能为空');
- $data = get_qrcode_arr($code);
- if(empty($data)) HelpHander::error('地点不存在');
- if($data['type'] !='address'){
- HelpHander::error('地点不存在');
- }
- $info = Db::name('address')->where('id',$data['id'])
- ->field('id,title,types')
- ->find();
- $types = $info['types']?explode(',',$info['types']):[];
- if(!in_array(9,$types)){
- HelpHander::error('二维码不正确');
- }
- unset($info['types']);
- HelpHander::success($info?$info:[]);
- }
- public function getWashItems(){
- $data = (new WashingItems())->getList($this->orgId);
- HelpHander::success($data?$data:[]);
- }
- public function add(){
- $orgId=$this->orgId;
- $userId=$this->userId;
- $depId=input('depId','0');
- $sqImg = input('sqImg','');
- $sqSign = input('sqSign','');
- if(empty($depId)) HelpHander::error('地点不能为空');
- $item = input('items','');
- if(empty($item)) HelpHander::error('物品信息不能为空');
- $items = json_decode($item,true);
- if(!is_array($items) || empty($items)) HelpHander::error('物品信息格式错误');
- $formatItem = [];
- foreach ($items as $k=>$v){
- if(empty($v['num'])) HelpHander::error('请填写'.$v['title'].'信息数量');
- $formatItem[$k]['items_id'] = $v['id'];
- $formatItem[$k]['num'] = $v['num'];
- }
- // if(!$sqImg)HelpHander::error('收取图片不能为空');
- if(!$sqSign)HelpHander::error('收取签名不能为空');
- $params['dep_id'] = $depId;
- $params['org_id'] = $orgId;
- $params['user_id'] = $userId;
- $params['items'] = $formatItem;
- $params['sq_img'] = $sqImg;
- $params['sq_sign'] = $sqSign;
- $res = (new WashingRecord())->addSave($params);
- if(!$res){
- HelpHander::error((new WashingRecord())->getError());
- }
- HelpHander::success([],'添加成功');
- }
- public function getWashList(){
- $orgId=$this->orgId;
- $userId=$this->userId;
- $type =input('type',1);
- $page =input('page',1);
- $size =input('size',10);
- $data = (new WashingRecord())->getApiList($page,$size,$type,$userId,$orgId);
- HelpHander::success($data);
- }
- public function getWashDetail(){
- $id=input('id',0);
- if(empty($id)) HelpHander::error('参数id不能为空');
- $map[] = ['id','=',$id];
- $map[] = ['user_id','=',$this->userId];
- $map[] = ['del','=',0];
- $data = Db::name('washing_record')
- ->field('mode,create_time,return_time,confirm_time,sign,sq_img,sq_sign,img')
- ->where($map)
- ->find();
- $data['sq_img'] = $data['sq_img']?$data['sq_img']:'';
- $data['sq_sign'] = $data['sq_sign']?$data['sq_sign']:'';
- $data['img'] = $data['img']?$data['img']:'';
- if(empty($data)) HelpHander::error('信息不存在');
- $item = Db::name('washing_record_item')->where('washing_record_id',$id)
- ->select();
- $items = [];
- foreach ($item as $k=>$v){
- $goods = Db::name('washing_items')
- ->where('id',$v['items_id'])
- ->find();
- $items[$k]['num'] = $v['num'];
- $items[$k]['title'] = $goods['title'];
- }
- $data['items'] = $items;
- $data['return_time'] = $data['return_time']?$data['return_time']:'';
- $data['confirm_time'] = $data['confirm_time']?$data['confirm_time']:'';
- $data['sign'] = $data['sign']?$data['sign']:'';
- $data['items'] = $items;
- HelpHander::success($data?$data:[]);
- }
- public function optionWash(){
- $id=input('id',0);
- $type=input('type');
- $sign=input('sign');
- $img = input('img');
- if(empty($type)) HelpHander::error('参数type不能为空');
- if(!in_array($type,[2,3])) HelpHander::error('参数type值错误');
- if($type==3){
- // if(empty($img)) HelpHander::error('确认照片不能为空');
- if(empty($sign)) HelpHander::error('签名照片不能为空');
- }
- switch ($type){
- case 2:
- $res = (new WashingRecord())->returnWash($id,$this->orgId);
- break;
- case 3:
- $res = (new WashingRecord())->confirmWash($id,$this->orgId,$sign,$img);
- break;
- }
- if(!$res) HelpHander::error((new WashingRecord())->getError());
- HelpHander::success([],'操作成功');
- }
- }
|