123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910 |
- <?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'];
- 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/>";
- }
-
- }
-
-
- }
|