SpringCompanyService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Services\Company;
  3. use App\Repositories\SpringCompanyRepository;
  4. use Illuminate\Support\Facades\DB;
  5. use App\Repositories\CompanyRepository;
  6. use Illuminate\Support\Facades\Hash;
  7. use App\Repositories\MemberLogRepository;
  8. use App\Services\Common\SmsService;
  9. class SpringCompanyService
  10. {
  11. protected $springCompanyRepository;
  12. protected $companyRepository;
  13. private $memberLogRepository;
  14. public function __construct(SpringCompanyRepository $springCompanyRepository, CompanyRepository $companyRepository, MemberLogRepository $memberLogRepository)
  15. {
  16. $this->springCompanyRepository = $springCompanyRepository;
  17. $this->companyRepository = $companyRepository;
  18. $this->memberLogRepository = $memberLogRepository;
  19. }
  20. public function saveCompany($data){
  21. DB::beginTransaction();
  22. try {
  23. if (!$id = $this->springCompanyRepository->add($data)) {
  24. throw new Exception('添加公司信息失败');
  25. }
  26. DB::commit();
  27. return $id;
  28. }catch (Exception $e){
  29. DB::rollback();
  30. return false;
  31. }
  32. }
  33. public function list($key = '', $status = 99, $page = ''){
  34. $where = array();
  35. $where[] = array('display','=','1');
  36. if ($key) {
  37. $where[] = array('company_name','like','%'.$key.'%');
  38. }
  39. if($status == '1'){
  40. $where[] = array('status','=',$status);
  41. }
  42. if($status == '0'){
  43. $where[] = array('status','=',99);
  44. }
  45. $list = $this->springCompanyRepository->getAllCompany($where, $page);
  46. return $list;
  47. }
  48. public function registerCompany($id){
  49. $smsService = new SmsService();
  50. $info = $this->springCompanyRepository->getOneCompany($id);
  51. $company = $this->companyRepository->getCompanyInfo(array('short_name'=>$info['company_name']));
  52. // if(!$company){
  53. // $data['contact'] = $info['real_name'];
  54. // $data['mobile'] = $info['phone'];
  55. // $data['username'] = $info['phone'];
  56. // $this->companyRepository->save($data,$company['id']);
  57. // }else{
  58. $password = uniqid();
  59. $data['companyname'] = $info['company_name'];
  60. $data['certificate_img'] = $info['license'];
  61. $data['contact'] = $info['real_name'];
  62. $data['mobile'] = $info['phone'];
  63. $data['username'] = $info['phone'];
  64. $data['email'] = '';
  65. $data['utype'] = 1;
  66. $data['reg_type'] = 1;
  67. $data['reg_source'] = 2;
  68. $data['landline_tel'] = '';
  69. $data['reg_source_cn']= '手机端';
  70. $data['reg_time'] = time();
  71. $data['short_name'] = '';
  72. $data['last_login_time']=time();
  73. $data['refresh_time']=time();
  74. $data['reg_ip']=ip2long(request()->ip());
  75. $data['password']=Hash::make($password);
  76. $data['subsite_id']=0;
  77. $company=$this->companyRepository->create($data);
  78. $this->memberLogRepository->createLog($company, 1000, []);
  79. $this->springCompanyRepository->companyChange($id);
  80. $smsService->sendSms($info['phone'],'sms_licenseallow',array('username'=>$info['phone'],'password'=>$password,'sitename'=>'聚才网','sitedomain'=>'http://www.jucai.gov.cn'));
  81. return array('company'=>$company,'id'=>$info['id']);
  82. //}
  83. }
  84. }