0], ]; } public function attributeLabels() { return [ 'erp_id'=>'对接的erp_id', 'code'=>'推广码', 'level'=>'级别', 'offical_seal'=>'公章', 'name'=>'名字', 'shouzimu'=>'首字母', 'start_time'=>'开始营业时间', 'end_time'=>'结束营业时间', 'qr_code'=>'门店二维码', ]; } //新增科室 public function SaveDepart() { if (!$this->validate()){ throw new Exception($this->getErrorMsg()); } $Department=Department::find()->where([ 'name'=>$this->name ])->one(); if ($Department) throw new Exception('科室已存在'); if ($this->level != 1){ if (empty($this->pid)){ return ['pid不能为空']; } } $department=new Department(); $department->attributes=$this->attributes; $department->saveOrFail(); return ['添加成功']; } //新增门店 public function SaveStore() { $admin=Admin::find()->where(['code'=>$this->code,'role'=>UserRoleEnum::SUPPLY])->one(); if (!$admin)throw new Exception('推广码或业务员不存在'); if ($this->id){ $Store=Store::find()->where([ 'plate_id'=>$this->plate_id, 'id'=>$this->id ])->one(); if (!$Store) throw new Exception('门店不存在'); if (!empty($this->bank_account_type)){ if ($this->bank_account_type== 1 || $this->bank_account_type == 5) { if (empty($this->bank_no)) { throw new Exception('bank_no不能为空'); } } else { if (substr($this->bank_card, 0, 2) != '62') { if (empty($this->bank_no)) { throw new Exception('bank_no不能为空'); } } } } $Store->plate_id=$this->plate_id; $Store->drugstore_id=$this->drugstore_id; $Store->name=$this->store_name; if($this->erp_id){ $Store->erp_id=$this->erp_id; } $Store->shouzimu=$this->shouzimu; $Store->contact=$this->contact; $Store->offical_seal=$this->offical_seal??$Store->offical_seal; $Store->province_id=$this->province_id; $Store->city_id=$this->city_id; $Store->position=$this->position; $Store->mobile=$this->mobile; $Store->uid=$admin->uid; $Store->code=$this->code; $Store->bank_user_name=$this->bank_user_name; $Store->bank_card=$this->bank_card; $Store->bank_name=$this->bank_name; $Store->bank_account_type=$this->bank_account_type; $Store->bank_no=$this->bank_no; $Store->start_time=$this->start_time; $Store->end_time=$this->end_time; if(!$Store->qr_code){ $scene = 'STORE_QR_CODE'.'_'.$this->id; $weappService = new WeappService(); $url= $weappService->getQrcode($scene); $Store->qr_code = $url; } $Store->saveOrFail(); return ['编辑成功']; } $Store=Store::find()->where([ 'plate_id'=>$this->plate_id, 'name'=>$this->name ])->one(); if ($Store) throw new Exception('门店已存在'); $t=\Yii::$app->db->beginTransaction(); try { $Store=new Store(); $Store->plate_id=$this->plate_id; $Store->drugstore_id=$this->drugstore_id; $Store->erp_id=$this->erp_id; $Store->name=$this->store_name; $Store->contact=$this->contact; $Store->offical_seal=$this->offical_seal??''; $Store->province_id=$this->province_id; $Store->city_id=$this->city_id; $Store->position=$this->position; $Store->mobile=$this->mobile; $Store->uid=$admin->uid; $Store->code=$this->code; // $Store->bank_user_name=$this->bank_user_name; // $Store->bank_card=$this->bank_card; // $Store->bank_name=$this->bank_name; // $Store->bank_account_type=$this->bank_account_type; // $Store->bank_no=$this->bank_no; $Store->start_time=$this->start_time; $Store->end_time=$this->end_time; $Store->shouzimu=$this->shouzimu; $Store->saveOrFail(); $add_store = Store::find()->where([ 'id' => $Store->id ])->one(); $scene = 'STORE_QR_CODE'.'_'.$add_store->id; $weappService = new WeappService(); $url= $weappService->getQrcode($scene); $add_store->qr_code=$url; $add_store->saveOrFail(); // StoreController::actionQrcode($Store->id); $t->commit(); return ['添加成功']; }catch (\Exception $e){ $t->rollBack(); throw new Exception($e->getMessage()); } } }