|
@@ -117,35 +117,75 @@ class Apply extends Backend
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 批量审核通过
|
|
|
|
|
|
+ * 删除
|
|
*/
|
|
*/
|
|
- public function multi($ids = null)
|
|
|
|
|
|
+ public function del($ids = null)
|
|
{
|
|
{
|
|
if (!$this->request->isPost()) {
|
|
if (!$this->request->isPost()) {
|
|
$this->error(__('Invalid parameters'));
|
|
$this->error(__('Invalid parameters'));
|
|
}
|
|
}
|
|
|
|
|
|
- $action = $this->request->post('action');
|
|
|
|
- if ($action != 'approve') {
|
|
|
|
- return parent::multi($ids);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (!$ids) {
|
|
if (!$ids) {
|
|
$this->error(__('Parameter %s can not be empty', 'ids'));
|
|
$this->error(__('Parameter %s can not be empty', 'ids'));
|
|
}
|
|
}
|
|
|
|
|
|
$ids = explode(',', $ids);
|
|
$ids = explode(',', $ids);
|
|
- $service = new AgentApplyService();
|
|
|
|
|
|
+ $deleteCount = 0;
|
|
|
|
|
|
- Db::transaction(function () use ($ids, $service) {
|
|
|
|
|
|
+ Db::transaction(function () use ($ids, &$deleteCount) {
|
|
foreach ($ids as $id) {
|
|
foreach ($ids as $id) {
|
|
$row = $this->model->get($id);
|
|
$row = $this->model->get($id);
|
|
- if ($row && $row->status == ApplyModel::STATUS_PENDING) {
|
|
|
|
- $service->approveApply($row, $this->auth->id);
|
|
|
|
|
|
+ if ($row) {
|
|
|
|
+ // 只允许删除待审核和已拒绝的申请
|
|
|
|
+ //if (in_array($row->status, [ApplyModel::STATUS_PENDING, ApplyModel::STATUS_REJECTED])) {
|
|
|
|
+ $row->delete();
|
|
|
|
+ $deleteCount++;
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- $this->success('批量审核成功');
|
|
|
|
|
|
+ if ($deleteCount > 0) {
|
|
|
|
+ $this->success("成功删除 {$deleteCount} 条申请记录");
|
|
|
|
+ } else {
|
|
|
|
+ $this->error('没有可删除的记录(只能删除待审核和已拒绝的申请)');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量审核通过
|
|
|
|
+ */
|
|
|
|
+ public function multi($ids = null)
|
|
|
|
+ {
|
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $action = $this->request->post('action');
|
|
|
|
+ if ($action == 'approve') {
|
|
|
|
+ // 批量审核通过
|
|
|
|
+ if (!$ids) {
|
|
|
|
+ $this->error(__('Parameter %s can not be empty', 'ids'));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $ids = explode(',', $ids);
|
|
|
|
+ $service = new AgentApplyService();
|
|
|
|
+
|
|
|
|
+ Db::transaction(function () use ($ids, $service) {
|
|
|
|
+ foreach ($ids as $id) {
|
|
|
|
+ $row = $this->model->get($id);
|
|
|
|
+ if ($row && $row->status == ApplyModel::STATUS_PENDING) {
|
|
|
|
+ $service->approveApply($row, $this->auth->id);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $this->success('批量审核成功');
|
|
|
|
+ } elseif ($action == 'del') {
|
|
|
|
+ // 批量删除
|
|
|
|
+ return $this->del($ids);
|
|
|
|
+ } else {
|
|
|
|
+ return parent::multi($ids);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|