123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?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','','trim');
- $data = model('address')->checkAddrCode($code,9,$this->orgId);
- if(!$data){
- HelpHander::error('二维码不正确');
- }
- HelpHander::success(['id'=>$data['id'],'title'=>$data['title']]);
- }
- 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');
- if(empty($depId)) HelpHander::error('地点不能为空');
- $item = input('items','');
- if(empty($item)) HelpHander::error('物品信息不能为空');
- $items = json_decode($item,true);
- if(!is_array($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'];
- }
- $params['dep_id'] = $depId;
- $params['org_id'] = $orgId;
- $params['user_id'] = $userId;
- $params['items'] = $formatItem;
- $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')
- ->where($map)
- ->find();
- 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');
- if(empty($type)) HelpHander::error('参数type不能为空');
- if(!in_array($type,[2,3])) HelpHander::error('参数type值错误');
- if($type==3){
- 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);
- break;
- }
- if(!$res) HelpHander::error((new WashingRecord())->getError());
- HelpHander::success([],'操作成功');
- }
- }
|