public function afterSave($insert, $changedAttributes) { if ($insert) { if (1 == self::getDetailsCount()) { \app\models\MMarketingServiceCenter::updateAll(['office_detailed_count' => 0, 'office_scored_count' => 0]); \app\models\MMarketingRegion::updateAll(['office_detailed_count' => 0, 'office_scored_count' => 0]); } if (self::DETAIL_COMPLETE == self::getDetailReadyStatus($this->office_id)) { $office = $this->office; $msc = $office->msc; $mr = $msc->marketingRegion; // if (0 == $msc->office_detailed_count) { // $detailed_count = $msc->getDetailedOfficeCount(); // $msc->updateAttributes(['office_detailed_count' => $detailed_count]); // } else { // $msc->updateCounters(['office_detailed_count' => 1]); // } // if ( 0 == $mr->office_detailed_count ) { // $detailed_count = $mr->getDetailedOfficeCount(); // $mr->updateAttributes(['office_detailed_count' => $detailed_count]); // } else { // $mr->updateCounters(['office_detailed_count' => 1]); // } $msc->updateCounters(['office_detailed_count' => 1]); $mr->updateCounters(['office_detailed_count' => 1]); } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MMarketingServiceCenter::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'region_id' => $this->region_id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * This command import office supervision data. * @param string $filename the file to be imported to DB. */ public function actionSupervisor($filename = 'supervisor.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) || trim($line) == '') { continue; } $fields = explode(",", $line); $office_name = trim($fields[0]); $office_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $office_name); $msc_name = trim(trim($fields[1]), "0..9"); $msc_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $msc_name); $region_name = trim(trim($fields[2]), "0..9"); $region_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $region_name); $supervisor_name = trim($fields[3]); $supervisor_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $supervisor_name); $supervisor_mobile = trim(isset($fields[4]) ? $fields[4] : ''); $comment = trim(isset($fields[5]) ? $fields[5] : ''); $comment_utf8 = iconv('GBK', 'UTF-8//IGNORE', $comment); // echo "comment = ".$comment.", comment_utf8 = ".$comment_utf8.PHP_EOL; $need2delete = false; if (mb_strpos($comment_utf8, '删除') === false) { } else { $need2delete = true; } if ($need2delete) { // echo "deleting ......".PHP_EOL; if (!empty($office_name_utf8) && $office_name_utf8 != '') { $office = MOffice::findOne(['title' => $office_name_utf8, 'gh_id' => \app\models\MGh::GH_XIANGYANGUNICOM]); if (!empty($office)) { // 删除督导关系 // echo "deleting supervision relation ...".$office->title.PHP_EOL; yii::$app->db->createCommand()->delete('wx_rel_supervision_staff_office', ['office_id' => $office->office_id])->execute(); // 删除营服所属关系 if (!empty($office->msc)) { // echo "deleting MSC/MR relation ...".$office->title.PHP_EOL; $office->msc->updateCounters(['office_total_count' => -1]); $office->msc->marketingRegion->updateCounters(['office_total_count' => -1]); if ($office->msc->marketingRegion->office_total_count == 0) { $office->msc->marketingRegion->delete(); } if ($office->msc->office_total_count == 0) { $office->msc->delete(); } yii::$app->db->createCommand()->delete('wx_rel_office_msc', ['office_id' => $office->office_id])->execute(); } } } continue; } if (empty($region_name_utf8) || $region_name_utf8 == '') { continue; } $region = MMarketingRegion::findOne(['name' => $region_name_utf8]); if (empty($region)) { // $region = new MMarketingRegion; // $region->name = $region_name_utf8; // $region->save(false); echo "{$region_name_utf8} 不存在。" . PHP_EOL; continue; } if (empty($msc_name_utf8) || $msc_name_utf8 == '') { continue; } $msc = MMarketingServiceCenter::findOne(['name' => $msc_name_utf8]); if (empty($msc)) { // $msc = new MMarketingServiceCenter; // $msc->name = $msc_name_utf8; // $msc->region_id = $region->id; // $msc->save(false); echo "{$msc_name_utf8} 不存在。" . PHP_EOL; continue; } if (empty($office_name_utf8) || $office_name_utf8 == '') { continue; } $office = MOffice::findOne(['title' => $office_name_utf8]); if (empty($office)) { // $office = new MOffice; // $office->gh_id = \app\models\MGh::GH_XIANGYANGUNICOM; // 襄阳联通公共ID // $office->title = $office_name_utf8; // $office->is_jingxiaoshang = 1; // $office->save(false); echo "{$office_name_utf8} 不存在。" . PHP_EOL; continue; } if (empty($office->msc)) { yii::$app->db->createCommand()->insert('wx_rel_office_msc', ['office_id' => $office->office_id, 'msc_id' => $msc->id])->execute(); $msc->updateCounters(['office_total_count' => 1]); $region->updateCounters(['office_total_count' => 1]); } if (empty($supervisor_name_utf8) || $supervisor_name_utf8 == '') { continue; } $staff = MStaff::findOne(['name' => $supervisor_name_utf8, 'gh_id' => \app\models\MGh::GH_XIANGYANGUNICOM]); // if (empty($staff)) { // $staff = new MStaff; // $staff->office_id = 25; // $staff->name = $supervisor_name_utf8; // $staff->gh_id = \app\models\MGh::GH_XIANGYANGUNICOM; // 襄阳联通公共ID // $staff->mobile = $supervisor_mobile; // $staff->cat = 0; // $staff->save(false); // } else if ($staff->mobile != $supervisor_mobile) { // $staff->updateAttributes(['mobile' => $supervisor_mobile]); // 修改员工电话 // } if (empty($staff) && empty($supervisor_mobile)) { echo "{$supervisor_name_utf8} 不在数据库中。" . PHP_EOL; continue; } else { if (empty($staff)) { $staff = new MStaff(); $staff->office_id = 25; $staff->name = $supervisor_name_utf8; $staff->gh_id = \app\models\MGh::GH_XIANGYANGUNICOM; // 襄阳联通公共ID $staff->mobile = $supervisor_mobile; $staff->cat = 0; $staff->save(false); } } if (empty($staff->supervisedOffices) || empty($office->supervisor)) { yii::$app->db->createCommand()->insert('wx_rel_supervision_staff_office', ['office_id' => $office->office_id, 'staff_id' => $staff->staff_id])->execute(); } else { if ($office->supervisor->staff_id != $staff->staff_id) { // 如果旧有的督导关系需要修改,先要删除原督导关系,再重新建立新的督导关系 yii::$app->db->createCommand()->delete('wx_rel_supervision_staff_office', ['office_id' => $office->office_id, 'staff_id' => $office->supervisor->staff_id])->execute(); yii::$app->db->createCommand()->insert('wx_rel_supervision_staff_office', ['office_id' => $office->office_id, 'staff_id' => $staff->staff_id])->execute(); } } } fclose($fh); }
public function getMscs() { return $this->hasMany(MMarketingServiceCenter::className(), ['region_id' => 'id']); }
/** * Finds the MMarketingServiceCenter model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MMarketingServiceCenter the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MMarketingServiceCenter::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionQdxcjspb3($backwards = true, $pop = false) { //$this->layout = 'wap'; $this->layout = false; $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); Yii::$app->wx->setGhId($gh_id); 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); } } $msc_id = $_GET['msc_id']; $msc = MMarketingServiceCenter::findOne(['id' => $msc_id]); $wx_user = \app\models\MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); return $this->render('qdxcjspb3', ['wx_user' => $wx_user, 'gh_id' => $gh_id, 'openid' => $openid, 'msc' => $msc, 'models_office' => $msc->offices, 'backwards' => $backwards]); }
public function getMsc() { return $this->hasOne(MMarketingServiceCenter::className(), ['id' => 'msc_id'])->viaTable('wx_rel_office_msc', ['office_id' => 'office_id']); }