TransferContent.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <?php
  2. namespace App\Console\Commands\Transfer;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Transfer\Notice;
  6. use App\Transfer\NoticeCategory;
  7. use App\Models\SubsiteNotice;
  8. use App\Models\NoticeCategory as newNoticeCategory;
  9. use App\Models\Notice as newNotice;
  10. use App\Transfer\ExplainCategory;
  11. use App\Models\SubsiteExplain;
  12. use App\Models\Explain as newExplain;
  13. use App\Models\ExplainCategory as newExplainCategory;
  14. use App\Transfer\Feedback;
  15. use App\Models\Feedback as newFeedback;
  16. use App\Transfer\Appeal;
  17. use App\Models\Appeal as newAppeal;
  18. use App\Transfer\Report;
  19. use App\Transfer\ReportResume;
  20. use App\Models\Report as newReport;
  21. use App\Transfer\Help;
  22. use App\Transfer\HelpCategory;
  23. use App\Models\Help as newHelp;
  24. use App\Models\HelpCategory as newHelpCategory;
  25. use App\Transfer\Hrtool;
  26. use App\Transfer\HrtoolCategory;
  27. use App\Models\Hrtools as newHrtools;
  28. use App\Models\HrtoolsCategory as newHrtoolsCategory;
  29. use App\Transfer\Link;
  30. use App\Transfer\LinkCategory;
  31. use App\Models\SubsiteLink;
  32. use App\Models\Link as newLink;
  33. use App\Models\LinkCategory as newLinkCategory;
  34. class TransferContent extends Command
  35. {
  36. /**
  37. * The name and signature of the console command.
  38. *
  39. * @var string
  40. */
  41. protected $signature = 'aix:transfer-content';
  42. /**
  43. * The console command description.
  44. *
  45. * @var string
  46. */
  47. protected $description = '转移旧系统内容数据';
  48. /**
  49. * Create a new command instance.
  50. *
  51. * @return void
  52. */
  53. public function __construct()
  54. {
  55. parent::__construct();
  56. }
  57. /**
  58. * Execute the console command.
  59. *
  60. * @return mixed
  61. */
  62. public function handle()
  63. {
  64. //转移新闻资讯模块(不导入)
  65. //转移广告模块(手动导入)
  66. //转移友情链接模块
  67. $this->info("清除友情链接分类数据表:link_categorys");
  68. DB::table('link_categorys')->delete();
  69. $this->info("清除友情链接数据表:links");
  70. DB::table('links')->delete();
  71. $this->info("清除友情链接与分站关系数据表:subsite_link");
  72. DB::table('subsite_link')->delete();
  73. $this->info("开始转移数据...");
  74. $total = LinkCategory::count();
  75. $bar = $this->output->createProgressBar($total);
  76. LinkCategory::orderBy('id', 'asc')->chunk(500, function ($categories) use ($bar) {
  77. $cate_array = [];
  78. $link_array = [];
  79. $link_subsite_array = [];
  80. foreach ($categories as $cate) {
  81. $this->handleLinkCategory($cate, $cate_array);
  82. $this->handleLink($cate->id, $cate->links, $link_array, $link_subsite_array);
  83. }
  84. //批量插入数据;
  85. if ($cate_array) {
  86. newLinkCategory::insert($cate_array);
  87. }
  88. if ($link_array) {
  89. newLink::insert($link_array);
  90. }
  91. if ($link_subsite_array) {
  92. SubsiteLink::insert($link_subsite_array);
  93. }
  94. $bar->advance(500);
  95. });
  96. $bar->finish();
  97. $this->line(" 完成!");
  98. $this->info("转移友情链接数据成功.");
  99. //转移HR工具箱模块
  100. $this->info("清除HR工具箱分类数据表:hrtools_categorys");
  101. DB::table('hrtools_categorys')->delete();
  102. $this->info("清除HR工具箱数据表:hrtools");
  103. DB::table('hrtools')->delete();
  104. $this->info("开始转移数据...");
  105. $total = HrtoolCategory::count();
  106. $bar = $this->output->createProgressBar($total);
  107. HrtoolCategory::orderBy('c_id', 'asc')->chunk(500, function ($hrtool_categories) use ($bar) {
  108. $hrtool_cate_array = [];
  109. $hrtool_array = [];
  110. foreach ($hrtool_categories as $cate) {
  111. $this->handleHrtoolCategory($cate, $hrtool_cate_array);
  112. $this->handleHrtool($cate->hrtools, $hrtool_array);
  113. }
  114. if ($hrtool_cate_array) {
  115. newHrtoolsCategory::insert($hrtool_cate_array);
  116. }
  117. if ($hrtool_array) {
  118. newHrtools::insert($hrtool_array);
  119. }
  120. $bar->advance(500);
  121. });
  122. $bar->finish();
  123. $this->line(" 完成!");
  124. $this->info("转移HR工具箱数据成功.");
  125. //转移帮助模块
  126. $this->info("清除帮助中心分类数据表:help_categorys");
  127. DB::table('help_categorys')->delete();
  128. $this->info("清除帮助中心数据表:helps");
  129. DB::table('helps')->delete();
  130. $this->info("开始转移数据...");
  131. $total = HelpCategory::count();
  132. $bar = $this->output->createProgressBar($total);
  133. HelpCategory::orderBy('id', 'asc')->chunk(500, function ($help_categories) use ($bar) {
  134. $help_cate_array = [];
  135. $help_array = [];
  136. foreach ($help_categories as $cate) {
  137. $this->handleHelpCategory($cate, $help_cate_array);
  138. $this->handleHelp($cate->helps, $help_array);
  139. }
  140. if ($help_cate_array) {
  141. newHelpCategory::insert($help_cate_array);
  142. }
  143. if ($help_array) {
  144. newHelp::insert($help_array);
  145. }
  146. $bar->advance(500);
  147. });
  148. $bar->finish();
  149. $this->line(" 完成!");
  150. $this->info("转移帮助中心数据成功.");
  151. //转移举报职位模块
  152. $this->info("清除举报数据表:reports");
  153. DB::table('reports')->delete();
  154. $this->info("开始转移数据...");
  155. $total = Report::count();
  156. $bar = $this->output->createProgressBar($total);
  157. Report::orderBy('id', 'asc')->chunk(500, function ($reports) use ($bar) {
  158. $report_array = [];
  159. foreach ($reports as $report) {
  160. $this->handleJobReport($report, $report_array);
  161. }
  162. if ($report_array) {
  163. newReport::insert($report_array);
  164. }
  165. $bar->advance(500);
  166. });
  167. $bar->finish();
  168. $this->line(" 完成!");
  169. $this->info("转移举报职位数据成功.");
  170. //转移举报简历模块
  171. $total = ReportResume::count();
  172. $bar = $this->output->createProgressBar($total);
  173. ReportResume::orderBy('id', 'asc')->chunk(500, function ($resume_reports) use ($bar) {
  174. $resume_report_array = [];
  175. foreach ($resume_reports as $report) {
  176. $this->handleResumeReport($report, $resume_report_array);
  177. }
  178. if ($resume_report_array) {
  179. newReport::insert($resume_report_array);
  180. }
  181. $bar->advance(500);
  182. });
  183. $bar->finish();
  184. $this->line(" 完成!");
  185. $this->info("转移举报简历数据成功.");
  186. //转移账号申诉模块
  187. $this->info("清除账号申诉数据表:appeals");
  188. DB::table('appeals')->delete();
  189. $this->info("开始转移数据...");
  190. $total = Appeal::count();
  191. $bar = $this->output->createProgressBar($total);
  192. Appeal::orderBy('id', 'asc')->chunk(500, function ($appeals) use ($bar) {
  193. $appeal_array = [];
  194. foreach ($appeals as $appeal) {
  195. $this->handleAppeal($appeal, $appeal_array);
  196. }
  197. if ($appeal_array) {
  198. newAppeal::insert($appeal_array);
  199. }
  200. $bar->advance(500);
  201. });
  202. $bar->finish();
  203. $this->line(" 完成!");
  204. $this->info("转移账号申诉数据成功.");
  205. //转移意见建议模块
  206. $this->info("清除意见建议数据表:feedbacks");
  207. DB::table('feedbacks')->delete();
  208. $this->info("开始转移数据...");
  209. $total = NoticeCategory::count();
  210. $bar = $this->output->createProgressBar($total);
  211. Feedback::orderBy('id', 'asc')->chunk(500, function ($feedbacks) use ($bar) {
  212. $feed_array = [];
  213. foreach ($feedbacks as $feedback) {
  214. $this->handleFeedback($feedback, $feed_array);
  215. }
  216. if ($feed_array) {
  217. newFeedback::insert($feed_array);
  218. }
  219. $bar->advance(500);
  220. });
  221. $bar->finish();
  222. $this->line(" 完成!");
  223. $this->info("转移意见建议数据成功.");
  224. //转移公告模块
  225. $this->info("清除公告分类数据表:notice_categorys");
  226. DB::table('notice_categorys')->delete();
  227. $this->info("清除公告数据表:notices");
  228. DB::table('notices')->delete();
  229. $this->info("清除公告分站关系数据表:subsite_notice");
  230. DB::table('subsite_notice')->delete();
  231. $this->info("开始转移数据...");
  232. $total = NoticeCategory::count();
  233. $bar = $this->output->createProgressBar($total);
  234. NoticeCategory::orderBy('id', 'asc')->chunk(500, function ($categories) use ($bar) {
  235. $cate_array = [];
  236. $notice_array = [];
  237. $notice_subsite_array = [];
  238. foreach ($categories as $cate) {
  239. //处理公告分类表
  240. $this->handleNoticeCategory($cate, $cate_array);
  241. //处理公告表、公告与分站关系表
  242. $this->handleNotice($cate->notices, $notice_array, $notice_subsite_array);
  243. }
  244. //批量插入数据;
  245. if ($cate_array) {
  246. newNoticeCategory::insert($cate_array);
  247. }
  248. if ($notice_array) {
  249. newNotice::insert($notice_array);
  250. }
  251. if ($notice_subsite_array) {
  252. SubsiteNotice::insert($notice_subsite_array);
  253. }
  254. $bar->advance(500);
  255. });
  256. $bar->finish();
  257. $this->line(" 完成!");
  258. $this->info("转移公告数据成功.");
  259. //转移说明页模块
  260. $this->info("清除说明页分类数据表:explain_categorys");
  261. DB::table('explain_categorys')->delete();
  262. $this->info("清除说明页数据表:explains");
  263. DB::table('explains')->delete();
  264. $this->info("清除说明页分站关系数据表:subsite_explain");
  265. DB::table('subsite_explain')->delete();
  266. $this->info("开始转移数据...");
  267. $total = ExplainCategory::count();
  268. $bar = $this->output->createProgressBar($total);
  269. ExplainCategory::orderBy('id', 'asc')->chunk(500, function ($categories) use ($bar) {
  270. $cate_array = [];
  271. $explain_array = [];
  272. $explain_subsite_array = [];
  273. foreach ($categories as $cate) {
  274. //处理说明页分类表
  275. $this->handleExplainCategory($cate, $cate_array);
  276. //处理说明页表、说明页与分站关系表
  277. $this->handleExplain($cate->explains, $explain_array, $explain_subsite_array);
  278. }
  279. //批量插入数据;
  280. if ($cate_array) {
  281. newExplainCategory::insert($cate_array);
  282. }
  283. if ($explain_array) {
  284. newExplain::insert($explain_array);
  285. }
  286. if ($explain_subsite_array) {
  287. SubsiteExplain::insert($explain_subsite_array);
  288. }
  289. $bar->advance(500);
  290. });
  291. $bar->finish();
  292. $this->line(" 完成!");
  293. $this->info("转移说明页数据成功.");
  294. }
  295. public function handleLinkCategory($link_cate, &$result_array)
  296. {
  297. $time = date('Y-m-d H:i:s', time());
  298. if (strpos($link_cate->c_alias, 'QS_') === 0) {
  299. $alias = substr_replace($link_cate->c_alias, 'AIX_', 0, 3);
  300. } else {
  301. $alias = $link_cate->c_alias;
  302. }
  303. $cate_data = array(
  304. 'id' => $link_cate->id,
  305. 'category_name' => $link_cate->categoryname,
  306. 'alias' => $alias,
  307. 'admin_set' => $link_cate->c_sys,
  308. 'created_at' => $time,
  309. 'updated_at' => $time
  310. );
  311. $result_array[] = $cate_data;
  312. }
  313. public function handleLink($type_id, $links, &$result_array, &$sub_array)
  314. {
  315. foreach ($links as $key => $link) {
  316. $ltime = date('Y-m-d H:i:s', time());
  317. $link_data = array(
  318. 'id' => $link->link_id,
  319. 'is_display' => $link->display,
  320. 'type_id' => $type_id,
  321. 'link_title' => $link->link_name,
  322. 'link_url' => $link->link_url,
  323. 'link_logo' => !empty($link->link_logo) ? 'old/link_logo/' . $link->link_logo : '',
  324. 'note' => htmlspecialchars_decode($link->notes),
  325. 'list_order' => $link->show_order,
  326. 'subsite_id' => $link->subsite_id,
  327. 'created_at' => $ltime,
  328. 'updated_at' => $ltime,
  329. );
  330. $result_array[] = $link_data;
  331. $sub_data = array(
  332. 'link_id' => $link->link_id,
  333. 'subsite_id' => $link->subsite_id,
  334. 'created_at' => $ltime,
  335. 'updated_at' => $ltime,
  336. );
  337. $sub_array[] = $sub_data;
  338. }
  339. }
  340. public function handleHrtoolCategory($hrtool_cate, &$result_array)
  341. {
  342. $time = date('Y-m-d H:i:s', time());
  343. $data = array(
  344. 'id' => $hrtool_cate->c_id,
  345. 'category_name' => $hrtool_cate->c_name,
  346. 'category_img' => !empty($hrtool_cate->c_img) ? 'old/resource/hrtools_img/' . $hrtool_cate->c_img : '',
  347. 'admin_set' => $hrtool_cate->c_adminset,
  348. 'list_order' => $hrtool_cate->c_order,
  349. 'content' => $hrtool_cate->c_desc,
  350. 'created_at' => $time,
  351. 'updated_at' => $time
  352. );
  353. $result_array[] = $data;
  354. }
  355. public function handleHrtool($hrtools, &$result_array)
  356. {
  357. foreach ($hrtools as $key => $val) {
  358. $htime = date('Y-m-d H:i:s', time());
  359. $hr_data = array(
  360. 'id' => $val->h_id,
  361. 'type_id' => $val->h_typeid,
  362. 'title' => $val->h_filename,
  363. 'tit_color' => $val->h_color,
  364. 'tit_b' => $val->h_strong,
  365. 'file_url' => !empty($val->h_fileurl) ? 'old/hrtools/' . $val->h_fileurl : '',
  366. 'list_order' => $val->h_order,
  367. 'created_at' => $htime,
  368. 'updated_at' => $htime,
  369. );
  370. $result_array[] = $hr_data;
  371. }
  372. }
  373. public function handleHelpCategory($help_cate, &$result_array)
  374. {
  375. $time = date('Y-m-d H:i:s', time());
  376. $cate_data = array(
  377. 'id' => $help_cate->id,
  378. 'parent_id' => $help_cate->parentid,
  379. 'category_name' => $help_cate->categoryname,
  380. 'list_order' => $help_cate->category_order,
  381. 'created_at' => $time,
  382. 'updated_at' => $time
  383. );
  384. $result_array[] = $cate_data;
  385. }
  386. public function handleHelp($helps, &$result_array)
  387. {
  388. foreach ($helps as $help) {
  389. $htime = date('Y-m-d H:i:s', $help->addtime);
  390. $help_data = array(
  391. 'id' => $help->id,
  392. 'type_id' => $help->type_id,
  393. 'parent_id' => $help->parentid,
  394. 'title' => $help->title,
  395. 'content' => $help->content,
  396. 'list_order' => $help->ordid,
  397. 'click' => $help->click,
  398. 'created_at' => $htime,
  399. 'updated_at' => $htime,
  400. );
  401. $result_array[] = $help_data;
  402. }
  403. }
  404. public function handleJobReport($report, &$result_array)
  405. {
  406. $data = array(
  407. 'uid' => $report->uid,
  408. 'username' => $report->username,
  409. 'utype' => 1,
  410. 'utype_id' => $report->jobs_id,
  411. 'utype_realname' => $report->jobs_name,
  412. 'type_id' => $report->report_type,
  413. 'phone' => $report->telephone,
  414. 'content' => $report->content,
  415. 'audit' => $report->audit,
  416. 'subsite_id' => $report->subsite_id,
  417. 'created_at' => date('Y-m-d H:i:s', $report->addtime),
  418. 'updated_at' => date('Y-m-d H:i:s', $report->addtime),
  419. );
  420. $result_array[] = $data;
  421. }
  422. public function handleResumeReport($resume_report, &$result_array)
  423. {
  424. $report_type = 7 + (int)$resume_report->report_type;
  425. $data = array(
  426. 'uid' => $resume_report->uid,
  427. 'username' => $resume_report->username,
  428. 'utype' => 2,
  429. 'utype_id' => $resume_report->resume_id,
  430. 'utype_realname' => $resume_report->resume_realname,
  431. 'type_id' => $report_type,
  432. 'phone' => '',
  433. 'content' => '',
  434. 'audit' => $resume_report->audit,
  435. 'subsite_id' => $resume_report->subsite_id,
  436. 'created_at' => date('Y-m-d H:i:s', $resume_report->addtime),
  437. 'updated_at' => date('Y-m-d H:i:s', $resume_report->addtime),
  438. );
  439. $result_array[] = $data;
  440. }
  441. public function handleAppeal($appeal, &$result_array)
  442. {
  443. $appeal_data = array(
  444. 'id' => $appeal->id,
  445. 'real_name' => $appeal->realname,
  446. 'mobile' => $appeal->mobile,
  447. 'email' => $appeal->email,
  448. 'description' => $appeal->description,
  449. 'subsite_id' => $appeal->subsite_id,
  450. 'status' => $appeal->status,
  451. 'created_at' => date('Y-m-d H:i:s', $appeal->addtime),
  452. 'updated_at' => date('Y-m-d H:i:s', $appeal->addtime)
  453. );
  454. $result_array[] = $appeal_data;
  455. }
  456. public function handleFeedback($feedback, &$result_array)
  457. {
  458. $audit = 0;
  459. if ($feedback->audit == 1) {
  460. $audit = 0;
  461. } elseif ($feedback->audit == 2) {
  462. $audit = 1;
  463. }
  464. $data = array(
  465. 'id' => $feedback->id,
  466. 'type' => $feedback->infotype,
  467. 'content' => $feedback->feedback,
  468. 'contact' => $feedback->tel,
  469. 'audit' => $audit,
  470. 'subsite_id' => $feedback->subsite_id?$feedback->subsite_id:0,
  471. 'created_at' => date('Y-m-d H:i:s', $feedback->addtime),
  472. 'updated_at' => date('Y-m-d H:i:s', $feedback->addtime)
  473. );
  474. $result_array[] = $data;
  475. }
  476. public function handleExplainCategory($cate, &$result_array)
  477. {
  478. $time = date('Y-m-d H:i:s', time());
  479. $data['id'] = $cate->id;
  480. $data['category_name'] = $cate->categoryname;
  481. $data['list_order'] = $cate->category_order;
  482. $data['admin_set'] = $cate->admin_set;
  483. $data['status'] = 1;
  484. $data['created_at'] = $time;
  485. $data['updated_at'] = $time;
  486. $result_array[] = $data;
  487. }
  488. public function handleExplain($explains, &$result_array, &$sub_array)
  489. {
  490. foreach ($explains as $key => $explain) {
  491. $etime = date('Y-m-d H:i:s', $explain->addtime);
  492. $is_url = $explain->is_url;
  493. if ($explain->is_url == 'http://') {
  494. $is_url = null;
  495. }
  496. $data['id'] = $explain->id;
  497. $data['title'] = $explain->title;
  498. $data['tit_color'] = $explain->tit_color ? $explain->tit_color : '#000000';
  499. $data['tit_b'] = $explain->tit_b;
  500. $data['content'] = htmlspecialchars_decode($explain->content);
  501. $data['is_display'] = $explain->is_display;
  502. $data['is_url'] = $is_url;
  503. $data['seo_keywords'] = $explain->seo_keywords;
  504. $data['seo_description'] = $explain->seo_description;
  505. $data['click'] = $explain->click;
  506. $data['list_order'] = $explain->show_order;
  507. $data['subsite_id'] = $explain->subsite_id;
  508. $data['created_at'] = $etime;
  509. $data['updated_at'] = $etime;
  510. $result_array[] = $data;
  511. //分站对应关系
  512. $sub_data = array(
  513. 'explain_id' => $explain->id,
  514. 'subsite_id' => $explain->subsite_id,
  515. 'created_at' => $etime,
  516. 'updated_at' => $etime,
  517. );
  518. $sub_array[] = $sub_data;
  519. }
  520. }
  521. public function handleNoticeCategory($cate, &$result_array)
  522. {
  523. $time = date('Y-m-d H:i:s', time());
  524. $data['id'] = $cate->id;
  525. $data['category_name'] = $cate->categoryname;
  526. $data['listorder'] = $cate->sort;
  527. $data['admin_set'] = $cate->admin_set;
  528. $data['status'] = 1;
  529. $data['created_at'] = $time;
  530. $data['updated_at'] = $time;
  531. $result_array[] = $data;
  532. }
  533. public function handleNotice($notices, &$result_array, &$sub_array)
  534. {
  535. foreach ($notices as $key => $notice) {
  536. $ntime = date('Y-m-d H:i:s', $notice->addtime);
  537. $is_url = $notice->is_url;
  538. if ($notice->is_url == 'http://') {
  539. $is_url = null;
  540. }
  541. $data['id'] = $notice->id;
  542. $data['type_id'] = $notice->type_id;
  543. $data['title'] = $notice->title;
  544. $data['content'] = htmlspecialchars_decode($notice->content);
  545. $data['tit_color'] = $notice->tit_color ? $notice->tit_color : '#000000';
  546. $data['tit_b'] = $notice->tit_b;
  547. $data['is_display'] = $notice->is_display;
  548. $data['is_url'] = $is_url;
  549. $data['seo_keywords'] = $notice->seo_keywords;
  550. $data['seo_description'] = $notice->seo_description;
  551. $data['click'] = $notice->click;
  552. $data['sort'] = $notice->sort;
  553. $data['subsite_id'] = $notice->subsite_id;
  554. $data['created_at'] = $ntime;
  555. $data['updated_at'] = $ntime;
  556. $result_array[] = $data;
  557. //分站对应关系
  558. $sub_data = array(
  559. 'notice_id' => $notice->id,
  560. 'subsite_id' => $notice->subsite_id,
  561. 'created_at' => $ntime,
  562. 'updated_at' => $ntime,
  563. );
  564. $sub_array[] = $sub_data;
  565. }
  566. }
  567. }