控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Cms.php 34KB

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