OutChildSend.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use app\admin\model\OrderOutChild;use app\model\FhdChild;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;use think\facade\Cache;
  9. class OutChildSend extends Command
  10. {
  11. protected function configure()
  12. {
  13. // 指令配置
  14. $this->setName('outchildsend')
  15. ->setDescription('the outchildsend command');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. // 指令输出
  20. $key='outchildsend';
  21. $rs = Cache::store('redis')->get($key);
  22. if ($rs!=1){
  23. Cache::store('redis')->set($key,1,3600);
  24. return true;
  25. }
  26. $date = date("Y-m-d H:i:s",time()-3600);
  27. $list = OrderOutChild::where([["addtime",">=",$date],["is_del","=",0]])->hidden(["id"])->select();
  28. if($list->isEmpty()==false){
  29. $Insert=[];
  30. foreach ($list->toArray() as $item){
  31. $isT =FhdChild::where(["outChildCode"=>$item['outChildCode']])->findOrEmpty();
  32. if($isT->isEmpty()){
  33. $Insert[]=$item;
  34. }
  35. if(count($Insert)>500){
  36. FhdChild::strict(false)->insertAll($Insert);
  37. $Insert=[];
  38. }
  39. }
  40. if(!empty($Insert))FhdChild::strict(false)->insertAll($Insert);
  41. }
  42. $output->writeln('outchildsend');
  43. }
  44. }