gold.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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\Db;
  10. class gold extends Command
  11. {
  12. protected function configure()
  13. {
  14. // 指令配置
  15. $this->setName('gold')
  16. ->setDescription('the gold command');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. // 指令输出
  21. $lsu=$this->getData();
  22. foreach ($lsu as $value){
  23. $uqi = Db::name("gold_price")->where(["uiq"=>$value['uiq']])->find();
  24. $value['type']=$value['type'] =="18K" ? 1 :($value['type'] =="24K" ? 2 :3);
  25. if($uqi){
  26. // Db::name("gold_price")->where(["uiq"=>$value['uiq']])->save($value);
  27. continue;
  28. }else{
  29. Db::name("gold_price")->save($value);
  30. }
  31. echo $value['addtime'];
  32. }
  33. $output->writeln('gold');
  34. }
  35. public function getData(){
  36. $date=date("Y-m-d H:i:s",strtotime("-1 day"));
  37. $db = Db::connect("mysql2");
  38. $var=" SELECT id as 'uiq', SUBSTRING(`name`,1,3) AS 'action_name',createdTime AS 'addtime',
  39. ShortText1619628038544 AS 'type',ifnull(Number1619628088467,0) AS 'price' FROM iw48m_GXJJ where createdTime>='{$date}' ";
  40. $list=$db->query($var);
  41. return $list;
  42. }
  43. }