控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | fastadmin: https://www.fastadmin.net/
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 邮箱验证码接口
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\member\controller\MemberApi;
  16. use think\Db;
  17. /**
  18. * @title 邮箱验证码接口
  19. * @controller api\controller\Ems
  20. * @group base
  21. */
  22. class Cms extends MemberApi
  23. {
  24. protected $noNeedLogin = ['login', 'register','getProduct','getProductSmall','createTask','tagHandle','taskHandle','getAreaJson','getTagListHandle','articleContentHandle','hkContent','upContent'];
  25. protected $noNeedRight = [];
  26. //初始化
  27. protected function initialize()
  28. {
  29. parent::initialize();
  30. }
  31. /**
  32. * @title 发送验证码
  33. * @desc 最基础的接口注释写法
  34. * @author 御宅男
  35. * @url /api/Ems/send
  36. * @method GET
  37. * @tag 邮箱 验证码
  38. * @param name:email type:string require:1 desc:邮箱
  39. * @param name:event type:string require:1 desc:事件名称
  40. * @return name:data type:array ref:definitions\dictionary
  41. */
  42. public function send()
  43. {
  44. }
  45. /**
  46. * @title 检测验证码
  47. * @desc 最基础的接口注释写法
  48. * @author 御宅男
  49. * @url /api/Ems/check
  50. * @method GET
  51. * @tag 邮箱 验证码
  52. * @param name:email type:string require:1 desc:邮箱
  53. * @param name:event type:string require:1 desc:事件名称
  54. * @param name:captcha type:string require:1 desc:验证码
  55. * @return name:data type:array ref:definitions\dictionary
  56. */
  57. public function check()
  58. {
  59. }
  60. /*
  61. *
  62. * 同步产品接口 - 大类
  63. * 每天同步一次
  64. * 防止产品未发布级别就同步过来 执行了
  65. * http://console.zx2049.com/api/cms/getProduct
  66. */
  67. public function getProduct()
  68. {
  69. //查找区域
  70. $area = Db::connect('db1')
  71. ->table('ey_citysite')
  72. ->where(['level'=>1,'is_open'=>1,'status'=>1])
  73. ->select();
  74. //dump($area);
  75. $area[] = [
  76. 'id' => 10000,
  77. ];
  78. foreach ($area as $index => $item) {
  79. //查找最后创建时间create_time
  80. $add_time = Db::name('cms_product')
  81. ->where(['catid'=>2,'diqu'=>$item['id']]) //产品大类
  82. ->order('add_time desc')
  83. ->value('add_time');
  84. //dump($create_time);
  85. if(empty($add_time)){
  86. $add_time = 0;
  87. }
  88. //不考虑分批次
  89. $list = Db::connect('db1')
  90. ->table('ey_arctype')
  91. ->where(['topid'=>38,'area_id'=>$item['id'],'is_del'=>0])
  92. ->where('add_time','>',$add_time)
  93. ->select();
  94. //dump($list);
  95. foreach ($list as $key=>$row){
  96. $one = Db::name('cms_product')->where([
  97. 'catid' => 2,
  98. 'aid' => $row['id'],
  99. 'diqu' => $item['id'],
  100. 'pid' => 0,
  101. ])->find();
  102. if(empty($one)){
  103. //插入数据库
  104. $insert_data = [
  105. 'catid' => 2,
  106. 'title' => $row['typename'],
  107. 'add_time' => $row['add_time'],
  108. 'create_time' => time(),
  109. 'update_time' => time(),
  110. 'status' => 1,
  111. 'diqu' => $item['id'],
  112. 'pid' => 0,
  113. 'aid' => $row['id'],
  114. 'site_id' => 1,
  115. 'link' => ''
  116. ];
  117. $run = Db::name('cms_product')->insert($insert_data);
  118. echo '插入'.$run.'条,产品id: '.$row['id'].'<br/>';
  119. }else{
  120. echo '插入0条,产品id: '.$row['id'].'已存在<br/>';
  121. }
  122. }
  123. }
  124. }
  125. /*
  126. * 同步产品接口 - 小类
  127. * http://console.zx2049.com/api/cms/getProductSmall
  128. */
  129. public function getProductSmall()
  130. {
  131. //查找最后创建时间create_time
  132. $add_time = Db::name('cms_product')
  133. ->where(['catid'=>3]) //产品小类
  134. ->order('add_time desc')
  135. ->value('add_time');
  136. //dump($create_time);
  137. if(empty($add_time)){
  138. $add_time = 0;
  139. }
  140. //不考虑分批次
  141. $list = Db::connect('db1')
  142. ->table('ey_arctype_cat')
  143. ->where(['is_del'=>0])
  144. ->where('add_time','>',$add_time)
  145. ->select();
  146. //dump($list);
  147. foreach ($list as $key=>$row){
  148. //查找上级所属区域id
  149. $area_id = Db::connect('db1')->table('ey_arctype')->where(['id'=>$row['parent_id']])->value('area_id');
  150. if(empty($area_id)){
  151. $area_id = 0;
  152. }
  153. $one = Db::name('cms_product')->where([
  154. 'catid' => 3,
  155. 'aid' => $row['id'],
  156. 'diqu' => $area_id,
  157. 'pid' => 0,
  158. ])->find();
  159. if(empty($one)){
  160. //插入数据库
  161. $insert_data = [
  162. 'catid' => 3,
  163. 'title' => $row['typename'],
  164. 'add_time' => $row['add_time'],
  165. 'create_time' => time(),
  166. 'update_time' => time(),
  167. 'status' => 1,
  168. 'diqu' => $area_id,
  169. 'pid' => $row['parent_id'],
  170. 'aid' => $row['id'],
  171. 'site_id' => 1,
  172. 'link' => ''
  173. ];
  174. $run = Db::name('cms_product')->insert($insert_data);
  175. echo '插入'.$run.'条,产品id: '.$row['id'].'<br/>';
  176. }else{
  177. echo '插入0条,产品id: '.$row['id'].'已存在<br/>';
  178. }
  179. }
  180. }
  181. /*
  182. * 同步删除操作
  183. * 增加字段 is_del 和 delete_time
  184. * 同步删除时间和是否删除
  185. * 目前先在发文的时候判断是否已删除就行
  186. */
  187. public function delHandle()
  188. {
  189. }
  190. /*
  191. * 存在小类就不创建发文任务,因为只有概述
  192. * 小类肯定都发文
  193. * 一个产品发一篇 不按级别 级别作为轮询为发文内容
  194. * 标签为 产品名+申报 (这个固定不变) 另 产品名与标签名 发生修改 不做统一校验
  195. * 同时判断产品是否正常(非删除状态)
  196. * 每一轮为一个定时任务 因为产品是不断增加的 同时任务也是不断增加的
  197. * 每一轮的任务分组不一样 会持续不断发文 对应发文模板也不一样
  198. * 参数 任务分组id
  199. * http://console.zx2049.com/api/cms/createTask?taskid=10
  200. */
  201. public function createTask()
  202. {
  203. $taskid = $this->request->get('taskid',0);
  204. if((int)$taskid === 0){
  205. $this->error('fail');
  206. }
  207. //查询
  208. $add_time = Db::table('yzn_task')
  209. ->where(['catid'=>$taskid])
  210. ->order('add_time desc')
  211. ->value('add_time');
  212. if(empty($add_time)){
  213. $add_time = 0;
  214. }
  215. //不做分批次处理
  216. //新赠的产品 大类
  217. $list = Db::table('yzn_cms_product')
  218. ->where(['status'=>1]) //,'catid'=>2 不管是大类还是小类
  219. ->where('add_time','>',$add_time)
  220. ->select();
  221. foreach ($list as $key=>$row){
  222. $one = Db::name('task')->where([
  223. 'catid' => $taskid,
  224. 'aid' => $row['aid'],
  225. 'diqu' => $row['diqu'],
  226. 'yid' => $row['catid'],
  227. 'cid' => 111,
  228. ])->find();
  229. if(empty($one)){
  230. //插入数据库
  231. $insert_data = [
  232. 'catid' => $taskid, //任务分组id
  233. 'title' => $row['title'],
  234. 'add_time' => $row['add_time'],
  235. 'create_time' => time(),
  236. 'update_time' => time(),
  237. 'status' => 0, //初始状态为0 未执行
  238. 'diqu' => $row['diqu'],
  239. 'yid' => $row['catid'], //产品大类还是小类
  240. 'aid' => $row['aid'], //产品id
  241. 'site_id' => 1,
  242. 'link' => '', //文章链接
  243. 'tagid' => 0, //标签id 初始为0
  244. 'cid' => 111, //常见问题
  245. 'run_time' => time(),
  246. 'is_run' => 0
  247. ];
  248. $run = Db::name('task')->insert($insert_data);
  249. echo '插入'.$run.'条,产品id: '.$row['aid'].'-'.$row['title'].'<br/>';
  250. }else{
  251. echo '插入0条,产品id: '.$row['aid'].'-'.$row['title'].'已存在<br/>';
  252. }
  253. }
  254. }
  255. /*
  256. * {"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":"主站"}
  257. *
  258. * http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=1
  259. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=30
  260. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6872
  261. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6791
  262. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6645
  263. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6344
  264. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6303
  265. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6003
  266. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5879
  267. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5742
  268. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5625
  269. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5448
  270. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5179
  271. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=5056
  272. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4833
  273. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4813
  274. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4667
  275. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4589
  276. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4474
  277. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4228
  278. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4042
  279. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4023
  280. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4003
  281. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6547
  282. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4359
  283. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=4004
  284. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=6990
  285. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=7092
  286. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=7144
  287. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=7171
  288. http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=10000
  289. */
  290. public function tagHandle()
  291. {
  292. $taskid = $this->request->get('taskid',0);
  293. if((int)$taskid === 0){
  294. $this->error('fail');
  295. }
  296. //地区参数
  297. $diqu = $this->request->get('diqu',0);
  298. if((int)$diqu === 0){
  299. $this->error('fail');
  300. }
  301. $page = 1;
  302. $list = Db::name('task')->where([
  303. 'catid' => $taskid, //任务分组id
  304. 'tagid' => 0,
  305. 'status' => 0,
  306. 'diqu' => (int)$diqu
  307. ])
  308. ->order('add_time asc')->paginate(1);
  309. $list = $list->toArray();
  310. $data = $list['data'];
  311. if(empty($data)){
  312. $this->error('fail',['ko'=>'不存在数据']);
  313. }
  314. foreach ($data as $index => $row) {
  315. //获取标签
  316. $tagname = $this->getName($row['title']);
  317. $tagname = $tagname.'申报';
  318. if((int)$row['diqu'] === 10000){
  319. $diqu = 0; //山东地区变为主页 区域为0
  320. }else{
  321. $diqu = $row['diqu'];
  322. }
  323. $one = Db::connect('db1')->table('ey_archives')
  324. ->where(['typeid' => 523,'province_id'=>$diqu,'is_del'=>0])
  325. ->where('title',$tagname)
  326. ->find();
  327. if(empty($one)){
  328. //不存在
  329. //判断是否需要增加标签
  330. //远程判断产品状态
  331. if((int)$row['yid'] === 2) {
  332. //大类
  333. $one = Db::connect('db1')->table('ey_arctype')->where(['id' => $row['aid']])->find();
  334. }else if((int)$row['yid'] === 3) {
  335. //小类
  336. $one = Db::connect('db1')->table('ey_arctype_cat')->where(['id' => $row['aid']])->find();
  337. }else{
  338. //任务异常 退出
  339. $this->error('fail');
  340. }
  341. if((int)$one['is_del'] === 1 || (int)$one['status'] === 0){
  342. //已删除
  343. Db::name('task')->where(['id'=>$row['id']])->update([
  344. 'is_run' => 4, //执行异常
  345. 'run_time' => time(),
  346. 'status' => 1,
  347. ]);
  348. $this->error('fail',['is_run'=>4]);
  349. }
  350. //是否只有一个页面 (远程)
  351. if((int)$row['yid'] === 2) {
  352. //大类
  353. $count = Db::connect('db1')->table('ey_archives')->where(['typeid' => $row['aid'],'product_id'=>0,'is_del'=>0])->count();
  354. }else if((int)$row['yid'] === 3) {
  355. //小类
  356. $count = Db::connect('db1')->table('ey_archives')->where(['product_id' => $row['aid'],'is_del'=>0])->count();
  357. }else{
  358. //任务异常 退出
  359. $this->error('fail');
  360. }
  361. //dump($count);
  362. if($count <= 1) {
  363. //只有一个主页 概述
  364. Db::name('task')->where(['id' => $row['id']])->update([
  365. 'is_run' => 3, //执行忽略
  366. 'run_time' => time(),
  367. 'status' => 1,
  368. ]);
  369. $this->error('fail',['is_run'=>3]);
  370. }
  371. //创建标签
  372. $insert_data = [
  373. 'typeid' => 523,
  374. 'status' => 1,
  375. 'is_del' => 0,
  376. 'channel' => 101,
  377. 'click' => rand(500,5000),
  378. 'arcrank' => 0,
  379. 'add_time' => time(),
  380. 'update_time' => time(),
  381. 'province_id' => (int)$diqu,
  382. 'product_tag_id' => 0, //由其他任务处理
  383. 'title' => $tagname,
  384. ];
  385. //执行插入
  386. $aid = Db::connect('db1')->table('ey_archives')->insertGetId($insert_data);
  387. if((int)$aid > 0) {
  388. //增加详情
  389. $insert_data_content = [
  390. 'aid' => $aid,
  391. 'add_time' => time(),
  392. 'update_time' => time()
  393. ];
  394. Db::connect('db1')->table('ey_suipian_content')->insert($insert_data_content);
  395. }
  396. //更新任务 标签id
  397. Db::name('task')->where(['id' => $row['id']])->update([
  398. 'tagid' => $aid,
  399. ]);
  400. $this->success('成功');
  401. }else{
  402. //写入标签id 到 任务记录
  403. Db::name('task')->where(['id' => $row['id']])->update([
  404. 'tagid' => $one['aid'],
  405. ]);
  406. $this->success('成功');
  407. }
  408. }
  409. }
  410. /*
  411. * 执行
  412. * 增加字段 is_run 未执行0 执行成功1 执行失败2(远程响应错误) 执行忽略3(存在小类或无级别-只有一个主页) 产品异常4(删除或未审核或屏蔽)
  413. * run_time 执行时间
  414. * is_run = 0 每次处理10条
  415. *
  416. * {"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":"主站"}
  417. *
  418. * http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=1
  419. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=30
  420. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6872
  421. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6791
  422. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6645
  423. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6344
  424. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6303
  425. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6003
  426. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5879
  427. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5742
  428. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5625
  429. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5448
  430. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5179
  431. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=5056
  432. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4833
  433. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4813
  434. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4667
  435. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4589
  436. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4474
  437. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4228
  438. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4042
  439. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4023
  440. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4003
  441. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6547
  442. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4359
  443. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=4004
  444. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=6990
  445. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=7092
  446. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=7144
  447. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=7171
  448. http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu=10000
  449. *
  450. */
  451. public function taskHandle()
  452. {
  453. $taskid = $this->request->get('taskid',0);
  454. if((int)$taskid === 0){
  455. $this->error('fail');
  456. }
  457. //地区参数
  458. $diqu = $this->request->get('diqu',0);
  459. if((int)$diqu === 0){
  460. $this->error('fail');
  461. }
  462. //查询未执行的任务
  463. $page = 1;
  464. $list = Db::name('task')->where([
  465. 'catid' => $taskid, //任务分组id
  466. 'is_run' => 0,
  467. 'status' => 0,
  468. 'diqu' => (int)$diqu
  469. ])
  470. ->where('tagid','>',0) //标签id需要已经获取到的
  471. ->order('add_time asc')->paginate(1);
  472. $list = $list->toArray();
  473. $data = $list['data'];
  474. //dump($data);die;
  475. if(empty($data)){
  476. $this->error('fail',['ko'=>'不存在数据']);
  477. }
  478. /*
  479. * 跨库 无法保证远程和本地的事务一致性
  480. * 这种机制 类似 支付
  481. * 先简单处理
  482. */
  483. foreach ($data as $index => $row) {
  484. //远程判断产品状态
  485. /*if((int)$row['yid'] === 2) {
  486. //大类
  487. $one = Db::connect('db1')->table('ey_arctype')->where(['id' => $row['aid']])->find();
  488. }else if((int)$row['yid'] === 3) {
  489. //小类
  490. $one = Db::connect('db1')->table('ey_arctype_cat')->where(['id' => $row['aid']])->find();
  491. }else{
  492. //任务异常 退出
  493. return false;
  494. }
  495. if((int)$one['is_del'] === 1 || (int)$one['status'] === 0){
  496. //已删除
  497. Db::name('task')->where(['id'=>$row['id']])->update([
  498. 'is_run' => 4, //执行异常
  499. 'run_time' => time(),
  500. 'status' => 1,
  501. ]);
  502. return false;
  503. }*/
  504. /*
  505. *
  506. *
  507. //不管有没有小类 只有一个主页 就执行忽略
  508. if((int)$row['yid'] === 2) {
  509. //该任务记录 为 大类 产品
  510. //是否存在小类(控制台产品不保证是最新数据 采用远程判断)
  511. Db::connect('db1')->table('ey_arctype_cat')->where(['parent_id' => $row['aid']])->find();
  512. }*/
  513. //是否只有一个页面 (远程)
  514. /*if((int)$row['yid'] === 2) {
  515. //大类
  516. $count = Db::connect('db1')->table('ey_archives')->where(['typeid' => $row['aid'],'product_id'=>0,'is_del'=>0])->count();
  517. }else if((int)$row['yid'] === 3) {
  518. //小类
  519. $count = Db::connect('db1')->table('ey_archives')->where(['product_id' => $row['aid'],'is_del'=>0])->count();
  520. }else{
  521. //任务异常 退出
  522. return false;
  523. }
  524. //dump($count);
  525. if($count <= 1) {
  526. //只有一个主页 概述
  527. Db::name('task')->where(['id' => $row['id']])->update([
  528. 'is_run' => 3, //执行忽略
  529. 'run_time' => time(),
  530. 'status' => 1,
  531. ]);
  532. return false;
  533. }*/
  534. //构建参数
  535. if((int)$row['diqu'] === 10000){
  536. $diqu = 0; //山东地区变为主页 区域为0
  537. }else{
  538. $diqu = $row['diqu'];
  539. }
  540. $insert_data = [
  541. 'typeid' => 111,
  542. 'status' => 1,
  543. 'is_del' => 0,
  544. 'channel' => 103,
  545. 'click' => rand(500,5000),
  546. 'arcrank' => 0,
  547. 'add_time' => time(),
  548. 'update_time' => time(),
  549. 'province_id' => (int)$diqu,
  550. 'product_tag_id' => $row['tagid'], //由其他任务处理
  551. 'title' => $this->getTitle($row,$diqu),
  552. 'seo_title' => $this->getSeoTitle($row,$diqu),
  553. 'seo_keywords' => $this->getKeywords($row,$diqu),
  554. 'seo_description' => $this->getDesc($row,$diqu),
  555. ];
  556. //执行插入
  557. $aid = Db::connect('db1')->table('ey_archives')->insertGetId($insert_data);
  558. //$aid=1;
  559. //dump($insert_data);die;
  560. if((int)$aid > 0) {
  561. //增加详情
  562. $content = $this->getContent($row,$diqu);
  563. //echo htmlspecialchars_decode($content);die;
  564. $insert_data_content = [
  565. 'aid' => $aid,
  566. 'add_time' => time(),
  567. 'update_time' => time(),
  568. 'content_5' => $content
  569. ];
  570. Db::connect('db1')->table('ey_zczygz_content')->insert($insert_data_content);
  571. //增加序列号
  572. $where6 = [
  573. "type" => 2,
  574. "tid" => 111,
  575. 'topid' => 0,
  576. 'parentid' => 0,
  577. 'area_id' => (int)$diqu, //如果是0的话 后续也不能改
  578. 'city_id' => 0, //如果是0的话 后续也不能改
  579. ];
  580. $last = Db::connect('db1')->name('seo_number')
  581. ->where($where6)->order('number desc')->find();
  582. if (empty($last['number'])) {
  583. $num = 1;
  584. } else {
  585. $num = (int)$last['number'] + 1;
  586. }
  587. $insert_data_seo = [
  588. "type" => 2, //产品类型
  589. "aid" => $aid, //实际的ID
  590. "tid" => 111, //属于哪个栏目的
  591. 'is_del' => 0,
  592. 'is_kan' => 0, // 0正常 1审核
  593. 'status' => 1,
  594. 'area_id' => (int)$diqu,
  595. 'city_id' => 0,
  596. 'topid' => 0,
  597. 'parentid' => 0,
  598. 'number' => $num
  599. ];
  600. Db::connect('db1')->table('ey_seo_number')->insert($insert_data_seo);
  601. //更新状态
  602. if ((int)$diqu === 0) {
  603. $link = 'https://www.gdzcfw.com/wthz' . $num;
  604. } else {
  605. $domain = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('domain');
  606. $link = 'https://' . $domain . '.gdzcfw.com/wthz' . $num;
  607. }
  608. Db::name('task')->where(['id' => $row['id']])->update([
  609. 'is_run' => 1, //执行成功
  610. 'run_time' => time(),
  611. 'status' => 1,
  612. 'link' => $link,
  613. ]);
  614. $this->success('成功');
  615. }
  616. }
  617. }
  618. /*
  619. * 产品名称处理
  620. */
  621. public function getName($str){
  622. $str = str_replace('职称', "", $str);
  623. $str = $str.'职称';
  624. return $str;
  625. }
  626. /*
  627. * 模板1
  628. */
  629. public function getTitle($row,$diqu)
  630. {
  631. $area_name = '';
  632. if((int)$diqu > 0){
  633. $area_name = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('name');
  634. }
  635. $title = $this->getName($row['title']);
  636. $str = $area_name.$title.'评定【2024年最新学历要求】';
  637. return $str;
  638. }
  639. public function getSeoTitle($row,$diqu)
  640. {
  641. $area_name = '';
  642. if((int)$diqu > 0){
  643. $area_name = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('name');
  644. }
  645. $title = $this->getName($row['title']);
  646. $str = $area_name.$title.'评定【2024年最新要求解读】';
  647. return $str;
  648. }
  649. public function getKeywords($row,$diqu){
  650. $area_name = '';
  651. if((int)$diqu > 0){
  652. $area_name = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('name');
  653. }
  654. $title = $this->getName($row['title']);
  655. $str = $area_name.$title.'评定学历要求';
  656. return $str;
  657. }
  658. public function getDesc($row,$diqu){
  659. $area_name = '';
  660. if((int)$diqu > 0){
  661. $area_name = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->value('name');
  662. }
  663. $title = $this->getName($row['title']);
  664. $str = $area_name.$title.'评定上【职称网】工程师职称破格评审绿色通道,专注工程师职称评审,专注工程师职称评审,提供职称材料撰写、职称申报、职称论文专利一站式服务。';
  665. return $str;
  666. }
  667. /*
  668. * 模板1
  669. */
  670. public function getContent($row,$diqu)
  671. {
  672. $area_name = '';
  673. $domain = 'www';
  674. if((int)$diqu > 0){
  675. $area = Db::connect('db1')->name('citysite')->where('id', '=', $diqu)->find();
  676. $area_name = $area['name'];
  677. $domain = $area['domain'];
  678. }
  679. $title = $this->getTitle($row,$diqu);
  680. //图片地址
  681. $op = rand(1,9);
  682. $imgurl = 'https://oss.gdzcfw.com/static/article/'.$op.'.png';
  683. $html = '';
  684. $html .= '<p style="text-align: center !important;">
  685. <img src="'.$imgurl.'" style="max-width:100%;" /><br/>
  686. <span style="font-size: 17px !important;">'.$title.'</span><br/>
  687. </p>';
  688. //调用其他级别的学历要求
  689. if((int)$row['yid'] === 2) {
  690. //大类
  691. $aids = Db::connect('db1')->table('ey_archives')->field('aid,title')->where(['typeid' => $row['aid'],'product_id'=>0,'is_del'=>0])->select();
  692. }else if((int)$row['yid'] === 3) {
  693. //小类
  694. $aids = Db::connect('db1')->table('ey_archives')->field('aid,title')->where(['product_id' => $row['aid'],'is_del'=>0])->order('level asc')->select();
  695. }
  696. $h = ['一)','二)','三)','四)','五)','六)','七)','八)','九)','十)','十一)'];
  697. $jk = 0;
  698. foreach ($aids as $k=>$v){
  699. $data = Db::connect('db1')->table('ey_zczygz_content')
  700. ->field('aid,content_6')->where('aid','=',$v['aid'])->find();
  701. if(!empty($data['content_6'])){
  702. $pro_title = $this->getName($row['title']);
  703. $html .= '<p style="text-align: left;font-weight: bold !important;font-size:16px !important;margin-top:5px;">
  704. '.$h[$jk].$area_name.$pro_title.'评定'.$v['title'].'学历要求:</p>';
  705. $html .= '<p style="text-align: left;">
  706. '.$data['content_6'].'</p>';
  707. $jk++;
  708. }
  709. }
  710. //拼装产品
  711. if((int)$row['yid'] === 2) {
  712. //大类
  713. $number = Db::connect('db1')->table('ey_seo_number')->where([
  714. 'type' => 1,
  715. 'aid' => $row['aid'],
  716. 'parentid' => 38
  717. ])->value('number');
  718. $link = 'https://'.$domain.'.gdzcfw.com/id'.$number;
  719. }else if((int)$row['yid'] === 3) {
  720. //小类
  721. $one = Db::connect('db1')->table('ey_seo_number')->where([
  722. 'type' => 1,
  723. 'aid' => $row['aid'],
  724. ])->where('parentid','<>',38)->find();
  725. $number = Db::connect('db1')->table('ey_seo_number')->where([
  726. 'type' => 1,
  727. 'aid' => $one['parentid'],
  728. 'parentid' => 38
  729. ])->value('number');
  730. $link = 'https://'.$domain.'.gdzcfw.com/id'.$number.'/sid'.$one['number'];
  731. }
  732. $html .= '<p style="text-align: left;margin-top:15px;">
  733. <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>';
  734. //其他链接
  735. $html .= '<p style="text-align: left;margin-top:15px;">
  736. <a href="https://www.gdzcfw.com" style="color: blue !important;">职称网</a>更多<a href="https://www.gdzcfw.com" style="color: blue !important;">职称评审</a>相关请点击:<br/>
  737. '.$area_name.'职称政策文件下载: <a href="https://www.gdzcfw.com/zccl" style="color: blue !important;">职称材料</a><br/>
  738. 职称答辩相关指引请点击: <a href="https://www.gdzcfw.com/zcdb" style="color: blue !important;">职称答辩</a><br/>
  739. 职称评审绿色破格通道: <a href="https://zczl.gdzcfw.com" style="color: blue !important;">职称代办</a><br/></p><br/>';
  740. return $html;
  741. }
  742. /*
  743. * 执行忽略 重新校验
  744. * 产品后面增加了级别 一开始没有级别 也没有小类
  745. * 产品后面增加了级别 一开始没有级别 有小类
  746. * 产品后面增加了小类 一开始没有级别 也没有小类
  747. * 产品后面增加了小类 一开始有级别 没有小类
  748. *
  749. * 不管有没有小类 是大类还是小类 只要没有级别 就不发文 就对了
  750. * 就算有小类 有级别 就发文
  751. * 正常情况 不会存在既有级别又有小类
  752. * 这里把执行忽略的 校验后 改为未执行
  753. */
  754. /*
  755. * 产品异常 校验产品如果正常了 任务改为未执行
  756. */
  757. /*
  758. * 生成地区json 方便增加查询条件
  759. * http://console.zx2049.com/api/cms/getAreaJson
  760. */
  761. public function getAreaJson()
  762. {
  763. $area = Db::connect('db1')
  764. ->table('ey_citysite')
  765. ->where(['level'=>1,'is_open'=>1,'status'=>1])
  766. ->select();
  767. //dump($area);
  768. $area[] = [
  769. 'id' => 10000,
  770. 'name' => '主站',
  771. ];
  772. //{ 0: '待审核', 1: '通过' }
  773. $collect = [];
  774. $str = '';
  775. foreach($area as $k=>$v){
  776. $collect[(int)$v['id']] = $v['name'];
  777. //$str .= 'http://console.zx2049.com/api/cms/taskHandle?taskid=10&diqu='.$v['id'].'<br/>';
  778. $str .= 'http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu='.$v['id'].'<br/>';
  779. }
  780. $collect = json_encode($collect,JSON_UNESCAPED_UNICODE);
  781. echo $str;
  782. //return $collect;
  783. }
  784. /*
  785. * 批量执行标签处理
  786. * 加入队列 http://console.zx2049.com/api/cms/getTagListHandle
  787. * 启动队列 php think queue:listen --queue tagHandle
  788. * 监听队列 进程守护管理器 (附加参数参考: https://www.kancloud.cn/ken678/yzncms/2383907)
  789. * redis查看数据器 默认重置次数1
  790. * workman实时推送消息
  791. * 添加自定义命令的方式来执行队列
  792. */
  793. public function getTagListHandle()
  794. {
  795. /* $a = new \app\api\queue\jobs\TagHandle();
  796. var_dump($a);
  797. return json([]);*/
  798. $area = Db::connect('db1')
  799. ->table('ey_citysite')
  800. ->where(['level'=>1,'is_open'=>1,'status'=>1])
  801. ->select();
  802. //dump($area);
  803. $area[] = [
  804. 'id' => 10000,
  805. 'name' => '主站',
  806. ];
  807. foreach ($area as $k=>$v){
  808. //http://console.zx2049.com/api/cms/tagHandle?taskid=10&diqu=1
  809. $jobData = ['ts' => time(),'url'=>'http://console.zx2049.com/api/cms/tagHandle','taskid'=>10, 'area_id' => $v['id'], 'area_name' => $v['name']];//当前任务所需的业务数据
  810. $isPushed = \think\Queue::push('app\common\jobs\TagHandle', $jobData,'tagHandle');//没有@使用默认方法fire,此方法为立即执行
  811. if ($isPushed !== false) {
  812. echo "ok";
  813. } else {
  814. echo 'warn';
  815. }
  816. echo "<br/>";
  817. }
  818. }
  819. /*
  820. * 处理内容 ai命令
  821. * http://console.zx2049.com/api/cms/articleContentHandle
  822. */
  823. public function articleContentHandle(){
  824. $list = Db::connect('db2')->table('ey_ai_content')->where('is_handle',0)->limit(80)->select();
  825. $num = 0;
  826. foreach ($list as $k=>$v){
  827. //echo $v['content_5'];
  828. $html = htmlspecialchars_decode($v['content_5']);
  829. $result = strip_tags($html);
  830. $ml = '请对以下内容进行洗稿,洗稿方式以采用同义词或近义词的方式替换进行洗稿,以下是需要洗稿的文章:”'.$result.'“';
  831. //echo $ml;
  832. Db::connect('db2')->table('ey_ai_content')
  833. ->where('id',$v['id'])->update([
  834. 'content_ml' => $ml,
  835. 'is_handle' => 1,
  836. ]);
  837. $num++;
  838. }
  839. echo $num;
  840. }
  841. /*
  842. * 去除 :</p> 第一段 重新保存
  843. * http://console.zx2049.com/api/cms/hkContent
  844. */
  845. public function hkContent(){
  846. $list = Db::connect('db2')
  847. ->table('ey_ai_content')
  848. ->where('is_handle',2)
  849. //->where('id',51)
  850. ->limit(80)
  851. ->select();
  852. $num = 0;
  853. foreach ($list as $k=>$v){
  854. //先将实体转为字符
  855. //查看网页源码即可
  856. //htmlspecialchars //转为&lt;p&gt
  857. //htmlspecialchars_decode //转为html标签 本身是html标签不会转
  858. $str = htmlspecialchars_decode($v['content']);
  859. //echo $str;
  860. //判断是否包含该字符 以下
  861. if (strpos($str, '以下') !== false) {
  862. //echo "字符串中包含子字符串";
  863. $str_1 = explode('以下',$str);
  864. $str_2 = explode('</p>',$str_1[1]);
  865. $keywords = '<p>以下'.$str_2[0].'</p>';
  866. $result = str_replace($keywords,'', $str);
  867. $result = str_replace('<p>“','<p>', $result);
  868. $result = str_replace('”</p>','</p>', $result);
  869. //echo $result;
  870. //更新到新字段
  871. Db::connect('db2')->table('ey_ai_content')
  872. ->where('id',$v['id'])->update([
  873. 'content_h' => $result,
  874. 'is_handle' => 3,
  875. ]);
  876. $info = '已处理';
  877. } else {
  878. //echo "字符串中不包含子字符串";
  879. //更新到新字段
  880. Db::connect('db2')->table('ey_ai_content')
  881. ->where('id',$v['id'])->update([
  882. 'is_handle' => 3,
  883. ]);
  884. $info = '未发现';
  885. }
  886. $num++;
  887. echo $num."-".$info."<br/>";
  888. }
  889. }
  890. /*
  891. * 更新到主记录
  892. * http://console.zx2049.com/api/cms/upContent
  893. */
  894. public function upContent(){
  895. $list = Db::connect('db2')
  896. ->table('ey_ai_content')
  897. ->where('is_handle',3)
  898. //->where('id',51)
  899. ->limit(80)
  900. ->select();
  901. $num = 0;
  902. foreach ($list as $k=>$v){
  903. $info = '';
  904. if(empty($v['content_h'])){
  905. $str = $v['content'];
  906. }else{
  907. $str = $v['content_h'];
  908. }
  909. $str = htmlspecialchars($str);
  910. //echo $str;
  911. //更新正文
  912. Db::connect('db2')
  913. ->table('ey_zczygz_content')
  914. ->where('aid',$v['aid'])->update([
  915. 'content_5' => $str,
  916. ]);
  917. //更新seo
  918. /*Db::connect('db2')
  919. ->table('ey_archives')
  920. ->where('aid',$v['aid'])->update([
  921. 'seo_description' => $str,
  922. ]);*/
  923. Db::connect('db2')->table('ey_ai_content')
  924. ->where('id',$v['id'])->update([
  925. 'is_handle' => 4, //表示已同步
  926. ]);
  927. $num++;
  928. $info = '文档id:'.$v['aid'];
  929. echo $num."-".$info."<br/>";
  930. }
  931. }
  932. }