ImportAll.php 990 B

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