199 lines
5.9 KiB
PHP
199 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller\backend;
|
|
|
|
use app\common\controller\Api;
|
|
use app\api\model\Admin as AdminModel;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 拒收红包控制器
|
|
*/
|
|
class RejectRedEnvelopes extends Api
|
|
{
|
|
protected $noNeedLogin = ['*'];
|
|
protected $noNeedRight = ['*'];
|
|
protected $user_id = '';
|
|
protected $level = '';
|
|
protected $group_id = '';
|
|
protected $auth_id = '';
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$id = $this->request->header('Token');
|
|
if(!$id){
|
|
return $this->error('缺少参数');
|
|
}
|
|
$user = Db::name('user')->where('token', $id)->find();
|
|
if(!$user){
|
|
return $this->error('用户不存在');
|
|
}
|
|
$this->user_id = $user['id'];
|
|
$this->group_id = $user['group_id'];
|
|
$this->auth_id = $user['auth_group_id'];
|
|
$this->level = Db::name('auth_group')->where('id', $user['auth_group_id'])->value('level');
|
|
|
|
}
|
|
/**
|
|
* Undocumented function
|
|
*列表
|
|
* @return void
|
|
*/
|
|
public function index() {
|
|
$page = $this->request->post('page', 1);
|
|
$limit = $this->request->post('size', 10);
|
|
$group= $this->request->post('group_id');
|
|
$status= $this->request->post('status');
|
|
$time= $this->request->post('fsdate');
|
|
$user_id= $this->request->post('user_id');
|
|
$where = [];
|
|
//判断该用户有没有权限审核
|
|
if($this->level == 2){
|
|
$where['a.user_id'] = $this->user_id;
|
|
if ($status) {
|
|
$where['a.status'] = $status;
|
|
}
|
|
if ($time) {
|
|
$where['a.fsdate'] = $time;
|
|
}
|
|
}
|
|
if($this->level == 1){
|
|
$where['a.group_id'] = $this->group_id;
|
|
if ($status) {
|
|
$where['a.status'] = $status;
|
|
}
|
|
if ($time) {
|
|
$where['a.fsdate'] = $time;
|
|
}
|
|
if ($user_id) {
|
|
$where['a.user_id'] = $user_id;
|
|
}
|
|
|
|
}
|
|
if($this->auth_id == 1 && $group){
|
|
$where['a.group_id'] = $group;
|
|
|
|
if ($status) {
|
|
$where['a.status'] = $status;
|
|
}
|
|
if ($time) {
|
|
$where['a.fsdate'] = $time;
|
|
}
|
|
if ($user_id) {
|
|
$where['a.user_id'] = $user_id;
|
|
}
|
|
}
|
|
// 获取指定科室及其子科室的ID
|
|
$groupIds = $this->getGroupAndSubGroupIds($group);
|
|
|
|
if (!empty($groupIds)) {
|
|
$where['a.group_id'] = ['in', $groupIds];
|
|
}
|
|
$date = Db::name('reject_red_envelopes')
|
|
->field('a.*,u.nickname,g.name as group_name,w.nickname as zm_nickname')
|
|
->alias('a')
|
|
->join('user u','a.user_id = u.id','LEFT')
|
|
->join('user_group g','a.group_id = g.id','LEFT')
|
|
->join('user w','a.zm_user_id = w.id','LEFT')
|
|
->where($where)
|
|
->order('a.id', 'desc')
|
|
->page($page, $limit)
|
|
->select();
|
|
$count = Db::name('reject_red_envelopes')
|
|
->field('a.*,u.nickname,g.name as group_name,w.nickname as zm_nickname')
|
|
->alias('a')
|
|
->join('user u','a.user_id = u.id','LEFT')
|
|
->join('user_group g','a.group_id = g.id','LEFT')
|
|
->join('user w','a.zm_user_id = w.id','LEFT')
|
|
->where($where)
|
|
->count();
|
|
foreach($date as $k => $v){
|
|
$date[$k]['level'] = $this->level;
|
|
}
|
|
$res = [
|
|
'count' => $count,
|
|
'data' => $date
|
|
];
|
|
return $this->success('查询成功',$res);
|
|
}
|
|
|
|
|
|
// 获取指定科室及其子科室的ID
|
|
private function getGroupAndSubGroupIds($groupId) {
|
|
if (!$groupId) {
|
|
return [];
|
|
}
|
|
|
|
// 获取指定科室及其子科室的ID
|
|
$groupIds = Db::name('user_group')
|
|
->where('id', $groupId)
|
|
->whereOr('pid', $groupId)
|
|
->column('id');
|
|
|
|
return $groupIds;
|
|
}
|
|
/**
|
|
* 详情查询
|
|
* @return void
|
|
*/
|
|
public function find(){
|
|
$id = $this->request->request('id');
|
|
if(!$id){
|
|
return $this->error('缺少参数');
|
|
}
|
|
$date = Db::name('reject_red_envelopes')
|
|
->field('a.*,u.nickname,g.name as group_name,w.nickname as zm_nickname')
|
|
->alias('a')
|
|
->join('user u','a.user_id = u.id','LEFT')
|
|
->join('user_group g','a.group_id = g.id','LEFT')
|
|
->join('user w','a.zm_user_id = w.id','LEFT')
|
|
->where('a.id', $id)
|
|
->find();
|
|
if($date){
|
|
return $this->success('查询成功',$date);
|
|
}
|
|
return $this->error('查询失败');
|
|
}
|
|
|
|
/**
|
|
* 审核
|
|
*/
|
|
public function examine(){
|
|
$id = $this->request->post('id');
|
|
$status = $this->request->post('status');
|
|
if($this->level == 2){
|
|
return $this->error('您没有权限');
|
|
}
|
|
if(!$id || !$status){
|
|
return $this->error('缺少参数');
|
|
}
|
|
$where = [
|
|
'id' => $id,
|
|
];
|
|
$update = [
|
|
'status' => $status,
|
|
];
|
|
$res = Db::name('reject_red_envelopes')->where($where)->update($update);
|
|
if($res){
|
|
return $this->success('审核成功');
|
|
}
|
|
return $this->error('审核失败');
|
|
}
|
|
|
|
/**
|
|
* 新增记录
|
|
*/
|
|
public function create()
|
|
{
|
|
$data = $this->request->post();
|
|
$data['createtime'] = date('Y-m-d H:i:s');
|
|
$result = Db::name('reject_red_envelopes')->strict(false)->insert($data);
|
|
if ($result) {
|
|
return $this->success('添加成功',$result);
|
|
} else {
|
|
return $this->error('添加失败',$result);
|
|
}
|
|
}
|
|
}
|