diffprice.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Cache;
  10. use think\facade\Db;
  11. class diffprice extends Command
  12. {
  13. protected function configure()
  14. {
  15. // 指令配置
  16. $this->setName('datacopy')
  17. ->setDescription('the datacopy command');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. $redis = Cache::store('redis');
  22. $iscgd = $redis->get("diffprice");
  23. if($iscgd==0){
  24. $redis->set("diffprice",1,1200);
  25. }else{
  26. return;
  27. }
  28. try {
  29. $data = $this->GetData();
  30. foreach ($data as $value) {
  31. $ist = Db::table("diff_price")->where('sequenceNo', "=", $value['sequenceNo'])->find();
  32. if (!$ist) {
  33. Db::table("diff_price")->insert($value);
  34. }
  35. }
  36. $redis->set("diffprice",0);
  37. $output->writeln('diff');
  38. }catch (\Exception $e){
  39. $redis->set("diffprice",0);
  40. $output->writeln('diff');
  41. }
  42. }
  43. public function getdata()
  44. {
  45. $this->db =Db::connect("mysql2");
  46. $date = date("Y-m-d H:i:s", strtotime("-11 day"));
  47. $sql = " SELECT
  48. NAME as name,
  49. (
  50. SELECT
  51. `b_`.`name`
  52. FROM
  53. `h_org_user` `b_`
  54. WHERE
  55. ( CONVERT ( `b_`.`id` USING utf8mb4 ) = `b`.`owner` )) AS ownername,
  56. (
  57. SELECT
  58. `b_`.`name`
  59. FROM
  60. `h_org_department` `b_`
  61. WHERE
  62. ( CONVERT ( `b_`.`id` USING utf8mb4 ) = `b`.`ownerDeptId` )) AS ownerDept,
  63. createdTime AS addtime,
  64. (
  65. SELECT
  66. `b_`.`name`
  67. FROM
  68. `h_org_user` `b_`
  69. WHERE
  70. ( CONVERT ( `b_`.`id` USING utf8mb4 ) = `b`.`modifier` )) AS modifier,
  71. modifiedTime AS updatetime,
  72. sequenceNo,
  73. sequenceStatus,
  74. ShortText1618324616212 'cgdNo',
  75. Date1618324623113 'cgdtime',
  76. (
  77. SELECT
  78. `b_`.`name`
  79. FROM
  80. `il150_Customer_info` `b_`
  81. WHERE
  82. ( CONVERT ( `b_`.`id` USING utf8mb4 ) = `b`.`RelevanceForm1618324639751` )) as khName,
  83. ShortText1618324650659 'khNo',
  84. ShortText1618324668256 'goodName',
  85. ShortText1618324670141 'goodNo',
  86. ShortText1618324697504 'materal',
  87. Number1618324752186 'good_weight',
  88. Number1618324771668 'goodNum',
  89. Number1618324774208 'diff_weight',
  90. Number1618325048841 'diff_fee',
  91. number1619456487393 'qrd_weight',
  92. number1619456505633 'qrd_fee',
  93. ShortText1619631384425 'qrdNo',
  94. if(ifnull(ShortText1625201144504,'否')='是',1,0) 'is_qrd'
  95. FROM
  96. iw48m_gongchadengji b where sequenceStatus= 'COMPLETED' and
  97. modifiedTime >='{$date}'";
  98. $data = $this->db->query($sql);
  99. return $data;
  100. }
  101. }