public static function getOfficeNameOptionAll($gh_id, $json = true, $need_prompt = true) { $offices = \app\models\MOffice::find()->where("gh_id = :gh_id", [':gh_id' => $gh_id])->asArray()->orderBy(['title' => SORT_ASC])->all(); $listData = $need_prompt ? ['0' => '全部'] : []; foreach ($offices as $office) { $value = $office['office_id']; $text = $office['title']; $listData[$value] = $text; } return $json ? json_encode($listData) : $listData; }
public function search($params) { $query = MOffice::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['office_id' => SORT_ASC]], 'pagination' => ['pageSize' => 20]]); $this->gh_id = Yii::$app->user->getGhid(); $this->addCondition($query, 'gh_id'); if (!($this->load($params) && $this->validate())) { return $dataProvider; } if (!Yii::$app->user->getIsAdmin()) { $this->office_id = Yii::$app->user->identity->office_id; $this->addCondition($query, 'office_id'); } else { $this->addCondition($query, 'office_id'); } $this->addCondition($query, 'title', true); $this->addCondition($query, 'mobile', true); $this->addCondition($query, 'address', true); $this->addCondition($query, 'manager', true); $this->addCondition($query, 'visable'); $this->addCondition($query, 'is_jingxiaoshang'); return $dataProvider; }
public function actionOutlets() { $outlets = \app\models\ClientOutlet::find()->all(); foreach ($outlets as $outlet) { $office = \app\models\MOffice::find()->where(['title' => $outlet->title])->one(); if (!empty($office)) { echo "found {$outlet->title}" . PHP_EOL; $details = \app\models\MOfficeCampaignDetail::findAll(['office_id' => $office->office_id]); $pics = []; foreach ($details as $detail) { $pic_urls = explode(',', $detail->pic_url); foreach ($pic_urls as $pic_url) { $from = $detail->getPicFileByMedia($pic_url); $media = str_replace('.jpg', '', $pic_url); $to = $outlet->getPicPathname($media); copy($from, $to); $pics[] = $media; } } $outlet->pics = implode(",", $pics); $outlet->original_office_id = $office->office_id; $outlet->latitude = $office->lat; $outlet->longitude = $office->lon; $outlet->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 actionCreateWxGroups() { $gh_id = Yii::$app->wx->getGhid(); $offices = MOffice::find()->where("gh_id = :gh_id AND visable = :visable", [':gh_id' => $gh_id, ':visable' => 1])->asArray()->all(); foreach ($offices as $office) { $office_id = $office['office_id']; $gname = mb_substr($office['title'], 0, 10, 'utf-8'); $arr = Yii::$app->wx->WxGroupCreate(['group' => ['name' => $gname]]); //U::W("{$arr['group']['id']},{$arr['group']['name']}"); $tableName = MGroup::tableName(); Yii::$app->db->createCommand("INSERT INTO {$tableName} (gh_id, gid, gname, office_id) VALUES (:gh_id, :gid, :gname, :office_id)", [':gh_id' => $gh_id, ':gid' => $arr['group']['id'], ':gname' => $gname, ':office_id' => $office_id])->execute(); } }
public function actionQrAllOffices() { $gh_id = 'gh_03a74ac96138'; $total_count = \app\models\MOffice::find()->where(['gh_id' => $gh_id])->count(); $step = 100; $start = 0; while ($start < $total_count) { $offices = \app\models\MOffice::find()->where(['gh_id' => $gh_id])->offset($start)->limit($step)->all(); foreach ($offices as $office) { try { $office->getQrImageUrl2(); } catch (\Exception $e) { U::W([$arr, $e->getMessage()]); sleep(3); //throw new \Exception('error'); } } $start += $step; } /* $offices = \app\models\MOffice::find() ->where('gh_id = :gh_id AND office_id > :office_id1 AND office_id < :office_id2', [':gh_id' => $gh_id, ':office_id1' => 2646, ':office_id2' => 2664]) ->all(); foreach ($offices as $office) { $office->getQrImageUrl2(); } */ echo "导出所有渠道二维码,ok."; }
<?php echo $form->field($model, 'user_name')->textInput(['maxlength' => 10, 'placeholder' => '输入姓名', 'class' => 'form-control input-lg'])->label(false); ?> <?php echo $form->field($model, 'user_contact')->textInput(['maxlength' => 128, 'placeholder' => '输入联系地址及手机号码', 'class' => 'form-control input-lg'])->label(false); ?> <?php echo $form->field($model, 'user_id')->textInput(['maxlength' => 18, 'placeholder' => '输入身份证号码', 'class' => 'form-control input-lg'])->label(false); ?> <select id="office_id" class="form-control input-lg" name="MIphone6Sub[office_id]"> <option value='--'>选择为营业厅</option> <?php $offices = \app\models\MOffice::find()->where(['is_selfOperated' => 1])->all(); foreach ($offices as $office) { ?> <option value='<?php echo $office->title; ?> '><?php echo $office->title; ?> </option> <?php } ?> </select>
public static function getTotalOffices() { $office_ids = (new \yii\db\Query())->select('belongto')->distinct()->from('wx_user')->where('subscribe=1')->column(); $office_ids = array_diff($office_ids, array_merge([0, 491], range(25, 48))); $offices = MOffice::find()->where(['office_id' => $office_ids])->orderBy('title')->all(); return $offices; }
public static function getNearestOffices($gh_id, $lon, $lat) { $key = __METHOD__ . "{$gh_id}_{$lon}_{$lat}"; $value = Yii::$app->cache->get($key); if ($value !== false) { return $value; } $map = new MMapApi(); $rows = MOffice::find()->where(['gh_id' => $gh_id])->asArray()->all(); foreach ($rows as $key => &$row) { if ($row['lon'] < 1) { unset($rows[$key]); continue; } $row['distance'] = $map->getDistance($lon, $lat, $row['lon'], $row['lat']); } unset($row); \yii\helpers\ArrayHelper::multisort($rows, 'distance'); Yii::$app->cache->set($key, $rows, YII_DEBUG ? 10 : 5 * 60); return $rows; }