Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ClientEmployee::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     \Yii::warning('yjhu_debugging: ' . \yii\helpers\Json::encode($params));
     \Yii::warning('yjhu_debugging: ' . \yii\helpers\Json::encode($this));
     $this->load($params);
     \Yii::warning('yjhu_debugging: ' . \yii\helpers\Json::encode($this));
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query = $query->joinWith('organizations');
     $query->andFilterWhere(['employee_id' => $this->employee_id, 'client_id' => $this->client_id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     $root_org = ClientOrganization::findOne(['organization_id' => $this->organization_id]);
     if (empty($root_org)) {
         $this->organization_id = 1;
         $root_org = ClientOrganization::findOne(['organization_id' => 1]);
     }
     $query->andFilterWhere(['client_organization.organization_id' => $root_org->getSubordinateIdArray()]);
     if (!empty($this->search_keyword)) {
         $query->leftJoin('client_employee_mobile', 'client_employee_mobile.employee_id = client_employee.employee_id');
         $query->andFilterWhere(['like', 'name', $this->search_keyword]);
         $query->orFilterWhere(['like', 'client_employee_mobile.mobile', $this->search_keyword]);
     }
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function deleteEmployee($employee_id)
 {
     \Yii::$app->db->createCommand()->delete('client_employee_outlet', ['employee_id' => $employee_id, 'outlet_id' => $this->outlet_id])->execute();
     $employee = \app\models\ClientEmployee::findOne(['employee_id' => $employee_id]);
     if (empty($employee->outlets) && empty($employee->organizations)) {
         return $employee->delete();
     }
     return true;
 }
Exemplo n.º 3
0
 public function actionEmployee($filename = 'employee.csv')
 {
     $xyunicom = \app\models\WosoClient::findOne(['title_abbrev' => '襄阳联通']);
     if (empty($xyunicom)) {
         die('不能找到襄阳联通。');
     }
     $filepathname = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'imported_data' . DIRECTORY_SEPARATOR . $filename;
     $fh = fopen($filepathname, "r");
     while (!feof($fh)) {
         $line = trim(fgets($fh));
         if (empty($line) || strlen($line) == 0) {
             continue;
         }
         $fields = explode(",", $line);
         $name = trim($fields[0]);
         $name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $name);
         $department = trim($fields[1]);
         $department_utf8 = iconv('GBK', 'UTF-8//IGNORE', $department);
         $position = trim($fields[2]);
         $position_utf8 = iconv('GBK', 'UTF-8//IGNORE', $position);
         $mobiles = explode(';', trim($fields[3]));
         echo "{$name_utf8},{$department_utf8},{$position_utf8},{$fields[3]}" . PHP_EOL;
         $employee = \app\models\ClientEmployee::findOne(['name' => $name_utf8]);
         if (empty($employee)) {
             $employee = new \app\models\ClientEmployee();
             $employee->client_id = $xyunicom->client_id;
             $employee->name = $name_utf8;
             $employee->save(false);
         }
         $organization = \app\models\ClientOrganization::findOne(['title' => $department_utf8]);
         if (empty($organization)) {
             $organization = new \app\models\ClientOrganization();
             $organization->client_id = $xyunicom->client_id;
             $organization->title = $department_utf8;
             $organization->save(false);
         }
         $row = (new \yii\db\Query())->select('*')->from('client_employee_organization')->where(['employee_id' => $employee->employee_id, 'organization_id' => $organization->organization_id])->one();
         if (false === $row) {
             \Yii::$app->db->createCommand()->insert('client_employee_organization', ['employee_id' => $employee->employee_id, 'organization_id' => $organization->organization_id, 'position' => $position_utf8])->execute();
         } else {
             \Yii::$app->db->createCommand()->update('client_employee_organization', ['position' => $position_utf8], ['employee_id' => $employee->employee_id, 'organization_id' => $organization->organization_id])->execute();
         }
         foreach ($mobiles as $mobile) {
             $mobile = trim($mobile);
             if (strlen($mobile) != 11 || !is_numeric($mobile)) {
                 echo "[{$mobile}]非手机号码;";
             } else {
                 $row = (new \yii\db\Query())->select('*')->from('client_employee_mobile')->where(['employee_id' => $employee->employee_id, 'mobile' => $mobile])->one();
                 if (false === $row) {
                     \Yii::$app->db->createCommand()->insert('client_employee_mobile', ['employee_id' => $employee->employee_id, 'mobile' => $mobile])->execute();
                 }
             }
         }
     }
     fclose($fh);
 }
Exemplo n.º 4
0
 public function getClientEmployee()
 {
     $subquery = (new Query())->select('client_employee.employee_id, name, mobile')->from('client_employee')->leftJoin('client_employee_mobile', 'client_employee.employee_id = client_employee_mobile.employee_id');
     $row = (new Query())->select('*')->from(['t' => $subquery])->where(['name' => $this->name, 'mobile' => $this->mobile])->one();
     if (empty($row)) {
         return NULL;
     } else {
         return ClientEmployee::findOne(['employee_id' => $row['employee_id']]);
     }
 }
Exemplo n.º 5
0
 public function actionClientOutletEmployeeEdit($gh_id, $openid, $backwards = true, $pop = false)
 {
     if (!$backwards) {
         \app\models\utils\BrowserHistory::delete($gh_id, $openid);
         \app\models\utils\BrowserHistory::push($gh_id, $openid);
     } else {
         if ($pop) {
             \app\models\utils\BrowserHistory::pop($gh_id, $openid);
         } else {
             \app\models\utils\BrowserHistory::push($gh_id, $openid);
         }
     }
     $wx_user = \app\models\MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
     $this->layout = false;
     $is_agent = $_GET['is_agent'];
     $outlet_id = $_GET['outlet_id'];
     if ($is_agent) {
         $agent_id = $_GET['entity_id'];
         $entity = \app\models\ClientAgent::findOne(['agent_id' => $agent_id]);
     } else {
         $employee_id = $_GET['entity_id'];
         $entity = \app\models\ClientEmployee::findOne(['employee_id' => $employee_id]);
     }
     $outlet = \app\models\ClientOutlet::findOne(['outlet_id' => $outlet_id]);
     return $this->render('client-outlet-employee-edit', ['wx_user' => $wx_user, 'entity' => $entity, 'is_agent' => $is_agent, 'outlet' => $outlet, 'backwards' => $backwards]);
 }
Exemplo n.º 6
0
 public function getEmployees()
 {
     return $this->hasMany(\app\models\ClientEmployee::className(), ['employee_id' => 'employee_id'])->viaTable('client_employee_organization', ['organization_id' => 'organization_id']);
 }
Exemplo n.º 7
0
 /**
  * Finds the ClientEmployee model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ClientEmployee the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ClientEmployee::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 8
0
 public function actionZjygajax()
 {
     $employee_name = $_GET['ygxm'];
     $employee_mobile = $_GET['ygsjhm'];
     $outlet_id = $_GET['office_id'];
     $is_agent = !$_GET['yuangongFlag'];
     $position = $_GET['ygzw'];
     if ($is_agent) {
         return \app\models\ClientAgent::addOutletAgent($employee_name, $employee_mobile, $position, $outlet_id);
     } else {
         return \app\models\ClientEmployee::addOutletEmployee($employee_name, $employee_mobile, $position, $outlet_id);
     }
     return json_encode(['code' => 0]);
 }