ImportAll.php 1.5 KB

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