thdata.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use think\facade\Cache;
  8. use think\facade\Db;
  9. class thdata extends Command
  10. {
  11. protected $db="";
  12. protected function configure()
  13. {
  14. // 指令配置
  15. $this->setName('thdata')
  16. ->setDescription('the thdata command');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. $redis = Cache::store('redis');
  21. $iscgd = $redis->get("thdata");
  22. if($iscgd==0){
  23. $redis->set("thdata",1,1200);
  24. }else{
  25. return;
  26. }
  27. $this->db =Db::connect("mysql2");
  28. $data = $this->getdata();
  29. foreach ($data as $value){
  30. $ist=Db::name("th_source")->where("thNo","=",$value['thNo'])->find();
  31. if($ist){
  32. Db::name("th_source")->where("thNo","=",$value['thNo'])->save($value);
  33. }else{
  34. Db::name("th_source")->save($value);
  35. }
  36. }
  37. $redis->set("thdata",0);
  38. }
  39. protected function getdata(){
  40. $time = date("Y-m-d H:i:s",strtotime("-3 day"));
  41. $sql="SELECT
  42. `b`.`sequenceNo` AS `thNo`,
  43. case `b`.`sequenceStatus` when 'COMPLETED' then 1 when 'PROCESSING' then 2 else 3 end AS `th_status`,
  44. `b`.`createdTime` AS `createtime`,
  45. `b`.`ShortText1622039439558` AS `th_company`,(
  46. SELECT
  47. `b_`.`name`
  48. FROM
  49. `h_org_user` `b_`
  50. WHERE
  51. ( CONVERT ( `b_`.`id` USING utf8mb4 ) = `b`.`creater` )) AS `th_user`,
  52. cast( `b`.`Number1615968695370` AS signed ) AS `th_num`,
  53. round( `b`.`Number1619615193432`, 2 ) AS `th_qrd_fee`,
  54. round( `b`.`Number1619492129873`, 2 ) AS `th_cgd_fee`,
  55. if(`b`.`ShortText1615968975747`='是',1,2) AS `is_th`,
  56. CONCAT(ifnull(`b`.`ShortText1619614836899`,''),ifnull(`b`.`ShortText1619623237989`,'')) AS `th_remark`,
  57. `b`.`ShortText1615969167025` AS `th_post_company`,
  58. `b`.`ShortText1615969170779` AS `th_post_code`,
  59. ifnull(`b`.`Number1615969017987`,0) AS `th_post_fee`,
  60. `b`.`ShortText1615969178999` AS `th_receiver`,
  61. `b`.`ShortText1615969187428` AS `th_phone`,
  62. `b`.`text1615969189698` AS `th_mobile`,
  63. `b`.`ShortText1619623279832` AS `th_addr`,
  64. `a`.`sequenceNo` as `th_qrdcpNo`,
  65. `a`.`ShortText1617650701648` as `th_qrdNo`,
  66. ifnull(`b2`.`ShortText1618315935182`,'') AS `th_cgdNo`,
  67. b.modifiedTime as addtime
  68. FROM
  69. (((`ifi4s_THGL_THJL` `b` LEFT JOIN `il150_querendanchanpin` `a` ON ((`b`.`ShortText1620718909731` = `a`.`sequenceNo` ))))
  70. LEFT JOIN `iw48m_CGDJL` `b2` ON (((`a`.`ShortText1617650701648` = `b2`.`ShortText1617866360004` ) AND ( `a`.`ShortText1619146965777` = `b2`.`ShortText1619147112929` ))))
  71. WHERE `b`.`modifiedTime`>='{$time}'
  72. ORDER BY `b`.`createdTime`";
  73. $data=$this->db->query($sql);
  74. echo $sql;
  75. return $data;
  76. }
  77. }