116 lines
3.0 KiB
PHP
116 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller\backend;
|
|
|
|
use app\common\controller\Api;
|
|
use app\api\model\Admin as AdminModel;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 征求意见
|
|
*/
|
|
class Solicitopinions extends Api
|
|
{
|
|
protected $noNeedLogin = ['*'];
|
|
protected $noNeedRight = ['*'];
|
|
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('用户不存在','',99998);
|
|
}
|
|
}
|
|
/**
|
|
* 首页
|
|
*
|
|
*/
|
|
public function index()
|
|
{
|
|
$param = $this->request->param();
|
|
|
|
// // 参数验证
|
|
$validate = $this->validate($param, [
|
|
|
|
'page' => 'number',
|
|
'size' => 'number',
|
|
]);
|
|
|
|
if (true !== $validate) {
|
|
return $this->error($validate);
|
|
}
|
|
$where = [];
|
|
if(!empty($param['group_id'])){
|
|
$where['a.group_id'] = $param['group_id'];
|
|
}
|
|
$query = Db::name('solicit_opinions')
|
|
->field('a.*,p.name as group_name')
|
|
->alias('a')
|
|
// ->join('user w','a.user_id = w.id','LEFT')
|
|
->join('user_group p','a.group_id = p.id','LEFT')
|
|
->where($where)
|
|
// ->where('a.deletetime', 'null')
|
|
->order('a.id', 'asc');
|
|
|
|
// 分页查询
|
|
$list = $query->paginate([
|
|
'page' => $param['page'] ?? 1,
|
|
'list_rows' => $param['size'] ?? 10,
|
|
]);
|
|
|
|
// 处理返回数据
|
|
$data = [
|
|
'total' => $list->total(),
|
|
'list' => $list->items(),
|
|
];
|
|
|
|
return $this->success('查询成功', $data);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function h5add()
|
|
{
|
|
$param = $this->request->param();
|
|
$user_id = $this->request->param('user_id', 0);
|
|
|
|
$param['politics_type'] = 1;
|
|
if($user_id != 0){
|
|
$param['politics_type'] = 2;
|
|
$user = Db::name('user')
|
|
->where('id', $user_id)
|
|
->find();
|
|
$param['nickname'] = $user['nickname'];
|
|
$param['phone'] = $user['mobile'];
|
|
}
|
|
$param['createtime'] = date('Y-m-d H:i:s');
|
|
$param['weigh'] = 100;
|
|
// 参数验证
|
|
$validate = $this->validate($param, [
|
|
'group_id' => 'require|number',
|
|
// 'nickname' => 'require',
|
|
'phone' => 'require|number',
|
|
'content' => 'require',
|
|
]);
|
|
|
|
if (true !== $validate) {
|
|
return $this->error($validate);
|
|
}
|
|
// 更新数据
|
|
$result = Db::name('solicit_opinions')->strict(false)->insert($param);
|
|
|
|
if ($result === false) {
|
|
return $this->error('添加失败');
|
|
}
|
|
|
|
return $this->success('添加成功');
|
|
}
|
|
}
|