接口更新
This commit is contained in:
parent
887738fab7
commit
1c17637059
@ -537,7 +537,7 @@ class Article extends BaseController
|
||||
public function edit($id)
|
||||
{
|
||||
$model =Db::table('fa_article');
|
||||
$find = $model->where('id', $id)->find()->toArray();
|
||||
$find = $model->where('id', $id)->find();
|
||||
if ($find && $find['is_vote'] == 1) {
|
||||
$data = Db::table('fa_article_vote_side_tables')->where('article_id', $find['id'])->find();
|
||||
$find['extend']['vote'] = $data;
|
||||
|
@ -6,7 +6,6 @@ use app\api\BaseController;
|
||||
use app\api\middleware\Auth;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
use fast\Random;
|
||||
use think\exception\ValidateException;
|
||||
use app\common\model\User;
|
||||
|
||||
@ -772,7 +771,7 @@ class Maintainentry extends BaseController
|
||||
$data['user_id'] = $user_id;
|
||||
|
||||
$data['createtime'] = time();
|
||||
$res = Db::table('fa_szxc_information_planting')->create($data);
|
||||
$res = Db::table('fa_szxc_information_planting')->insert($data);
|
||||
if ($res) {
|
||||
$this->apiSuccess('保存成功', null, 1);
|
||||
} else {
|
||||
@ -1232,7 +1231,7 @@ class Maintainentry extends BaseController
|
||||
$mobile = $post['phone'];
|
||||
$ip = request()->ip();
|
||||
$time = time();
|
||||
$salt = Random::alnum(); //随机字符串
|
||||
$salt = set_salt(); //随机字符串
|
||||
// 注册用户
|
||||
$params = [
|
||||
'username' => $mobile,
|
||||
@ -1527,7 +1526,7 @@ class Maintainentry extends BaseController
|
||||
$mobile = $post['phone'];
|
||||
$ip = request()->ip();
|
||||
$time = time();
|
||||
$salt = Random::alnum(); //随机字符串
|
||||
$salt = set_salt(); //随机字符串
|
||||
// 注册用户
|
||||
$params = [
|
||||
'username' => $mobile,
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use fast\Random;
|
||||
use app\common\controller\Api;
|
||||
|
||||
/**
|
||||
@ -32,7 +31,7 @@ class Token extends Api
|
||||
$token = $this->auth->getToken();
|
||||
\app\common\library\Token::delete($token);
|
||||
//创建新Token
|
||||
$token = Random::uuid();
|
||||
$token = make_token();
|
||||
\app\common\library\Token::set($token, $this->auth->id, 2592000);
|
||||
$tokenInfo = \app\common\library\Token::get($token);
|
||||
$this->success('', ['token' => $tokenInfo['token'], 'expires_in' => $tokenInfo['expires_in']]);
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use fast\Random;
|
||||
use Firebase\JWT\JWT;
|
||||
use think\facade\Validate;
|
||||
use think\facade\Config;
|
||||
@ -31,7 +30,8 @@ class User extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->apiSuccess('', ['nickname' => $this->auth->nickname,'avatar'=>$this->auth->avatar]);
|
||||
$user = Db::table('fa_user')->where('id',JWT_UID)->find();
|
||||
$this->apiSuccess('', ['nickname' => $user['nickname'],'avatar'=>$user['avatar']]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,9 +4,9 @@ namespace app\api\controller;
|
||||
|
||||
use app\api\BaseController;
|
||||
use app\api\middleware\Auth;
|
||||
use Firebase\JWT\JWT;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
use fast\Random;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Request;
|
||||
|
||||
@ -190,7 +190,7 @@ class Userinfo extends BaseController
|
||||
// $ret = $this->auth->login($user['username'], '');
|
||||
// if ($ret) {
|
||||
//创建新Token
|
||||
$token = Random::uuid();
|
||||
$token = $this->getToken($user['id']);
|
||||
\app\common\library\Token::set($token, $user['id'], 2592000);
|
||||
$tokenInfo = \app\common\library\Token::get($token);
|
||||
$Userinfo = $user;
|
||||
@ -224,6 +224,27 @@ class Userinfo extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $user_id
|
||||
* @return string
|
||||
*/
|
||||
public function getToken($user_id){
|
||||
$time = time(); //当前时间
|
||||
$conf = $this->jwt_conf;
|
||||
$token = [
|
||||
'iss' => $conf['iss'], //签发者 可选
|
||||
'aud' => $conf['aud'], //接收该JWT的一方,可选
|
||||
'iat' => $time, //签发时间
|
||||
'nbf' => $time-1 , //(Not Before):某个时间点后才能访问,比如设置time+30,表示当前时间30秒后才能使用
|
||||
'exp' => $time+$conf['exptime'], //过期时间,这里设置2个小时
|
||||
'data' => [
|
||||
//自定义信息,不要定义敏感信息
|
||||
'userid' =>$user_id,
|
||||
]
|
||||
];
|
||||
return JWT::encode($token, $conf['secrect'], 'HS256'); //输出Token 默认'HS256'
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 根据身份证号码获取性别
|
||||
|
@ -319,6 +319,7 @@ class Village extends BaseController
|
||||
}
|
||||
$this->apiSuccess('获取成功', $news);
|
||||
} else {
|
||||
$news['id'] = $address['village_id'];
|
||||
$news['title'] = $address_name;
|
||||
$news['address'] = $address_name;
|
||||
$news['images'] = ["https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230115/4dc84e69408fef859e8553a5c7091197.jpg"];
|
||||
|
@ -1,18 +1,24 @@
|
||||
<?php
|
||||
namespace app\api\controller\party;
|
||||
use app\common\controller\Api;
|
||||
use app\admin\model\party\Article as ArticleModel;
|
||||
use app\admin\validate\party\Article as ArticleValdate;
|
||||
use think\facade\Cache;
|
||||
|
||||
use app\api\BaseController;
|
||||
use app\api\middleware\Auth;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 党群文章
|
||||
*/
|
||||
class Article extends Api{
|
||||
protected $noNeedLogin = ['index','details'];
|
||||
protected $noNeedRight = ['*'];
|
||||
class Article extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 控制器中间件 [不需要鉴权]
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
Auth::class => ['except' => ['index','hot_list','getArticleList','details','indexs'] ]
|
||||
];
|
||||
|
||||
public function index($search='',$category_id=1,$page=1) {
|
||||
$order = $this->request->request('order', 1);
|
||||
@ -22,14 +28,13 @@ class Article extends Api{
|
||||
}else{
|
||||
$orders='asc';
|
||||
}
|
||||
$model = new ArticleModel();
|
||||
$where=[
|
||||
['status','=', 1],
|
||||
['category_id','=', $category_id]
|
||||
];
|
||||
//根据个人村id进行查询
|
||||
if ($this->auth->id) {
|
||||
$find = Db::name('szxc_information_useraddress')->where('user_id', $this->auth->id)->find();
|
||||
if (JWT_UID) {
|
||||
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find();
|
||||
if ($find) {
|
||||
if ($find['auth_range']==1){
|
||||
$where[] = ['village', '=', $find['village_id']];
|
||||
@ -40,19 +45,18 @@ class Article extends Api{
|
||||
}
|
||||
}
|
||||
}
|
||||
$count=$model->where($where)->count();
|
||||
$month_count=$model->where($where)->whereMonth('view_time')->count();
|
||||
$count=Db::table('fa_szxc_party_article')->where($where)->count();
|
||||
$month_count=Db::table('fa_szxc_party_article')->where($where)->whereMonth('view_time')->count();
|
||||
if ($search!=''){
|
||||
$where[]=['title','like','%'.$search.'%'];
|
||||
}
|
||||
$select=$model->with('user')->where($where)->page($page)->limit(20)
|
||||
$select=Db::table('fa_szxc_party_article')->with('user')->where($where)->page($page)->limit(20)
|
||||
->field('id,title,user_id,view,view_time,image')->order('id',$orders)->select();
|
||||
return $this->success('ok',['list'=>$select,'count'=>['count'=>$count,'month_count'=>$month_count]]);
|
||||
return $this->apiSuccess('ok',['list'=>$select,'count'=>['count'=>$count,'month_count'=>$month_count]]);
|
||||
}
|
||||
public function details($id)
|
||||
{
|
||||
$model = new ArticleModel();
|
||||
$find=$model->where('id',$id)->find();
|
||||
$find=Db::table('fa_szxc_party_article')->where('id',$id)->find();
|
||||
if ($find){
|
||||
// 增加阅读数
|
||||
// $ip = 'party_article-details-'.$this->request->ip().'-'.$id;
|
||||
@ -60,23 +64,22 @@ class Article extends Api{
|
||||
// if(empty($ip_cache)){
|
||||
// Cache::set($ip,$id,3600*24);
|
||||
$map[] =['id','=', $id];
|
||||
Db::name('szxc_party_article')->where($map)->inc('view','1')->update();
|
||||
Db::table('fa_szxc_party_article')->where($map)->inc('view','1')->update();
|
||||
// }
|
||||
}
|
||||
return $this->success('ok',$find);
|
||||
return $this->apiSuccess('ok',$find);
|
||||
}
|
||||
public function add(){
|
||||
|
||||
}
|
||||
public function post(){
|
||||
$input=$this->request->post();
|
||||
$valdate = new ArticleValdate();
|
||||
$res=$valdate->check($input);
|
||||
if (!$res){
|
||||
return $this->error($valdate->getError());
|
||||
}
|
||||
$model = new ArticleModel();
|
||||
$useraddress = Db::name('szxc_information_useraddress')->where('user_id', $this->auth->id)->where('status', 1)->find();
|
||||
$input=get_params();
|
||||
// $valdate = new ArticleValdate();
|
||||
// $res=$valdate->check($input);
|
||||
// if (!$res){
|
||||
// return $this->apiError($valdate->getError());
|
||||
// }
|
||||
$useraddress = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->where('status', 1)->find();
|
||||
if ($useraddress) {
|
||||
$input['county'] = $useraddress['area_id'];
|
||||
$input['township'] = $useraddress['street_id'];
|
||||
@ -84,43 +87,40 @@ class Article extends Api{
|
||||
}
|
||||
$input['add_time'] = date('Y-m-d H:i:s');
|
||||
$input['view_time'] = date('Y-m-d H:i:s');
|
||||
$input['user_id'] = $this->auth->id;
|
||||
$res=$model->save($input);
|
||||
$input['user_id'] = JWT_UID;
|
||||
$res=Db::table('fa_szxc_party_article')->save($input);
|
||||
if ($res){
|
||||
return $this->success('添加成功');
|
||||
return $this->apiSuccess('添加成功');
|
||||
}else{
|
||||
return $this->error('添加失败');
|
||||
return $this->apiError('添加失败');
|
||||
}
|
||||
}
|
||||
public function edit($id){
|
||||
$model = new ArticleModel();
|
||||
$find=$model->where('id',$id)->find();
|
||||
return $this->success('ok',$find);
|
||||
$find=Db::table('fa_szxc_party_article')->where('id',$id)->find();
|
||||
return $this->apiSuccess('ok',$find);
|
||||
|
||||
}
|
||||
public function put($id){
|
||||
$input=$this->request->post();
|
||||
$valdate = new ArticleValdate();
|
||||
$res=$valdate->check($input);
|
||||
if (!$res){
|
||||
return $this->error($valdate->getError());
|
||||
}
|
||||
$model = new ArticleModel();
|
||||
$input['user_id'] = $this->auth->id;
|
||||
$res=$model->where('id',$id)->update($input);
|
||||
$input=get_params();
|
||||
// $valdate = new ArticleValdate();
|
||||
// $res=$valdate->check($input);
|
||||
// if (!$res){
|
||||
// return $this->apiError($valdate->getError());
|
||||
// }
|
||||
$input['user_id'] = JWT_UID;
|
||||
$res=Db::table('fa_szxc_party_article')->where('id',$id)->update($input);
|
||||
if ($res){
|
||||
return $this->success('修改成功');
|
||||
return $this->apiSuccess('修改成功');
|
||||
}else{
|
||||
return $this->error('修改失败');
|
||||
return $this->apiError('修改失败');
|
||||
}
|
||||
}
|
||||
public function delete($id){
|
||||
$model = new ArticleModel();
|
||||
$res=$model->where('id',$id)->update(['status'=>0]);
|
||||
$res=Db::table('fa_szxc_party_article')->where('id',$id)->update(['status'=>0]);
|
||||
if ($res){
|
||||
return $this->success('删除成功');
|
||||
return $this->apiSuccess('删除成功');
|
||||
}else{
|
||||
return $this->error('删除失败');
|
||||
return $this->apiError('删除失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,9 +82,9 @@ class Maintainentry extends Validate
|
||||
* 验证场景.
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['name', 'gender_id', 'age', 'phone','idcard', 'marriage_id', 'zzmm_id', 'nation_id'],
|
||||
'add' => ['name', 'gender_id', 'age', 'phone','idcard', 'marriage_id', 'nation_id'],
|
||||
'myadd' => ['name', 'gender_id', 'age', 'phone','idcard', 'marriage_id', 'zzmm_id', 'nation_id'],
|
||||
'edit' => ['name', 'gender', 'age', 'phone','idcard', 'marriage_id', 'zzmm_id', 'nation_id'],
|
||||
'edit' => ['name', 'gender', 'age', 'phone','idcard', 'marriage_id', 'nation_id'],
|
||||
'insurancemsg' => ['endowment_insurance_status_id', 'insurance_type_id', 'disability_type_id','ny_insurance_id','sy_insurance_id'],
|
||||
];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user