示例#1
0
 public function getClient()
 {
     return \app\models\WosoClient::findOne(['client_id' => $this->client_id]);
 }
示例#2
0
 public function actionAgent($filename = 'agent.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)) {
         $contact_person = trim($fields[0]);
         $contact_person_utf8 = iconv('GBK', 'UTF-8//IGNORE', $contact_person);
         $msc_brev_name = trim($fields[1]);
         $msc_brev_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $msc_brev_name);
         $title = trim($fields[2]);
         $title_utf8 = iconv('GBK', 'UTF-8//IGNORE', $title);
         $mobiles = explode(';', trim($fields[3]));
         //            echo "{$contact_person_utf8},{$msc_brev_name_utf8},{$title_utf8},{$fields[3]}".PHP_EOL;
         $supervision_organization = \app\models\ClientOrganization::find()->where(['like', 'title', $msc_brev_name_utf8])->andWhere(['client_id' => $xyunicom->client_id])->one();
         //            $supervision_organization = \Yii::$app->db->createCommand('select * from client_organization where title like \'%:title%\'')
         //                    ->bindValue(':title', $msc_brev_name_utf8)->queryOne();
         if (empty($supervision_organization)) {
             die("找不到{$msc_brev_name_utf8}");
         }
         //            var_dump($supervision_organization);
         $row = false;
         foreach ($mobiles as $mobile) {
             $mobile = trim($mobile);
             $row = (new \yii\db\Query())->select('*')->from('client_agent')->join('INNER JOIN', 'client_agent_mobile', ['client_agent.agent_id' => 'client_agent_mobile.agent_id'])->where(['name' => $contact_person_utf8, 'mobile' => $mobile])->one();
             if (false !== $row) {
                 break;
             }
         }
         if (false !== $row) {
             $agent = \app\models\ClientAgent::findOne(['agent_id' => $row['agent_id']]);
         } else {
             $agent = new \app\models\ClientAgent();
             $agent->name = $contact_person_utf8;
             $agent->save(false);
         }
         $outlet = \app\models\ClientOutlet::findOne(['title' => $title_utf8]);
         if (empty($outlet)) {
             $outlet = new \app\models\ClientOutlet();
             $outlet->title = $title_utf8;
             $outlet->client_id = $xyunicom->client_id;
             $outlet->telephone = $fields[3];
             $outlet->category = \app\models\ClientOutlet::CATEGORY_COOPERATED;
             $outlet->supervison_organization_id = $supervision_organization->organization_id;
             $outlet->save(false);
         } else {
             $outlet->client_id = $xyunicom->client_id;
             $outlet->telephone = $fields[3];
             $outlet->category = \app\models\ClientOutlet::CATEGORY_COOPERATED;
             $outlet->supervison_organization_id = $supervision_organization->organization_id;
             $outlet->save(false);
         }
         $row = (new \yii\db\Query())->select('*')->from('client_agent_outlet')->where(['agent_id' => $agent->agent_id, 'outlet_id' => $outlet->outlet_id])->one();
         if (false === $row) {
             \Yii::$app->db->createCommand()->insert('client_agent_outlet', ['agent_id' => $agent->agent_id, 'outlet_id' => $outlet->outlet_id, 'position' => '店主'])->execute();
         }
         foreach ($mobiles as $mobile) {
             if (strlen($mobile) != 11 || !is_numeric($mobile)) {
                 echo "[{$mobile}]非手机号码." . PHP_EOL;
             } else {
                 $row = (new \yii\db\Query())->select('*')->from('client_agent_mobile')->where(['mobile' => $mobile])->one();
                 if (false === $row) {
                     \Yii::$app->db->createCommand()->insert('client_agent_mobile', ['agent_id' => $agent->agent_id, 'mobile' => $mobile])->execute();
                 }
             }
         }
     }
     fclose($fh);
 }
示例#3
0
 public function getClient()
 {
     return $this->hasOne(\app\models\WosoClient::className(), ['client_id' => 'client_id']);
 }