request->post();
$rule = new Validate([
"article_id" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$aWhere = ['article_id' => $data['article_id'],'state' => 0];
$production_info = $this->production_article_obj->where($aWhere)->find();
if ($production_info == null) {
return jsonError("Object is null");
}
$dois = $this->production_article_refer_obj->where("p_article_id", $production_info['p_article_id'])->where("refer_doi","<>","")->where("state",0)->group("refer_doi")->having("count(*)>1")->column("refer_doi");
$list = $this->production_article_refer_obj->where("p_article_id", $production_info['p_article_id'])->where('state', 0)->order("index")->select();
foreach ($list as $k => $v){
if(in_array($v['refer_doi'],$dois)){
$list[$k]['is_repeat'] = 1;
}else{
$list[$k]['is_repeat'] = 0;
}
}
$re["refers"] = $list;
return jsonSuccess($re);
}
/**清空引用文献
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function discardRefers()
{
$data = $this->request->post();
$rule = new Validate([
"article_id" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$production_info = $this->production_article_obj->where('article_id', $data['article_id'])->find();
$this->production_article_refer_obj->where('p_article_id', $production_info['p_article_id'])->update(['state' => 1]);
return jsonSuccess([]);
}
/**清空引用文献byp_article_id
* @return void
*/
public function discardRefersByParticleid(){
$data = $this->request->post();
$rule = new Validate([
"p_article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->production_article_refer_obj->where('p_article_id',$data['p_article_id'])->update(["state"=>1]);
return jsonSuccess([]);
}
/**添加refer
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function addRefer()
{
$data = $this->request->post();
$rule = new Validate([
"article_id" => "require",
"pre_p_refer_id" => "require",
"refer_type"=>"require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$p_info = $this->production_article_obj->where('article_id', $data['article_id'])->where('state', 0)->find();
$pre_refer = $this->production_article_refer_obj->where('p_refer_id', $data['pre_p_refer_id'])->find();
$insert['p_article_id'] = $p_info['p_article_id'];
$insert['index'] = $pre_refer['index'] + 1;
$insert['ctime'] = time();
$insert['is_change'] = 1;
$insert['refer_type'] = $data['refer_type'];
if($data['refer_type']=="journal"){
$insert['refer_doi'] = isset($data['doi'])?$data['doi']:'';
$insert['author'] = trim($data['author']);
$insert['title'] = trim($data['title']);
$insert['joura'] = trim($data['joura']);
$insert['dateno'] = $data['dateno'];
$insert['doilink'] = $data['doilink'];
$insert['cs'] = 1;
$insert['is_ja'] = 1;
}elseif($data['refer_type']=="book"){
$insert['author'] = trim($data['author']);
$insert['title'] = trim($data['title']);
$insert['dateno'] = $data['dateno'];
$insert['isbn'] = $data['isbn'];
$insert['cs'] = 1;
$insert['is_ja'] = 1;
}else{
$insert['cs'] = 0;
$insert['refer_frag'] = trim($data['content']);
}
$adId= $this->production_article_refer_obj->insertGetId($insert);
$this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where("p_refer_id", "<>", $adId)->where("index", ">", $pre_refer['index'])->where('state', 0)->setInc('index');
return jsonSuccess([]);
// $adId = $this->production_article_refer_obj->insertGetId($insert);
// my_doiToFrag2($this->production_article_refer_obj->where('p_refer_id', $adId)->find());
// //判断是否合法
// $check = $this->production_article_refer_obj->where('p_refer_id', $adId)->find();
// if ($check['author']) {//合法
// $this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where("p_refer_id", "<>", $adId)->where("index", ">", $pre_refer['index'])->where('state', 0)->setInc('index');
// return jsonSuccess([]);
// } else {//非法
// $this->production_article_refer_obj->where('p_refer_id', $adId)->update(['state' => 1]);
// return jsonError("Doi error");
// }
}
public function addReferByParticleid(){
$data = $this->request->post();
$rule = new Validate([
"p_article_id" => "require",
"pre_p_refer_id" => "require",
"refer_type"=>"require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$p_info = $this->production_article_obj->where('p_article_id', $data['p_article_id'])->find();
$pre_refer = $this->production_article_refer_obj->where('p_refer_id', $data['pre_p_refer_id'])->find();
$insert['p_article_id'] = $p_info['p_article_id'];
$insert['index'] = $pre_refer['index'] + 1;
$insert['ctime'] = time();
$insert['is_change'] = 1;
$insert['refer_type'] = $data['refer_type'];
if($data['refer_type']=="journal"){
$insert['refer_doi'] = isset($data['doi'])?$data['doi']:'';
$insert['author'] = trim($data['author']);
$insert['title'] = trim($data['title']);
$insert['joura'] = trim($data['joura']);
$insert['dateno'] = $data['dateno'];
$insert['doilink'] = $data['doilink'];
$insert['cs'] = 1;
$insert['is_ja'] = 1;
}elseif($data['refer_type']=="book"){
$insert['author'] = trim($data['author']);
$insert['title'] = trim($data['title']);
$insert['dateno'] = $data['dateno'];
$insert['isbn'] = $data['isbn'];
$insert['cs'] = 1;
$insert['is_ja'] = 1;
}else{
$insert['cs'] = 0;
$insert['refer_frag'] = trim($data['content']);
}
$adId= $this->production_article_refer_obj->insertGetId($insert);
$this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where("p_refer_id", "<>", $adId)->where("index", ">", $pre_refer['index'])->where('state', 0)->setInc('index');
return jsonSuccess([]);
}
/**非doi形式添加refer节点
* @return void
*/
public function addReferNotdoi()
{
$data = $this->request->post();
$rule = new Validate([
"article_id" => "require",
"pre_p_refer_id" => "require",
"author" => "require",
"title" => "require",
"joura" => "require",
"dateno" => "require",
"doilink" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$p_info = $this->production_article_obj->where('article_id', $data['article_id'])->where('state', 0)->find();
$pre_refer = $this->production_article_refer_obj->where('p_refer_id', $data['pre_p_refer_id'])->find();
$insert['p_article_id'] = $p_info['p_article_id'];
$insert['index'] = $pre_refer['index'] + 1;
$insert['author'] = trim($data['author']);
$insert['title'] = trim($data['title']);
$insert['joura'] = trim($data['joura']);
$insert['dateno'] = trim($data['dateno']);
$insert['doilink'] = trim($data['doilink']);
$insert['refer_doi'] = trim($data['doilink']);
$insert['is_web'] = 1;
$insert['cs'] = 1;
$adId = $this->production_article_refer_obj->insertGetId($insert);
$this->production_article_refer_obj->where('p_article_id', $p_info['p_article_id'])->where("p_refer_id", "<>", $adId)->where("index", ">", $pre_refer['index'])->where('state', 0)->setInc('index');
return jsonSuccess([]);
}
public function editReferNotdoi()
{
$data = $this->request->post();
$rule = new Validate([
"p_refer_id" => "require",
"author" => "require",
"title" => "require",
"joura" => "require",
"dateno" => "require",
"doilink" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$update['author'] = trim($data['author']);
$update['title'] = trim($data['title']);
$update['joura'] = trim($data['joura']);
$update['dateno'] = trim($data['dateno']);
$update['doilink'] = trim($data['doilink']);
$update['refer_doi'] = trim($data['doilink']);
$this->production_article_refer_obj->where('p_refer_id', $data['p_refer_id'])->update($update);
return jsonSuccess([]);
}
// public function aaa(){
// $list = $this->production_article_refer_obj->where('p_article_id',423)->where('state',0)->where('index',">",0)->setInc('index');
// dump($list);
// }
/**删除refer
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function delRefer()
{
$data = $this->request->post();
$rule = new Validate([
"p_refer_id" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$this->delOneRefer($data['p_refer_id']);
return jsonSuccess([]);
}
public function delRefers(){
$data = $this->request->post();
$rule = new Validate([
"ids" => "require|array"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
foreach ($data['ids'] as $v){
$this->delOneRefer($v);
}
return jsonSuccess([]);
}
public function positioningImage(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require",
"ami_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
$ami_info = $this->article_main_image_obj->where("ami_id",$data['ami_id'])->find();
$check = $this->article_main_obj->where("article_id",$am_info['article_id'])->where("ami_id",$data['ami_id'])->whereIn("state",[0,2])->find();
if($check){
return jsonError("Repeat operation");
}
$sort_check = $this->article_main_obj->where("article_id",$am_info['article_id'])->whereIn("state",[0,2])->where("sort",$am_info['sort']+1)->find();
if($sort_check){
$this->article_main_obj->where("article_id",$am_info['article_id'])->whereIn("state",[0,2])->where("sort",">",$am_info['sort'])->inc("sort",1)->update();
}
$insert['article_id'] = $am_info['article_id'];
$insert['type'] = 1;
$insert['content'] = "
";
$insert['ami_id'] = $data['ami_id'];
$insert['sort'] = $am_info['sort']+1;
$insert['ctime'] = time();
$this->article_main_obj->insert($insert);
return jsonSuccess([]);
}
public function removeImage(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
if($am_info['type']!=1){
return jsonError("error");
}
$this->article_main_obj->where("am_id",$data['am_id'])->update(['state'=>1]);
return jsonSuccess([]);
}
public function removeTable(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
if($am_info['type']!=2){
return jsonError("error");
}
$this->article_main_obj->where("am_id",$data['am_id'])->update(['state'=>1]);
return jsonSuccess([]);
}
public function positioningTable(){
$data = $this->request->post();
$rule = new Validate([
"am_id" => "require",
"amt_id" => "require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
$amt_info = $this->article_main_table_obj->where("amt_id",$data['amt_id'])->find();
$check = $this->article_main_obj->where("article_id",$am_info['article_id'])->where("amt_id",$data['amt_id'])->whereIn('state',[0,2])->find();
if($check){
return jsonError("Repeat operation");
}
$sort_check = $this->article_main_obj->where("article_id",$amt_info['article_id'])->whereIn("state",[0,2])->where("sort",$am_info['sort']+1)->find();
if ($sort_check){
$this->article_main_obj->where("article_id",$am_info['article_id'])->whereIn("state",[0,2])->where('sort',">",$am_info['sort'])->inc("sort",1)->update();
}
$insert['article_id'] = $am_info['article_id'];
$insert['type'] = 2;
$insert['amt_id'] = $data['amt_id'];
$insert["content"] = "
";
$insert['sort'] = $am_info['sort']+1;
$insert['ctime'] = time();
$this->article_main_obj->insert($insert);
return jsonSuccess([]);
}
/**编辑refer
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function editRefer()
{
$data = $this->request->post();
$rule = new Validate([
"p_refer_id" => "require",
"refer_type" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$old_refer_info = $this->production_article_refer_obj->where('p_refer_id',$data['p_refer_id'])->find();
$updata['refer_type'] = $data['refer_type'];
$updata['is_change'] = 1;
if($data['refer_type']=="journal"){
$updata['refer_doi'] = isset($data['doi'])?$data['doi']:'';
$updata['author'] = trim($data['author']);
$updata['title'] = trim($data['title']);
$updata['joura'] = trim($data['joura']);
$updata['dateno'] = $data['dateno'];
$updata['doilink'] = $data['doilink'];
$updata['cs'] = 1;
$updata['is_ja'] = 1;
}elseif($data['refer_type']=="book"){
$updata['author'] = trim($data['author']);
$updata['title'] = trim($data['title']);
$updata['dateno'] = $data['dateno'];
$updata['isbn'] = $data['isbn'];
$updata['cs'] = 1;
$updata['is_ja'] = 1;
}else{
$updata['cs'] = 0;
$updata['refer_frag'] = trim($data['content']);
}
$this->production_article_refer_obj->where('p_refer_id',$data['p_refer_id'])->update($updata);
// $doi = trim($data['doi']);
// $url = "https://citation.crosscite.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";
// $res = myGet($url);
// $frag = trim(substr($res, strpos($res, '.') + 1));
// if ($frag == "") {
// return jsonError("doi error");
// }
// $this->production_article_refer_obj->where('p_refer_id', $data['p_refer_id'])->update(['refer_doi' => $data['doi']]);
// my_doiToFrag2($this->production_article_refer_obj->where('p_refer_id', $data['p_refer_id'])->find());
return jsonSuccess([]);
}
/**添加文章主体内容的备注(马上废弃)
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function addMainsRemark(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require",
"remark"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$update['remark'] = trim($data['remark']);
$update['state'] = 2;
$this->article_main_obj->where("am_id",$data['am_id'])->update($update);
return jsonSuccess([]);
}
/**编辑发布文章正文更改意见
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function createArticleMainCheckForEditor(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require",
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
if(!$am_info){
return jsonError("am state error");
}
$insert['article_id'] = $data['article_id'];
$insert['am_id'] = $data['am_id'];
if(isset($data['remark'])&&$data['remark']!=""){
$insert["remark"] = $data['remark'];
}
if(isset($data['content'])&&$data['content']!=""){
$insert["content"] = $data['content'];
}
$insert['ctime'] = time();
$this->article_main_check_obj->insert($insert);
return jsonSuccess([]);
}
/**编辑整改信息备注
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function editArticleMainCheck(){
$data = $this->request->post();
$rule = new Validate([
"amc_id"=>"require",
"remark"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$amc_info = $this->article_main_check_obj->where("amc_id",$data['amc_id'])->find();
if($amc_info['estate']==1){
return jsonError("The author has completed");
}
$this->article_main_check_obj->where("amc_id",$data['amc_id'])->update(['remark'=>$data['remark']]);
return jsonSuccess([]);
}
/**作者标记完成整改条目
* @return void
*/
public function completeArticleMainCheckForAuthor(){
$data = $this->request->post();
$rule = new Validate([
"amc_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->article_main_check_obj->where("amc_id",$data['amc_id'])->update(['estate'=>1]);
return jsonSuccess([]);
}
/**作者驳回整改条目
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function rejectArticleMainCheckForAuthor(){
$data = $this->request->post();
$rule = new Validate([
"amc_id"=>"require",
"author_remark"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->article_main_check_obj->where("amc_id",$data['amc_id'])->update(['author_remark'=>$data['author_remark']]);
return jsonSuccess([]);
}
/**编辑驳回作者的修复
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function rejectArticleMainCheckForEditor(){
$data = $this->request->post();
$rule = new Validate([
"amc_id"=>"require",
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->article_main_check_obj->where("amc_id",$data['amc_id'])->update(["estate"=>0]);
return jsonSuccess([]);
}
/**上调文章main位置
* @return \think\response\Json|void
*/
public function upArticleMain(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$main_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
$list = $this->article_main_obj->where("article_id",$main_info['article_id'])->where("sort","<",$main_info['sort'])->order("sort desc")->limit(1)->select();
if(!$list){
return jsonError("error");
}
$main1 = $list[0];
$cache_sort = $main1['sort'];
$this->article_main_obj->where("am_id",$main1['am_id'])->update(['sort'=>$main_info['sort']]);
$this->article_main_obj->where("am_id",$main_info['am_id'])->update(['sort'=>$cache_sort]);
return jsonSuccess([]);
}
/**下调文章main位置
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function downArticleMain(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$main_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
$list = $this->article_main_obj->where("article_id",$main_info['article_id'])->where("sort",">",$main_info['sort'])->order("sort asc")->limit(1)->select();
if(!$list){
return jsonError("error");
}
$main1 = $list[0];
$cache_sort = $main1['sort'];
$this->article_main_obj->where("am_id",$main1['am_id'])->update(['sort'=>$main_info['sort']]);
$this->article_main_obj->where("am_id",$main_info['am_id'])->update(['sort'=>$cache_sort]);
return jsonSuccess([]);
}
/**删除文章全文校对
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function delArticleMainCheckForEditor(){
$data = $this->request->post();
$rule = new Validate([
"amc_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$amc_info = $this->article_main_check_obj->where("amc_id",$data['amc_id'])->find();
if($amc_info['estate']==1){
return jsonError("status is complete");
}
$this->article_main_check_obj->where("amc_id",$data['amc_id'])->update(['state'=>1]);
return jsonSuccess([]);
}
/**获取文章正文内容修改建议列表
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getArticleMainCheckList(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$list = $this->article_main_check_obj->where("article_id",$data['article_id'])->where("state",0)->order("am_id")->select();
$frag = [];
foreach ($list as $k => $v){
$frag[$v['am_id']][] = $v;
}
$re['list'] = $frag;
return jsonSuccess($re);
}
public function clearMainsRemark(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->article_main_obj->where("am_id",$data['am_id'])->update(['remark'=>"","state"=>0]);
return jsonSuccess([]);
}
public function searchDoi()
{
$data = $this->request->post();
$rule = new Validate([
"doi" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$doi = str_replace('/', '%2F', $data['doi']);
// $url = "https://citation.crosscite.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";
$url = "https://citation.doi.org/format?doi=$doi&style=cancer-translational-medicine&lang=en-US";
$res = myGet($url);
$frag = trim(substr($res, strpos($res, '.') + 1));
if ($frag == "") {
return jsonError("not find");
}
if (mb_substr_count($frag, '.') != 3) {
return jsonError("formate fail");
}
$res = explode('.', $frag);
$f['author'] = prgeAuthor($res[0]);
$f['title'] = trim($res[1]);
$bj = bekjournal($res[2]);
$joura = formateJournal(trim($bj[0]));
$f['joura'] = $joura;
$f['dateno'] = str_replace(' ', '', str_replace('-', '–', trim($bj[1])));
$f['doilink'] = strpos($data['doi'], "http") === false ? "http://doi.org/" . $data['doi'] : $data['doi'];
$re['formate'] = $f;
return jsonSuccess($re);
}
public function mytt(){
$ss[] = "this id test this id 3test 55this id test this id test this id test this id test";
$ss[] = "this id test this id 3test 55this id test this id test this id test this id test";
$ss[] = "
";
$ss[] = "this id test this id 3test 55this id test this id test this id test this id test";
$ss[] = "this id test this id 3test 55this id test this id test this id test this id test";
$re['detail'] = json_encode($ss);
return jsonSuccess($re);
}
/**预接收前对文章的支付信息,审核以及相关操作
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function getPreacceptPayment(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$article_info = $this->article_obj->where("article_id",$data['article_id'])->find();
$order_info = $this->order_obj->where("article_id",$article_info['article_id'])->find();
$re['state'] = $article_info['is_buy'];
$re['order'] = $order_info;
$re["fee"] = $article_info['fee'];
return jsonSuccess($re);
// if(intval($journal_info['fee'])==0||$article_info['ctime']<1735660800){//非收费期刊的文章直接返回
// $re['state'] = 1;
// $re['order'] = null;
// $re["fee"] = 0;
// return jsonSuccess($re);
// }
//
// if($order_info==null){//这里有疑问
// $re['state'] = 1;
// $re['order'] = null;
// $re["fee"] = 0;
// return jsonSuccess($re);
// }
//// if($order_info['pay_type']==2){
// $paystation = $this->paystation_obj->where("ps_id",$order_info['ps_id'])->find();
// $order_info['paystation'] = $paystation;
// if($order_info['state']==0){
// $res = object_to_array(json_decode(paystationLookup($paystation['transaction_id'])));
// if(isset($res['result']['success'])&&$res['result']['success']){
// $this->article_obj->where("article_id",$order_info['article_id'])->update(['is_buy'=>1]);
// $this->order_obj->where("order_id",$order_info['order_id'])->update(['state'=>1]);
// $re['state'] = 1;
// $re['fee'] = $journal_info['fee'];
// $re['order'] = $order_info;
// return jsonSuccess($re);
// }else{
// $re['state'] = 0;
// $re['fee'] = $journal_info['fee'];
// $re['order'] = $order_info;
// return jsonSuccess($re);
// }
// }else{
// $re['state'] = 1;
// $re['fee'] = $journal_info['fee'];
// $re['order'] = $order_info;
// return jsonSuccess($re);
// }
// }
}
public function myCreatMains(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$mains = $this->article_main_obj->where("article_id",$data['article_id'])->whereIn("state",[0,2])->order("sort asc")->select();
if(!$mains) {
$this->addArticleMainEx($data["article_id"]);
}
return jsonSuccess([]);
}
public function getArticleMains(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$mains = $this->article_main_obj->where("article_id",$data['article_id'])->whereIn("state",[0,2])->order("sort asc")->select();
if(!$mains){
$this->addArticleMainEx($data['article_id']);
}
$mains = getArticleMains($data['article_id']);
$re['list'] = $mains;
return jsonSuccess($re);
}
public function changeH1(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
//上一行,空行
$p_list = $this->article_main_obj->where("article_id",$am_info['article_id'])->where("sort","<",$am_info['sort'])->whereIn("state",[0,2])->order("sort desc")->limit(1)->select();
if($p_list&&($p_list[0]['type']>0||$p_list[0]['content']!="")){
$this->addBRow($am_info['article_id'],$p_list[0]['am_id']);
}
$n_list = $this->article_main_obj->where("article_id",$am_info['article_id'])->where("sort",">",$am_info['sort'])->whereIn("state",[0,2])->order("sort asc")->limit(1)->select();
if($n_list[0]['type']>0||$n_list[0]['content']!=""){
$this->addBRow($am_info['article_id'],$data['am_id']);
}
$this->article_main_obj->where("am_id",$data['am_id'])->update(["is_h1"=>1,"is_h2"=>0,"is_h3"=>0]);
return jsonSuccess([]);
}
public function changeH2(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
//上一行,空行
$p_list = $this->article_main_obj->where("article_id",$am_info['article_id'])->where("sort","<",$am_info['sort'])->whereIn("state",[0,2])->order("sort desc")->limit(1)->select();
if($p_list&&($p_list[0]['type']>0||$p_list[0]['content']!="")){
$this->addBRow($am_info['article_id'],$p_list[0]['am_id']);
}
$this->article_main_obj->where("am_id",$data['am_id'])->update(["is_h1"=>0,"is_h2"=>1,"is_h3"=>0]);
return jsonSuccess([]);
}
public function changeH3(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
$this->article_main_obj->where("am_id",$data['am_id'])->update(["is_h1"=>0,"is_h2"=>0,"is_h3"=>1]);
return jsonSuccess([]);
}
public function changeNormal(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->article_main_obj->where("am_id",$data['am_id'])->update(["is_h1"=>0,"is_h2"=>0,"is_h3"=>0]);
return jsonSuccess([]);
}
public function addBlankRow(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require",
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
if(isset($data['row'])){
$row = (int)$data['row'];
}else{
$row = 1;
}
while ($row>0){
$this->addBRow($data['article_id'],$data['am_id']);
$row--;
}
return jsonSuccess([]);
}
/**添加批量主体内容
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function addMoreRow(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require",
"am_id" => "require",
"rows"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
if($data['am_id']==0){//顶级
$this->article_main_obj->where("article_id",$data['article_id'])->inc("sort",count($data['rows']))->update();
$sort = 1;
}else{
$r = $this->article_main_obj->where("am_id",$data['am_id'])->find();
$this->article_main_obj->where("article_id",$data['article_id'])->where("sort",">",$r['sort'])->inc("sort",count($data['rows']))->update();
$sort = $r['sort']+1;
}
foreach ($data['rows'] as $v){
$insert['article_id'] = $data['article_id'];
$insert['content'] = $v;
$insert['sort'] = $sort;
$insert['ctime'] = time();
$this->article_main_obj->insert($insert);
$sort++;
}
return jsonSuccess([]);
}
private function addBRow($article_id,$am_id){
if($am_id==0){//顶行
$this->article_main_obj->where("article_id",$article_id)->inc("sort",1)->update();
$insert['article_id'] = $article_id;
$insert['content'] = "";
$insert['sort'] = 1;
$insert['ctime'] = time();
$this->article_main_obj->insert($insert);
}else{
$am_info = $this->article_main_obj->where("am_id",$am_id)->find();
$this->article_main_obj->where("article_id",$article_id)->where("sort",">",$am_info['sort'])->inc("sort",1)->update();
$insert['article_id'] = $article_id;
$insert['content'] = "";
$insert['sort'] = $am_info['sort']+1;
$insert['ctime'] = time();
$this->article_main_obj->insert($insert);
}
}
public function getMainImages(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$list = $this->article_main_image_obj
->field("*,if((select am_id from t_article_main where ami_id = t_article_main_image.ami_id and state <>1)>0 ,1,0) as has_selected")
->where("t_article_main_image.article_id",$data['article_id'])
->where("t_article_main_image.state",0)
->select();
$re['list'] = $list;
return jsonSuccess($re);
}
public function getNotes(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$list = $this->article_main_obj->where("article_id",$data['article_id'])->where("state",2)->select();
$re['list'] = $list;
return jsonSuccess($re);
}
public function getMainTables(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$list = $this->article_main_table_obj
->field("*,if((select am_id from t_article_main where amt_id = t_article_main_table.amt_id and state <>1)>0 ,1,0) as has_selected")
->where("t_article_main_table.article_id",$data['article_id'])
->where("t_article_main_table.state",0)
->select();
$re['list'] = $list;
return jsonSuccess($re);
}
public function delArticleMains(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$this->article_main_obj->where("am_id",$data['am_id'])->update(['state'=>1]);
return jsonSuccess([]);
}
/**批量删除正文的行
* @return void
*/
public function delMoreArticleMains(){
$data = $this->request->post();
$rule = new Validate([
"ids"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$idList = explode(",",$data['ids']);
$this->article_main_obj->whereIn("am_id",$idList)->update(['state'=>1]);
return jsonSuccess([]);
}
public function editArticleMainsForAuthor(){
$data = $this->request->post();
$rule = new Validate([
"am_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$am_info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
$insert['article_id'] = $am_info['article_id'];
$insert['am_id'] = $data['am_id'];
$insert['type'] = 0;
$insert['act_type'] = 0;
$insert['p_content'] = $am_info['content'];
$insert['n_content'] = $data['content'];
$insert['ctime'] = time();
$this->article_main_log_obj->insert($insert);
$update['content'] = $this->formatMain($data['content']);
$update['state'] = 0;
$this->article_main_obj->where("am_id",$data['am_id'])->update($update);
return jsonSuccess([]);
}
public function getArticleMainsRecycle(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$list = $this->article_main_obj->where("article_id",$data['article_id'])->where("type",0)->where("state",1)->select();
$re['list'] = $list;
return jsonSuccess($re);
}
public function addMainImage(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require",
"url"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$insert['article_id'] = $data['article_id'];
$insert['url'] = $data['url'];
if(isset($data['note'])){
$insert['note'] = $data['note'];
}
if(isset($data['title'])){
$insert['title'] = $data['title'];
}
$insert['ctime'] = time();
$this->article_main_image_obj->insert($insert);
$re['url'] = $data['url'];
return jsonSuccess($re);
}
public function editMainImage(){
$data = $this->request->post();
$rule = new Validate([
"ami_id"=>"require",
"url"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$update['url'] = $data['url'];
$update['note'] = isset($data['note'])?$data['note']:"";
$update['title'] = isset($data['title'])?$data['title']:"";
$this->article_main_image_obj->where("ami_id",$data['ami_id'])->update($update);
return jsonSuccess([]);
}
public function addMainTable(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require",
"table_data"=>"require",
"title"=>"require",
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$insert['article_id'] = $data['article_id'];
$insert['type'] = 0;
$insert['table_data'] = $data['table_data'];
if(isset($data['html_data'])){
$insert['html_data'] = $data['html_data'];
}
$insert['title']=$data['title'];
if(isset($data['note'])){
$insert['note'] = $data['note'];
}
$insert['ctime'] = time();
$this->article_main_table_obj->insert($insert);
return jsonSuccess([]);
}
public function editMainTable(){
$data = $this->request->post();
$rule = new Validate([
"amt_id"=>"require",
"table_data"=>"require",
"html_data"=>"require",
"title"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$update['table_data'] = $data['table_data'];
$update['html_data'] = $data['html_data'];
$update['title'] = $data['title'];
if (isset($data['note'])){
$update['note'] = $data['note'];
}
$this->article_main_table_obj->where("amt_id",$data['amt_id'])->update($update);
return jsonSuccess([]);
}
public function up_img_mainImage(){
$article_id = input('post.article_id');
$file = request()->file('mainImage');
// 检查文件是否有效
if (!$file) {
return jsonError("error");
}
// 定义上传目录
$uploadDir = ROOT_PATH . 'public' . DS . "articleImage".DS.$article_id;
$extension = pathinfo($file->getInfo("name"),PATHINFO_EXTENSION);
// 生成自定义文件名,使用 uniqid 生成唯一的文件名
$fileName = uniqid('file_') . '.' .$extension;
// 移动文件到指定目录,并重命名
$info = $file->move($uploadDir, $fileName);
// 检查文件是否上传成功
if ($info) {
$ff = '';
if($extension=="tif"||$extension=="tiff"){
$ff = $this->crossTifToPng($article_id."/".$fileName);
}else{
$ff = $article_id."/".$fileName;
}
$re['upurl'] = $ff;
return jsonSuccess($re);
} else {
return jsonError("error");
}
}
public function replyArticleRecycle(){
$data = $this->request->post();
$rule = new Validate([
'am_id'=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
$info = $this->article_main_obj->where("am_id",$data['am_id'])->find();
$check = $this->article_main_obj->where("article_id",$info['article_id'])->where("sort",$info['sort'])->whereIn("state",[0,2])->find();
if($check){
$this->article_main_obj->where("article_id",$info['article_id'])->where("sort",">=",$info['sort'])->inc('sort',1)->update();
}
$this->article_main_obj->where("am_id",$data['am_id'])->update(['state'=>0]);
return jsonSuccess([]);
}
/**调整refer排序
* @return \think\response\Json
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function sortRefer()
{
$data = $this->request->post();
$rule = new Validate([
"p_refer_id" => "require",
"act" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$refer_info = $this->production_article_refer_obj->where('p_refer_id', $data['p_refer_id'])->find();
if ($data['act'] == "up") {
$up_info = $this->production_article_refer_obj->where('p_article_id', $refer_info['p_article_id'])->where('index', $refer_info['index'] - 1)->where('state', 0)->find();
if (!$up_info) {
return jsonError("system error");
}
$this->production_article_refer_obj->where('p_refer_id', $up_info['p_refer_id'])->setInc("index");
$this->production_article_refer_obj->where('p_refer_id', $refer_info['p_refer_id'])->setDec("index");
} else {
$down_info = $this->production_article_refer_obj->where('p_article_id', $refer_info['p_article_id'])->where('index', $refer_info['index'] + 1)->where('state', 0)->find();
if (!$down_info) {
return jsonError("system error");
}
$this->production_article_refer_obj->where('p_refer_id', $refer_info['p_refer_id'])->setInc("index");
$this->production_article_refer_obj->where('p_refer_id', $down_info['p_refer_id'])->setDec("index");
}
return jsonSuccess([]);
}
public function payStationTest(){
$accessToken = $this->payStationAccessToken();
$data_array = [
'paystation_id' => Env::get("paystation.client_id"),
'gateway_id' => "PAYSTATION",//GATEWAY_ID,
'merchant_session' => "myTestSN001",
// 'merchant_reference' => 'testReference',
'amount' => 2000, //$20 in cents value
"test_mode"=>true
];
// OPTIONAL, ideally should be set on your Paystation account
$data_array += [
'return_url' => "http://192.168.110.110/tougao/public/index.php/api/Preaccept/patStationReturn",//'http://localhost:8002/3party/return.php',
// Webhook receipt page. This should be publicly accessible (see example post-response.php)
'response_url' => "https://www.tmrjournals.com"//'https://webhook.site/sample-code-webhook'
];
$data = json_encode($data_array);
// Purchase initiate request
$purchase = $this->postRequest('v1/hosted/purchases', $accessToken, $data);
return jsonSuccess($purchase);
if ($purchase) {
$result = json_decode($purchase);
if ($result && isset($result->payment_url)) {
header("Location: {$result->payment_url}");
} else {
//@todo: Replace with your own error handling
print_r($result);
return null;
}
}
}
public function payStationTest1(){
$accessToken = $this->payStationAccessToken();
$data_array = [
'paystation_id' => Env::get("paystation.client_id"),
'gateway_id' => "PAYSTATION",//GATEWAY_ID,
"order_name" => "mytestOrderSn11",
"amount" =>100,
"test_mode"=>true
];
$data = json_encode($data_array);
$purchase = $this->postRequest('v1/payme/purchases', $accessToken, $data);
$r= object_to_array(json_decode($purchase));
return jsonSuccess($r);
}
private function payStationAccessToken(){
$bodyParams = [
'client_id' => Env::get("paystation.client_id"),
'client_secret' => Env::get("paystation.client_secret"),
'grant_type' => 'client_credentials',
'scope' => "read write"
];
$accessTokenUrl = Env::get("paystation.api_url") . '/oauth/token';
$curlHandle = curl_init($accessTokenUrl);
$options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => [
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"accept: *",
"accept-encoding: gzip, deflate",
],
CURLOPT_POSTFIELDS => http_build_query($bodyParams)
];
curl_setopt_array($curlHandle, $options);
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
$curlResponse = curl_exec($curlHandle);
$error = curl_error($curlHandle);
curl_close($curlHandle);
if ($error) {
echo "cURL error: " . $error;
} else {
$response = json_decode($curlResponse);
if (array_key_exists('access_token', $response)) {
return $response->access_token;
}
if (array_key_exists('error', $response)) {
echo $response->error_description;
}
}
}
public function postRequest($endpoint, $token, $body)
{
$curlHandle = curl_init(Env::get("paystation.api_url") . '/' . $endpoint);
$options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_HTTPHEADER => [
"cache-control: no-cache",
"content-type: application/json",
"accept: *",
"accept-encoding: gzip, deflate",
"Authorization: Bearer " . $token
],
CURLOPT_POSTFIELDS => $body
];
curl_setopt_array($curlHandle, $options);
$response = curl_exec($curlHandle);
$error = curl_error($curlHandle);
curl_close($curlHandle);
if ($error) {
echo "cURL error: " . $error;
} else {
return $response ?: null;
}
return null;
}
// public function getArticleMains(){
// $data = $this->request->post();
// $rule = new Validate([
// "article_id"=>"require"
// ]);
// if(!$rule->check($data)){
// return jsonError($rule->getError());
// }
// $article_info = $this->article_obj->where("article_id",$data['article_id'])->find();
// $product_info = $this->production_article_obj->where("article_id".$data['article_id'])->find();
//
//
//
// }
public function addRefersByExcel()
{
$data = $this->request->post();
$rule = new Validate([
"article_id" => "require",
"referFile" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
$production_info = $this->production_article_obj->where('article_id', $data['article_id'])->where("state", 0)->find();
if (!$production_info) {
return jsonError("Object is null");
}
$file = ROOT_PATH . 'public' . DS . "referFile" . DS . $data['referFile'];
$list = $this->readRefersExcel($file);
foreach ($list as $k => $v) {
$ca['p_article_id'] = $production_info['p_article_id'];
$ca['refer_content'] = $v['content'];
$ca['refer_doi'] = $v['doi'];
$ca['index'] = $k;
$ca['ctime'] = time();
$adId = $this->production_article_refer_obj->insertGetId($ca);
my_doiToFrag2($this->production_article_refer_obj->where('p_refer_id', $adId)->find());
}
return jsonSuccess([]);
}
/**读取excel文件获取refer列表
* @param $afile
* @return array
* @throws \PHPExcel_Exception
* @throws \PHPExcel_Reader_Exception
*/
public function readRefersExcel($afile)
{
$extension = substr($afile, strrpos($afile, '.') + 1);
vendor("PHPExcel.PHPExcel");
if ($extension == 'xlsx') {
$objReader = new \PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load($afile);
} else if ($extension == 'xls') {
$objReader = new \PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load($afile);
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$frag = [];
for ($i = 2; $i <= $highestRow; $i++) {
if ($objPHPExcel->getActiveSheet()->getCell("A" . $i)->getValue() == '') {
continue;
}
$aa['content'] = $objPHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();
$aa['doi'] = $objPHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();
$frag[] = $aa;
}
return $frag;
}
/**上传引用文献文件,并返回读取到的内容
* @return \think\response\Json|void
*/
public function up_refer_file()
{
$file = request()->file("referFile");
if ($file) {
$info = $file->move(ROOT_PATH . 'public' . DS . "referFile");
if ($info) {
$file = ROOT_PATH . 'public' . DS . "referFile" . DS . str_replace("\\", "/", $info->getSaveName());
$re["refers"] = $this->readRefersExcel($file);
$re["upurl"] = str_replace("\\", "/", $info->getSaveName());
$re['code'] = 0;
return json($re);
} else {
return json(['code' => 1, 'msg' => $file->getError()]);
}
}
}
public function getArticleMainsNew(){
$data = $this->request->post();
$rule = new Validate([
"article_id"=>"require"
]);
if(!$rule->check($data)){
return jsonError($rule->getError());
}
//定义空数组
$re = ['list' => []];
//获取数量
$aWhere = ['article_id' => $data['article_id'],'state' => ['in',[0,2]]];
$iCount = $this->article_main_obj->where($aWhere)->count();
if(empty($iCount)){
$this->addArticleMainEx($data['article_id']);
}
//获取数据
$aArticleMain = Db::name("article_main")->where($aWhere)->order("sort asc")->select();
if(empty($aArticleMain)){
return null;
}
//处理数据
$iSize = 300;
$aChunk = array_chunk($aArticleMain, $iSize);
$mains = [];
foreach ($aChunk as $item) {
$aMId = array_column($item, 'am_id');
//查询article_main_check
$aWhere = ['am_id' => ['in',$aMId],'state' => 0];
$aMainCheck = Db::name("article_main_check")->where($aWhere)->select();
$aMainCheckData = [];
if(!empty($aMainCheck)){
foreach ($aMainCheck as $value) {
if(empty($value['am_id'])){
continue;
}
$aMainCheckData[$value['am_id']][] = $value;
}
}
//获取图片信息
$aMiId = array_unique(array_column($item, 'ami_id'));
$aWhere = ['ami_id' => ['in',$aMiId],'state' => 0];
$aArticleMainImage = Db::name("article_main_image")->where($aWhere)->select();
$aArticleMainImage = empty($aArticleMainImage) ? [] : array_column($aArticleMainImage, null,'ami_id');
//获取表格信息
$aMiId = array_unique(array_column($item, 'amt_id'));
$aWhere = ['amt_id' => ['in',$aMiId],'state' => 0];
$aArticleMainTable = Db::name("article_main_table")->where($aWhere)->select();
$aArticleMainTable = empty($aArticleMainTable) ? [] : array_column($aArticleMainTable, null,'amt_id');
//查询校对数量 t_article_proofread
$aWhere = ['am_id' => ['in',$aMId],'state' => ['between',[1,2]],'is_delete' => 2];
$aArticleProofread = Db::name("article_proofread")->field('am_id,count(id) as num,state')->where($aWhere)->group('am_id,state')->select();
$aArticleProofreadData = [];
if(!empty($aArticleProofread)){
foreach ($aArticleProofread as $key => $value) {
$aArticleProofreadData[$value['am_id']][$value['state']] = $value['num'];
}
}
foreach ($item as $k => $main) {
if($main['is_h1']==1){
$main['content'] = "".$main['content']."";
}
if($main['is_h2']==1||$main['is_h3']==1){
$main['content'] = "".$main['content']."";
}
$main['checks'] = empty($aMainCheckData[$main['am_id']]) ? [] : $aMainCheckData[$main['am_id']];
if($main['type'] == 1){
$main['image'] = empty($aArticleMainImage[$main['ami_id']]) ? [] : $aArticleMainImage[$main['ami_id']];
}
if($main['type'] == 2){
$main['table'] = empty($aArticleMainTable[$main['amt_id']]) ? [] : $aArticleMainTable[$main['amt_id']];
}
if($main['type'] == 0){
$aDataInfo = empty($aArticleProofreadData[$main['am_id']]) ? [] : $aArticleProofreadData[$main['am_id']];
$main['proof_read_num'] = -1;
if(!empty($aDataInfo)){
$main['proof_read_num'] = empty($aDataInfo[2]) ? 0 : $aDataInfo[2];
}
}
$mains[] = $main;
}
}
$re['list'] = $mains;
return jsonSuccess($re);
}
//作者上传参考文献 - 新
public function addRefersByExcelNew(){
$data = $this->request->post();
$rule = new Validate([
"article_id" => "require",
"referFile" => "require"
]);
if (!$rule->check($data)) {
return jsonError($rule->getError());
}
//判断数据是否存在 不存在直接入库数据 chengxiaoling 20251119 start
$aWhere = ['article_id' => $data['article_id'],'state' => 0];
$production_info = $this->production_article_obj->where($aWhere)->find();
if (!$production_info) {
$aResult = $this->addProductionEx($data['article_id']);
$aResult = empty($aResult->getData()) ? [] : $aResult->getData();
$iCode = isset($aResult['code']) ? $aResult['code'] : -1;
$sMsg = empty($aResult['msg']) ? 'Data processing failed' : $aResult['msg'];
if($iCode != 0){
return jsonError($sMsg);
}
}
$production_info = $this->production_article_obj->where($aWhere)->find();
if(!$production_info){
return jsonError("Object is null");
}
//判断数据是否存在 不存在直接入库数据 chengxiaoling 20251119 end
$file = ROOT_PATH . 'public' . DS . "referFile" . DS . $data['referFile'];
$list = $this->readRefersExcelNew($file,$production_info['p_article_id'],$data['article_id']);
if(!empty($list)){
$result = $this->production_article_refer_obj->insertAll($list);
}
//写入获取参考文献详情队列
\think\Queue::push('app\api\job\ArticleReferQueue@fire',['article_id' => $data['article_id'],'p_article_id' => $production_info['p_article_id']], 'ArticleReferQueue');
return jsonSuccess([]);
}
public function readRefersExcelNew($afile,$p_article_id = 0,$article_id = 0){
if(empty($p_article_id)){
return [];
}
// //查询参考文献
// $aWhere = ['p_article_id' => $p_article_id,'article_id' => $article_id,'state' => 0,'refer_doi' => ['<>','']];
// $aRefer = Db::name('production_article_refer')->where($aWhere)->column('refer_doi');
$extension = substr($afile, strrpos($afile, '.') + 1);
vendor("PHPExcel.PHPExcel");
if ($extension == 'xlsx') {
$objReader = new \PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load($afile);
} else if ($extension == 'xls') {
$objReader = new \PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load($afile);
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$frag = [];
$k = 0;
for ($i = 2; $i <= $highestRow; $i++) {
if ($objPHPExcel->getActiveSheet()->getCell("A" . $i)->getValue() == '') {
continue;
}
$aa['refer_content'] = $objPHPExcel->getActiveSheet()->getCell("A" . $i)->getValue();
$aa['refer_doi'] = $objPHPExcel->getActiveSheet()->getCell("B" . $i)->getValue();
if(empty($aa['refer_doi'])){
continue;
}
$aa['refer_doi'] = trim($aa['refer_doi']);
$aa['refer_content'] = trim($aa['refer_content']);
// //判断是否添加过
// $doiLinkPattern = '/^(https?:\/\/)?([a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+\.[a-zA-Z]{2,}(\/.*)?$/i';
// if(preg_match($doiLinkPattern, $aa['refer_doi'], $matches)){
// if(in_array($aa['refer_doi'], $aRefer)){
// continue;
// }
// }
$aa['p_article_id'] = $p_article_id;
$aa['article_id'] = $article_id;
$aa['index'] = $k;
$aa['ctime'] = time();
$aa['index'] = $k;
$aa['refer_frag'] = $aa['refer_content'];
$aa['refer_type'] = 'other';
$aa['is_deal'] = 2;
$k++;
$frag[] = $aa;
}
return $frag;
}
//获取参考文献的状态
public function getReferState(){
//获取参数
$aParam = empty($aParam) ? $this->request->post() : $aParam;
//获取文章ID
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
if(empty($iArticleId)){
return json_encode(['status' => 2,'msg' => 'Please select the article']);
}
$aWhere = ['article_id' => $iArticleId,'state' => 0];
$aProductionArticle = $this->production_article_obj->field('p_article_id')->where($aWhere)->find();
$iPArticleId = empty($aProductionArticle['p_article_id']) ? 0 : $aProductionArticle['p_article_id'];
if(empty($iPArticleId)) {
return json_encode(array('status' => 2,'msg' => 'No articles found'));
}
//查询参考文献数据
$aWhere = ['p_article_id' => $iPArticleId,'article_id' => $iArticleId,'state' => 0];
$aRefer = Db::name('production_article_refer')->where($aWhere)->select();
if(empty($aRefer)){
return json_encode(array('status' => 3,'msg' => 'Reference is empty','data' => ['total' => 0,'unprocessed_total' => 0,'processed_total' => 0]));
}
//获取总数量
$iCount = empty($aRefer) ? 0 : count($aRefer);
$aWhere["refer_doi"] = ["<>",""];
$aDoi = Db::name('production_article_refer')->field('count(p_article_id) as num,refer_doi')->where($aWhere)->group('refer_doi')->select();
$aDoi = empty($aDoi) ? [] : array_column($aDoi, 'num','refer_doi');
//数据处理
$iUnprocessed = $iProcessed = 0;
foreach ($aRefer as $key => $value) {
if($value['is_deal'] == 1){
$iProcessed++;
}
if($value['is_deal'] == 2){
$iUnprocessed++;
}
$iIsRepat = 0;
if(!empty($value['refer_doi']) && (!empty($aDoi[$value['refer_doi']]) && $aDoi[$value['refer_doi']] > 1)){
$iIsRepat = 1;
}
$aRefer[$key]['is_repeat'] = $iIsRepat;
}
$aRefer = ['total' => $iCount,'unprocessed_total' => $iUnprocessed,'processed_total' => $iProcessed,'refer' => $aRefer];
return json_encode(['status' => 1,'msg' => 'success','data' => $aRefer]);
}
//使文章进入生产状态
public function beginProduce(){
//获取参数
$aParam = empty($aParam) ? $this->request->post() : $aParam;
//获取文章ID
$iArticleId = empty($aParam['article_id']) ? 0 : $aParam['article_id'];
if(empty($iArticleId)){
return jsonError('Please select the article');
}
//查询是否缴费
$aWhere = ['article_id' => $iArticleId,'state' => ['in',[5,6]]];
$aArticle = $this->article_obj->field('is_buy')->where($aWhere)->find();
if(empty($aArticle)){
return jsonError('No article information found');
}
$iIsBuy = empty($aArticle['is_buy']) ? 0 : $aArticle['is_buy'];
if($iIsBuy != 1){
return jsonError('Article unpaid');
}
$aWhere = ['article_id' => $iArticleId,'state' => 0];
$aProductionArticle = $this->production_article_obj->field('p_article_id')->where($aWhere)->find();
if(!empty($aProductionArticle)) {
return jsonError('The article has entered production');
}
$aResult = $this->addProductionEx($iArticleId);
$aResult = empty($aResult->getData()) ? [] : $aResult->getData();
$iCode = isset($aResult['code']) ? $aResult['code'] : -1;
$sMsg = empty($aResult['msg']) ? 'Data processing failed' : $aResult['msg'];
if($iCode != 0){
return jsonError($sMsg);
}
return jsonSuccess([]);
}
}