ImportAll.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Import;
  3. use App\Service\ImportService;
  4. use Maatwebsite\Excel\Concerns\ToArray;
  5. use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;
  6. class ImportAll implements ToArray,WithCalculatedFormulas {
  7. private $msg = '';
  8. public $crt_id = 0;
  9. public $type = "";
  10. public $user = [];
  11. public function array (array $array){
  12. $this->handleData($array);
  13. }
  14. public function setCrt($crt_id){
  15. $this->crt_id = $crt_id;
  16. }
  17. public function setType($type){
  18. $this->type = $type;
  19. }
  20. public function setUser($user){
  21. $this->user = $user;
  22. }
  23. public function getMsg(){
  24. return $this->msg;
  25. }
  26. public function setMsg($msg){
  27. $this->msg = $msg;
  28. }
  29. public function handleData (array $array) {
  30. $func = $this->type . "Import";
  31. if(! $func) {
  32. $this->setMsg("意外错误");
  33. return;
  34. }
  35. list($status,$msg) = (new ImportService())->$func($array,$this->user);
  36. if(empty($status)) $this->setMsg($msg);
  37. }
  38. }