model = new \app\admin\model\FcMerchant; } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 审核商家资质 */ /** * 获取单个商家的入驻资质与质检详情 * * @param int|null $ids 商家ID * @return string|\think\response\Json */ public function detail($ids = null) { $id = $this->request->param('ids', 0) ?: $this->request->param('id/d', 0); if (!$id) { $this->error('缺少参数ID'); } $row = $this->model->where('id', $id)->find(); if (!$row) { $this->error('商家不存在或已删除'); } $userInfo = [ 'id' => $row->user_id, 'nickname' => '未知用户', 'mobile' => '', 'avatar' => '/assets/img/avatar.png' ]; $user = Db::name('user')->where('id', $row->user_id)->field('id,nickname,mobile,avatar')->find(); if ($user) { $userInfo['nickname'] = $user['nickname'] ?: $userInfo['nickname']; $userInfo['mobile'] = $user['mobile'] ?: ''; $userInfo['avatar'] = $user['avatar'] ?: $userInfo['avatar']; } if ($this->request->param('format') === 'json') { $data = [ 'id' => $row->id, 'name' => $row->name, 'logo' => $row->logo, 'banner' => $row->banner, 'contact' => $row->contact, 'category' => $row->category, 'license' => $row->license, 'notice' => $row->notice, 'recommend' => $row->recommend, 'audit_status' => $row->audit_status, 'audit_reason' => $row->audit_reason, 'shop_status' => $row->shop_status, 'violations' => $row->violations, 'post_count' => $row->post_count, 'createtime_text' => date('Y-m-d H:i:s', $row->createtime), 'user' => $userInfo ]; $this->success('获取成功', null, $data); } // 区分模式:audit=专属审核界面,view=纯净详情档案界面 $mode = $this->request->param('mode', ''); if (!$mode) { $mode = ((int)$row->audit_status === 0) ? 'audit' : 'view'; } $this->view->assign('mode', $mode); $this->view->assign('row', $row); $this->view->assign('userInfo', $userInfo); if ($mode === 'audit') { return $this->view->fetch('audit'); } return $this->view->fetch('detail'); } public function audit() { $ids = $this->request->post('ids'); $auditStatus = (int)$this->request->post('auditStatus'); $reason = $this->request->post('reason', ''); if (!in_array($auditStatus, [1, 2])) { $this->error('审核状态仅支持通过(1)/驳回(2)'); } $ids = is_array($ids) ? $ids : explode(',', (string)$ids); $ids = array_filter($ids); if (!$ids) { $this->error('请选择要审核的商家'); } $merchants = Db::name('fc_merchant')->where('id', 'in', $ids)->select(); if (!$merchants) { $this->error('商家不存在'); } foreach ($merchants as $merchant) { Db::name('fc_merchant')->where('id', $merchant['id'])->update([ 'audit_status' => $auditStatus, 'audit_reason' => $reason, 'shop_status' => $auditStatus === 1 ? 'normal' : 'banned', 'updatetime' => time(), ]); if ($auditStatus === 1) { Db::name('fc_user_ext')->where('user_id', $merchant['user_id'])->update(['user_type' => 2]); } Db::name('fc_message')->insert([ 'user_id' => $merchant['user_id'], 'type' => 'system', 'title' => $auditStatus === 1 ? '审核通过' : '审核驳回', 'content' => $auditStatus === 1 ? '您的商家「' . $merchant['name'] . '」资质已审核通过' : '您的商家「' . $merchant['name'] . '」资质审核未通过' . ($reason ? ',原因:' . $reason : ''), 'isread' => 0, 'createtime' => time(), ]); } $this->success('审核成功'); } }