nk-lihaink-cn/app/api/controller/party/BranchPayUser.php
2023-01-19 02:36:01 +00:00

128 lines
4.3 KiB
PHP

<?php
namespace app\api\controller\party;
use app\common\controller\Api;
use app\admin\model\party\BranchPayUser as BranchPayUsertModel;
use app\admin\validate\party\BranchPayUser as BranchPayUserValdate;
use app\admin\model\party\BranchPayList;
use think\App;
use think\facade\Db;
/**
* 党支部
*/
class BranchPayUser extends Api{
protected $noNeedRight = ['*'];
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new BranchPayUsertModel();
$this->validate = new BranchPayUserValdate();
}
public function index($id,$page=1,$search='',$type=0) {
$find=BranchPayList::where('id',$id)->find();
if (!$find) return $this->edit('清单数据不存在');
$where=[
['branch_id','=',$find['branch_id']],
['status','=', 1]
];
if ($search!=''){
$userall=Db::name('user')->where('nickname','like', $search . '%')->field('id')->select();
if ($userall){
$ids=[];
foreach ($userall as $user){
$ids[]=$user['id'];
}
$where[]=['user_id','in',implode(',',$ids)];
}else{
return $this->error('查询内容不存在');
}
}
if ($type>0){
$where[]=['is_pay','=',$type];
}
$select=Db::name('szxc_party_branch_pay_user')->where($where)
->withAttr('user',function ($value, $data){
$user = Db::name('user')->where('id',$data['user_id'])->field('nickname,avatar')->find();
return $user;
})
->page($page)->limit(20)->select();
$count=Db::name('szxc_party_info')->where('party_branch',$id)->count();
$data['info']=$find;
$data['list']=$select;
$data['count']=$count;
return $this->success('ok',$data);
}
public function add($id,$page=1){
$find=BranchPayList::where('id',$id)->find();
$strtotime1=strtotime($find['start_time']);
$strtotime2=strtotime($find['end_time']);
$m=date('m',$strtotime1);
$ms=date('m',$strtotime2);
$m_count=$ms-$m;
if (!$find) return $this->edit('清单数据不存在');
$select=Db::name('szxc_party_info')->where('party_branch',$find['branch_id'])
->withAttr('user_info',function($data,$value){
$user = Db::name('user')->where('id',$value['user_id'])->field('nickname,avatar')->find();
return $user;
})->field('id,user_id,branch_pay')
->select();
$data_list=$select->toArray();
foreach($data_list as $key=>$value){
$data_list[$key]['month_pay_count']= $value['branch_pay']*$m_count;
$data_list[$key]['month_count']=$m_count;
}
$count=Db::name('szxc_party_info')->where('party_branch',$find['branch_id'])->count();
$data['info']=$find;
$data['list']=$data_list;
$data['count']=$count;
return $this->success('ok',$data);
}
public function post(){
$input=$this->request->post();
foreach ($input as $k=>$v){
$res=$this->validate->check($v);
if (!$res){
return $this->error($this->validate->getError());
}
}
$res=$this->model->saveAll($input);
if ($res){
return $this->success('添加成功');
}else{
return $this->error('添加失败');
}
}
public function edit($id){
$find=$this->model->where('id',$id)->find();
return $this->success('ok',$find);
}
public function put($id){
$input=$this->request->post();;
$res=$this->validate->check($input);
if (!$res){
return $this->error($this->validate->getError());
}
$res=$this->model->where('id',$id)->update($input);
if ($res){
return $this->success('修改成功');
}else{
return $this->error('修改失败');
}
}
public function delete($id){
$res=$this->model->where('id',$id)->update(['status'=>0]);
if ($res){
return $this->success('删除成功');
}else{
return $this->error('删除失败');
}
}
}