public function getPromoter($gh_id) { $promoter = \app\models\MStaff::find()->where(['name' => $this->name, 'gh_id' => $gh_id])->andWhere(['in', 'mobile', $this->mobiles])->one(); if (empty($promoter)) { $promoter = new \app\models\MStaff(); $promoter->name = $this->name; $promoter->mobile = !empty($this->mobiles) ? $this->mobiles[0] : ''; $promoter->gh_id = $gh_id; $promoter->cat = \app\models\MStaff::SCENE_CAT_IN; $promoter->save(false); } return $promoter; }
public function search($params) { $query = MStaff::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['staff_id' => SORT_ASC]], 'pagination' => ['pageSize' => 20]]); $this->gh_id = Yii::$app->user->getGhid(); $this->addCondition($query, 'gh_id'); if (!Yii::$app->user->getIsAdmin()) { $this->office_id = Yii::$app->user->identity->office_id; $this->addCondition($query, 'office_id'); } $this->addCondition($query, 'cat'); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->addCondition($query, 'office_id'); $this->addCondition($query, 'cat'); $this->addCondition($query, 'name', true); $this->addCondition($query, 'mobile', true); $this->addCondition($query, 'is_manager'); 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); } }
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); } } }
public function getPromoter($gh_id) { if (empty($this->original_office_id)) { $office = new \app\models\MOffice(); $office->title = $this->title; $office->gh_id = $gh_id; $office->save(false); $this->updateAttributes(['original_office_id' => $office->office_id]); } $promoter = \app\models\MStaff::find()->where(['office_id' => $this->original_office_id, 'gh_id' => $gh_id, 'cat' => \app\models\MStaff::SCENE_CAT_OFFICE])->one(); if (empty($promoter)) { $promoter = new \app\models\MStaff(); $promoter->name = $this->title; $promoter->office_id = $this->original_office_id; $promoter->gh_id = $gh_id; $promoter->cat = \app\models\MStaff::SCENE_CAT_OFFICE; $promoter->save(false); } return $promoter; }
public static function newSceneId($gh_id) { $staffs = MStaff::find()->where("gh_id = :gh_id AND scene_id != 0", [':gh_id' => $gh_id])->asArray()->all(); if (empty($staffs)) { return 1; } $scene_ids = \yii\helpers\ArrayHelper::getColumn($staffs, 'scene_id'); if (count($scene_ids) >= 100000) { U::W([__METHOD__, 'not find avail scene_id']); return false; } while (true) { $i = rand(1, 100000); if (!in_array($i, $scene_ids)) { return $i; } } // just for test, hbhe // for ($i=1; $i<10000; $i++) // { // if (!in_array($i, $scene_ids)) { // return $i; // } // } }
public function actionSetLiantongFlag() { $gh_id = Yii::$app->wx->getGhid(); $models = MStaff::find()->where("gh_id = :gh_id AND openid != '' ", [':gh_id' => $gh_id])->asArray()->all(); foreach ($models as $model) { $gh_id = $model['gh_id']; $openid = $model['openid']; $user = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); if ($user !== null && $user->is_liantongstaff == 0) { $user->is_liantongstaff = 1; $user->save(false); } } }
public function actionYgglchaxunajax() { $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 = MStaff::find()->select('*')->orFilterWhere(['like', 'name', $searchStr])->orFilterWhere(['like', 'mobile', $searchStr])->andWhere(['office_id' => $office_id, 'cat' => MStaff::SCENE_CAT_IN])->asArray()->all(); //U::W("+++++++++++++++++++++++"); //U::W($data); return json_encode(['code' => 0, 'data' => $data]); }
public function actionStaffScoreTop($date1 = null, $date2 = null) { $gh_id = 'gh_03a74ac96138'; $total_count = \app\models\MStaff::find()->where(['gh_id' => $gh_id])->count(); $step = 300; $start = 0; if ($date1 == null || $date2 == null) { echo "\n例子: php yii export/staff-score-range 2015-7-1 2015-7-31\n"; echo "需要输入起始和结束日期!\n\n"; exit; } $date_start = date('Y-m-d', strtotime($date1)) . " 00:00:00"; $date_end = date('Y-m-d', strtotime($date2)) . " 23:59:59"; echo "-----------------------------------------------------\n"; echo " STAFF SCORE BY RANGE \n"; echo " " . $date_start . " 至 " . $date_end . "\n"; echo "-----------------------------------------------------\n"; echo "推广者,手机号码,推广成绩\n"; while ($start < $total_count) { $staffs = \app\models\MStaff::find()->where(['gh_id' => $gh_id, 'cat' => 0])->offset($start)->limit($step)->all(); foreach ($staffs as $staff) { //$office->getQrImageUrl2(); if ($staff->getMemberScoreByRange($date1, $date2) == 0) { continue; } echo $staff->name . "," . $staff->mobile . "," . $staff->getMemberScoreByRange($date1, $date2) . "\n"; } $start += $step; } echo "-----------------------------------------------\nok.\n\n"; }
public function getNormalStaffs() { return MStaff::find()->where("office_id = :office_id AND cat != :cat", [':office_id' => $this->office_id, ':cat' => MStaff::SCENE_CAT_OFFICE])->all(); }