Example #1
0
 public function deleteAgent($agent_id)
 {
     \Yii::$app->db->createCommand()->delete('client_agent_outlet', ['agent_id' => $agent_id, 'outlet_id' => $this->outlet_id])->execute();
     $agent = \app\models\ClientAgent::findOne(['agent_id' => $agent_id]);
     if (empty($agent->outlets)) {
         return $agent->delete();
     }
     return true;
 }
Example #2
0
 public function actionClientAgent($gh_id, $openid, $agent_id, $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]);
     $agent = \app\models\ClientAgent::findOne(['agent_id' => $agent_id]);
     $this->layout = false;
     return $this->render('client-agent', ['wx_user' => $wx_user, 'agent' => $agent, 'backwards' => $backwards]);
 }
Example #3
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);
 }
Example #4
0
 public function actionYggl2()
 {
     $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('yggl2', ['entity' => $entity, 'is_agent' => $is_agent, 'outlet' => $outlet]);
 }