public function search($params) { $query = MGh::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['create_time' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->addCondition($query, 'gh_id', true); return $dataProvider; }
public static function refreshAccessToken() { $tableName = MGh::tableName(); $gh_ids = Yii::$app->db->createCommand("SELECT gh_id FROM {$tableName}")->queryColumn(); foreach ($gh_ids as $gh_id) { Yii::$app->wx->clearGh(); Yii::$app->wx->setGhId($gh_id); //U::W(['old', $gh_id, Yii::$app->wx->getAccessToken()]); Yii::$app->wx->getAccessToken(true); //U::W(['new', $gh_id, Yii::$app->wx->getAccessToken()]); } }
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 getGh() { return $this->hasOne(MGh::className(), ['gh_id' => 'gh_id']); }
public static function addRecommendFanAmount($date_start, $date_end) { U::W(__METHOD__ . " BEGIN from {$date_start}, {$date_end}"); // $tableName = MSceneDay::tableName(); $ghs = MGh::find()->all(); foreach ($ghs as $gh) { if ($gh->gh_id !== MGh::GH_XIANGYANGUNICOM) { continue; } foreach ($gh->staffs as $staff) { if ($staff->scene_id != 0 && ($staff->cat == MStaff::SCENE_CAT_OUT || $staff->cat == MStaff::SCENE_CAT_FAN) && !empty($staff->openid)) { $real_score = MAccessLog::getRealScoreByRange($gh->gh_id, $staff->scene_id, $date_start, $date_end); if ($real_score > 0) { //$amount = intval($real_score) * 100; //$amount = intval($real_score/3) * 500; $amount = intval($real_score) * 500; if ($amount > 0) { $model = new MUserAccount(); $model->gh_id = $staff->gh_id; $model->openid = $staff->openid; $model->scene_id = $staff->scene_id; $model->cat = MUserAccount::CAT_DEBIT_FAN; $model->amount = $amount; $model->memo = '推荐有礼'; $model->save(false); // U::W("SAVE OK, scene_id={$staff->scene_id}, openid={$staff->openid}, amount={$model->amount}"); } } else { // U::W("scene_id={$staff->scene_id}, openid={$staff->openid}, realscore={$real_score}, "); } } else { // U::W("scene_id={$staff->scene_id}, openid={$staff->openid}"); } } } U::W(__METHOD__ . " END"); return; }
public function beforeDelete() { if (parent::beforeDelete()) { if (!empty($this->scene_id)) { $gh = MGh::findOne($this->gh_id); $gh->freeSceneId($this->scene_id); return $gh->save(false); } return true; } else { return false; } }
public function actionGhdelete($id) { $model = MGh::findOne($id); $model->delete(); return $this->redirect(['ghlist']); }
public function getGh() { if ($this->_gh !== null) { return $this->_gh; } if (empty($this->_gh_id) && empty($this->_appid)) { U::W(debug_backtrace()); U::D("gh_id and appid can can not be empty at the same time!"); } $db = \Yii::$app->db; $tableName = \app\models\MGh::tableName(); if (!empty($this->_gh_id)) { $command = $db->createCommand("SELECT * FROM {$tableName} WHERE gh_id=:gh_id", [':gh_id' => $this->_gh_id]); } else { $command = $db->createCommand("SELECT * FROM {$tableName} WHERE appid=:appid", [':appid' => $this->_appid]); } //$db->beginCache(YII_DEBUG ? 10 : 3600); $row = $command->queryOne(); //$db->endCache(); if ($row === false) { U::D("no exists in db!, gh_id={$this->_gh_id}, appid={$this->_appid}"); } $this->_gh = $row; return $row; }
echo $form->field($model, 'digest')->textInput(['maxlength' => 256]); ?> <!-- <iframe align=middle marginwidth=0 marginheight=0 src="./wosotech-edit/index.html" frameborder=no scrolling=yes width=960 height=600></iframe> --> <?php echo $form->field($model, 'content')->widget(Widget::className(), ['settings' => ['lang' => 'zh_cn', 'minHeight' => 200, 'maxHeight' => 400, 'buttonSource' => true, 'convertDivs' => false, 'removeEmptyTags' => false, 'plugins' => ['clips', 'fullscreen', 'fontcolor', 'fontfamily', 'fontsize', 'limiter', 'table', 'textexpander', 'textdirection', 'video', 'definedlinks', 'filemanager', 'imagemanager'], 'imageManagerJson' => Url::to(['/article/imagesget']), 'imageUpload' => Url::to(['/article/imageupload'])]]); ?> <?php echo $form->field($model, 'content_source_url')->textInput(['maxlength' => 256]); ?> <?php echo $form->field($model, 'show_cover_pic')->dropDownList(MGh::getNoYesOptionName()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>