/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MOfficeCampaignScorer::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'department', $this->department])->andFilterWhere(['like', 'position', $this->position])->andFilterWhere(['like', 'mobile', $this->mobile]); return $dataProvider; }
public function actionOfficeCampaignScorer() { $scorers = \app\models\MOfficeCampaignScorer::find()->all(); foreach ($scorers as $scorer) { $openidbindmobile = \app\models\OpenidBindMobile::findOne(['mobile' => $scorer->mobile]); if (empty($openidbindmobile)) { echo "{$scorer->name}({$scorer->mobile})手机未绑定。" . PHP_EOL; } $staffs = \app\models\MStaff::find()->where(['gh_id' => \app\models\MGh::GH_XIANGYANGUNICOM, 'mobile' => $scorer->mobile])->all(); if (empty($staffs)) { echo "{$scorer->name}({$scorer->mobile})不在Staff表中。" . PHP_EOL; $staff = new \app\models\MStaff(); } else { if (count($staffs) > 1) { echo "{$scorer->name}({$scorer->mobile})在Staff表中存在多项。" . PHP_EOL; $n = count($staffs); $selected = -1; for ($i = 0; $i < $n; $i++) { $staff = $staffs[$i]; if (empty($staff->openid) || $selected != -1) { $staff->delete(); } else { if (!empty($staff->openid)) { $selected = $i; } } } if ($selected == -1) { $staff = new \app\models\MStaff(); } else { $staff = $staffs[$selected]; } } else { $staff = $staffs[0]; } } $staff->gh_id = \app\models\MGh::GH_XIANGYANGUNICOM; $staff->name = $scorer->name; $staff->mobile = $scorer->mobile; $staff->cat = \app\models\MStaff::SCENE_CAT_IN; $staff->save(false); } }
/** * This command import office supervision data. * @param string $filename the file to be imported to DB. */ public function actionScorer($filename = 'scorer.csv') { $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'imported_data' . DIRECTORY_SEPARATOR . $filename; $fh = fopen($file, "r"); $i = 0; while (!feof($fh)) { $line = fgets($fh); $i++; if (empty($line)) { continue; } $fields = explode(",", $line); $scorer_name = trim($fields[0]); $scorer_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $scorer_name); $scorer_department = trim(trim($fields[1]), "0..9"); $scorer_department_utf8 = iconv('GBK', 'UTF-8//IGNORE', $scorer_department); $scorer_position = trim(trim($fields[2]), "0..9"); $scorer_position_utf8 = iconv('GBK', 'UTF-8//IGNORE', $scorer_position); $scorer_mobile = trim($fields[3]); $scorer = \app\models\MOfficeCampaignScorer::findOne(['name' => $scorer_name_utf8, 'mobile' => $scorer_mobile]); if (empty($scorer)) { $scorer = new \app\models\MOfficeCampaignScorer(); $scorer->name = $scorer_name_utf8; $scorer->department = $scorer_department_utf8; $scorer->position = $scorer_position_utf8; $scorer->mobile = $scorer_mobile; $scorer->save(false); } } fclose($fh); }
public function getOfficeCampaignScorer() { return $this->hasOne(MOfficeCampaignScorer::className(), ['mobile' => 'mobile']); }
/** * Finds the MOfficeCampaignScorer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MOfficeCampaignScorer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MOfficeCampaignScorer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }