MobileImportCommand.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\admin\command;
  3. use app\admin\model\MobileUpload;
  4. use app\common\service\MobileImport;
  5. use PhpOffice\PhpSpreadsheet\IOFactory;
  6. use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
  7. use think\Cache;
  8. use think\console\Command;
  9. use think\console\Input;
  10. use think\console\Output;
  11. use think\Db;
  12. class MobileImportCommand extends Command
  13. {
  14. protected function configure()
  15. {
  16. $this
  17. ->setName('mobile:import');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. if(MobileUpload::where('status',1)->find()){
  22. return;
  23. }
  24. $upload= MobileUpload::where('status',0)->find();
  25. if(!$upload){
  26. return;
  27. }
  28. $upload['status']=1;
  29. $upload->save();
  30. try {
  31. MobileImport::import($upload['file'],$upload['admin_id'],$upload['params']['type'],$upload['params']['status'],$upload);
  32. }catch (\Exception $e){
  33. Db::rollback();
  34. $upload['remark']=$e->getMessage();
  35. $upload['status']=2;
  36. $upload->save();
  37. self::logError($e);
  38. }
  39. }
  40. }