mobile_import.php 1009 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. use app\admin\model\MobileUpload;
  3. use app\common\service\MobileImport;
  4. use PhpOffice\PhpSpreadsheet\IOFactory;
  5. use Workerman\Lib\Timer;
  6. use Workerman\Worker as WO;
  7. class MobileImportWork extends Com{
  8. public static function run(){
  9. $work=self::newWorker();
  10. $work->onWorkerStart=function (WO $worker){
  11. Timer::add(3,function ()use ($worker){
  12. self::import();
  13. });
  14. };
  15. }
  16. public static function import(){
  17. $upload= MobileUpload::where('status',0)->find();
  18. if(!$upload){
  19. return;
  20. }
  21. $upload['status']=1;
  22. $upload->save();
  23. try {
  24. MobileImport::import($upload['file'],$upload['admin_id'],$upload['params']['type'],$upload['params']['status'],$upload);
  25. }catch (\Exception $e){
  26. $upload['remark']=$e->getMessage();
  27. $upload['status']=2;
  28. $upload->save();
  29. self::logError($e);
  30. }
  31. }
  32. }
  33. //MobileImportWork::run();