1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039 |
- <?php
- // +----------------------------------------------------------------------
- // | Yzncms [ 御宅男工作室 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2018 http://yzncms.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | fastadmin: https://www.fastadmin.net/
- // +----------------------------------------------------------------------
-
- // +----------------------------------------------------------------------
- // | 邮箱验证码接口
- // +----------------------------------------------------------------------
- namespace app\api\controller;
-
- use app\member\controller\MemberApi;
- use think\Db;
-
- /**
- * @title 邮箱验证码接口
- * @controller api\controller\Ems
- * @group base
- */
- class Cms extends MemberApi
- {
-
- protected $noNeedLogin = ['login', 'register','getProduct','getProductSmall','createTask','tagHandle','taskHandle','getAreaJson','getTagListHandle','articleContentHandle','hkContent','upContent'];
- protected $noNeedRight = [];
-
- //初始化
- protected function initialize()
- {
- parent::initialize();
- }
-
- /**
- * @title 发送验证码
- * @desc 最基础的接口注释写法
- * @author 御宅男
- * @url /api/Ems/send
- * @method GET
- * @tag 邮箱 验证码
- * @param name:email type:string require:1 desc:邮箱
- * @param name:event type:string require:1 desc:事件名称
- * @return name:data type:array ref:definitions\dictionary
- */
- public function send()
- {
-
- }
-
- /**
- * @title 检测验证码
- * @desc 最基础的接口注释写法
- * @author 御宅男
- * @url /api/Ems/check
- * @method GET
- * @tag 邮箱 验证码
- * @param name:email type:string require:1 desc:邮箱
- * @param name:event type:string require:1 desc:事件名称
- * @param name:captcha type:string require:1 desc:验证码
- * @return name:data type:array ref:definitions\dictionary
- */
- public function check()
- {
-
- }
-
- /*
- *
- * 同步产品接口 - 大类
- * 每天同步一次
- * 防止产品未发布级别就同步过来 执行了
- * http://console.zx2049.com/api/cms/getProduct
- */
- public function getProduct()
- {
- //查找区域
- $area = Db::connect('db1')
- ->table('ey_citysite')
- ->where(['level'=>1,'is_open'=>1,'status'=>1])
- ->select();
- //dump($area);
- $area[] = [
- 'id' => 10000,
- ];
-
- foreach ($area as $index => $item) {
-
- //查找最后创建时间create_time
- $add_time = Db::name('cms_product')
- ->where(['catid'=>2,'diqu'=>$item['id']]) //产品大类
- ->order('add_time desc')
- ->value('add_time');
- //dump($create_time);
- if(empty($add_time)){
- $add_time = 0;
- }
-
- //不考虑分批次
- $list = Db::connect('db1')
- ->table('ey_arctype')
- ->where(['topid'=>38,'area_id'=>$item['id'],'is_del'=>0])
- ->where('add_time','>',$add_time)
- ->select();
- //dump($list);
-
- foreach ($list as $key=>$row){
- $one = Db::name('cms_product')->where([
- 'catid' => 2,
- 'aid' => $row['id'],
- 'diqu' => $item['id'],
- 'pid' => 0,
- ])->find();
- if(empty($one)){
- //插入数据库
- $insert_data = [
- 'catid' => 2,
- 'title' => $row['typename'],
- 'add_time' => $row['add_time'],
- 'create_time' => time(),
- 'update_time' => time(),
- 'status' => 1,
- 'diqu' => $item['id'],
- 'pid' => 0,
- 'aid' => $row['id'],
- 'site_id' => 1,
- 'link' => ''
- ];
- $run = Db::name('cms_product')->insert($insert_data);
- echo '插入'.$run.'条,产品id: '.$row['id'].'<br/>';
- }else{
- echo '插入0条,产品id: '.$row['id'].'已存在<br/>';
- }
- }
- }
- }
-
- /*
- * 同步产品接口 - 小类
- * http://console.zx2049.com/api/cms/getProductSmall
- */
- public function getProductSmall()
- {
-
- //查找最后创建时间create_time
- $add_time = Db::name('cms_product')
- ->where(['catid'=>3]) //产品小类
- ->order('add_time desc')
- ->value('add_time');
- //dump($create_time);
- if(empty($add_time)){
- $add_time = 0;
- }
-
- //不考虑分批次
- $list = Db::connect('db1')
- ->table('ey_arctype_cat')
- ->where(['is_del'=>0])
- ->where('add_time','>',$add_time)
- ->select();
- //dump($list);
-
- foreach ($list as $key=>$row){
-
- //查找上级所属区域id
- $area_id = Db::connect('db1')->table('ey_arctype')->where(['id'=>$row['parent_id']])->value('area_id');
-
- if(empty($area_id)){
- $area_id = 0;
- }
-
- $one = Db::name('cms_product')->where([
- 'catid' => 3,
- 'aid' => $row['id'],
- 'diqu' => $area_id,
- 'pid' => 0,
- ])->find();
- if(empty($one)){
- //插入数据库
- $insert_data = [
- 'catid' => 3,
- 'title' => $row['typename'],
- 'add_time' => $row['add_time'],
- 'create_time' => time(),
- 'update_time' => time(),
- 'status' => 1,
- 'diqu' => $area_id,
- 'pid' => $row['parent_id'],
- 'aid' => $row['id'],
- 'site_id' => 1,
- 'link' => ''
- ];
- $run = Db::name('cms_product')->insert($insert_data);
- echo '插入'.$run.'条,产品id: '.$row['id'].'<br/>';
- }else{
- echo '插入0条,产品id: '.$row['id'].'已存在<br/>';
- }
- }
- }
-
- /*
- * 同步删除操作
- * 增加字段 is_del 和 delete_time
- * 同步删除时间和是否删除
- * 目前先在发文的时候判断是否已删除就行
- */
- public function delHandle()
- {
-
- }
-
- /*
- * 存在小类就不创建发文任务,因为只有概述
- * 小类肯定都发文
- * 一个产品发一篇 不按级别 级别作为轮询为发文内容
- * 标签为 产品名+申报 (这个固定不变) 另 产品名与标签名 发生修改 不做统一校验
- * 同时判断产品是否正常(非删除状态)
- * 每一轮为一个定时任务 因为产品是不断增加的 同时任务也是不断增加的
- * 每一轮的任务分组不一样 会持续不断发文 对应发文模板也不一样
- * 参数 任务分组id
- * http://console.zx2049.com/api/cms/createTask?taskid=10
- */
- public function createTask()
- {
- $taskid = $this->request->get('taskid',0);
- if((int)$taskid === 0){
- $this->error('fail');
- }
-
- //查询
- $add_time = Db::table('yzn_task')
- ->where(['catid'=>$taskid])
- ->order('add_time desc')
- ->value('add_time');
-
- if(empty($add_time)){
- $add_time = 0;
- }
-
- //不做分批次处理
- //新赠的产品 大类
- $list = Db::table('yzn_cms_product')
- ->where(['status'=>1]) //,'catid'=>2 不管是大类还是小类
- ->where('add_time','>',$add_time)
- ->select();
-
- foreach ($list as $key=>$row){
- $one = Db::name('task')->where([
- 'catid' => $taskid,
- 'aid' => $row['aid'],
- 'diqu' => $row['diqu'],
- 'yid' => $row['catid'],
- 'cid' => 111,
- ])->find();
- if(empty($one)){
- //插入数据库
- $insert_data = [
- 'catid' => $taskid, //任务分组id
- 'title' => $row['title'],
- 'add_time' => $row['add_time'],
- 'create_time' => time(),
- 'update_time' => time(),
- 'status' => 0, //初始状态为0 未执行
- 'diqu' => $row['diqu'],
- 'yid' => $row['catid'], //产品大类还是小类
- 'aid' => $row['aid'], //产品id
- 'site_id' => 1,
- 'link' => '', //文章链接
- 'tagid' => 0, //标签id 初始为0
- 'cid' => 111, //常见问题
- 'run_time' => time(),
- 'is_run' => 0
- ];
- $run = Db::name('task')->insert($insert_data);
- echo '插入'.$run.'条,产品id: '.$row['aid'].'-'.$row['title'].'<br/>';
- }else{
- echo '插入0条,产品id: '.$row['aid'].'-'.$row['title'].'已存在<br/>';
- }
- }
- }
-
- /*
- * {"1":"广东","30":"福建","6872":"陕西","6791":"西藏","6645":"云南","6344":"四川","6303":"重庆","6003":"海南","5879":"广西","5742":"湖南","5625":"湖北","5448":"河南","5179":"江西","5056":"安徽","4833":"江苏","4813":"上海","4667":"黑龙江","4589":"吉林","4474":"辽宁","4228":"山西","4042":"河北","4023":"天津","4003":"浙江","6547":"贵州","4359":"内蒙古","4004":"北京","6990":"甘肃","7092":"青海","7144":"宁夏","7171":"新疆","10000":"主站"}
- *
- * http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=1
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=30
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6872
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6791
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6645
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6344
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6303
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6003
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5879
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5742
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5625
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5448
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5179
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5056
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4833
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4813
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4667
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4589
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4474
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4228
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4042
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4023
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4003
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6547
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4359
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4004
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6990
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=7092
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=7144
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=7171
- http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=10000
- */
- public function tagHandle()
- {
-
- $taskid = $this->request->get('taskid',0);
- if((int)$taskid === 0){
- $this->error('fail');
- }
-
- //地区参数
- $diqu = $this->request->get('diqu',0);
- if((int)$diqu === 0){
- $this->error('fail');
- }
-
- $page = 1;
- $list = Db::name('task')->where([
- 'catid' => $taskid, //任务分组id
- 'tagid' => 0,
- 'status' => 0,
- 'diqu' => (int)$diqu
- ])
- ->order('add_time asc')->paginate(1);
- $list = $list->toArray();
- $data = $list['data'];
-
- if(empty($data)){
- $this->error('fail',['ko'=>'不存在数据']);
- }
-
- foreach ($data as $index => $row) {
-
- //获取标签
- $tagname = $this->getName($row['title']);
- $tagname = $tagname.'申报';
-
-
- if((int)$row['diqu'] === 10000){
- $diqu = 0; //山东地区变为主页 区域为0
- }else{
- $diqu = $row['diqu'];
- }
-
- $one = Db::connect('db1')->table('ey_archives')
- ->where(['typeid' => 523,'province_id'=>$diqu,'is_del'=>0])
- ->where('title',$tagname)
- ->find();
- if(empty($one)){
-
- //不存在
- //判断是否需要增加标签
- //远程判断产品状态
- if((int)$row['yid'] === 2) {
- //大类
- $one = Db::connect('db1')->table('ey_arctype')->where(['id' => $row['aid']])->find();
- }else if((int)$row['yid'] === 3) {
- //小类
- $one = Db::connect('db1')->table('ey_arctype_cat')->where(['id' => $row['aid']])->find();
- }else{
- //任务异常 退出
- $this->error('fail');
- }
-
- if((int)$one['is_del'] === 1 || (int)$one['status'] === 0){
- //已删除
- Db::name('task')->where(['id'=>$row['id']])->update([
- 'is_run' => 4, //执行异常
- 'run_time' => time(),
- 'status' => 1,
- ]);
- $this->error('fail',['is_run'=>4]);
- }
-
- //是否只有一个页面 (远程)
- if((int)$row['yid'] === 2) {
- //大类
- $count = Db::connect('db1')->table('ey_archives')->where(['typeid' => $row['aid'],'product_id'=>0,'is_del'=>0])->count();
- }else if((int)$row['yid'] === 3) {
- //小类
- $count = Db::connect('db1')->table('ey_archives')->where(['product_id' => $row['aid'],'is_del'=>0])->count();
- }else{
- //任务异常 退出
- $this->error('fail');
- }
- //dump($count);
-
- if($count <= 1) {
- //只有一个主页 概述
- Db::name('task')->where(['id' => $row['id']])->update([
- 'is_run' => 3, //执行忽略
- 'run_time' => time(),
- 'status' => 1,
- ]);
- $this->error('fail',['is_run'=>3]);
- }
-
- //创建标签
- $insert_data = [
- 'typeid' => 523,
- 'status' => 1,
- 'is_del' => 0,
- 'channel' => 101,
- 'click' => rand(500,5000),
- 'arcrank' => 0,
- 'add_time' => time(),
- 'update_time' => time(),
- 'province_id' => (int)$diqu,
- 'product_tag_id' => 0, //由其他任务处理
- 'title' => $tagname,
- ];
- //执行插入
- $aid = Db::connect('db1')->table('ey_archives')->insertGetId($insert_data);
- if((int)$aid > 0) {
- //增加详情
- $insert_data_content = [
- 'aid' => $aid,
- 'add_time' => time(),
- 'update_time' => time()
- ];
- Db::connect('db1')->table('ey_suipian_content')->insert($insert_data_content);
- }
- //更新任务 标签id
- Db::name('task')->where(['id' => $row['id']])->update([
- 'tagid' => $aid,
- ]);
- $this->success('成功');
- }else{
- //写入标签id 到 任务记录
- Db::name('task')->where(['id' => $row['id']])->update([
- 'tagid' => $one['aid'],
- ]);
- $this->success('成功');
- }
- }
- }
-
- /*
- * 执行
- * 增加字段 is_run 未执行0 执行成功1 执行失败2(远程响应错误) 执行忽略3(存在小类或无级别-只有一个主页) 产品异常4(删除或未审核或屏蔽)
- * run_time 执行时间
- * is_run = 0 每次处理10条
- *
- * {"1":"广东","30":"福建","6872":"陕西","6791":"西藏","6645":"云南","6344":"四川","6303":"重庆","6003":"海南","5879":"广西","5742":"湖南","5625":"湖北","5448":"河南","5179":"江西","5056":"安徽","4833":"江苏","4813":"上海","4667":"黑龙江","4589":"吉林","4474":"辽宁","4228":"山西","4042":"河北","4023":"天津","4003":"浙江","6547":"贵州","4359":"内蒙古","4004":"北京","6990":"甘肃","7092":"青海","7144":"宁夏","7171":"新疆","10000":"主站"}
- *
- * http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=1
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=30
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6872
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6791
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6645
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6344
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6303
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6003
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5879
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5742
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5625
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5448
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5179
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5056
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4833
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4813
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4667
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4589
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4474
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4228
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4042
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4023
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4003
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6547
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4359
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4004
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6990
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=7092
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=7144
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=7171
- http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=10000
- *
- */
- public function taskHandle()
- {
- $taskid = $this->request->get('taskid',0);
- if((int)$taskid === 0){
- $this->error('fail');
- }
-
- //地区参数
- $diqu = $this->request->get('diqu',0);
- if((int)$diqu === 0){
- $this->error('fail');
- }
-
- //查询未执行的任务
- $page = 1;
- $list = Db::name('task')->where([
- 'catid' => $taskid, //任务分组id
- 'is_run' => 0,
- 'status' => 0,
- 'diqu' => (int)$diqu
- ])
- ->where('tagid','>',0) //标签id需要已经获取到的
- ->order('add_time asc')->paginate(1);
- $list = $list->toArray();
- $data = $list['data'];
- //dump($data);die;
-
- if(empty($data)){
- $this->error('fail',['ko'=>'不存在数据']);
- }
- /*
- * 跨库 无法保证远程和本地的事务一致性
- * 这种机制 类似 支付
- * 先简单处理
- */
- foreach ($data as $index => $row) {
-
- //远程判断产品状态
- /*if((int)$row['yid'] === 2) {
- //大类
- $one = Db::connect('db1')->table('ey_arctype')->where(['id' => $row['aid']])->find();
- }else if((int)$row['yid'] === 3) {
- //小类
- $one = Db::connect('db1')->table('ey_arctype_cat')->where(['id' => $row['aid']])->find();
- }else{
- //任务异常 退出
- return false;
- }
-
- if((int)$one['is_del'] === 1 || (int)$one['status'] === 0){
- //已删除
- Db::name('task')->where(['id'=>$row['id']])->update([
- 'is_run' => 4, //执行异常
- 'run_time' => time(),
- 'status' => 1,
- ]);
- return false;
- }*/
-
- /*
- *
- *
- //不管有没有小类 只有一个主页 就执行忽略
- if((int)$row['yid'] === 2) {
- //该任务记录 为 大类 产品
- //是否存在小类(控制台产品不保证是最新数据 采用远程判断)
- Db::connect('db1')->table('ey_arctype_cat')->where(['parent_id' => $row['aid']])->find();
- }*/
-
- //是否只有一个页面 (远程)
- /*if((int)$row['yid'] === 2) {
- //大类
- $count = Db::connect('db1')->table('ey_archives')->where(['typeid' => $row['aid'],'product_id'=>0,'is_del'=>0])->count();
- }else if((int)$row['yid'] === 3) {
- //小类
- $count = Db::connect('db1')->table('ey_archives')->where(['product_id' => $row['aid'],'is_del'=>0])->count();
- }else{
- //任务异常 退出
- return false;
- }
- //dump($count);
-
- if($count <= 1) {
- //只有一个主页 概述
- Db::name('task')->where(['id' => $row['id']])->update([
- 'is_run' => 3, //执行忽略
- 'run_time' => time(),
- 'status' => 1,
- ]);
- return false;
- }*/
-
- //构建参数
- if((int)$row['diqu'] === 10000){
- $diqu = 0; //山东地区变为主页 区域为0
- }else{
- $diqu = $row['diqu'];
- }
- $insert_data = [
- 'typeid' => 111,
- 'status' => 1,
- 'is_del' => 0,
- 'channel' => 103,
- 'click' => rand(500,5000),
- 'arcrank' => 0,
- 'add_time' => time(),
- 'update_time' => time(),
- 'province_id' => (int)$diqu,
- 'product_tag_id' => $row['tagid'], //由其他任务处理
- 'title' => $this->getTitle($row,$diqu),
- 'seo_title' => $this->getSeoTitle($row,$diqu),
- 'seo_keywords' => $this->getKeywords($row,$diqu),
- 'seo_description' => $this->getDesc($row,$diqu),
- ];
- //执行插入
- $aid = Db::connect('db1')->table('ey_archives')->insertGetId($insert_data);
-
- //$aid=1;
- //dump($insert_data);die;
-
- if((int)$aid > 0) {
- //增加详情
- $content = $this->getContent($row,$diqu);
- //echo htmlspecialchars_decode($content);die;
-
- $insert_data_content = [
- 'aid' => $aid,
- 'add_time' => time(),
- 'update_time' => time(),
- 'content_5' => $content
- ];
- Db::connect('db1')->table('ey_zczygz_content')->insert($insert_data_content);
-
- //增加序列号
- $where6 = [
- "type" => 2,
- "tid" => 111,
- 'topid' => 0,
- 'parentid' => 0,
- 'area_id' => (int)$diqu, //如果是0的话 后续也不能改
- 'city_id' => 0, //如果是0的话 后续也不能改
- ];
- $last = Db::connect('db1')->name('seo_number')
- ->where($where6)->order('number desc')->find();
- if (empty($last['number'])) {
- $num = 1;
- } else {
- $num = (int)$last['number'] + 1;
- }
- $insert_data_seo = [
- "type" => 2, //产品类型
- "aid" => $aid, //实际的ID
- "tid" => 111, //属于哪个栏目的
- 'is_del' => 0,
- 'is_kan' => 0, // 0正常 1审核
- 'status' => 1,
- 'area_id' => (int)$diqu,
- 'city_id' => 0,
- 'topid' => 0,
- 'parentid' => 0,
- 'number' => $num
- ];
- Db::connect('db1')->table('ey_seo_number')->insert($insert_data_seo);
-
- //更新状态
- if ((int)$diqu === 0) {
- $link = 'https://www.gdzcfw.com/wthz' . $num;
- } else {
- $domain = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('domain');
- $link = 'https://' . $domain . '.gdzcfw.com/wthz' . $num;
- }
- Db::name('task')->where(['id' => $row['id']])->update([
- 'is_run' => 1, //执行成功
- 'run_time' => time(),
- 'status' => 1,
- 'link' => $link,
- ]);
- $this->success('成功');
- }
- }
- }
-
- /*
- * 产品名称处理
- */
- public function getName($str){
- $str = str_replace('职称', "", $str);
- $str = $str.'职称';
- return $str;
- }
- /*
- * 模板1
- */
- public function getTitle($row,$diqu)
- {
- $area_name = '';
- if((int)$diqu > 0){
- $area_name = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('name');
- }
- $title = $this->getName($row['title']);
- $str = $area_name.$title.'评定【2024年最新学历要求】';
- return $str;
- }
-
- public function getSeoTitle($row,$diqu)
- {
- $area_name = '';
- if((int)$diqu > 0){
- $area_name = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('name');
- }
- $title = $this->getName($row['title']);
- $str = $area_name.$title.'评定【2024年最新要求解读】';
- return $str;
- }
-
- public function getKeywords($row,$diqu){
- $area_name = '';
- if((int)$diqu > 0){
- $area_name = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('name');
- }
- $title = $this->getName($row['title']);
- $str = $area_name.$title.'评定学历要求';
- return $str;
- }
-
- public function getDesc($row,$diqu){
- $area_name = '';
- if((int)$diqu > 0){
- $area_name = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('name');
- }
- $title = $this->getName($row['title']);
- $str = $area_name.$title.'评定上【职称网】工程师职称破格评审绿色通道,专注工程师职称评审,专注工程师职称评审,提供职称材料撰写、职称申报、职称论文专利一站式服务。';
- return $str;
- }
-
- /*
- * 模板1
- */
- public function getContent($row,$diqu)
- {
- $area_name = '';
- $domain = 'www';
- if((int)$diqu > 0){
- $area = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->find();
- $area_name = $area['name'];
- $domain = $area['domain'];
- }
- $title = $this->getTitle($row,$diqu);
-
- //图片地址
- $op = rand(1,9);
- $imgurl = 'https://oss.gdzcfw.com/static/article/'.$op.'.png';
-
- $html = '';
- $html .= '<p style="text-align: center !important;">
- <img src="'.$imgurl.'" style="max-width:100%;" /><br/>
- <span style="font-size: 17px !important;">'.$title.'</span><br/>
- </p>';
-
- //调用其他级别的学历要求
- if((int)$row['yid'] === 2) {
- //大类
- $aids = Db::connect('db1')->table('ey_archives')->field('aid,title')->where(['typeid' => $row['aid'],'product_id'=>0,'is_del'=>0])->select();
- }else if((int)$row['yid'] === 3) {
- //小类
- $aids = Db::connect('db1')->table('ey_archives')->field('aid,title')->where(['product_id' => $row['aid'],'is_del'=>0])->order('level asc')->select();
- }
-
- $h = ['一)','二)','三)','四)','五)','六)','七)','八)','九)','十)','十一)'];
- $jk = 0;
- foreach ($aids as $k=>$v){
- $data = Db::connect('db1')->table('ey_zczygz_content')
- ->field('aid,content_6')->where('aid','=',$v['aid'])->find();
- if(!empty($data['content_6'])){
- $pro_title = $this->getName($row['title']);
- $html .= '<p style="text-align: left;font-weight: bold !important;font-size:16px !important;margin-top:5px;">
- '.$h[$jk].$area_name.$pro_title.'评定'.$v['title'].'学历要求:</p>';
- $html .= '<p style="text-align: left;">
- '.$data['content_6'].'</p>';
- $jk++;
- }
- }
-
- //拼装产品
- if((int)$row['yid'] === 2) {
- //大类
- $number = Db::connect('db1')->table('ey_seo_number')->where([
- 'type' => 1,
- 'aid' => $row['aid'],
- 'parentid' => 38
- ])->value('number');
- $link = 'https://'.$domain.'.gdzcfw.com/id'.$number;
- }else if((int)$row['yid'] === 3) {
- //小类
- $one = Db::connect('db1')->table('ey_seo_number')->where([
- 'type' => 1,
- 'aid' => $row['aid'],
- ])->where('parentid','<>',38)->find();
- $number = Db::connect('db1')->table('ey_seo_number')->where([
- 'type' => 1,
- 'aid' => $one['parentid'],
- 'parentid' => 38
- ])->value('number');
- $link = 'https://'.$domain.'.gdzcfw.com/id'.$number.'/sid'.$one['number'];
- }
-
- $html .= '<p style="text-align: left;margin-top:15px;">
- <font style="font-weight: bold !important;font-size:16px !important;">最新'.$area_name.$pro_title.'评定政策详情请点击:</font><a href="'.$link.'" targey="_blank" style="color: blue !important;font-size:16px !important;">'.$area_name.$pro_title.'</a></p>';
-
- //其他链接
- $html .= '<p style="text-align: left;margin-top:15px;">
- <a href="https://www.gdzcfw.com" style="color: blue !important;">职称网</a>更多<a href="https://www.gdzcfw.com" style="color: blue !important;">职称评审</a>相关请点击:<br/>
- '.$area_name.'职称政策文件下载: <a href="https://www.gdzcfw.com/zccl" style="color: blue !important;">职称材料</a><br/>
- 职称答辩相关指引请点击: <a href="https://www.gdzcfw.com/zcdb" style="color: blue !important;">职称答辩</a><br/>
- 职称评审绿色破格通道: <a href="https://zczl.gdzcfw.com" style="color: blue !important;">职称代办</a><br/></p><br/>';
-
- return $html;
- }
-
- /*
- * 执行忽略 重新校验
- * 产品后面增加了级别 一开始没有级别 也没有小类
- * 产品后面增加了级别 一开始没有级别 有小类
- * 产品后面增加了小类 一开始没有级别 也没有小类
- * 产品后面增加了小类 一开始有级别 没有小类
- *
- * 不管有没有小类 是大类还是小类 只要没有级别 就不发文 就对了
- * 就算有小类 有级别 就发文
- * 正常情况 不会存在既有级别又有小类
- * 这里把执行忽略的 校验后 改为未执行
- */
-
- /*
- * 产品异常 校验产品如果正常了 任务改为未执行
- */
-
-
- /*
- * 生成地区json 方便增加查询条件
- * http://console.zx2049.com/api/cms/getAreaJson
- */
- public function getAreaJson()
- {
- $area = Db::connect('db1')
- ->table('ey_citysite')
- ->where(['level'=>1,'is_open'=>1,'status'=>1])
- ->select();
- //dump($area);
- $area[] = [
- 'id' => 10000,
- 'name' => '主站',
- ];
-
- //{ 0: '待审核', 1: '通过' }
- $collect = [];
- $str = '';
- foreach($area as $k=>$v){
- $collect[(int)$v['id']] = $v['name'];
- //$str .= 'http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu='.$v['id'].'<br/>';
- $str .= 'http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu='.$v['id'].'<br/>';
-
- }
-
- $collect = json_encode($collect,JSON_UNESCAPED_UNICODE);
-
-
- echo $str;
- //return $collect;
-
- }
-
- /*
- * 批量执行标签处理
- * 加入队列 http://console.zx2049.com/api/cms/getTagListHandle
- * 启动队列 php think queue:listen --queue tagHandle
- * 监听队列 进程守护管理器 (附加参数参考: https://www.kancloud.cn/ken678/yzncms/2383907)
- * redis查看数据器 默认重置次数1
- * workman实时推送消息
- * 添加自定义命令的方式来执行队列
- */
- public function getTagListHandle()
- {
-
-
- /* $a = new \app\api\queue\jobs\TagHandle();
- var_dump($a);
- return json([]);*/
-
-
-
- $area = Db::connect('db1')
- ->table('ey_citysite')
- ->where(['level'=>1,'is_open'=>1,'status'=>1])
- ->select();
- //dump($area);
- $area[] = [
- 'id' => 10000,
- 'name' => '主站',
- ];
-
- foreach ($area as $k=>$v){
- //http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=1
- $jobData = ['ts' => time(),'url'=>'http://console.zx2049.com/api/cms/tagHandle','taskid'=>10, 'area_id' => $v['id'], 'area_name' => $v['name']];//当前任务所需的业务数据
- $isPushed = \think\Queue::push('app\common\jobs\TagHandle', $jobData,'tagHandle');//没有@使用默认方法fire,此方法为立即执行
- if ($isPushed !== false) {
- echo "ok";
- } else {
- echo 'warn';
- }
- echo "<br/>";
- }
-
- }
-
- /*
- * 处理内容 ai命令
- * http://console.zx2049.com/api/cms/articleContentHandle
- */
- public function articleContentHandle(){
-
- $list = Db::connect('db2')->table('ey_ai_content')->where('is_handle',0)->limit(80)->select();
-
- $num = 0;
- foreach ($list as $k=>$v){
- //echo $v['content_5'];
- $html = htmlspecialchars_decode($v['content_5']);
- $result = strip_tags($html);
- $ml = '请对以下内容进行洗稿,洗稿方式以采用同义词或近义词的方式替换进行洗稿,以下是需要洗稿的文章:”'.$result.'“';
- //echo $ml;
- Db::connect('db2')->table('ey_ai_content')
- ->where('id',$v['id'])->update([
- 'content_ml' => $ml,
- 'is_handle' => 1,
- ]);
- $num++;
-
- }
- echo $num;
- }
-
- /*
- * 去除 :</p> 第一段 重新保存
- * http://console.zx2049.com/api/cms/hkContent
- */
- public function hkContent(){
-
-
- $list = Db::connect('db2')
- ->table('ey_ai_content')
- ->where('is_handle',2)
- //->where('id',51)
- ->limit(80)
- ->select();
-
- $num = 0;
- foreach ($list as $k=>$v){
-
- //先将实体转为字符
- //查看网页源码即可
- //htmlspecialchars //转为<p>
- //htmlspecialchars_decode //转为html标签 本身是html标签不会转
- $str = htmlspecialchars_decode($v['content']);
- //echo $str;
- //判断是否包含该字符 以下
- if (strpos($str, '以下') !== false) {
- //echo "字符串中包含子字符串";
-
- $str_1 = explode('以下',$str);
- $str_2 = explode('</p>',$str_1[1]);
- $keywords = '<p>以下'.$str_2[0].'</p>';
- $result = str_replace($keywords,'', $str);
- $result = str_replace('<p>“','<p>', $result);
- $result = str_replace('”</p>','</p>', $result);
- //echo $result;
- //更新到新字段
- Db::connect('db2')->table('ey_ai_content')
- ->where('id',$v['id'])->update([
- 'content_h' => $result,
- 'is_handle' => 3,
- ]);
- $info = '已处理';
- } else {
- //echo "字符串中不包含子字符串";
- //更新到新字段
- Db::connect('db2')->table('ey_ai_content')
- ->where('id',$v['id'])->update([
- 'is_handle' => 3,
- ]);
- $info = '未发现';
- }
- $num++;
- echo $num."-".$info."<br/>";
- }
- }
-
-
- /*
- * 更新到主记录
- * http://console.zx2049.com/api/cms/upContent
- */
- public function upContent(){
- $list = Db::connect('db2')
- ->table('ey_ai_content')
- ->where('is_handle',3)
- //->where('id',51)
- ->limit(80)
- ->select();
-
- $num = 0;
- foreach ($list as $k=>$v){
-
- $info = '';
-
- if(empty($v['content_h'])){
- $str = $v['content'];
- }else{
- $str = $v['content_h'];
- }
- $str = htmlspecialchars($str);
- //echo $str;
-
- //更新正文
- Db::connect('db2')
- ->table('ey_zczygz_content')
- ->where('aid',$v['aid'])->update([
- 'content_5' => $str,
- ]);
- //更新seo
- /*Db::connect('db2')
- ->table('ey_archives')
- ->where('aid',$v['aid'])->update([
- 'seo_description' => $str,
- ]);*/
-
- Db::connect('db2')->table('ey_ai_content')
- ->where('id',$v['id'])->update([
- 'is_handle' => 4, //表示已同步
- ]);
-
- $num++;
- $info = '文档id:'.$v['aid'];
- echo $num."-".$info."<br/>";
- }
- }
- }
|