ImportAll.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 $is_long_text = false;
  12. public function array (array $array){
  13. $this->handleData($array);
  14. }
  15. public function setCrt($crt_id){
  16. $this->crt_id = $crt_id;
  17. }
  18. public function setType($type){
  19. $this->type = $type;
  20. }
  21. public function setUser($user){
  22. $this->user = $user;
  23. }
  24. public function getMsg(){
  25. return $this->msg;
  26. }
  27. public function setMsg($msg){
  28. $this->msg = $msg;
  29. }
  30. public function setIsLongText($bool = true){
  31. $this->is_long_text = $bool;
  32. }
  33. public function getIsLongText(){
  34. return $this->is_long_text;
  35. }
  36. public function handleData (array $array) {
  37. $func = $this->type . "Import";
  38. if(! $func) {
  39. $this->setMsg("意外错误");
  40. return;
  41. }
  42. list($status,$msg) = (new ImportService())->$func($array,$this->user);
  43. if(empty($status)) {
  44. if($status === 0) $this->setIsLongText();
  45. $this->setMsg($msg);
  46. }
  47. }
  48. }