Example #1
0
 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;
     }
 }
Example #2
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);
         }
     }
 }
Example #3
0
 public function actionGhdelete($id)
 {
     $model = MGh::findOne($id);
     $model->delete();
     return $this->redirect(['ghlist']);
 }