/**
  * 撤回某个申请
  * @param $id
  */
 public function delete($id)
 {
     $me = $_SESSION['id'];
     $service = $this->get_service();
     // 禁止操作别人的申请
     if (!$service->is_owner($id, $me)) {
         $this->exit_with_error(10, '您无权操作此申请', 403);
     }
     // 禁止操作已操作的申请
     if (!$service->is_available($id)) {
         $this->exit_with_error(11, '此申请已处理,您不能再次操作', 403);
     }
     // 禁止操作正在处理的申请
     $this->judge_check($id);
     $attr = array('handler' => $me, 'status' => Apply::WITHDRAWN);
     $check = $service->update($attr, $id);
     if (!$check) {
         $this->exit_with_error(20, '操作失败', 400);
     }
     // 同时撤回相关通知
     $notice = new Notification();
     $notice->set_status(array('uid' => $id), Notification::$HANDLED);
     $this->output(array('code' => 0, 'msg' => 'deleted'));
 }
Exemplo n.º 2
0
 /**
  * 删除广告
  *
  * @param $id
  */
 public function delete($id)
 {
     $ad = new ADModel(['id' => $id]);
     $ad->fetch();
     // 拒绝操作已经上线的广告
     if (in_array($ad->get('status'), [0, 1])) {
         $this->exit_with_error(50, '此广告已经推广,不能删除。您可以申请将其下线。', 400);
     }
     // 拒绝操作别人的广告
     $check = $ad->check_owner();
     if (!$check) {
         $this->exit_with_error(51, '您无权操作此广告', 403);
     }
     // 被编辑锁定的广告不能撤销
     $redis = $this->get_redis();
     $redis_key = self::REDIS_PREFIX . $id;
     $value = $redis->get($redis_key);
     if ($value) {
         $value = json_decode($value, true);
         $this->exit_with_error(52, '此广告正由' . $value['name'] . '审查中,请联系ta进行处理。', 403);
     }
     // 撤回替换广告申请
     $apply_service = new Apply();
     $apply_service->remove_replace_apply($id);
     // 撤回通知
     $notice = new Notification();
     $notice->set_status(array('ad_id' => $id, 'alarm_type' => array(Notification::$NEW_AD, Notification::$REPLACE_AD)), Notification::$HANDLED);
     $attr = array('status' => ADModel::DELETED);
     $this->update($id, $attr);
 }