MobileExportCommand.php 1.0 KB

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