Esempio n. 1
0
 public function add()
 {
     $this->checkPageAction($this->page_id, Action::$Add);
     if (Request::ajax()) {
         if (Input::has('actionType')) {
             switch (Input::get('actionType')) {
                 case 'checkCompany':
                     if (Input::has('company_name')) {
                         $name = Input::get('company_name');
                         $data = Company::where(array('company_name' => $name))->get();
                         if (count($data) > 0) {
                             return 'false';
                         }
                     }
                     return 'true';
                     break;
                 case 'addCompany':
                     if (Request::isMethod('post') && Input::has('company') && Input::has('companyInfo')) {
                         $company_detail = json_decode(Input::get('company'), TRUE);
                         $companyInfo = json_decode(Input::get('companyInfo'), TRUE);
                         $company = Company::where(array('company_name' => $company_detail['company_name']))->get();
                         if (count($company) > 0) {
                             return json_encode(array('msg' => 'Company already exists!'));
                         } else {
                             $company = new Company();
                             $company->fill($company_detail);
                             if ($company->save()) {
                                 $companyInfo['company_id'] = $company->company_id;
                                 if ($company->companyInfo()->insert($companyInfo)) {
                                     $this->generateGroups($company->company_id);
                                     return json_encode(array('status' => 'true', 'msg' => 'Successfully Added Company!'));
                                 } else {
                                     $company->delete();
                                     return json_encode(array('status' => 'false', 'msg' => 'Unable To Add Company!'));
                                 }
                             }
                             return json_encode(array('status' => 'false', 'msg' => 'Unable To Add Company, Please try again later!'));
                         }
                     }
                     return json_encode(array('status' => 'false', 'msg' => 'Invalid Request!'));
                     break;
             }
         }
     }
     return view('content.setting.company.form.company_form');
 }
Esempio n. 2
0
 /**
  * 创建新公司
  */
 public function store()
 {
     DB::beginTransaction();
     try {
         $company = new Company();
         $company->name = $this->request->get('name');
         $company->full_name = $this->request->get('full_name');
         $company->logo = $this->request->get('logo');
         $company->website = $this->request->get('website');
         $company->brief = $this->request->get('brief');
         $company->address = $this->request->get('province') . $this->request->get('city') . $this->request->get('dist');
         if (empty($this->request->get('sub_field'))) {
             $company->field_id = $this->request->get('company_field');
         } else {
             $company->field_id = $this->request->get('sub_field');
         }
         //获取公司类型
         $company->type = $this->request->get('type');
         if ($this->request->has('iphoneAppstoreLink')) {
             $company->iphoneAppstoreLink = $this->request->get('iphoneAppstoreLink');
         }
         if ($this->request->has('androidLink')) {
             $company->androidLink = $this->request->get('androidLink');
         }
         if ($this->request->has('website')) {
             $company->website = $this->request->get('website');
         }
         if ($this->request->has('weixin')) {
             $company->weixin = $this->request->get('weixin');
         }
         if ($this->request->has('operationStatus')) {
             $company->operationStatus = $this->request->get('operationStatus');
         }
         $company->save();
         //增加公司详情
         $extend = new CompanyExtend();
         $extend->company_id = $company->id;
         $extend->projectAdvantage = $this->request->get('projectAdvantage');
         $extend->dataLights = $this->request->get('dataLights');
         $extend->story = $this->request->get('story');
         $extend->save();
         //增加公司认证信息
         $auth = new CompanyAuth();
         $auth->customer_id = $this->user()->id;
         $auth->company_id = $company->id;
         $auth->position = $this->request->get('position');
         $auth->position_detail = $this->request->get('position_detail');
         $auth->start_year = $this->request->get('startYear');
         $auth->start_month = $this->request->get('startMonth');
         $auth->is_today = $this->request->get('is_today');
         if ($this->request->get('is_today') == 0) {
             $auth->end_year = $this->request->get('end_year') ? $this->request->get('endYear') : Carbon::now()->year;
             $auth->end_month = $this->request->get('end_month') ? $this->request->get('endMonth') : Carbon::now()->month;
         }
         $auth->bizCardLinkFile = $this->request->get('auth');
         $auth->company_name = $company->name;
         $auth->save();
         //更新用户公司信息
         //创建公司 如果用户类型为3游客 变更为1创业者
         Customer::where('id', $this->user()->id)->update(['company_id' => $company->id, 'position' => $this->request->get('position'), 'position_detail' => $this->request->get('position_detail'), 'is_company_creator' => 1, 'type' => 1, 'type_state' => 1]);
         //添加创业经历
         $experience = new CompanyExperience();
         $experience->company_id = $company->id;
         $experience->startYear = $this->request->get('startYear');
         $experience->startMouth = $this->request->get('startMonth');
         $experience->is_today = $this->request->get('is_today');
         $experience->endYear = $this->request->has('endYear') ? $this->request->has('endYear') : '';
         $experience->endMouth = $this->request->has('endMonth') ? $this->request->has('endMonth') : '';
         $experience->bizCardLink = $this->request->get('auth');
         $experience->customer_id = $this->user()->id;
         $experience->save();
         //公司介绍
         //            $introduce=new CompanyIntroduce();
         if ($this->request->has('product')) {
             CompanyIntroduce::create(['company_id' => $company->id, 'config_id' => 1, 'content' => $this->request->get('product')]);
         }
         if ($this->request->has('consumer')) {
             CompanyIntroduce::create(['company_id' => $company->id, 'config_id' => 2, 'content' => $this->request->get('consumer')]);
         }
         if ($this->request->has('future')) {
             CompanyIntroduce::create(['company_id' => $company->id, 'config_id' => 3, 'content' => $this->request->get('future')]);
         }
         if ($this->request->has('similar')) {
             CompanyIntroduce::create(['company_id' => $company->id, 'config_id' => 4, 'content' => $this->request->get('similar')]);
         }
         if ($this->request->has('others')) {
             CompanyIntroduce::create(['company_id' => $company->id, 'config_id' => 5, 'content' => $this->request->get('others')]);
         }
         DB::commit();
         return return_rest('1', '', '公司添加成功');
     } catch (\Exception $e) {
         DB::rollBack();
         return return_rest('0', '', $e->getMessage());
     }
 }