Exemplo n.º 1
0
 public function search($params)
 {
     $query = MUser::find();
     $query->joinWith('openidBindMobiles');
     //        $query->select('*');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->gh_id = Yii::$app->user->getGhid();
     $this->addCondition($query, 'wx_user.gh_id');
     if (!Yii::$app->user->getIsAdmin()) {
         $office = Yii::$app->user->identity;
         $scene_ids = $office->getSceneids();
         $query->andWhere(['scene_pid' => $scene_ids]);
     }
     $query->andWhere(['subscribe' => 1]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $this->addCondition($query, 'id');
     $this->addCondition($query, 'nickname', true);
     $this->addCondition($query, 'status');
     $this->addCondition($query, 'update_time');
     $this->addCondition($query, 'scene_pid');
     $this->addCondition($query, 'is_liantongstaff');
     $query->andFilterWhere(['like', 'wx_openid_bind_mobile.mobile', $this->mobile]);
     if (!empty($this->office_id)) {
         $office = MOffice::findOne($this->office_id);
         if (!empty($office)) {
             $query->andFilterWhere(['scene_pid' => $office->getSceneids()]);
         }
     }
     if (trim($this->create_time) !== '') {
         $query->andWhere('date(wx_user.create_time)>=:create_time', [':create_time' => $this->create_time]);
     }
     if (trim($this->create_time_2) !== '') {
         $query->andWhere('date(wx_user.create_time)<=:create_time_2', [':create_time_2' => $this->create_time_2]);
     }
     return $dataProvider;
 }
Exemplo n.º 2
0
 public static function confirmAjax($office_id, $cat)
 {
     $office = MOffice::findOne(['office_id' => $office_id]);
     if (empty($office)) {
         $score = 0;
     } else {
         $score = $office->score;
     }
     if ($cat == self::CAT_30YUAN_DAIJINJUAN) {
         $dh_score = self::CAT_30YUAN_DAIJINJUAN_SCORE;
     } else {
         if ($cat == self::CAT_100YUAN_DAIJINJUAN) {
             $dh_score = self::CAT_100YUAN_DAIJINJUAN_SCORE;
         } else {
             $dh_score = self::CAT_30YUAN_DAIJINJUAN_SCORE;
         }
     }
     if ($score < $dh_score) {
         U::W("----------score not enough--------");
         return \yii\helpers\Json::encode(['code' => 1]);
     } else {
         $office_score_event = new MOfficeScoreEvent();
         $office_score_event->gh_id = 'gh_03a74ac96138';
         $office_score_event->openid = '';
         $office_score_event->office_id = $office_id;
         $office_score_event->cat = $cat;
         $office_score_event->score = $dh_score;
         $office_score_event->memo = self::getCatNameOption($cat);
         $office_score_event->status = 0;
         $office_score_event->code = '';
         $office_score_event->create_time = date('y-m-d h:i:s', time());
         $office_score_event->save(false);
         $office = MOffice::findOne(['office_id' => $office_id]);
         $office->score = $office->score - $dh_score;
         $office->save(false);
     }
     return \yii\helpers\Json::encode(['code' => 0]);
 }
Exemplo n.º 3
0
 public function actionOfficewb($filename = 'office-wb.csv')
 {
     //$xyunicom = \app\models\WosoClient::findOne(['title_abbrev' => '襄阳联通']);
     //if (empty($xyunicom)) die('不能找到襄阳联通。');
     //gh_id,branch,region,title,address,manager,member_cnt,mobile
     //$filepathname = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . $filename;
     $filepathname = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'imported_data' . DIRECTORY_SEPARATOR . $filename;
     $fh = fopen($filepathname, "r");
     while (!feof($fh)) {
         $line = trim(fgets($fh));
         if (empty($line) || strlen($line) == 0) {
             continue;
         }
         //襄阳,樊城,襄阳市城区家客樊东网格逐日电子,李孔恒,13177226622
         $fields = explode(",", $line);
         $branch = trim($fields[0]);
         $branch_utf8 = iconv('GBK', 'UTF-8//IGNORE', $branch);
         $region = trim($fields[1]);
         $region_utf8 = iconv('GBK', 'UTF-8//IGNORE', $region);
         $title = trim($fields[2]);
         $title_utf8 = iconv('GBK', 'UTF-8//IGNORE', $title);
         $manager = trim($fields[3]);
         $manager_utf8 = iconv('GBK', 'UTF-8//IGNORE', $manager);
         $mobile = trim($fields[4]);
         $mobile_utf8 = iconv('GBK', 'UTF-8//IGNORE', $mobile);
         $office = MOffice::findOne(['title' => $title_utf8]);
         if (empty($office)) {
             echo $title_utf8 . "\t\t" . "insert ... \n";
             $office = new MOffice();
             $office->gh_id = \app\models\MGh::GH_XIANGYANGUNICOM;
             // 襄阳联通公共ID
             $office->branch = $branch_utf8;
             $office->region = $region_utf8;
             $office->title = $title_utf8;
             $office->manager = $manager_utf8;
             $office->mobile = $mobile_utf8;
             $office->save(false);
         } else {
             echo $title_utf8 . "\t\t" . "update ...\n";
             $office->branch = $branch_utf8;
             $office->region = $region_utf8;
             $office->title = $title_utf8;
             $office->manager = $manager_utf8;
             $office->mobile = $mobile_utf8;
             $office->save(false);
         }
         //echo $branch_utf8."\t".$region_utf8."\t".$title_utf8."\t".$manager_utf8."\t".$mobile_utf8."\n";
     }
     fclose($fh);
     echo "done\n";
 }
Exemplo n.º 4
0
 public function getQrImageUrl2()
 {
     $gh_id = $this->gh_id;
     if (empty($this->scene_id)) {
         // hbhe
         if (yii::$app->mutex->acquire(MStaff::SCENE_LOCK, MStaff::SCENE_LOCK_WAIT_TIME_SECOND)) {
             $this->scene_id = MStaff::newSceneId($this->gh_id);
             $this->save(false);
             //yii::$app->mutex->release($lock);
             yii::$app->mutex->release(MStaff::SCENE_LOCK);
         } else {
             yii::error('acquire lock error');
         }
     }
     $scene_id = $this->scene_id;
     $office_id = $this->office_id;
     $office = MOffice::findOne(['office_id' => $office_id]);
     $office_title = $office->title;
     //$log_file_path = Yii::$app->getRuntimePath().DIRECTORY_SEPARATOR.'qr'.DIRECTORY_SEPARATOR."{$gh_id}_{$scene_id}.jpg";
     $log_file_path = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'qr-all-offices' . DIRECTORY_SEPARATOR . "{$scene_id}_{$office_title}.jpg";
     if (!file_exists($log_file_path) || filesize($log_file_path) == 0) {
         Yii::$app->wx->setGhId($gh_id);
         $arr = Yii::$app->wx->WxgetQRCode($scene_id, true);
         $url = Yii::$app->wx->WxGetQRUrl($arr['ticket']);
         Wechat::downloadFile($url, $log_file_path);
     }
     //$url = Yii::$app->getRequest()->baseUrl."/../runtime/qr/{$gh_id}_{$scene_id}.jpg";
     //return $url;
 }
Exemplo n.º 5
0
 protected function findOfficeModel($id)
 {
     if (($model = MOffice::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 6
0
 public function actionMetronic($office_id = 0)
 {
     $this->layout = 'metronic';
     if (\Yii::$app->user->isAdmin) {
         if (0 !== $office_id) {
             $office = \app\models\MOffice::findOne(['office_id' => $office_id]);
         } else {
             $office = null;
         }
     } else {
         if (\Yii::$app->user->isOffice) {
             $office = \Yii::$app->user->identity;
         }
     }
     return $this->render('blank', ['target_office' => $office]);
 }
Exemplo n.º 7
0
 public function actionProfile()
 {
     $user = MOffice::findOne(Yii::$app->user->id);
     //        if (is_numeric(Yii::$app->user->identity->openid))
     //            $office = MOffice::findOne(Yii::$app->user->identity->openid);
     if ($user->load(Yii::$app->request->post())) {
         if ($user->save(false, ['pswd'])) {
             Yii::$app->session->setFlash('success', '设置成功!');
             return $this->refresh();
         } else {
             U::W($user->getErrors());
         }
     }
     return $this->render('profile', ['model' => $user]);
 }
Exemplo n.º 8
0
 public function getOutlet()
 {
     if ($this->belongto === 0) {
         return null;
     }
     $office = MOffice::findOne(['office_id' => $this->belongto]);
     return $office->outlet;
 }
Exemplo n.º 9
0
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('新增消息', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['msg_id', 'title', 'digest', 'author', ['attribute' => 'receiver_type', 'value' => function ($model, $key, $index, $column) {
    return Messagebox::getReceiverTypeOptionName($model->receiver_type);
}, 'filter' => Messagebox::getReceiverTypeOptionName()], ['attribute' => 'receiver', 'value' => function ($model, $key, $index, $column) {
    $office = MOffice::findOne(['office_id' => $model->receiver]);
    if ($model->receiver_type == 0) {
        /*经销商*/
        return '--';
    } else {
        return $office->title;
    }
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Exemplo n.º 10
0
 public function actionGroupmember($filename = 'groupmember.csv')
 {
     //$xyunicom = \app\models\WosoClient::findOne(['title_abbrev' => '襄阳联通']);
     //if (empty($xyunicom)) die('不能找到襄阳联通。');
     $filepathname = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . $filename;
     $fh = fopen($filepathname, "r");
     while (!feof($fh)) {
         $line = trim(fgets($fh));
         if (empty($line) || strlen($line) == 0) {
             continue;
         }
         $fields = explode(",", $line);
         $mobile = trim($fields[0]);
         $mobile_utf8 = iconv('GBK', 'UTF-8//IGNORE', $mobile);
         $office_title = trim($fields[1]);
         $office_title_utf8 = iconv('GBK', 'UTF-8//IGNORE', $office_title);
         $bind = OpenidBindMobile::findOne(['mobile' => $mobile]);
         if (!empty($bind)) {
             $user = MUser::findOne(['openid' => $bind->openid]);
             if (!empty($user)) {
                 $office = MOffice::findOne(['title' => $office_title_utf8]);
                 if (!empty($office)) {
                     $user->belongto = $office->office_id;
                     $user->save(false);
                 }
             }
         }
         echo "done\n";
     }
     fclose($fh);
 }
Exemplo n.º 11
0
 public static function getScore($office_id, $date = null)
 {
     $pic_categories = MOfficeCampaignPicCategory::find()->all();
     $office = \app\models\MOffice::findOne(['office_id' => $office_id]);
     $total = 0;
     foreach ($pic_categories as $pic_category) {
         if (!$office->is_selfOperated && $pic_category->sort_order == 6) {
             continue;
         }
         $scores = self::getScoreByPicCategory($office_id, $pic_category->id, $date);
         if ($scores['count'] == 0) {
             return false;
         }
         $total += $scores['count'] == 1 ? $scores['total'] : $scores['total'] / $scores['count'];
     }
     return $total;
 }
Exemplo n.º 12
0
 public function actionAddbindmobile($gh_id, $openid)
 {
     $this->layout = 'wap';
     $model = new OpenidBindMobile();
     $model->gh_id = $gh_id;
     $model->openid = $openid;
     $model->setScenario('bind_mobile');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //非自营厅渠道新增会员时,+积分100
         $user = MUser::findOne(['openid' => $openid]);
         $office = MOffice::findOne(['office_id' => $user->belongto]);
         if (!empty($office)) {
             if ($office->is_selfOperated == 0) {
                 //wx_office_score_event 增加一条记录
                 $offce_score_event = new MOfficeScoreEvent();
                 $offce_score_event->gh_id = $gh_id;
                 $offce_score_event->openid = $openid;
                 $offce_score_event->office_id = $user->belongto;
                 $offce_score_event->cat = MOfficeScoreEvent::CAT_ADD_NEW_MEMBER;
                 $offce_score_event->create_time = date('y-m-d h:i:s', time());
                 $offce_score_event->score = MOfficeScoreEvent::CAT_ADD_NEW_MEMBER_SCORE;
                 $offce_score_event->memo = '新增会员';
                 $offce_score_event->save(false);
                 //wx_office表中对应渠道score 加100分
                 $office->score = $office->score + 100;
                 $office->save(false);
             }
         }
         Yii::$app->wx->setGhId($gh_id);
         $url = Url::to(['hyzx1', 'gh_id' => $gh_id, 'openid' => $openid], true);
         Yii::$app->wx->WxTemplateSend(Wechat::getTemplateBindSuccessNotify($openid, $url, "{$model->user->nickname},您的手机号码已成功绑定襄阳联通官方微信营业厅", "您已成为襄阳联通的会员,可随时查询话费余额,办理业务,参与更多专享优惠!", $model->mobile, date('Y-m-d')));
         $url = Yii::$app->getSession()->get('RETURN_URL');
         if (!empty($url)) {
             return $this->redirect($url);
         } else {
             Yii::$app->session->setFlash('success', '恭喜您,会员注册成功!');
             return $this->refresh();
         }
     }
     $searchModel = new OpenidBindMobileSearch();
     $searchModel->gh_id = $gh_id;
     $searchModel->openid = $openid;
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('addbindmobile', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'model' => $model]);
 }
Exemplo n.º 13
0
 public function actionOrder($filename = 'order.csv', $date = null)
 {
     $filepathname = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'exported_data' . DIRECTORY_SEPARATOR . $filename;
     $fh = fopen($filepathname, 'w');
     if (null === $date) {
         $date = \app\models\U::getFirstDate(date('Y'), date('m'));
     }
     $total_count = \app\models\MOrder::find()->where(['>', 'create_time', $date])->count();
     //$total_count = \app\models\MUser::find()->count();
     $step = 300;
     $start = 0;
     while ($start < $total_count) {
         $orders = \app\models\MOrder::find()->offset($start)->limit($step)->where(['>', 'create_time', $date])->orderBy(['create_time' => SORT_ASC])->all();
         fprintf($fh, "营业厅, 订单号, 商品, 价格, 订单时间, 身份证, 用户姓名, 联系电话, 支付方式, 订单状态, 开通, 备注, 用户类型\n");
         foreach ($orders as $order) {
             $office = \app\models\MOffice::findOne(['office_id' => $order->office_id]);
             if (!empty($office)) {
                 $office_title = $office->title;
             } else {
                 $office_title = "";
             }
             $user = \app\models\MUser::findOne(['openid' => $order->openid]);
             $customerFlag = '--';
             /*
             if ($user->bindMobileIsInside('wx_t1')) {
                 $customerFlag = '老';
             } elseif ($user->bindMobileIsInside('wx_t2')) {
                 $customerFlag = '老';
             }elseif ($user->bindMobileIsInside('wx_t3')) {
                 $customerFlag = '老';
             } else {
                 $customerFlag = '新';
             }
             */
             if ($user->bindMobileIsInside('wx_oldcustomer')) {
                 $customerFlag = '老';
             } else {
                 $customerFlag = '新';
             }
             $pay_kind = \app\models\MOrder::getOrderPayKindOption($order->pay_kind);
             $price = $order->feesum / 100;
             $paystatus = \app\models\MOrder::getOrderStatusName($order->status);
             //echo $office_title."\t".$order->oid."\t".$order->title."\t".$price."\t".$order->create_time."\t".$order->userid."\t".$order->username."\t".$order->usermobile."\t".$pay_kind."\t".$order->memo."\t".$order->customerFlag."\t\n";
             fprintf($fh, "%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s\n", $office_title, $order->oid, $order->title, $price, $order->create_time, $order->userid, $order->username, $order->usermobile, $pay_kind, $paystatus, $order->kaitong, $order->memo, $order->customerFlag);
         }
         $start += $step;
     }
     fclose($fh);
 }
Exemplo n.º 14
0
 public static function getDetailReadyStatus($office_id, $date = null)
 {
     $start_date = \app\models\utils\OfficeCampaignUtils::getOfficeCampaignBeginDate($date);
     $end_date = \app\models\utils\OfficeCampaignUtils::getOfficeCampaignEndDate($date);
     $pic_categories = MOfficeCampaignPicCategory::find()->all();
     $office = \app\models\MOffice::findOne(['office_id' => $office_id]);
     $category_count = 0;
     $detail_count = 0;
     foreach ($pic_categories as $pic_category) {
         if (!$office->is_selfOperated && $pic_category->sort_order == 6) {
             continue;
         }
         $category_count++;
         $detail = self::find()->andWhere(['office_id' => $office_id, 'pic_category' => $pic_category->id])->andWhere('created_time >= :start_time', [':start_time' => $start_date->format("Y-m-d H:i:s")])->andWhere('created_time < :end_time', [':end_time' => $end_date->format("Y-m-d H:i:s")])->one();
         if (!empty($detail)) {
             $detail_count++;
         }
     }
     if ($category_count == $detail_count) {
         return self::DETAIL_COMPLETE;
     }
     if ($detail_count == 0) {
         return self::DETAIL_IMCOMPLETE;
     } else {
         return self::DETAIL_PARTIALLY;
     }
 }
Exemplo n.º 15
0
    <//?= $form->field($model, 'score')->textInput() ?>

    <//?= $form->field($model, 'memo')->textInput(['maxlength' => 128]) ?>

    <//?= $form->field($model, 'code')->textInput(['maxlength' => 64]) ?>
    -->

    <!--
    <//?= $form->field($model, 'status')->textInput() ?>
    -->

    <br><br>

    <?php 
$office = MOffice::findOne(["office_id" => $model->office_id]);
if (empty($office)) {
    $title = "--";
} else {
    $title = $office->title;
}
echo "<h1>渠道名称: " . $title . "</h1>";
echo "<h3>代金卷: " . MOfficeScoreEvent::getCatNameOption($model->cat) . "</h3>";
echo "<h3>减积分: " . $model->score . "</h3>";
echo "<h3>时间: " . $model->create_time . "</h3>";
?>

    <br>

    <?php 
echo $form->field($model, 'status')->dropDownList(MOfficeScoreEvent::getOseStatusOption());
Exemplo n.º 16
0
 public static function closeExpiredOrders()
 {
     $tableName = MOrder::tableName();
     $n = Yii::$app->db->createCommand()->delete($tableName, 'status=:status AND create_time < DATE_SUB(NOW(), INTERVAL 2 day)', [':status' => MOrder::STATUS_DRAFT])->execute();
     U::W("UPDATE {$tableName}, {$n} --- 系统删除2天前的僵死订单。");
     // auto close the orders exceed 2 days
     $n = Yii::$app->db->createCommand()->update($tableName, ['status' => MOrder::STATUS_SYSTEM_CLOSED], 'status=:status AND create_time < DATE_SUB(NOW(), INTERVAL 2 day)', [':status' => MOrder::STATUS_SUBMITTED])->execute();
     U::W("UPDATE {$tableName}, {$n} --- 系统自动关闭超时2天的提交订单。");
     $n = Yii::$app->db->createCommand()->update($tableName, ['status' => MOrder::STATUS_SYSTEM_SUCCEEDED], 'status=:status AND create_time < DATE_SUB(NOW(), INTERVAL 2 day)', [':status' => MOrder::STATUS_FULFILLED])->execute();
     U::W("UPDATE {$tableName}, {$n} --- 系统自动确认超时2天的已办理订单。");
     //找到超时2天的成功订单, 将其归属的渠道 +积分100
     $orders = MOrder::find()->where(['status' => MOrder::STATUS_FULFILLED])->andWhere(['<', 'create_time', 'DATE_SUB(NOW(), INTERVAL 2 day)'])->all();
     foreach ($orders as $order) {
         $user = MUser::findOne(['openid' => $order->openid]);
         $office = MOffice::findOne(['office_id' => $user->belongto]);
         if ($office->is_selfOperated == 0) {
             //wx_office_score_event 增加一条记录
             $offce_score_event = new MOfficeScoreEvent();
             $offce_score_event->gh_id = $order->gh_id;
             $offce_score_event->openid = $order->openid;
             $offce_score_event->office_id = $user->belongto;
             $offce_score_event->cat = MOfficeScoreEvent::CAT_ADD_ORDER;
             $offce_score_event->create_time = date('y-m-d h:i:s', time());
             $offce_score_event->score = MOfficeScoreEvent::CAT_ADD_ORDER_SCORE;
             $offce_score_event->memo = '会员订单';
             $offce_score_event->save(false);
             //wx_office表中对应渠道score 加100分
             $office->score = $office->score + 100;
             $office->save(false);
         }
     }
     /* 		
      //move the unsuccessful orders exceed 90 days to bak table
      $n = Yii::$app->db->createCommand("INSERT INTO {$tableName}_arc SELECT * FROM $tableName WHERE status!=:status AND create_time < DATE_SUB(NOW(), INTERVAL 90 day)", [':status'=>MOrder::STATUS_OK])->execute();
      U::W("INSERT $tableName, $n");
     
      $n = Yii::$app->db->createCommand("DELETE FROM $tableName WHERE status!=:status AND create_time < DATE_SUB(NOW(), INTERVAL 90 day)", [':status'=>MOrder::STATUS_OK])->execute();
      U::W("DELETE $tableName, $n");
     */
     //release mobile number
     $tableName = MMobnum::tableName();
     $n = Yii::$app->db->createCommand()->update($tableName, ['status' => MMobnum::STATUS_UNUSED, 'locktime' => 0], 'status=:status AND locktime < :locktime', [':status' => MMobnum::STATUS_LOCKED, ':locktime' => time() - 2 * 24 * 3600])->execute();
     U::W("UPDATE {$tableName}, {$n}");
     $n = Yii::$app->db->createCommand("DELETE FROM {$tableName} WHERE status=:status", [':status' => MMobnum::STATUS_USED])->execute();
     U::W("DELETE {$tableName}, {$n}");
 }
Exemplo n.º 17
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);
         }
     }
 }
Exemplo n.º 18
0
          <span id="item2mobile" class="control-content">
              <ul class="table-view">
              <?php 
if (count($ranking) == 0) {
    ?>
                <li class="table-view-cell media">
                  <div class="pull-right"></div>
                  <div class="media-body">本期活动暂无排名</div>
                </li>
              <?php 
} else {
    $rank = 0;
    foreach ($ranking as $rank_item) {
        $rank++;
        $office = \app\models\MOffice::findOne(['office_id' => $rank_item['office_id']]);
        ?>
                    <li class="table-view-cell media">
                      <a data-ignore="push" class="navigate-right" href="<?php 
        echo Url::to(['qdxcjspb4', 'office_id' => $rank_item['office_id']], true);
        ?>
">
                        <div class="pull-right">
                          <span class="badge badge-primary"><?php 
        echo number_format($rank_item['score'], 2);
        ?>
分</span>
                        </div>
                        <div class="media-body">
                          <?php 
        echo $rank;