예제 #1
0
 public function search($params)
 {
     $query = MChannel::find();
     // method #1
     //        $query->with('fans');
     // method #2
     //        $query->with(['fans'=>function($query) { $query->andWhere('subscribe=1'); }]);
     // method #3
     $subQuery = MUser::find()->select('gh_id as gh_id_x, scene_pid as scene_pid_x, count(*) as fans_cnt')->where('scene_pid!=0')->groupBy(['gh_id', 'scene_pid']);
     $query->leftJoin(['wx_user' => $subQuery], 'gh_id=gh_id_x AND scene_id = scene_pid_x');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => [], 'attributes' => ['title', 'mobile', 'fansCount' => ['asc' => ['wx_user.fans_cnt' => SORT_ASC], 'desc' => ['wx_user.fans_cnt' => SORT_DESC]]]], 'pagination' => ['pageSize' => 20]]);
     /*        
             if (Yii::$app->user->identity->gh_id == 'root')
                  throw new NotFoundHttpException("Please selected one gh_id for the root first!");
             else if (Yii::$app->user->identity->openid == 'admin')
             {
                 $this->gh_id = Yii::$app->user->identity->gh_id;
                 $this->addCondition($query, 'gh_id');        
             }
     */
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->addCondition($query, 'id');
     $this->addCondition($query, 'title', true);
     $this->addCondition($query, 'mobile', true);
     $query->andFilterWhere(['wx_user.fans_cnt' => $this->fansCount]);
     return $dataProvider;
 }
예제 #2
0
 public function search($params)
 {
     $query = \app\models\MUser::find()->join('INNER JOIN', 'wx_openid_bind_mobile', 'wx_openid_bind_mobile.gh_id = wx_user.gh_id and wx_openid_bind_mobile.openid = wx_user.openid')->where(['wx_user.subscribe' => 1])->orderBy(['wx_user.create_time' => SORT_DESC]);
     $dataProvider = new \yii\data\ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if (!empty($this->page)) {
         $dataProvider->pagination->page = $this->page;
     }
     if (!empty($this->searchStr)) {
         $query->andWhere(['or', ['like', 'wx_user.nickname', $this->searchStr], ['like', 'wx_openid_bind_mobile.mobile', $this->searchStr]]);
     }
     $this->addCondition($query, 'nickname', true);
     if (!empty($this->gh_id)) {
         $query->andWhere(['wx_user.gh_id' => $this->gh_id]);
     }
     if (!empty($this->office_id)) {
         $query->andWhere(['wx_user.belongto' => $this->office_id]);
     }
     $query->andFilterWhere(['like', 'wx_openid_bind_mobile.mobile', $this->mobile]);
     if (trim($this->create_time_start) !== '') {
         $query->andWhere('date(wx_user.create_time)>=:create_time', [':create_time' => $this->create_time_start]);
     }
     if (trim($this->create_time_end) !== '') {
         $query->andWhere('date(wx_user.create_time)<=:create_time_2', [':create_time_2' => $this->create_time_end]);
     }
     return $dataProvider;
 }
예제 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MUser::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     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->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'role' => $this->role, 'usertype' => $this->usertype]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'mobile', $this->mobile])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
예제 #4
0
 public function actionWxuserBelongto()
 {
     $total_count = \app\models\MUser::find()->count();
     $offset = 0;
     $step = 1000;
     while (true) {
         if ($offset > $total_count) {
             break;
         }
         $wx_users = \app\models\MUser::find()->orderBy('id')->offset($offset)->limit($step)->all();
         foreach ($wx_users as $wx_user) {
             //                echo $wx_user->openid.PHP_EOL;
             if ($wx_user->belongto == 0) {
                 $wx_user->belongto = $wx_user->getBelongTo();
                 $wx_user->save(false);
             }
         }
         $offset += $step;
     }
     echo "done with " . $total_count . PHP_EOL;
 }
예제 #5
0
 public function search($params)
 {
     $query = MUser::find();
     $query->joinWith('openidBindMobiles');
     //        $query->select('*');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->gh_id = Yii::$app->user->getGhid();
     $this->addCondition($query, 'wx_user.gh_id');
     if (!Yii::$app->user->getIsAdmin()) {
         $office = Yii::$app->user->identity;
         $scene_ids = $office->getSceneids();
         $query->andWhere(['scene_pid' => $scene_ids]);
     }
     $query->andWhere(['subscribe' => 1]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->addCondition($query, 'id');
     $this->addCondition($query, 'nickname', true);
     $this->addCondition($query, 'status');
     $this->addCondition($query, 'update_time');
     $this->addCondition($query, 'scene_pid');
     $this->addCondition($query, 'is_liantongstaff');
     $query->andFilterWhere(['like', 'wx_openid_bind_mobile.mobile', $this->mobile]);
     if (!empty($this->office_id)) {
         $office = MOffice::findOne($this->office_id);
         if (!empty($office)) {
             $query->andFilterWhere(['scene_pid' => $office->getSceneids()]);
         }
     }
     if (trim($this->create_time) !== '') {
         $query->andWhere('date(wx_user.create_time)>=:create_time', [':create_time' => $this->create_time]);
     }
     if (trim($this->create_time_2) !== '') {
         $query->andWhere('date(wx_user.create_time)<=:create_time_2', [':create_time_2' => $this->create_time_2]);
     }
     return $dataProvider;
 }
예제 #6
0
 protected function onTextOld()
 {
     $openid = $this->getRequest('FromUserName');
     $gh_id = $this->getRequest('ToUserName');
     while (1) {
         $Content = $this->getRequest('Content');
         $msg = trim($Content);
         $state = $this->getState($gh_id, $openid);
         if ($msg == '0' && $state != self::STATE_NONE) {
             U::W('deleteState');
             $this->deleteState($gh_id, $openid);
             return $this->responseText("谢谢,再见!");
         }
         U::W($state);
         switch ($state) {
             case self::STATE_NONE:
                 //if ($msg !== 'Xy')
                 if ($msg == 'New') {
                     $url = Url::to(['wapx/staffsearch', 'gh_id' => $gh_id, 'openid' => $openid], true);
                     return $this->responseText("see my score? <a href=\"{$url}\">click me</a>");
                 } else {
                     if ($msg == '.debug') {
                         $url = Url::to(['wapx/staffsearch', 'gh_id' => $gh_id, 'openid' => $openid], true);
                         return $this->responseText("see my score? <a href=\"{$url}\">click me</a>");
                     }
                 }
                 if ($msg !== 'Xy') {
                     //return Wechat::NO_RESP;
                     $model = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                     $items = array(new RespNewsItem("{$model->nickname}, 欢迎进入襄阳联通官方微信营业厅", '猛戳进入首页!', Url::to('images/metro-intro.jpg', true), Url::to(['wap/home', 'gh_id' => $gh_id, 'openid' => $openid], true)));
                     return $this->responseNews($items);
                 }
                 $model = MStaff::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                 if ($model === null) {
                     $this->setState($gh_id, $openid, self::STATE_MOBILE);
                     return $this->responseText("请输入手机号, 0:退出");
                 } else {
                     if (empty($model->office_id)) {
                         $this->setState($gh_id, $openid, self::STATE_OFFICE);
                         return $this->responseText($this->getOfficePrompt($gh_id));
                     } else {
                         $this->setState($gh_id, $openid, self::STATE_MENU_ONE);
                         return $this->responseText(self::PROMPT_MENU_ONE);
                     }
                 }
                 break;
             case self::STATE_MOBILE:
                 if (!is_numeric($msg) || substr($msg, 0, 1) !== '1' || strlen($msg) != 11) {
                     return $this->responseText("无效的手机号!\n\n" . "请重新输入手机号, 0:退出");
                 }
                 $model = MStaff::findOne(['mobile' => $msg]);
                 if ($model === null) {
                     return $this->responseText("非襄阳联通员工手机号!\n\n" . "请重新输入手机号, 0:退出");
                 }
                 $model->gh_id = $gh_id;
                 $model->openid = $openid;
                 $model->save(false);
                 if (empty($model->office_id)) {
                     $this->setState($gh_id, $openid, self::STATE_OFFICE);
                     $str = $this->getOfficePrompt($gh_id);
                     return $this->responseText("{$model->name},您好!\n,{$str}");
                 } else {
                     $this->setState($gh_id, $openid, self::STATE_MENU_ONE);
                     return $this->responseText(self::PROMPT_MENU_ONE);
                 }
             case self::STATE_OFFICE:
                 //$offices =MOffice::find()->where(['gh_id'=>$gh_id])->asArray()->all();
                 $offices = MOffice::find()->where("gh_id = '{$gh_id}' AND office_id <=25 ")->asArray()->all();
                 $office_ids = [];
                 foreach ($offices as $office) {
                     $office_ids[] = $office['office_id'];
                 }
                 if (!is_numeric($msg) || $msg < 0 || !in_array($msg, $office_ids)) {
                     return $this->responseText("无效的部门号!\n\n" . $this->getOfficePrompt($gh_id));
                 }
                 $model = MStaff::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                 $model->office_id = $msg;
                 $model->save(false);
                 $this->setState($gh_id, $openid, self::STATE_MENU_ONE);
                 return $this->responseText(self::PROMPT_MENU_ONE);
             case self::STATE_CHANGE_MOBILE:
                 if (!is_numeric($msg) || substr($msg, 0, 1) !== '1' || strlen($msg) != 11) {
                     return $this->responseText("无效的手机号!\n\n" . "请重新输入手机号, 0:退出");
                 }
                 $model = MStaff::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                 $model->mobile = $msg;
                 $model->save(false);
                 $this->setState($gh_id, $openid, self::STATE_MENU_ONE);
                 return $this->responseText(self::PROMPT_MENU_ONE);
             case self::STATE_MENU_ONE:
                 if (!is_numeric($msg) || $msg < 0 || $msg > 7) {
                     return $this->responseText("输入无效!\n\n" . self::PROMPT_MENU_ONE);
                 }
                 switch ($msg) {
                     case 1:
                         //U::W('enter 111111');
                         $model = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                         if (empty($model->scene_id)) {
                             $gh = MGh::findOne($gh_id);
                             $scene_id = $gh->newSceneId();
                             $gh->save(false);
                             $model->scene_id = $scene_id;
                             $model->save(false);
                             //U::W("new a scene_id=$scene_id");
                         } else {
                             $scene_id = $model->scene_id;
                             //U::W("old scene_id=$scene_id");
                         }
                         $log_file_path = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'qr' . DIRECTORY_SEPARATOR . "{$gh_id}_{$scene_id}.jpg";
                         //U::W($log_file_path);
                         if (!file_exists($log_file_path)) {
                             $arr = $this->WxgetQRCode($scene_id, true);
                             $url = $this->WxGetQRUrl($arr['ticket']);
                             Wechat::downloadFile($url, $log_file_path);
                         }
                         //$url = Url::to(['wap/aboutqr','name'=>$model->nickname, 'qrurl'=>Yii::$app->getRequest()->baseUrl."/../runtime/qr/{$gh_id}_{$scene_id}.jpg"],true);
                         $url = "http://mp.weixin.qq.com/s?__biz=MzA4ODkwOTYxMA==&mid=203659175&idx=1&sn=0efaf2269fb7ba6a022f5c31d0d5e255#rd";
                         //U::W($url);
                         $msg = ['touser' => $openid, 'msgtype' => 'text', 'text' => ['content' => "如何使用个人的二维码? <a href=\"{$url}\">点击这里...</a>"]];
                         $arr = $this->WxMessageCustomSend($msg);
                         return $this->responseLocalImage('image', $log_file_path);
                     case 2:
                         $model = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                         if ($model->scene_id == 0) {
                             $count = 0;
                         } else {
                             $count = MUser::find()->where(['gh_id' => $gh_id, 'scene_pid' => $model->scene_id])->count();
                         }
                         return $this->responseText("你的推广人数是:{$count}\n\n" . self::PROMPT_MENU_ONE);
                     case 3:
                         $staff = MStaff::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                         if (empty($staff->office_id)) {
                             $this->setState($gh_id, $openid, self::STATE_OFFICE);
                             return $this->responseText($this->getOfficePrompt($gh_id));
                         }
                         $model = MOffice::findOne($staff->office_id);
                         if ($model === null) {
                             $this->setState($gh_id, $openid, self::STATE_OFFICE);
                             $str = $this->getOfficePrompt($gh_id);
                             return $this->responseText("invalid office id\n,{$str}");
                         }
                         if (empty($model->scene_id)) {
                             $gh = MGh::findOne($gh_id);
                             $scene_id = $gh->newSceneId();
                             $gh->save(false);
                             $model->scene_id = $scene_id;
                             $model->save(false);
                             U::W("scene_id={$scene_id}");
                         } else {
                             $scene_id = $model->scene_id;
                         }
                         $log_file_path = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'qr' . DIRECTORY_SEPARATOR . "{$gh_id}_{$scene_id}.jpg";
                         //U::W($log_file_path);
                         if (!file_exists($log_file_path)) {
                             $arr = $this->WxgetQRCode($scene_id, true);
                             $url = $this->WxGetQRUrl($arr['ticket']);
                             Wechat::downloadFile($url, $log_file_path);
                         }
                         //$msg = ['touser'=>$openid, 'msgtype'=>'text', 'text'=>['content'=>'如何使用部门的二维码? <a href="http://baidu.com">点击这里...</a>']];
                         //$url = Url::to(['wap/aboutqr','name'=>$model->title, 'qrurl'=>Yii::$app->getRequest()->baseUrl."/../runtime/qr/{$gh_id}_{$scene_id}.jpg"],true);
                         $url = "http://mp.weixin.qq.com/s?__biz=MzA4ODkwOTYxMA==&mid=203659175&idx=1&sn=0efaf2269fb7ba6a022f5c31d0d5e255#rd";
                         $msg = ['touser' => $openid, 'msgtype' => 'text', 'text' => ['content' => "如何使用部门的二维码? <a href=\"{$url}\">点击这里...</a>"]];
                         $arr = $this->WxMessageCustomSend($msg);
                         return $this->responseLocalImage('image', $log_file_path);
                     case 4:
                         $staff = MStaff::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                         if (empty($staff->office_id)) {
                             $this->setState($gh_id, $openid, self::STATE_OFFICE);
                             return $this->responseText($this->getOfficePrompt($gh_id));
                         }
                         $model = MOffice::findOne($staff->office_id);
                         if ($model === null) {
                             $this->setState($gh_id, $openid, self::STATE_OFFICE);
                             $str = $this->getOfficePrompt($gh_id);
                             return $this->responseText("invalid office id\n,{$str}");
                         }
                         if ($model->scene_id == 0) {
                             $count = 0;
                         } else {
                             $count = MUser::find()->where(['gh_id' => $gh_id, 'scene_pid' => $model->scene_id])->count();
                         }
                         //U::W($user->office_id);
                         //U::W('a1111111111');
                         $staffs = MStaff::find()->where(['gh_id' => $gh_id, 'office_id' => $staff->office_id])->asArray()->all();
                         $openids = [];
                         //U::W($staffs);
                         foreach ($staffs as $staff) {
                             if (!empty($staff['openid'])) {
                                 $openids[] = $staff['openid'];
                             }
                         }
                         if (empty($openids)) {
                             $staff_count = 0;
                         } else {
                             $users = MUser::find()->where(['gh_id' => $gh_id, 'openid' => $openids])->asArray()->all();
                             $scene_ids = [];
                             foreach ($users as $user) {
                                 if ($user['scene_id'] != 0) {
                                     $scene_ids[] = $user['scene_id'];
                                 }
                             }
                             if (empty($scene_ids)) {
                                 $staff_count = 0;
                             } else {
                                 $staff_count = MUser::find()->where(['gh_id' => $gh_id, 'scene_pid' => $scene_ids])->count();
                             }
                         }
                         return $this->responseText("部门所属员工推广人数是:{$staff_count}\n部门推广人数是:{$count}\n\n" . self::PROMPT_MENU_ONE);
                     case 5:
                         $this->setState($gh_id, $openid, self::STATE_CHANGE_MOBILE);
                         return $this->responseText("请重新输入手机号, 0:退出");
                     case 6:
                         $staff = MStaff::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                         $current_office_id = empty($staff->office_id) ? '' : "当前所属部门号:{$staff->office_id}\n";
                         $this->setState($gh_id, $openid, self::STATE_OFFICE);
                         return $this->responseText($current_office_id . $this->getOfficePrompt($gh_id));
                     case 7:
                         $staff = MStaff::findOne(['gh_id' => $gh_id, 'openid' => $openid]);
                         if ($staff !== null) {
                             $staff->openid = '';
                             $staff->save(false);
                             return $this->responseText("成功解除微信号与员工之间的绑定!\n\n" . self::PROMPT_MENU_ONE);
                         } else {
                             return $this->responseText("你不需要解除绑定\n\n" . self::PROMPT_MENU_ONE);
                         }
                     default:
                         return $this->responseText("输入无效!\n\n" . self::PROMPT_MENU_ONE);
                 }
                 return $this->responseText(self::PROMPT_MENU_ONE);
         }
     }
 }
예제 #7
0
파일: MStaff.php 프로젝트: noikiy/wowewe
 public function getFanBoundCount()
 {
     return MUser::find()->joinWith('openidBindMobiles')->where(['wx_user.gh_id' => $this->gh_id, 'scene_pid' => $this->scene_id, 'subscribe' => 1])->andWhere(['not', ['wx_openid_bind_mobile.mobile' => '']])->count();
 }
예제 #8
0
파일: MChannel.php 프로젝트: noikiy/wowewe
 public function getScore()
 {
     if ($this->scene_id == 0) {
         $count = 0;
     } else {
         $count = MUser::find()->where(['gh_id' => $this->gh_id, 'scene_pid' => $this->scene_id, 'subscribe' => 1])->count();
     }
     return $count;
 }
예제 #9
0
 public function getWechat()
 {
     return \app\models\MUser::find()->join('INNER JOIN', 'wx_openid_bind_mobile', 'wx_user.gh_id = wx_openid_bind_mobile.gh_id and wx_user.openid = wx_openid_bind_mobile.openid')->where(['in', 'wx_openid_bind_mobile.mobile', $this->mobiles])->andWhere(['subscribe' => 1])->one();
 }
예제 #10
0
 public function actionSetMemberFlag()
 {
     $gh_id = MGh::GH_XIANGYANGUNICOM;
     $total_count = MUser::find()->where(['gh_id' => $gh_id, 'subscribe' => 1])->count();
     $step = 500;
     $start = 0;
     while ($start < $total_count) {
         $users = MUser::find()->offset($start)->limit($step)->where(['gh_id' => $gh_id, 'subscribe' => 1])->orderBy(['id' => SORT_ASC])->all();
         foreach ($users as $user) {
             //if($user->id < 41674)  continue;
             $member = OpenidBindMobile::findOne(['openid' => $user->openid]);
             if (!empty($member)) {
                 echo "User #ID\t" . $user->id . "\t" . "会员\n";
                 $user->is_member = 1;
                 $user->save(false);
             } else {
                 echo "User #ID\t" . $user->id . "\t" . "非会员\n";
             }
         }
         $start += $step;
     }
 }
예제 #11
0
 public function actionFsglchaxunajax()
 {
     $office_id = $_GET['office_id'];
     $searchStr = $_GET['searchStr'];
     //$searchStr = $_GET['searchStr'];
     /*
             $uid   = $_GET['uid'];
     
             $user_account = \app\models\MUserAccount::findOne(['id' => $uid]);
             if (empty($user_account)) return json_encode(['code' => 0]);
             if (
             $user_account->cat    != \app\models\MUserAccount::CAT_CREDIT_CHARGE_MOBILE ||
             $user_account->status != \app\models\MUserAccount::STATUS_CHARGE_REQUEST
             ) {
             return json_encode(['code' => -1]);
             }
             P
             $user_account->delete();
     */
     //        $data = MStaff::find()->select('*')->where(['office_id'=>$office_id])->andFilterWhere(['like', 'name', $searchStr])->asArray()->all();
     $data = MUser::find()->select('*')->orFilterWhere(['like', 'nickname', $searchStr])->orFilterWhere(['like', 'mobile', $searchStr])->orFilterWhere(['like', 'create_time', $searchStr])->andWhere(['belongto' => $office_id])->asArray()->all();
     return json_encode(['code' => 0, 'data' => $data]);
 }
예제 #12
0
 public function actionFans($filename = 'fans.csv')
 {
     $filepathname = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'exported_data' . DIRECTORY_SEPARATOR . $filename;
     $fh = fopen($filepathname, 'w');
     // if (null === $date) {
     //     $date = \app\models\U::getFirstDate(date('Y'), date('m'));
     // }
     $total_count = \app\models\MUser::find()->count();
     $step = 3000;
     $start = 0;
     while ($start < $total_count) {
         $fans = \app\models\MUser::find()->offset($start)->limit($step)->all();
         foreach ($fans as $fan) {
             fprintf($fh, "%s, %s, %s, %s, %s, %s\n", $fan->nickname, $fan->country, $fan->province, $fan->city, implode(';', $fan->bindMobileNumbers), date('Y-m-d H:i:s', $fan->subscribe_time));
         }
         $start += $step;
     }
     fclose($fh);
 }
예제 #13
0
파일: MOffice.php 프로젝트: noikiy/wowewe
 public function getWechatFanCount()
 {
     return \app\models\MUser::find()->where(['gh_id' => $this->gh_id, 'belongto' => $this->office_id, 'subscribe' => 1])->count();
 }
예제 #14
0
파일: MOffice.php 프로젝트: noikiy/wowewe
 public function getScore()
 {
     $officeStaff = $this->getOfficeStaff();
     if (empty($officeStaff)) {
         return 0;
     }
     $count = MUser::find()->where(['gh_id' => $this->gh_id, 'scene_pid' => $officeStaff->scene_id, 'subscribe' => 1])->count();
     return $count;
 }