CompanyService.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Modules\Mini\Services;
  3. use App\Base\BaseService;
  4. use App\Models\User\User;
  5. use App\Models\User\UserCompany;
  6. use Illuminate\Support\Arr;
  7. class CompanyService extends BaseService
  8. {
  9. public function company(User $user, $params)
  10. {
  11. if ($user->company) {
  12. // if ($user->company->status == UserCompany::STATUS_INIT) {
  13. // throw new ClientException("已经提交过资料了");
  14. // } else {
  15. $user->company->name = $params['name'];
  16. $user->company->tax_no = $params['tax_no'];
  17. $user->company->status = 1;
  18. $user->company->tel = Arr::get($params, "tel");
  19. $user->company->department = Arr::get($params, "department");
  20. $user->company->linkman = Arr::get($params, "linkman");
  21. $user->company->address = Arr::get($params, "address");
  22. $user->company->save();
  23. // }
  24. return $user->company;
  25. } else {
  26. $company = new UserCompany();
  27. $company->name = $params['name'];
  28. $company->user_id = $user->id;
  29. $company->tax_no = $params['tax_no'];
  30. $company->status = 1;
  31. $company->tel = Arr::get($params, "tel");
  32. $company->department = Arr::get($params, "department");
  33. $company->linkman = Arr::get($params, "linkman");
  34. $company->address = Arr::get($params, "address");
  35. $company->save();
  36. return $company;
  37. }
  38. }
  39. }