You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
4.0 KiB
122 lines
4.0 KiB
<?php
|
|
|
|
namespace app\admin\controller\liveroom;
|
|
|
|
use app\admin\model\LiveRoom;
|
|
use app\admin\model\User;
|
|
use app\admin\validate\TaskValidate;
|
|
use app\common\controller\AdminController;
|
|
use think\App;
|
|
use app\admin\model\Task as TaskModel;
|
|
use think\exception\ValidateException;
|
|
|
|
class Task extends AdminController
|
|
{
|
|
|
|
public function __construct(App $app)
|
|
{
|
|
parent::__construct($app);
|
|
$this->model = new TaskModel();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
if ($this->request->isAjax()) {
|
|
if (input('selectFields')) {
|
|
return $this->selectList();
|
|
}
|
|
list($page, $limit, $where) = $this->buildTableParames();
|
|
$count = $this->model
|
|
->where($where)
|
|
->count();
|
|
$list = $this->model
|
|
->withoutField('update_time, delete_time')
|
|
->where($where)
|
|
->page($page, $limit)
|
|
->order('id')
|
|
->select()
|
|
->each(function ($item) {
|
|
$item['status_str'] = TaskModel::$statusArr[$item['status']] ?? '-';
|
|
$item['add_uid'] = User::getUserValue($item['add_uid']);
|
|
$item['assign_uid'] = User::getUserValue($item['assign_uid']);
|
|
$item['deduction_ratio'] = $item['deduction_ratio'] * 1;
|
|
return $item;
|
|
});
|
|
$data = [
|
|
'code' => 0,
|
|
'msg' => '',
|
|
'count' => $count,
|
|
'data' => $list
|
|
];
|
|
return json($data);
|
|
}
|
|
$this->assign('status_json', json_encode(TaskModel::$statusArr));
|
|
return $this->fetch();
|
|
}
|
|
|
|
/**
|
|
* @NodeAnotation(title="添加")
|
|
*/
|
|
public function add()
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$post = $this->request->post();
|
|
try {
|
|
validate(TaskValidate::class)->scene('add')->check($post);
|
|
$save = $this->model->save($post);
|
|
} catch (ValidateException $e) {
|
|
$this->error($e->getMessage());
|
|
} catch (\Exception $e) {
|
|
$this->error('保存失败');
|
|
}
|
|
$save ? $this->success('保存成功') : $this->error('保存失败');
|
|
}
|
|
return $this->fetch();
|
|
}
|
|
|
|
/**
|
|
* @NodeAnotation(title="编辑")
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$row = $this->model->find($id);
|
|
empty($row) && $this->error('数据不存在');
|
|
if ($this->request->isPost()) {
|
|
$post = $this->request->post();
|
|
try {
|
|
validate(TaskValidate::class)->scene('add')->check($post);
|
|
$save = $row->save($post);
|
|
} catch (ValidateException $e) {
|
|
$this->error($e->getMessage());
|
|
} catch (\Exception $e) {
|
|
$this->error('保存失败');
|
|
}
|
|
$save ? $this->success('保存成功') : $this->error('保存失败');
|
|
}
|
|
$row['room_id'] = LiveRoom::where('id', $row['live_room_id'])->value('room_id') ?? '';
|
|
$row['add_uname'] = User::getUserValue($row['add_uid']);
|
|
$row['assign_uname'] = User::getUserValue($row['assign_uid']);
|
|
$row['deduction_ratio'] = $row['deduction_ratio'] * 1;
|
|
$this->assign('row', $row);
|
|
return $this->fetch();
|
|
}
|
|
|
|
/**
|
|
* @NodeAnotation(title="删除")
|
|
*/
|
|
public function delete($id)
|
|
{
|
|
$this->checkPostRequest();
|
|
$row = $this->model->whereIn('id', $id)->select();
|
|
$row->isEmpty() && $this->error('数据不存在');
|
|
try {
|
|
$save = false;
|
|
foreach ($row as $value) {
|
|
$save = $this->model->where('id', $value['id'])->useSoftDelete('delete_time', time())->delete();
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->error('删除失败');
|
|
}
|
|
$save ? $this->success('删除成功') : $this->error('删除失败');
|
|
}
|
|
}
|
|
|