Exemplo n.º 1
0
 public function search($params)
 {
     $query = MAccessLog::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['access_log_id' => SORT_DESC]], 'pagination' => ['pageSize' => 20]]);
     //$dataProvider->sort->attributes['user.nickname'] =  ['asc'=>['user.nickname' => SORT_ASC],'desc'=>['user.nickname' => SORT_DESC]];
     $query->select(['wx_user.*', 'wx_staff.*', 'wx_access_log.*']);
     //$query->select('*');
     //$query->with('user');
     $query->joinWith('user');
     //$query->joinWith(['user' => function($query) { $query->from(['user'=>'wx_user']); }]);
     //$query->joinWith('staff');
     $query->leftJoin('wx_staff', 'wx_access_log.ToUserName = wx_staff.gh_id AND wx_access_log.scene_pid = wx_staff.scene_id AND wx_access_log.scene_pid != 0');
     if (!Yii::$app->user->getIsAdmin()) {
         $office = Yii::$app->user->identity;
         $query->andWhere(['wx_access_log.scene_pid' => $office->getSceneids()]);
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['create_time' => $this->create_time, 'scene_pid' => $this->scene_pid, 'CreateTime' => $this->CreateTime]);
     $query->andFilterWhere(['like', 'ToUserName', $this->ToUserName])->andFilterWhere(['like', 'FromUserName', $this->FromUserName])->andFilterWhere(['like', 'wx_user.nickname', $this->user_nickname])->andFilterWhere(['like', 'wx_staff.name', $this->staff_name])->andFilterWhere(['like', 'MsgType', $this->MsgType])->andFilterWhere(['like', 'Content', $this->Content])->andFilterWhere(['like', 'event', $this->Event])->andFilterWhere(['like', 'EventKey', $this->EventKey]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 public function getFansByRange($date_start, $date_end)
 {
     if ($this->scene_id == 0) {
         return [];
     }
     $fans = [];
     $accessLogs = MAccessLog::find()->where('ToUserName=:ToUserName AND scene_pid=:scene_pid AND Event=:Event AND date(create_time)>=:date_start AND date(create_time)<=:date_end ', [':ToUserName' => $this->gh_id, ':scene_pid' => $this->scene_id, ':Event' => 'subscribe', ':date_start' => $date_start, ':date_end' => $date_end])->all();
     foreach ($accessLogs as $accessLog) {
         $fan = $accessLog->user;
         if (!empty($fan)) {
             if ($fan->subscribe) {
                 $fans[] = $fan;
             }
         }
     }
     return $fans;
 }
Exemplo n.º 3
0
 public function getScoreFromLogRange($date_start, $date_end)
 {
     if ($this->scene_id == 0) {
         return 0;
     }
     $count_plus = MAccessLog::find()->where('ToUserName=:ToUserName AND scene_pid=:scene_pid AND Event=:Event AND date(create_time)>=:date_start AND date(create_time)<=:date_end ', [':ToUserName' => $this->gh_id, ':scene_pid' => $this->scene_id, ':Event' => 'subscribe', ':date_start' => $date_start, ':date_end' => $date_end])->count();
     $count_minus = MAccessLog::find()->where('ToUserName=:ToUserName AND scene_pid=:scene_pid AND Event=:Event AND date(create_time)>=:date_start AND date(create_time)<=:date_end ', [':ToUserName' => $this->gh_id, ':scene_pid' => $this->scene_id, ':Event' => 'unsubscribe', ':date_start' => $date_start, ':date_end' => $date_end])->count();
     return $count_plus - $count_minus;
 }
Exemplo n.º 4
0
 public static function getRealScoreByRange($gh_id, $scene_id, $date_start, $date_end)
 {
     //U::W("scene_id=$scene_id,$date_start, $date_end");
     $count_plus = 0;
     $fan_openids = array();
     $accessLogs = MAccessLog::find()->where('ToUserName=:ToUserName AND scene_pid=:scene_pid AND Event=:Event AND date(create_time)>=:date_start AND date(create_time)<=:date_end ', [':ToUserName' => $gh_id, ':scene_pid' => $scene_id, ':Event' => 'subscribe', ':date_start' => $date_start, ':date_end' => $date_end])->andWhere(['booked' => 0])->all();
     foreach ($accessLogs as $accessLog) {
         $fan = $accessLog->user;
         if (!empty($fan)) {
             // just can get money only if the recommended fan bind a mobile
             if (in_array($fan->openid, $fan_openids)) {
                 $accessLog->updateAttributes(['booked' => 1]);
                 continue;
             }
             $fan_openids[] = $fan->openid;
             if ($fan->subscribe && !empty($fan->openidBindMobiles)) {
                 $accessLog->updateAttributes(['booked' => 1]);
                 $count_plus++;
             }
         }
     }
     //        $count_minus = MAccessLog::find()->where('ToUserName=:ToUserName AND scene_pid=:scene_pid AND Event=:Event AND date(create_time)>=:date_start AND date(create_time)<=:date_end ', [':ToUserName'=>$gh_id, ':scene_pid' => $scene_id, ':Event'=>'unsubscribe', ':date_start'=>$date_start, ':date_end'=>$date_end])->count();
     //        return $count_plus - $count_minus;
     return $count_plus;
 }