/** * 删除广告 * * @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); }