Merge remote-tracking branch 'origin/master'
This commit is contained in:
553
application/api/controller/Wechatprogram.php
Normal file
553
application/api/controller/Wechatprogram.php
Normal file
@@ -0,0 +1,553 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
use app\api\controller\Base;
|
||||||
|
use think\Db;
|
||||||
|
/**
|
||||||
|
* @title 微信小程序相关方法
|
||||||
|
*/
|
||||||
|
class Wechatprogram extends Base
|
||||||
|
{
|
||||||
|
|
||||||
|
private $sAppID = 'wxe07868a09209e18b';
|
||||||
|
private $sAppSecret = '77bebfbae54b78bf0c79eb3ddd05be87';
|
||||||
|
private $sCode2SessionUrl = 'https://api.weixin.qq.com/sns/jscode2session';//登录凭证验证
|
||||||
|
|
||||||
|
public function __construct(\think\Request $request = null) {
|
||||||
|
parent::__construct($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录微信的openid和unionid
|
||||||
|
*/
|
||||||
|
public function getLogin(){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//获取微信登录code
|
||||||
|
$sLoginCode = empty($aParam['login_code']) ? '' : $aParam['login_code'];
|
||||||
|
if(empty($sLoginCode)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the login code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//调用接口
|
||||||
|
//url拼接
|
||||||
|
$sCode2SessionUrl = $this->sCode2SessionUrl;
|
||||||
|
$sCode2SessionUrl .= '?appid='.$this->sAppID.'&secret='.$this->sAppSecret.'&js_code='.$sLoginCode.'&grant_type=GRANT_TYPE';
|
||||||
|
$aResult = json_decode(myGet($sCode2SessionUrl),true);
|
||||||
|
if(isset($aResult['errcode'])){
|
||||||
|
$sMsg = empty($aResult['errmsg']) ? 'Interface request error:'.$aResult['errcode'] : $aResult['errmsg'];
|
||||||
|
return json_encode(['status' => 3,'msg' => $sMsg]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取微信登录openid
|
||||||
|
$sOpenId= empty($aResult['openid']) ? '' : trim($aResult['openid']);
|
||||||
|
if(empty($sOpenId)){
|
||||||
|
return json_encode(['status' => 4,'msg' => 'User login information not obtained']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//根绝openid获取用户信息
|
||||||
|
$aData = [];
|
||||||
|
$aUser = json_decode($this->getUser(['openid' => $sOpenId,'is_select_role' => 2]),true);
|
||||||
|
$aUser = empty($aUser['data']) ? [] : $aUser['data'];
|
||||||
|
if(!empty($aUser)){
|
||||||
|
$aData['user'] = $aUser;
|
||||||
|
}
|
||||||
|
$aData['wechat'] = $aResult;
|
||||||
|
return json_encode(['status' => 1,'msg' => 'success','data' => $aData]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据OPENID查询用户信息
|
||||||
|
*/
|
||||||
|
public function getUser($aParam = []){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//获取用户ID
|
||||||
|
$iUserId= empty($aParam['user_id']) ? '' : $aParam['user_id'];
|
||||||
|
|
||||||
|
//获取微信登录openid
|
||||||
|
$sOpenId= empty($aParam['openid']) ? '' : $aParam['openid'];
|
||||||
|
if(empty($sOpenId) && empty($iUserId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the login openid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询用户是否存在
|
||||||
|
$aWhere = ['state' => 0];
|
||||||
|
if(!empty($iUserId)){
|
||||||
|
$aWhere['user_id'] = $iUserId;
|
||||||
|
}
|
||||||
|
if(!empty($sOpenId)){
|
||||||
|
$aWhere['openid'] = $sOpenId;
|
||||||
|
}
|
||||||
|
$aUser = Db::name('user')->field('user_id,account,openid,icon,email,type')->where($aWhere)->find();
|
||||||
|
if(empty($aUser)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'No user information found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断是否查询用户角色
|
||||||
|
$iIsSelectRole = empty($aParam['is_select_role']) ? 1 : $aParam['is_select_role'];
|
||||||
|
if($iIsSelectRole == 1){
|
||||||
|
$aUser['roles'] = $this->getUserRoles($aUser);
|
||||||
|
}
|
||||||
|
return json_encode(['status' => 1,'msg' => 'success','data' => $aUser]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名密码绑定openid
|
||||||
|
*/
|
||||||
|
public function bindAccount($aParam = []){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//账号名
|
||||||
|
$sAccount= empty($aParam['account']) ? '' : trim($aParam['account']);
|
||||||
|
if(empty($sAccount)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter your account']);
|
||||||
|
}
|
||||||
|
//密码
|
||||||
|
$sPassword= empty($aParam['password']) ? '' : trim($aParam['password']);
|
||||||
|
if(empty($sPassword)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the password']);
|
||||||
|
}
|
||||||
|
//openid
|
||||||
|
$sOpenId= empty($aParam['openid']) ? '' : trim($aParam['openid']);
|
||||||
|
// //unionid
|
||||||
|
// $sUnionId= empty($aParam['unionid']) ? '' : trim($aParam['unionid']);
|
||||||
|
if(empty($sOpenId)){// && empty($sUnionId)
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the login openid/unionid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询用户是否存在
|
||||||
|
$aWhere = ['account|email' => $sAccount,'state' => 0];
|
||||||
|
$aUser = Db::name('user')->field('user_id,account,password,openid')->where($aWhere)->find();
|
||||||
|
if(empty($aUser)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Login account does not exist, please confirm']);
|
||||||
|
}
|
||||||
|
//验证密码是否一致
|
||||||
|
$sPassword = md5($sPassword);
|
||||||
|
if($aUser['password'] != $sPassword){
|
||||||
|
return json_encode(['status' => 4,'msg' => 'Login password input error, please confirm']);
|
||||||
|
}
|
||||||
|
//验证是否绑定账号
|
||||||
|
if(!empty($aUser['openid'])){// || !empty($aUser['unionid'])
|
||||||
|
return json_encode(['status' => 5,'msg' => 'Login account already linked to WeChat account']);
|
||||||
|
}
|
||||||
|
//验证openid是否被绑定
|
||||||
|
$iUserId = empty($aUser['user_id']) ? 0 : $aUser['user_id'];
|
||||||
|
$aWhere = ['state' => 0,'user_id' => ['<>',$iUserId]];
|
||||||
|
// if(!empty($sUnionId)){
|
||||||
|
// $aWhere['unionid'] = $sUnionId;
|
||||||
|
// }
|
||||||
|
if(!empty($sOpenId)){
|
||||||
|
$aWhere['openid'] = $sOpenId;
|
||||||
|
}
|
||||||
|
$aUserOpenId = Db::name('user')->field('user_id')->where($aWhere)->find();
|
||||||
|
if(!empty($aUserOpenId)){
|
||||||
|
return json_encode(['status' => 6,'msg' => 'This WeChat account has been bound']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新
|
||||||
|
$aUpdate = [];
|
||||||
|
// if(!empty($sUnionId)){
|
||||||
|
// $aUpdate['unionid'] = $sUnionId;
|
||||||
|
// }
|
||||||
|
if(!empty($sOpenId)){
|
||||||
|
$aUpdate['openid'] = $sOpenId;
|
||||||
|
}
|
||||||
|
if(empty($aUpdate)){
|
||||||
|
return json_encode(['status' => 7,'msg' => 'Update data to empty']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//执行操作
|
||||||
|
$aWhere = ['user_id' => $iUserId,'state' => 0];
|
||||||
|
$result = Db::name('user')->where($aWhere)->limit(1)->update($aUpdate);
|
||||||
|
if($result === false){
|
||||||
|
return json_encode(['status' => 8,'msg' => "Binding failed"]);
|
||||||
|
}
|
||||||
|
// $aUser['unionid'] = empty($aUpdate['unionid']) ? $aUser['unionid'] : $aUpdate['unionid'];
|
||||||
|
$aUser['openid'] = empty($aUpdate['openid']) ? $aUser['openid'] : $aUpdate['openid'];
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Binding successful','data' => $aUser]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名密码解绑openid
|
||||||
|
*/
|
||||||
|
public function unbindAccount(){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//账号名
|
||||||
|
$sAccount= empty($aParam['account']) ? '' : trim($aParam['account']);
|
||||||
|
if(empty($sAccount)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter your account']);
|
||||||
|
}
|
||||||
|
//密码
|
||||||
|
$sPassword= empty($aParam['password']) ? '' : trim($aParam['password']);
|
||||||
|
if(empty($sPassword)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the password']);
|
||||||
|
}
|
||||||
|
//openid
|
||||||
|
$sOpenId= empty($aParam['openid']) ? '' : trim($aParam['openid']);
|
||||||
|
//unionid
|
||||||
|
// $sUnionId= empty($aParam['unionid']) ? '' : trim($aParam['unionid']);
|
||||||
|
if(empty($sOpenId)){// && empty($sUnionId)
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the login openid/unionid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询用户是否存在
|
||||||
|
$aWhere = ['account|email' => $sAccount,'state' => 0];
|
||||||
|
$aUser = Db::name('user')->field('user_id,account,password,openid')->where($aWhere)->find();
|
||||||
|
if(empty($aUser)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'Login account does not exist, please confirm']);
|
||||||
|
}
|
||||||
|
//验证密码是否一致
|
||||||
|
$sPassword = md5($sPassword);
|
||||||
|
if($aUser['password'] != $sPassword){
|
||||||
|
return json_encode(['status' => 4,'msg' => 'Login password input error, please confirm']);
|
||||||
|
}
|
||||||
|
//验证是否绑定账号
|
||||||
|
if(empty($aUser['openid'])){// && empty($aUser['unionid'])
|
||||||
|
return json_encode(['status' => 5,'msg' => 'This account is not bound to any mini program, there is no need to unbind it']);
|
||||||
|
}
|
||||||
|
//验证unionid是否相等
|
||||||
|
// if(!empty($sUnionId) && !empty($aUser['unionid']) & $sUnionId != $aUser['unionid']){
|
||||||
|
// return json_encode(['status' => 6,'msg' => 'Unbind account not bound']);
|
||||||
|
// }
|
||||||
|
//验证openid是否相等
|
||||||
|
if(!empty($sOpenId) && !empty($aUser['openid']) & $sOpenId != $aUser['openid']){
|
||||||
|
return json_encode(['status' => 7,'msg' => 'Unbind account not bound']);
|
||||||
|
}
|
||||||
|
$iUserId = empty($aUser['user_id']) ? 0 : $aUser['user_id'];
|
||||||
|
|
||||||
|
//执行操作
|
||||||
|
$aWhere = ['user_id' => $iUserId,'state' => 0];
|
||||||
|
$aUpdate = ['openid' => ''];//,'unionid' => ''
|
||||||
|
$result = Db::name('user')->where($aWhere)->limit(1)->update($aUpdate);
|
||||||
|
if($result === false){
|
||||||
|
return json_encode(['status' => 8,'msg' => "Unbinding failed"]);
|
||||||
|
}
|
||||||
|
$aUpdate['user_id'] = $iUserId;
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Unbound successfully','data' => $aUpdate]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户账号注册
|
||||||
|
*/
|
||||||
|
public function registerAccount(){
|
||||||
|
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//邮箱
|
||||||
|
$sEmail = empty($aParam['email']) ? '' : trim($aParam['email']);
|
||||||
|
if(empty($sEmail)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter your email']);
|
||||||
|
}
|
||||||
|
//密码
|
||||||
|
$sPassword= empty($aParam['password']) ? '' : trim($aParam['password']);
|
||||||
|
if(empty($sPassword)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the password']);
|
||||||
|
}
|
||||||
|
//openid
|
||||||
|
$sOpenId= empty($aParam['openid']) ? '' : trim($aParam['openid']);
|
||||||
|
if(empty($sOpenId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter the login openid/unionid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询用户是否存在
|
||||||
|
$aWhere = ['account|email' => $sEmail,'state' => 0];
|
||||||
|
$aUser = Db::name('user')->field('user_id')->where($aWhere)->find();
|
||||||
|
if(!empty($aUser)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'The registered account already exists, please confirm']);
|
||||||
|
}
|
||||||
|
//验证OPENID是否绑定
|
||||||
|
$aWhere = ['openid' => $sOpenId,'state' => 0];
|
||||||
|
$aUser = Db::name('user')->field('user_id')->where($aWhere)->find();
|
||||||
|
if(!empty($aUser)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'WeChat account has been bound']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//数据插入
|
||||||
|
Db::startTrans();
|
||||||
|
//用户主表
|
||||||
|
$aInsert = ['account' => $sEmail,'email' => $sEmail,'password' => md5($sPassword),'ctime' => time(),'openid' => $sOpenId];
|
||||||
|
$iId = Db::name('user')->insertGetId($aInsert);
|
||||||
|
if(empty($iId)){
|
||||||
|
return json_encode(['status' => 4,'msg' => 'Registration failed']);
|
||||||
|
}
|
||||||
|
//用户附属表
|
||||||
|
$aReviewInsert = ['reviewer_id' => $iId,'test_from' => 'wechat_register'];
|
||||||
|
$iInfoId = Db::name('user_reviewer_info')->insertGetId($aReviewInsert);
|
||||||
|
if(empty($iInfoId)){
|
||||||
|
return json_encode(['status' => 5,'msg' => 'Registration failed']);
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
$aInsert['user_id'] = $iId;
|
||||||
|
return json_encode(['status' => 1,'msg' => 'registered successfully','data' => $aInsert]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取用户身份
|
||||||
|
*/
|
||||||
|
private function getUserRoles($aUser = []){
|
||||||
|
if(empty($aUser)){
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取账号名
|
||||||
|
$sAccount = empty($aUser['account']) ? '' : trim($aUser['account']);
|
||||||
|
if($aUser['type'] == 2) {
|
||||||
|
$aRoles = ['editor'];
|
||||||
|
if($sAccount=="liuna" || $sAccount=="zhuwenjing"){
|
||||||
|
array_push($aRoles, 'superadmin');
|
||||||
|
}
|
||||||
|
return $aRoles;
|
||||||
|
}
|
||||||
|
|
||||||
|
$aRoles = ['author'];
|
||||||
|
//查询是否是审稿人
|
||||||
|
$iUserId = empty($aUser['user_id']) ? 0 : $aUser['user_id'];
|
||||||
|
$aWhere = ['reviewer_id' => $iUserId,'state' => 0];
|
||||||
|
$aUserInfo = Db::name('reviewer_to_journal')->field('rtj_id')->where($aWhere)->find();
|
||||||
|
if(!empty($aUserInfo)) {
|
||||||
|
array_push($aRoles,'reviewer');
|
||||||
|
}
|
||||||
|
|
||||||
|
//青年编委
|
||||||
|
$aWhere = ['user_id' => $iUserId,'state' => 0];
|
||||||
|
$aUserInfo = Db::name('user_to_yboard')->field('user_id')->where($aWhere)->find();
|
||||||
|
if(!empty($aUserInfo)) {
|
||||||
|
array_push($aRoles,'yboard');
|
||||||
|
}
|
||||||
|
//主编与期刊
|
||||||
|
$aWhere = ['user_id' => $iUserId,'state' => 0];
|
||||||
|
$aUserInfo = Db::name('chief_to_journal')->field('user_id')->where($aWhere)->find();
|
||||||
|
if(!empty($aUserInfo)) {
|
||||||
|
array_push($aRoles,'chief');
|
||||||
|
}
|
||||||
|
//期刊主编类型
|
||||||
|
$aWhere = ['user_id' => $iUserId,'state' => 0];
|
||||||
|
$aUserInfo = Db::name('board_to_journal')->field('user_id,type')->where($aWhere)->find();
|
||||||
|
if(!empty($aUserInfo)) {
|
||||||
|
array_push($aRoles,'board');
|
||||||
|
$iType = isset($aUserInfo['type']) ? $aUserInfo['type'] : '-1';
|
||||||
|
if($iType == 0){
|
||||||
|
array_push($aRoles,'chief_editor');
|
||||||
|
}
|
||||||
|
if($iType == 1){
|
||||||
|
array_push($aRoles,'deputy_editor');
|
||||||
|
}
|
||||||
|
if($iType == 2){
|
||||||
|
array_push($aRoles,'editor_board');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//期刊主编类型
|
||||||
|
$aWhere = ['user_id' => $iUserId,'uts_state' => 0];
|
||||||
|
$aUserInfo = Db::name('user_to_special')->field('user_id')->where($aWhere)->find();
|
||||||
|
if (!empty($aUserInfo)) {
|
||||||
|
array_push($aRoles,'special');
|
||||||
|
}
|
||||||
|
return $aRoles;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取我的稿件
|
||||||
|
*/
|
||||||
|
public function getManuscript($aParam = []){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//获取用户ID
|
||||||
|
$iUserId= empty($aParam['user_id']) ? '' : $aParam['user_id'];
|
||||||
|
//获取状态
|
||||||
|
$iState = isset($aParam['state']) ? $aParam['state'] : -2;
|
||||||
|
//获取微信登录openid
|
||||||
|
$sOpenId= empty($aParam['openid']) ? '' : $aParam['openid'];
|
||||||
|
if(empty($sOpenId) && empty($iUserId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter your login account']);
|
||||||
|
}
|
||||||
|
//标题
|
||||||
|
$sTitle = empty($aParam['title']) ? '': $aParam['title'];
|
||||||
|
//获取用户信息
|
||||||
|
$aParam['is_select_role'] = 2;
|
||||||
|
$aUser = json_decode($this->getUser($aParam),true);
|
||||||
|
$aUser = empty($aUser['data']) ? [] : $aUser['data'];
|
||||||
|
if(empty($aUser)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'No user information found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取分页相关参数
|
||||||
|
$iSize = empty($aParam['size']) ? 15 : $aParam['size'];//每页显示条数
|
||||||
|
$iPage = empty($aParam['page']) ? 1 : $aParam['page'];// 当前页码
|
||||||
|
|
||||||
|
$iUserId = empty($aUser['user_id']) ? 0 : $aUser['user_id'];
|
||||||
|
//获取数量
|
||||||
|
$aWhere = ['user_id' => $iUserId,'accept_sn' => ['not like','Draft%']];
|
||||||
|
$aWhere['state'] = ['<>',-1];
|
||||||
|
if($iState != -2 && $iState != -1){
|
||||||
|
$aWhere['state'] = $iState;
|
||||||
|
}
|
||||||
|
if($iState == -2){
|
||||||
|
$aWhere['state'] = ['<>',-1];
|
||||||
|
}
|
||||||
|
if(!empty($sTitle)){
|
||||||
|
$aWhere['title'] =['like','%'.trim($sTitle).'%'];
|
||||||
|
}
|
||||||
|
$iCount = Db::name('article')->where($aWhere)->count();
|
||||||
|
if(empty($iCount)){
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Article not found','data' => ['total' => 0,'lists' => []]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断页数是否超过最大分页限制
|
||||||
|
$iPageNum = ceil($iCount/$iSize);
|
||||||
|
if($iPage > $iPageNum){
|
||||||
|
return json_encode(['status' => 1,'msg' => 'The number of pages has exceeded the limit, maximum page number:'.$iPageNum,'data' => ['total' => $iCount,'lists' => []]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询详细数据
|
||||||
|
$sField = 'article_id,journal_id,accept_sn,title,type,abstrart,ctime,state';
|
||||||
|
$sOrder = 'article_id desc';
|
||||||
|
$aArticle = Db::name('article')
|
||||||
|
->field($sField)
|
||||||
|
->where($aWhere)
|
||||||
|
->page($iPage, $iSize)
|
||||||
|
->order($sOrder)
|
||||||
|
->select();
|
||||||
|
if(empty($aArticle)){
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Data is empty','data' => ['total' => 0,'lists' => []]]);
|
||||||
|
}
|
||||||
|
//获取期刊
|
||||||
|
$aJournalId = array_unique(array_column($aArticle, 'journal_id'));
|
||||||
|
$aWhere = ['journal_id' => ['in',$aJournalId],'state' => 0];
|
||||||
|
$aJournal = DB::name('journal')->where($aWhere)->column('journal_id,title');
|
||||||
|
//数据处理
|
||||||
|
foreach ($aArticle as $key => $value) {
|
||||||
|
$aArticle[$key]['type_name'] = translateType($value['type']);
|
||||||
|
$aArticle[$key]['journal_title'] = empty($aJournal[$value['journal_id']]) ? '' : $aJournal[$value['journal_id']];
|
||||||
|
$aArticle[$key]['ctime'] = empty($value['ctime']) ? '' : date('Y-m-d',$value['ctime']);
|
||||||
|
}
|
||||||
|
return json_encode(['status' => 1,'msg' => 'success','data' => ['total' => $iCount,'lists' => $aArticle]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取我的消息
|
||||||
|
*/
|
||||||
|
public function getMessagesLists($aParam = []){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//获取用户ID
|
||||||
|
$iUserId= empty($aParam['user_id']) ? '' : $aParam['user_id'];
|
||||||
|
//获取微信登录openid
|
||||||
|
$sOpenId= empty($aParam['openid']) ? '' : $aParam['openid'];
|
||||||
|
if(empty($sOpenId) && empty($iUserId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter your login account']);
|
||||||
|
}
|
||||||
|
//标题
|
||||||
|
$sTitle = empty($aParam['title']) ? '': $aParam['title'];
|
||||||
|
|
||||||
|
//状态
|
||||||
|
$iIsRead = empty($aParam['is_read']) ? -1 : $aParam['is_read'];
|
||||||
|
|
||||||
|
//获取用户信息
|
||||||
|
$aParam['is_select_role'] = 2;
|
||||||
|
$aUser = json_decode($this->getUser($aParam),true);
|
||||||
|
$aUser = empty($aUser['data']) ? [] : $aUser['data'];
|
||||||
|
if(empty($aUser)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'No user information found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取分页相关参数
|
||||||
|
$iSize = empty($aParam['size']) ? 15 : $aParam['size'];//每页显示条数
|
||||||
|
$iPage = empty($aParam['page']) ? 1 : $aParam['page'];// 当前页码
|
||||||
|
|
||||||
|
$iUserId = empty($aUser['user_id']) ? 0 : $aUser['user_id'];
|
||||||
|
//获取数量
|
||||||
|
$aWhere = ['user_id' => $iUserId];
|
||||||
|
if(!empty($sTitle)){
|
||||||
|
$aWhere['title'] =['like','%'.trim($sTitle).'%'];
|
||||||
|
}
|
||||||
|
if(in_array($iIsRead, [1,2])){
|
||||||
|
$aWhere['is_read'] = $iIsRead;
|
||||||
|
}
|
||||||
|
$iCount = Db::name('messages')->where($aWhere)->count();
|
||||||
|
if(empty($iCount)){
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Message is empty','data' => ['total' => 0,'lists' => []]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//判断页数是否超过最大分页限制
|
||||||
|
$iPageNum = ceil($iCount/$iSize);
|
||||||
|
if($iPage > $iPageNum){
|
||||||
|
return json_encode(['status' => 1,'msg' => 'The number of pages has exceeded the limit, maximum page number:'.$iPageNum,'data' => ['total' => $iCount,'lists' => []]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询详细数据
|
||||||
|
$sField = 'message_id,article_id,type,title,content,is_read,create_time';
|
||||||
|
$sOrder = 'create_time desc';
|
||||||
|
$aMessages = Db::name('messages')
|
||||||
|
->field($sField)
|
||||||
|
->where($aWhere)
|
||||||
|
->page($iPage, $iSize)
|
||||||
|
->order($sOrder)
|
||||||
|
->select();
|
||||||
|
if(empty($aMessages)){
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Data is empty','data' => ['total' => 0,'lists' => []]]);
|
||||||
|
}
|
||||||
|
//获取期刊
|
||||||
|
$aJournalId = array_unique(array_column($aMessages, 'journal_id'));
|
||||||
|
$aWhere = ['journal_id' => ['in',$aJournalId],'state' => 0];
|
||||||
|
$aJournal = DB::name('journal')->where($aWhere)->column('journal_id,title');
|
||||||
|
//数据处理
|
||||||
|
foreach ($aMessages as $key => $value) {
|
||||||
|
$aMessages[$key]['create_time'] = empty($value['create_time']) ? '' : date('Y-m-d H:i:s',$value['create_time']);
|
||||||
|
}
|
||||||
|
return json_encode(['status' => 1,'msg' => 'success','data' => ['total' => $iCount,'lists' => $aMessages]]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 更改消息状态
|
||||||
|
*/
|
||||||
|
public function markRead($aParam = []){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
//获取消息ID
|
||||||
|
$iMessageId= empty($aParam['message_id']) ? 0 : $aParam['message_id'];
|
||||||
|
if(empty($iMessageId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please select a message']);
|
||||||
|
}
|
||||||
|
//获取用户ID
|
||||||
|
$iUserId= empty($aParam['user_id']) ? '' : $aParam['user_id'];
|
||||||
|
//获取微信登录openid
|
||||||
|
$sOpenId= empty($aParam['openid']) ? '' : $aParam['openid'];
|
||||||
|
if(empty($sOpenId) && empty($iUserId)){
|
||||||
|
return json_encode(['status' => 2,'msg' => 'Please enter your login account']);
|
||||||
|
}
|
||||||
|
//获取用户信息
|
||||||
|
$aParam['is_select_role'] = 2;
|
||||||
|
$aUser = json_decode($this->getUser($aParam),true);
|
||||||
|
$aUser = empty($aUser['data']) ? [] : $aUser['data'];
|
||||||
|
if(empty($aUser)){
|
||||||
|
return json_encode(['status' => 3,'msg' => 'No user information found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$iUserId = empty($aUser['user_id']) ? 0 : $aUser['user_id'];
|
||||||
|
//获取未读数据
|
||||||
|
$aWhere = ['user_id' => $iUserId,'is_read' => 2];
|
||||||
|
if($iMessageId != -1){
|
||||||
|
$aWhere['message_id'] = ['in',$iMessageId];
|
||||||
|
}
|
||||||
|
$aMessagesId = Db::name('messages')->where($aWhere)->column('message_id');
|
||||||
|
if(empty($aMessagesId)){
|
||||||
|
return json_encode(['status' => 4,'msg' => 'Message is empty']);
|
||||||
|
}
|
||||||
|
//更新为已读
|
||||||
|
$aWhere = ['is_read' => 2,'message_id' => ['in',$aMessagesId]];
|
||||||
|
$aUpdate = ['is_read' => 1,'update_time' => time(),'update_user_id' => $iUserId];
|
||||||
|
$result = Db::name('messages')->where($aWhere)->limit(count($aMessagesId))->update($aUpdate);
|
||||||
|
if($result === false){
|
||||||
|
return json_encode(['status' => 5,'msg' => 'Marking failed']);
|
||||||
|
}
|
||||||
|
return json_encode(['status' => 1,'msg' => 'Marking successful']);
|
||||||
|
}
|
||||||
|
}
|
||||||
184
application/common/Messages.php
Normal file
184
application/common/Messages.php
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
<?php
|
||||||
|
namespace app\common;
|
||||||
|
use think\Db;
|
||||||
|
class Messages
|
||||||
|
{
|
||||||
|
//消息类型
|
||||||
|
private $aMessagesType = [
|
||||||
|
1 => [
|
||||||
|
'title' => 'Submission Received',
|
||||||
|
'content' => '<b>Your manuscript(ID: {#accept_sn#}) has been successfully submitted.</b><br/>
|
||||||
|
The editorial office is conducting an initial assessment. You will be notified once the review process begins.'
|
||||||
|
],//'投稿成功',
|
||||||
|
2 => [
|
||||||
|
'title' => 'Manuscript Under Review',
|
||||||
|
'content' => 'Your manuscript is now under review.<br>
|
||||||
|
Manuscript (ID: {#accept_sn#}) has been sent to peer reviewers for evaluation. You will be notified once a review decision becomes available.'
|
||||||
|
],//'稿件进入审稿',
|
||||||
|
3 => [
|
||||||
|
'title' => 'Declined for Publication',
|
||||||
|
'content' => '<b>Editorial decision issued.</b><br/>
|
||||||
|
After evaluation, your manuscript(ID: {#accept_sn#}) has not been accepted for publication. Please refer to the decision letter for details and reviewer comments.'
|
||||||
|
],//'退稿通知',
|
||||||
|
4 => [
|
||||||
|
'title' => 'Revision Requested',
|
||||||
|
'content' => '<b>Revision requested.</b><br/>
|
||||||
|
Editors/reviewers have requested revisions to your manuscript(ID: {#accept_sn#}). Please review the comments and submit your revised version within the required timeframe.'
|
||||||
|
],//'退修通知',
|
||||||
|
5 => [
|
||||||
|
'title' => 'Accepted for Publication',
|
||||||
|
'content' => '<b>Revision requested.</b><br/>
|
||||||
|
Editors/reviewers have requested revisions to your manuscript(ID: {#accept_sn#}). Please review the comments and submit your revised version within the required timeframe.'
|
||||||
|
],//'录用通知',
|
||||||
|
6 => [
|
||||||
|
'title' => 'APC Payment Required',
|
||||||
|
'content' => '<b>APC payment required.</b><br/>
|
||||||
|
Your manuscript(ID: {#accept_sn#}) has reached the payment stage. Please complete the Article Processing Charge (APC) to proceed with publication processing.'
|
||||||
|
],//'缴费提醒',
|
||||||
|
7 => [
|
||||||
|
'title' => 'Proofreading Confirmation Required',
|
||||||
|
'content' => '<b>Proofs ready for review.</b><br/>
|
||||||
|
Your manuscript(ID: {#accept_sn#}) proof is available. Please check and confirm carefully within 48 hours.'
|
||||||
|
],//'校对通知',
|
||||||
|
8 => [
|
||||||
|
'title' => 'Manuscript Published Online',
|
||||||
|
'content' => '<b>Your article is now published online!</b><br/>
|
||||||
|
The final version of your manuscript(ID: {#accept_sn#}) is available on the journal website. Thank you for publishing with us.'
|
||||||
|
],//'发表通知',
|
||||||
|
9 => [
|
||||||
|
'title' => 'APC Update',
|
||||||
|
'content' => '<b>APC update applied.</b><br/>
|
||||||
|
The Article Processing Charge for your manuscript(ID: {#accept_sn#}) has been adjusted. Please check the updated payment details in your submission dashboard.'
|
||||||
|
],//'稿费修改',
|
||||||
|
10 => [
|
||||||
|
'title' => 'Review Invitation(ID: {#accept_sn#})',
|
||||||
|
'content' => '<b>Review invitation received.</b><br/>
|
||||||
|
You are invited to review a manuscript (ID: {#accept_sn#}). Please accept or decline the invitation via your reviewer dashboard.'
|
||||||
|
],//'审稿通知',
|
||||||
|
11 => [
|
||||||
|
'title' => 'Review Invitation Reminder',
|
||||||
|
'content' => '<b>Reminder: Review invitation pending.</b><br/>
|
||||||
|
You have a pending review invitation (ID: {#accept_sn#}). Kindly respond at your earliest convenience.'
|
||||||
|
],//'审稿提醒',
|
||||||
|
12 => [
|
||||||
|
'title' => 'Review Report Reminder',
|
||||||
|
'content' => '<b>Reminder: Review report due.</b><br/>
|
||||||
|
Thank you for accepting the review (ID: {#accept_sn#}). Please submit your review report to help us proceed with the editorial decision.'
|
||||||
|
],//'审稿报告提交',
|
||||||
|
13 => [
|
||||||
|
'title' => 'Re-review Invitation',
|
||||||
|
'content' => '<b>Re-review request received.</b><br/>
|
||||||
|
A revised version of manuscript (ID: {#accept_sn#}) is available for your follow-up assessment. Please access the reviewer dashboard to proceed.'
|
||||||
|
],//'复审邀请',
|
||||||
|
14 => [
|
||||||
|
'title' => 'Re-review Reminder',
|
||||||
|
'content' => '<b>Reminder: Re-review pending.</b><br/>
|
||||||
|
Your follow-up review for manuscript (ID: {#accept_sn#}) is still pending. We would appreciate your evaluation at your earliest convenience.'
|
||||||
|
],//'复审提醒',
|
||||||
|
15 => [
|
||||||
|
'title' => 'Review Closed',
|
||||||
|
'content' => '<b>Review assignment closed.</b><br/>
|
||||||
|
Your review for manuscript (ID: {#accept_sn#}) is no longer required. Thank you for your support and contribution to the journal.'
|
||||||
|
],//审稿关闭提醒
|
||||||
|
];
|
||||||
|
|
||||||
|
private $aField = ['article_id','user_id','type','title','content','is_read','create_time','update_user_id','update_time'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 站内信息添加
|
||||||
|
*/
|
||||||
|
public function add($aParam = []){
|
||||||
|
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? [] : $aParam;
|
||||||
|
//必填参数验证
|
||||||
|
$iType = empty($aParam['type']) ? 0 : $aParam['type'];
|
||||||
|
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
|
||||||
|
if(empty($iArticleId) || empty($iType) || empty($aParam['user_id'])){
|
||||||
|
return ['status' => 2, 'msg' => 'Parameter is empty article title/message type/user_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($iType == 2){//验证是否插入
|
||||||
|
$aMessages = $this->get($aParam);
|
||||||
|
if(!empty($aMessages['data'])){
|
||||||
|
return ['status' => 3, 'msg' => 'The review reminder has been sent'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//根据类型获取消息内容
|
||||||
|
$aMessagesType = $this->aMessagesType;
|
||||||
|
$aMessagesTypeInfo = empty($aMessagesType[$iType]) ? [] : $aMessagesType[$iType];
|
||||||
|
if(empty($aMessagesTypeInfo)){
|
||||||
|
return ['status' => 4, 'msg' => 'Message content not found'];
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取表字段 进行字段赋值
|
||||||
|
$aField = $this->aField;
|
||||||
|
$aInsert = [];
|
||||||
|
foreach ($aField as $key => $value) {
|
||||||
|
if(empty($aParam[$value])){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$aInsert[$value] = $aParam[$value];
|
||||||
|
}
|
||||||
|
//获取稿件号
|
||||||
|
$sAcceptSn = empty($aParam['accept_sn']) ? '' : $aParam['accept_sn'];
|
||||||
|
$aInsert['title'] = str_replace('{#accept_sn#}', $sAcceptSn, $aMessagesTypeInfo['title']);
|
||||||
|
$aInsert['content'] = str_replace('{#accept_sn#}', $sAcceptSn, $aMessagesTypeInfo['content']);
|
||||||
|
$aInsert['create_time'] = time();
|
||||||
|
|
||||||
|
//拒稿和退修 查询是否有同意审稿但未审稿的审稿人
|
||||||
|
if(in_array($iType, [3,4])){
|
||||||
|
$aWhere = ['article_id' => $iArticleId,'state' => 0];
|
||||||
|
$aReviewer = Db::name('article_reviewer')->where($aWhere)->column('reviewer_id');
|
||||||
|
$aBatchInsert = [];
|
||||||
|
if(!empty($aReviewer)){
|
||||||
|
$aMessagesTypeInfo = $aMessagesType[15];
|
||||||
|
$sTitle = str_replace('{#accept_sn#}', $sAcceptSn, $aMessagesTypeInfo['title']);
|
||||||
|
$sContent = str_replace('{#accept_sn#}', $sAcceptSn, $aMessagesTypeInfo['content']);
|
||||||
|
$aReviewer =array_unique($aReviewer);
|
||||||
|
foreach ($aReviewer as $key => $value) {
|
||||||
|
if(empty($value)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$aBatchInsert[] = ['title' => $sTitle,'content' => $sContent,'type' => 15,'create_time' => time(),'article_id' => $iArticleId,'user_id' => $value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aBatchInsert[] = ['title' => $aInsert['title'],'content' => $aInsert['content'],'type' => $aInsert['type'],'create_time' => time(),'article_id' => $iArticleId,'user_id' => $aInsert['user_id']];
|
||||||
|
|
||||||
|
$result = Db::name('messages')->insertAll($aBatchInsert);
|
||||||
|
if(empty($result)){
|
||||||
|
return ['status' => 6, 'msg' => '数据插入失败'.Db::getLastSql()."\n数据内容:",'data' => $aParam];
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$result = Db::name('messages')->insertGetId($aInsert);
|
||||||
|
if(empty($result)){
|
||||||
|
return ['status' => 5, 'msg' => '数据插入失败'.Db::getLastSql()."\n数据内容:",'data' => $aParam];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['status' => 1, 'msg' => '数据插入成功'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取信息
|
||||||
|
*/
|
||||||
|
public function get($aParam = []){
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? [] : $aParam;
|
||||||
|
//必填参数验证
|
||||||
|
if(empty($aParam['article_id']) || empty($aParam['type']) || empty($aParam['user_id'])){
|
||||||
|
return ['status' => 2, 'msg' => '非法操作'];
|
||||||
|
}
|
||||||
|
//获取表字段 进行字段赋值
|
||||||
|
$aField = $this->aField;
|
||||||
|
$aWhere = [];
|
||||||
|
foreach ($aField as $key => $value) {
|
||||||
|
if(empty($aParam[$value])){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$aWhere[$value] = $aParam[$value];
|
||||||
|
}
|
||||||
|
$aMessages = Db::name('messages')->where($aWhere)->find();
|
||||||
|
return ['status' => 1, 'msg' => '获取数据成功','data' => $aMessages];
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user