/** * Lists all ClientEmployee models. * @return mixed */ public function actionIndex() { $searchModel = new ClientEmployeeSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); if (isset($_GET['download'])) { $datetime_start = str_replace('\'', '', $_GET['datetime_start']); $datetime_end = str_replace('\'', '', $_GET['datetime_end']); $filename = Yii::$app->getRuntimePath() . "/员工会员推广排行榜-" . $datetime_start . '到' . $datetime_end . '.csv'; $fh = fopen($filename, 'w'); fprintf($fh, "排名,会员推广数量,员工姓名,电话,营业厅" . PHP_EOL); $i = 1; \Yii::warning('yjhu:' . $datetime_start); $rows = \app\models\MUser::getMemberPromotionTopList(0, 5000, $datetime_start . ' 00:00:00', $datetime_end . ' 23:59:59'); foreach ($rows as $row) { $staff = \app\models\MStaff::findOne(['scene_id' => $row['scene_pid']]); fprintf($fh, $i++ . ','); fprintf($fh, $row['members'] . ','); fprintf($fh, $staff->name . ','); fprintf($fh, $staff->mobile . ','); fprintf($fh, (empty($staff->office) ? '' : $staff->office->title) . PHP_EOL); } fclose($fh); Yii::$app->response->sendFile($filename); return; } return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
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 actionClientOrder($gh_id, $openid, $backwards = true, $pop = false) { if (!$backwards) { \app\models\utils\BrowserHistory::delete($gh_id, $openid); \app\models\utils\BrowserHistory::push($gh_id, $openid); } else { if ($pop) { \app\models\utils\BrowserHistory::pop($gh_id, $openid); } else { \app\models\utils\BrowserHistory::push($gh_id, $openid); } } $wx_user = \app\models\MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); $this->layout = false; $office_id = $_GET['office_id']; $office = MOffice::findOne(['office_id' => $office_id]); $staff_id = $_GET['staff_id']; $staff = MStaff::findOne(['staff_id' => $staff_id]); $oid = $_GET['oid']; $order = MOrder::findOne(['oid' => $oid]); return $this->render('client-order', ['wx_user' => $wx_user, 'backwards' => $backwards, 'office' => $office, 'staff' => $staff, 'order' => $order]); }
echo $form->field($model, 'office_id')->hiddenInput(['value' => Yii::$app->user->identity->office_id])->label(false); ?> <?php } ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => 24]); ?> <?php echo $form->field($model, 'mobile')->textInput(['maxlength' => 24]); ?> <?php echo $form->field($model, 'cat')->dropDownList(MStaff::getStaffCatOptionName()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? '增加' : '修改', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div> </div>
</div> <div data-role="page" id="dialog_staff_qr" data-dialog="true"> <div data-role="header"><h1>我的推广二维码</h1></div> <div role="main" class="ui-content"> <?php // echo Html::img($user->getQrImageUrl(), ['style'=>'display: block;max-width:100%;height: auto;']); echo Html::img($model->getQrImageUrl(), ['style' => 'display: block;max-width:100%;height: auto;']); ?> </div> </div> <div data-role="dialog" id="staffhome_stafftop"> <?php $rows = MStaff::getStaffScoreTop($user->gh_id, 10); ?> <div data-role="header"><h1>明星员工</h1></div> <div role="main" class="ui-content"> <ul data-role="listview" data-count-theme="b" data-inset="true"> <?php foreach ($rows as $row) { ?> <li> <img src="<?php echo U::getUserHeadimgurl($row['headimgurl'], 64); ?> "> <h2><?php echo $row['name']; ?>
public function getBelongTo() { if ($this->scene_pid == 0) { return 0; } $staff = MStaff::findOne(['gh_id' => $this->gh_id, 'scene_id' => $this->scene_pid]); if (empty($staff)) { return 0; } if ($staff->cat == MStaff::SCENE_CAT_OFFICE || $staff->cat == MStaff::SCENE_CAT_IN) { return $staff->office_id; } $wx_user = $staff->user; if (empty($wx_user)) { return 0; } if ($wx_user->scene_pid == $staff->scene_id) { return 0; } // if ($wx_user->belongto) return $wx_user->belongto; // return $wx_user->getBelongTo(); }
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); } } }
/** * This command import office supervision data. * @param string $filename the file to be imported to DB. */ public function actionSupervisor($filename = 'supervisor.csv') { $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'imported_data' . DIRECTORY_SEPARATOR . $filename; $fh = fopen($file, "r"); $i = 0; while (!feof($fh)) { $line = fgets($fh); $i++; if (empty($line) || trim($line) == '') { continue; } $fields = explode(",", $line); $office_name = trim($fields[0]); $office_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $office_name); $msc_name = trim(trim($fields[1]), "0..9"); $msc_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $msc_name); $region_name = trim(trim($fields[2]), "0..9"); $region_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $region_name); $supervisor_name = trim($fields[3]); $supervisor_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $supervisor_name); $supervisor_mobile = trim(isset($fields[4]) ? $fields[4] : ''); $comment = trim(isset($fields[5]) ? $fields[5] : ''); $comment_utf8 = iconv('GBK', 'UTF-8//IGNORE', $comment); // echo "comment = ".$comment.", comment_utf8 = ".$comment_utf8.PHP_EOL; $need2delete = false; if (mb_strpos($comment_utf8, '删除') === false) { } else { $need2delete = true; } if ($need2delete) { // echo "deleting ......".PHP_EOL; if (!empty($office_name_utf8) && $office_name_utf8 != '') { $office = MOffice::findOne(['title' => $office_name_utf8, 'gh_id' => \app\models\MGh::GH_XIANGYANGUNICOM]); if (!empty($office)) { // 删除督导关系 // echo "deleting supervision relation ...".$office->title.PHP_EOL; yii::$app->db->createCommand()->delete('wx_rel_supervision_staff_office', ['office_id' => $office->office_id])->execute(); // 删除营服所属关系 if (!empty($office->msc)) { // echo "deleting MSC/MR relation ...".$office->title.PHP_EOL; $office->msc->updateCounters(['office_total_count' => -1]); $office->msc->marketingRegion->updateCounters(['office_total_count' => -1]); if ($office->msc->marketingRegion->office_total_count == 0) { $office->msc->marketingRegion->delete(); } if ($office->msc->office_total_count == 0) { $office->msc->delete(); } yii::$app->db->createCommand()->delete('wx_rel_office_msc', ['office_id' => $office->office_id])->execute(); } } } continue; } if (empty($region_name_utf8) || $region_name_utf8 == '') { continue; } $region = MMarketingRegion::findOne(['name' => $region_name_utf8]); if (empty($region)) { // $region = new MMarketingRegion; // $region->name = $region_name_utf8; // $region->save(false); echo "{$region_name_utf8} 不存在。" . PHP_EOL; continue; } if (empty($msc_name_utf8) || $msc_name_utf8 == '') { continue; } $msc = MMarketingServiceCenter::findOne(['name' => $msc_name_utf8]); if (empty($msc)) { // $msc = new MMarketingServiceCenter; // $msc->name = $msc_name_utf8; // $msc->region_id = $region->id; // $msc->save(false); echo "{$msc_name_utf8} 不存在。" . PHP_EOL; continue; } if (empty($office_name_utf8) || $office_name_utf8 == '') { continue; } $office = MOffice::findOne(['title' => $office_name_utf8]); if (empty($office)) { // $office = new MOffice; // $office->gh_id = \app\models\MGh::GH_XIANGYANGUNICOM; // 襄阳联通公共ID // $office->title = $office_name_utf8; // $office->is_jingxiaoshang = 1; // $office->save(false); echo "{$office_name_utf8} 不存在。" . PHP_EOL; continue; } if (empty($office->msc)) { yii::$app->db->createCommand()->insert('wx_rel_office_msc', ['office_id' => $office->office_id, 'msc_id' => $msc->id])->execute(); $msc->updateCounters(['office_total_count' => 1]); $region->updateCounters(['office_total_count' => 1]); } if (empty($supervisor_name_utf8) || $supervisor_name_utf8 == '') { continue; } $staff = MStaff::findOne(['name' => $supervisor_name_utf8, 'gh_id' => \app\models\MGh::GH_XIANGYANGUNICOM]); // if (empty($staff)) { // $staff = new MStaff; // $staff->office_id = 25; // $staff->name = $supervisor_name_utf8; // $staff->gh_id = \app\models\MGh::GH_XIANGYANGUNICOM; // 襄阳联通公共ID // $staff->mobile = $supervisor_mobile; // $staff->cat = 0; // $staff->save(false); // } else if ($staff->mobile != $supervisor_mobile) { // $staff->updateAttributes(['mobile' => $supervisor_mobile]); // 修改员工电话 // } if (empty($staff) && empty($supervisor_mobile)) { echo "{$supervisor_name_utf8} 不在数据库中。" . PHP_EOL; continue; } else { if (empty($staff)) { $staff = new MStaff(); $staff->office_id = 25; $staff->name = $supervisor_name_utf8; $staff->gh_id = \app\models\MGh::GH_XIANGYANGUNICOM; // 襄阳联通公共ID $staff->mobile = $supervisor_mobile; $staff->cat = 0; $staff->save(false); } } if (empty($staff->supervisedOffices) || empty($office->supervisor)) { yii::$app->db->createCommand()->insert('wx_rel_supervision_staff_office', ['office_id' => $office->office_id, 'staff_id' => $staff->staff_id])->execute(); } else { if ($office->supervisor->staff_id != $staff->staff_id) { // 如果旧有的督导关系需要修改,先要删除原督导关系,再重新建立新的督导关系 yii::$app->db->createCommand()->delete('wx_rel_supervision_staff_office', ['office_id' => $office->office_id, 'staff_id' => $office->supervisor->staff_id])->execute(); yii::$app->db->createCommand()->insert('wx_rel_supervision_staff_office', ['office_id' => $office->office_id, 'staff_id' => $staff->staff_id])->execute(); } } } fclose($fh); }
public function actionHeatmapsdownload() { $searchModel = new HeatMapSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->setPagination(false); $data = $dataProvider->getModels(); $rows = []; foreach ($data as $model) { $row['openid'] = $model->openid; $row['nickname'] = $model->user->nickname; $staff = MStaff::findOne(['gh_id' => $model->gh_id, 'scene_id' => $model->user->scene_pid]); if ($staff->cat == 0) { $row['scene_pid_name'] = empty($staff->name) ? '' : $staff->name; $row['scene_pid_office'] = empty($staff->office->title) ? '' : $staff->office->title; $row['scene_pid_cat'] = '内部员工'; } else { $row['scene_pid_name'] = empty($staff->name) ? '' : $staff->name; $row['scene_pid_office'] = '-'; $row['scene_pid_cat'] = '-'; } //$row['user_account_charge_mobile'] = $model->user->user_account_charge_mobile; if (empty($model->user)) { //return ''; $row['user_account_charge_mobile'] = ''; } else { $mobiles = $model->user->getBindMobileNumbers(); //return empty($mobiles) ? '' : implode(',', $mobiles); $row['user_account_charge_mobile'] = empty($mobiles) ? '' : implode(',', $mobiles); } $row['create_time'] = $model->create_time; if ($model->status == 0) { $row['status'] = '有效'; } else { $row['status'] = '无效'; } $rows[] = $row; } $data = $rows; $filename = Yii::$app->getRuntimePath() . '/heatmaps.csv'; $csv = new \app\models\ECSVExport($data); $attributes = ['openid', 'nickname', 'scene_pid_name', 'scene_pid_office', 'scene_pid_cat', 'user_account_charge_mobile', 'create_time', 'status']; $csv->setInclude($attributes); $csv->setHeaders(['openid' => 'openid', 'nickname' => '昵称', 'scene_pid_name' => '粉丝来源', 'scene_pid_office' => '粉丝来源所属部门', 'scene_pid_cat' => '粉丝来源类别', 'user_account_charge_mobile' => '手机号码', 'create_time' => '创建时间', 'status' => '是否有效']); $csv->toCSV($filename); Yii::$app->response->sendFile($filename); return; }
public function getStaff() { return $this->hasOne(MStaff::className(), ['gh_id' => 'gh_id', 'scene_id' => 'scene_id']); }
public function actionFsgl1() { //$this->layout = 'wap'; $this->layout = false; // $gh_id = U::getSessionParam('gh_id'); // $openid = U::getSessionParam('openid'); $staff_id = $_GET['staff_id']; $staff = MStaff::findOne(['staff_id' => $staff_id]); $office = $staff->office; return $this->render('fsgl1', ['office' => $office, 'staff' => $staff]); }
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"; }
<span class="caption-helper"> 员工会员推广 </span> </div> <div class="actions"> <a href="javascript:;" class="btn btn-sm btn-circle btn-default" id="member-promotion-download"> <i class="fa fa-download"></i> 下载 </a> </div> </div> <div class="portlet-body"> <ul class="feeds" id="member-promotion-top-list"> <?php $rows = \app\models\MUser::getMemberPromotionTopList(0, 20); foreach ($rows as $row) { $staff = \app\models\MStaff::findOne(['scene_id' => $row['scene_pid']]); $employee = $staff->clientEmployee; ?> <li> <div class="col1"> <div class="cont"> <div class="cont-col1"> <div> <img style="width:32px;height:32px" src="<?php echo $staff->user->headImgUrl; ?> " /> </div> </div> <div class="cont-col2"> <div class="desc">
?> <div class="heat-map-index"> <p> <?php echo Html::a('下载 <span class="glyphicon glyphicon-arrow-down"></span>', ['heatmapsdownload'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['label' => '微信昵称', 'value' => function ($model, $key, $index, $column) { return empty($model->user) ? '' : $model->user->nickname; }], ['label' => '粉丝来源', 'value' => function ($model, $key, $index, $column) { if (empty($model->user->scene_pid)) { return ''; } $staff = MStaff::findOne(['gh_id' => $model->gh_id, 'scene_id' => $model->user->scene_pid]); if (empty($staff)) { return ''; } if ($staff->cat == 0) { return empty($staff->name) ? '' : $staff->name . '-' . $staff->office->title . '-' . '内部员工'; } else { return empty($staff->name) ? '' : $staff->name; } }], ['label' => '手机号', 'value' => function ($model, $key, $index, $column) { if (empty($model->user)) { return ''; } $mobiles = $model->user->getBindMobileNumbers(); return empty($mobiles) ? '' : implode(',', $mobiles); }], 'lon', 'lat', 'speed_up', 'speed_down', 'create_time', ['label' => '图片大小', 'value' => function ($model, $key, $index, $column) {
public function actionStafftop() { $rows = MStaff::getStaffScoreTop(Yii::$app->user->getGhid()); $dataProvider = new ArrayDataProvider(['allModels' => $rows, 'sort' => ['attributes' => ['score', 'name', 'mobile']], 'pagination' => ['pageSize' => 50]]); return $this->render('stafftop', ['dataProvider' => $dataProvider]); }
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 getStaff() { return $this->hasOne(MStaff::className(), ['staff_id' => 'staff_id']); }
//return ''; if (empty($model->openid)) { //$wxbind_info = "微信未绑定"; return "<img width=48 src='/wx/web/images/wxmpres/headimg-nowx-blank.png' title='微信未绑定'>"; } else { $mobiles = $model->user->getBindMobileNumbers(); $mobile = empty($mobiles) ? '无' : $mobiles[0]; if (empty($model->user->headimgurl)) { return "<img style='float:left;' width=48 src='/wx/web/images/wxmpres/headimg-blank.png'> <span style='color:#aaa'>昵称 " . $model->user->nickname . "<br> 地区 " . $model->user->country . " " . $model->user->province . " " . $model->user->city . "<br> 绑定手机 " . $mobile . "</span>"; } else { return "<img style='float:left;' width=48 src=" . $model->user->headimgurl . "> <span style='color:#aaa'>昵称 " . $model->user->nickname . "<br> 地区 " . $model->user->country . " " . $model->user->province . " " . $model->user->city . "<br> 绑定手机 " . $mobile . "</span>"; } } }, 'headerOptions' => array('style' => 'width:24%;')], ['attribute' => 'scene_id', 'visible' => false], ['attribute' => 'cat', 'value' => function ($model, $key, $index, $column) { return MStaff::getStaffCatOptionName($model->cat); }, 'filter' => MStaff::getStaffCatOptionName(), 'visible' => false], ['label' => '二维码', 'format' => 'raw', 'value' => function ($model, $key, $index, $column) { //return Html::img($model->getQrImageUrl(), ['width'=>'32'])."<a class='/wx/imges/wxmpres/download_gary.png'>下载</a>"; //return "<a href='index.php?r=order/downloadqr&qrurl=".$model->getQrImageUrl()."'><img src='/wx/web/images/wxmpres/download_gary.png'></a>"; //return "<a href='index.php?r=order/downloadqr&qrurl=".$model->getQrImageUrl()."'><img src='/wx/web/images/wxmpres/download_gary.png'></a>"; return Html::a(Html::img(Url::to(Yii::$app->getRequest()->baseUrl . '/images/wxmpres/download_gary.png')), ['downloadqr', 'staff_id' => $model->staff_id], ['target' => '_blank']); }, 'filter' => false, 'headerOptions' => array('style' => 'width:8%;')], ['label' => '推广成绩', 'format' => 'html', 'value' => function ($model, $key, $index, $column) { if ($model->score == 0) { return $model->score; } else { // MStaffSearch[mobile] //return "<a href='#'>".$model->score."</a>"; return Html::a($model->score, ['admin/index', 'MUserSearch[scene_pid]' => $model->scene_id]); } }, 'filter' => false, 'headerOptions' => array('style' => 'width:10%;')]]]); ?> </div>
public function actionSelfopStaffUpdate($filename = 'staff_20150819.csv') { $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'imported_data' . DIRECTORY_SEPARATOR . $filename; $fh = fopen($file, "r"); $i = 1; while (!feof($fh)) { $line = fgets($fh); $i++; if (empty($line)) { continue; } $fields = explode(",", $line); $office_title = trim($fields[3]); $office_title_utf8 = iconv('GBK', 'UTF-8//IGNORE', $office_title); $staff_name = trim($fields[4]); $staff_name_utf8 = iconv('GBK', 'UTF-8//IGNORE', $staff_name); $staff_role = trim($fields[5]); $staff_role_utf8 = iconv('GBK', 'UTF-8//IGNORE', $staff_role); if ($staff_role_utf8 == '营业厅经理') { $is_manager = 1; } else { $is_manager = 0; } $office = MOffice::findOne(['title' => $office_title_utf8]); echo $office->office_id . "," . $office->title . "," . $office_title_utf8 . "," . $staff_name_utf8 . "," . $staff_role_utf8 . "," . $is_manager . "\n"; $staff = MStaff::findOne(['name' => $staff_name_utf8]); if (!empty($staff)) { $staff->office_id = $office->office_id; $staff->is_manager = $is_manager; $staff->cat = 0; $staff->save(false); } } fclose($fh); echo "staff data(20150819) update ok\n"; }
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 function getStaffs() { return $this->hasMany(MStaff::className(), ['gh_id' => 'gh_id']); }
public function actionSceneId() { $sql = 'select scene_id, count(*) as c from wx_staff where scene_id != 0 group by scene_id having c > 1 order by c desc'; $rows = \Yii::$app->db->createCommand($sql)->queryAll(); foreach ($rows as $row) { // echo $row['scene_id'] . ': ' . $row['c'] . PHP_EOL; $staffs = MStaff::findAll(['scene_id' => $row['scene_id']]); $cat_staffs = []; foreach ($staffs as $staff) { $cat_staffs[$staff->cat][] = $staff; } $cat_staffs['individual'] = []; if (!empty($cat_staffs[MStaff::SCENE_CAT_IN])) { $cat_staffs['individual'] = array_merge($cat_staffs['individual'], $cat_staffs[MStaff::SCENE_CAT_IN]); } if (!empty($cat_staffs[MStaff::SCENE_CAT_OUT])) { $cat_staffs['individual'] = array_merge($cat_staffs['individual'], $cat_staffs[MStaff::SCENE_CAT_OUT]); } if (!empty($cat_staffs[MStaff::SCENE_CAT_FAN])) { $cat_staffs['individual'] = array_merge($cat_staffs['individual'], $cat_staffs[MStaff::SCENE_CAT_FAN]); } $first = null; foreach ($cat_staffs['individual'] as $individual_staff) { if (null === $first) { $first = $individual_staff; continue; } if ($individual_staff->openid == $first->openid) { echo "duplicate staff! " . $individual_staff->openid . ' ' . $individual_staff->name . PHP_EOL; $individual_staff->delete(); } } if (empty($cat_staffs[MStaff::SCENE_CAT_OFFICE])) { } else { if (count($cat_staffs[MStaff::SCENE_CAT_OFFICE]) > 1) { $all_offices = []; $first = null; foreach ($cat_staffs[MStaff::SCENE_CAT_OFFICE] as $cat_staff) { echo $cat_staff->scene_id . $cat_staff->name . PHP_EOL; if (null === $first) { $first = $cat_staff; $all_offices[] = $first; continue; } if ($cat_staff->office_id == $first->office_id) { echo "duplicate staff! " . $cat_staff->office_id . ' ' . $cat_staff->name . PHP_EOL; $cat_staff->delete(); } else { $cat_staff->scene_id = MStaff::newSceneId($cat_staff->gh_id); $cat_staff->save(false); echo 'change OFFICE sceneid: ' . $cat_staff->name . ' ' . $first->scene_id . ' -> ' . $cat_staff->scene_id . PHP_EOL; $all_offices[] = $cat_staff; } } $musers = MUser::findAll(['scene_pid' => $first->scene_id]); foreach ($musers as $muser) { $cnt = count($all_offices); $index = rand(0, $cnt - 1); echo 'change USER belongto: ' . $muser->nickname . ' ' . $muser->belongto . ' -> ' . $all_offices[$index]->office_id . PHP_EOL; $muser->belongto = $all_offices[$index]->office_id; $muser->scene_pid = $all_offices[$index]->scene_id; $muser->save(false); } } else { $cat_staff = $cat_staffs[MStaff::SCENE_CAT_OFFICE][0]; echo $cat_staff->scene_id . $cat_staff->name . PHP_EOL; $musers = MUser::findAll(['scene_pid' => $cat_staff->scene_id]); foreach ($musers as $muser) { echo 'change USER belongto: ' . $muser->nickname . ' ' . $muser->belongto . ' -> ' . $cat_staff->office_id . PHP_EOL; $muser->belongto = $cat_staff->office_id; $muser->save(false); } } foreach ($cat_staffs['individual'] as $individual_staff) { $individual_staff->scene_id = MStaff::newSceneId($individual_staff->gh_id); $individual_staff->save(false); echo 'change INDIVIDUAL sceneid: ' . $individual_staff->name . ' ' . $cat_staff->scene_id . ' -> ' . $individual_staff->scene_id . PHP_EOL; } } } }
public function getQrImageUrl2() { $officeStaff = $this->officeStaff; if (empty($officeStaff)) { $officeStaff = new MStaff(); $officeStaff->gh_id = $this->gh_id; $officeStaff->office_id = $this->office_id; $officeStaff->cat = MStaff::SCENE_CAT_OFFICE; $officeStaff->name = $this->title; $officeStaff->save(false); // return false; } return $officeStaff->getQrImageUrl2(); }