141 lines
3.8 KiB
PHP
141 lines
3.8 KiB
PHP
<?php
|
|
/**
|
|
* VR票务插件 - 核销员管理
|
|
*
|
|
* @package vr_ticket\admin\controller
|
|
*/
|
|
|
|
namespace app\plugins\vr_ticket\admin\controller;
|
|
|
|
class Verifier
|
|
{
|
|
/**
|
|
* 核销员列表
|
|
*/
|
|
public function list()
|
|
{
|
|
$where = [];
|
|
|
|
$keywords = input('keywords', '', null, 'trim');
|
|
if (!empty($keywords)) {
|
|
$where[] = ['name|user_id', 'like', "%{$keywords}%"];
|
|
}
|
|
|
|
$status = input('status', '', null);
|
|
if ($status !== '' && $status !== null) {
|
|
$where[] = ['status', '=', intval($status)];
|
|
}
|
|
|
|
$list = \Db::name('plugins_vr_verifiers')
|
|
->where($where)
|
|
->order('id', 'desc')
|
|
->paginate(20)
|
|
->toArray();
|
|
|
|
// 关联 ShopXO 用户信息
|
|
$user_ids = array_filter(array_column($list['data'], 'user_id'));
|
|
if (!empty($user_ids)) {
|
|
$users = \Db::name('User')
|
|
->where('id', 'in', $user_ids)
|
|
->column('nickname|username', 'id');
|
|
foreach ($list['data'] as &$item) {
|
|
$item['user_name'] = $users[$item['user_id']] ?? '已删除用户';
|
|
}
|
|
unset($item);
|
|
}
|
|
|
|
return view('', [
|
|
'list' => $list['data'],
|
|
'page' => $list['page'],
|
|
'count' => $list['total'],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 添加/编辑核销员
|
|
*/
|
|
public function save()
|
|
{
|
|
$id = input('id', 0, 'intval');
|
|
|
|
if (IS_AJAX_POST) {
|
|
$user_id = input('user_id', 0, 'intval');
|
|
$name = input('name', '', null, 'trim');
|
|
$status = input('status', 1, 'intval');
|
|
|
|
if ($user_id <= 0) {
|
|
return DataReturn('请选择关联用户', -1);
|
|
}
|
|
if (empty($name)) {
|
|
return DataReturn('核销员名称不能为空', -1);
|
|
}
|
|
|
|
// 检查是否已存在
|
|
$exist = \Db::name('plugins_vr_verifiers')
|
|
->where('user_id', $user_id)
|
|
->where('id', '<>', $id)
|
|
->find();
|
|
if ($exist) {
|
|
return DataReturn('该用户已是核销员', -1);
|
|
}
|
|
|
|
if ($id > 0) {
|
|
\Db::name('plugins_vr_verifiers')
|
|
->where('id', $id)
|
|
->update([
|
|
'name' => $name,
|
|
'status' => $status,
|
|
]);
|
|
return DataReturn('更新成功', 0);
|
|
} else {
|
|
\Db::name('plugins_vr_verifiers')->insert([
|
|
'user_id' => $user_id,
|
|
'name' => $name,
|
|
'status' => $status,
|
|
'created_at' => time(),
|
|
]);
|
|
return DataReturn('添加成功', 0);
|
|
}
|
|
}
|
|
|
|
$info = [];
|
|
if ($id > 0) {
|
|
$info = \Db::name('plugins_vr_verifiers')->find($id);
|
|
}
|
|
|
|
// 用户列表(用于选择)
|
|
$users = \Db::name('User')
|
|
->where('is_delete', 0)
|
|
->field('id, nickname, username')
|
|
->order('id', 'desc')
|
|
->select();
|
|
|
|
return view('', [
|
|
'info' => $info,
|
|
'users' => $users,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 删除核销员
|
|
*/
|
|
public function delete()
|
|
{
|
|
if (!IS_AJAX_POST) {
|
|
return DataReturn('非法请求', -1);
|
|
}
|
|
|
|
$id = input('id', 0, 'intval');
|
|
if ($id <= 0) {
|
|
return DataReturn('参数错误', -1);
|
|
}
|
|
|
|
// 不允许删除,改为禁用
|
|
\Db::name('plugins_vr_verifiers')
|
|
->where('id', $id)
|
|
->update(['status' => 0]);
|
|
|
|
return DataReturn('已禁用', 0);
|
|
}
|
|
}
|