MobileExportCommand.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\admin\command;
  3. use app\admin\model\Admin;
  4. use app\admin\model\MobileExportLog;
  5. use app\common\service\MobileExport;
  6. use think\console\Command;
  7. use think\console\Input;
  8. use think\console\Output;
  9. use think\Db;
  10. class MobileExportCommand extends Command
  11. {
  12. protected function configure()
  13. {
  14. $this
  15. ->setName('mobile:export');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. if(MobileExportLog::where('status',1)->find()){
  20. return;
  21. }
  22. $export=MobileExportLog::where('status',0)->find();
  23. if(!$export){
  24. return;
  25. }
  26. $export['status']=1;
  27. $export->save();
  28. try {
  29. $list=Db::query($export['sql']);
  30. $listCount=count($list);
  31. self::log("【{$export['id']}】共{$listCount}条数据");
  32. MobileExport::export($list,$export);
  33. }catch (\Exception $e){
  34. Db::rollback();
  35. $export['status']=3;
  36. $export->save();
  37. self::logError($e);
  38. }
  39. }
  40. }