OutChildSend.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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)return true;
  23. Cache::store('redis')->set($key,1,3000);
  24. $date = date("Y-m-d H:i:s",time()-3600);
  25. $list = OrderOutChild::where([["addtime",">=",$date],["is_del","=",0]])->hidden(["id"])->select();
  26. if($list->isEmpty()==false){
  27. $Insert=[];
  28. foreach ($list->toArray() as $item){
  29. $isT =FhdChild::where(["outChildCode"=>$item['outChildCode']])->findOrEmpty();
  30. if($isT->isEmpty()){
  31. $Insert[]=$item;
  32. }
  33. if(count($Insert)>500){
  34. FhdChild::strict(false)->insertAll($Insert);
  35. $Insert=[];
  36. }
  37. }
  38. if(!empty($Insert))FhdChild::strict(false)->insertAll($Insert);
  39. }
  40. $output->writeln('outchildsend');
  41. }
  42. }