コード例 #1
0
 protected function saveAccessLog($params = [])
 {
     $request = $this->getRequest();
     $log = new MAccessLog();
     $log->setAttributes($request, false);
     $log->setAttributes($params, false);
     $log->save(false);
 }
コード例 #2
0
ファイル: MAccessLogSearch.php プロジェクト: noikiy/wowewe
 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;
 }
コード例 #3
0
ファイル: AccesslogController.php プロジェクト: noikiy/wowewe
 /**
  * Finds the MAccessLog model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return MAccessLog the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MAccessLog::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #4
0
ファイル: MStaff.php プロジェクト: noikiy/wowewe
 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;
 }
コード例 #5
0
ファイル: NightController.php プロジェクト: noikiy/wowewe
 public static function addRecommendFanAmount($date_start, $date_end)
 {
     U::W(__METHOD__ . " BEGIN from {$date_start}, {$date_end}");
     //        $tableName = MSceneDay::tableName();
     $ghs = MGh::find()->all();
     foreach ($ghs as $gh) {
         if ($gh->gh_id !== MGh::GH_XIANGYANGUNICOM) {
             continue;
         }
         foreach ($gh->staffs as $staff) {
             if ($staff->scene_id != 0 && ($staff->cat == MStaff::SCENE_CAT_OUT || $staff->cat == MStaff::SCENE_CAT_FAN) && !empty($staff->openid)) {
                 $real_score = MAccessLog::getRealScoreByRange($gh->gh_id, $staff->scene_id, $date_start, $date_end);
                 if ($real_score > 0) {
                     //$amount = intval($real_score) * 100;
                     //$amount = intval($real_score/3) * 500;
                     $amount = intval($real_score) * 500;
                     if ($amount > 0) {
                         $model = new MUserAccount();
                         $model->gh_id = $staff->gh_id;
                         $model->openid = $staff->openid;
                         $model->scene_id = $staff->scene_id;
                         $model->cat = MUserAccount::CAT_DEBIT_FAN;
                         $model->amount = $amount;
                         $model->memo = '推荐有礼';
                         $model->save(false);
                         //                            U::W("SAVE OK, scene_id={$staff->scene_id}, openid={$staff->openid}, amount={$model->amount}");
                     }
                 } else {
                     //                        U::W("scene_id={$staff->scene_id}, openid={$staff->openid}, realscore={$real_score}, ");
                 }
             } else {
                 //                    U::W("scene_id={$staff->scene_id}, openid={$staff->openid}");
             }
         }
     }
     U::W(__METHOD__ . " END");
     return;
 }
コード例 #6
0
ファイル: MChannel.php プロジェクト: noikiy/wowewe
 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;
 }
コード例 #7
0
ファイル: MAccessLog.php プロジェクト: noikiy/wowewe
 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;
 }