123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Exception;
- use think\Db;
- class PatrolTaskApply extends Base
- {
- public function dealApply($userId,$orgId){
- $id = input('id/d',0);
- $status = input('status/d',0);
- $remark = input('remark','','trim');
- if(!in_array($status,[1,2]) || $id <= 0){
- $this->error = "参数错误";
- return false;
- }
- $info = Db::name('patrol_task_apply')->where('id',$id)->where('org_id',$orgId)->find();
- if(!$info){
- $this->error = "记录不存在";
- return false;
- }
- if($info['status'] != 0){
- $this->error = "申请已处理";
- return false;
- }
- // if(strtotime($info['end_time']) <= time()){
- // $this->error = "延期时间已失效";
- // Db::name('patrol_task_delay')->where('id',$id)->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]);
- // return false;
- // }
- Db::startTrans();
- try{
- $ret = Db::name('patrol_task_apply')->where('id',$id)->update([
- 'deal_user_id'=>$userId,
- 'status'=>$status,
- 'remark'=>$remark,
- 'update_time'=>date('Y-m-d H:i:s')
- ]);
- if(!$ret){
- \exception('操作失败');
- }
- if($status == 1){
- // 恢复计划任务
- $res = Db::name('patrol_task')->where('id',$info['task_id'])->update([
- 'status' => 2,
- 'del' => 0,
- 'update_time' => date('Y-m-d H:i:s')
- ]);
- if(!$res){
- \exception('操作失败');
- }
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- $this->error = $e->getMessage();
- return false;
- }
- return true;
- }
- }
|