Exemple #1
0
 public function actionOfficeDirector()
 {
     $selfOperated_offices = \app\models\MOffice::findAll(['is_selfOperated' => 1, 'gh_id' => \app\models\MGh::GH_XIANGYANGUNICOM]);
     $i = 0;
     foreach ($selfOperated_offices as $selfOperated_office) {
         echo ++$i;
         echo ":";
         echo $selfOperated_office->title;
         $director = $selfOperated_office->director;
         if (!empty($director)) {
             echo " " . $director->name . ' ' . $director->mobile;
             if (empty($director->office) || $director->office->office_id != $selfOperated_office->office_id) {
                 echo " " . "班长的营业厅对应错了。";
                 if (empty($director->office)) {
                     echo "(NULL)";
                 } else {
                     echo "{$director->office->title}({$director->office->office_id} != {$selfOperated_office->office_id})";
                 }
                 $director->office_id = $selfOperated_office->office_id;
                 $director->save(false);
             }
         }
         echo PHP_EOL;
     }
 }
Exemple #2
0
 public function actionSelfOwnedOutlets($date = null, $is_selfOperated = 1, $filename = 'self-owned-outlets.csv')
 {
     $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'exported_data' . DIRECTORY_SEPARATOR . $filename;
     $offices = \app\models\MOffice::findAll(['is_selfOperated' => $is_selfOperated]);
     if ($date == null) {
         $date = date('Y-m-d');
     }
     $lastmonth_start = date('Y-m-01', strtotime('-1 month', strtotime($date))) . " 00:00:00";
     $lastmonth_end = date('Y-m-d', strtotime('-1 month', strtotime($date))) . " 23:59:59";
     $thismonth_start = date('Y-m-01', strtotime($date)) . " 00:00:00";
     $thismonth_end = date('Y-m-d', strtotime($date)) . " 23:59:59";
     //        $lastmonth_start = \app\models\U::getFirstDayOfLastMonth();
     //        $lastmonth_end = date('Y-m-d', strtotime('-1 month', strtotime('yesterday')))." 23:59:59";;
     //        $thismonth_start = \app\models\U::getFirstDate(date('Y'), date('m'));
     //        $thismonth_end = date('Y-m-d', strtotime('yesterday'))." 23:59:59";
     $fh = fopen($file, "w");
     //fprintf($fh, "自营厅名称,粉丝总数量,绑定手机粉丝总数量,上月(%s)同期发展粉丝数量,上月(%s)同期发展绑定手机粉丝数量,本月(%s)发展粉丝数量,本月(%s)发展绑定手机粉丝数量,归属客户总数量,已微信关联客户数量,上月(%s)同期关联客户数量,本月(%s)关联客户数量\n",
     //绑定手机粉丝总数量 == 会员总数量
     fprintf($fh, "自营厅名称,累计粉丝量(从发展到现在),会员总数量, 本月新增会员, 上月(%s)同期发展粉丝数量,(%s)新用户发展同比,%s月新增粉丝量,(%s)新用户发展量,归属客户总数量,已微信关联客户数量,(%s)维系用户同比,%s维系用户发展量, 发展业务量\n", date('Y-m', strtotime($lastmonth_start)), date('Y-m', strtotime($lastmonth_start)), date('Y-m-d', strtotime($thismonth_start)) . "至" . date('Y-m-d', strtotime($thismonth_end)), date('Y-m-d', strtotime($thismonth_start)) . "至" . date('Y-m-d', strtotime($thismonth_end)), date('Y-m', strtotime($lastmonth_start)), date('Y-m-d', strtotime($thismonth_start)) . "至" . date('Y-m-d', strtotime($thismonth_end)));
     foreach ($offices as $office) {
         //            $wx_count = \app\models\MUser::find()->where(['scene_pid' => $office->getSceneids(), 'subscribe' => 1])->count();
         //            $wx_bound_count = \app\models\MUser::find()->joinWith('openidBindMobiles')
         //                    ->where(['scene_pid' => $office->getSceneids(), 'subscribe' => 1])
         //                    ->andWhere(['wx_openid_bind_mobile.mobile' => null])
         //                    ->count();
         $wx_count = \app\models\MUser::find()->where(['belongto' => $office->office_id, 'subscribe' => 1])->count();
         $order_count = \app\models\MOrder::find()->where(['office_id' => $office->office_id])->andWhere(['>=', 'create_time', $thismonth_start])->andWhere(['<=', 'create_time', $thismonth_end])->count();
         $wx_bound_count = \app\models\MUser::find()->joinWith('openidBindMobiles')->where(['belongto' => $office->office_id, 'subscribe' => 1])->andWhere(['wx_openid_bind_mobile.mobile' => null])->count();
         $wx_bound_count = $wx_count - $wx_bound_count;
         $wx_bound_thismonth_count = \app\models\MUser::find()->joinWith('openidBindMobiles')->where(['belongto' => $office->office_id, 'subscribe' => 1])->andWhere(['not', ['wx_openid_bind_mobile.mobile' => null]])->andWhere(['>', 'subscribe_time', strtotime($thismonth_start)])->andWhere(['<', 'subscribe_time', strtotime($thismonth_end)])->groupBy(['gh_id', 'openid'])->count();
         //            $wx_lastmonth_count = \app\models\MUser::find()->andWhere(['scene_pid' => $office->getSceneids(), 'subscribe' => 1])
         //                    ->andWhere(['>=', 'create_time', $lastmonth_start])
         //                    ->andWhere(['<=', 'create_time', $lastmonth_end])
         //                    ->count();
         //            $wx_lastmonth_bound_count = \app\models\MUser::find()->joinWith('openidBindMobiles')
         //                    ->andWhere(['scene_pid' => $office->getSceneids(), 'subscribe' => 1])
         //                    ->andWhere(['>=', 'wx_user.create_time', $lastmonth_start])
         //                    ->andWhere(['<=', 'wx_user.create_time', $lastmonth_end])
         //                    ->andWhere(['wx_openid_bind_mobile.mobile' => null])
         //                    ->count();
         $wx_lastmonth_count = \app\models\MUser::find()->andWhere(['belongto' => $office->office_id, 'subscribe' => 1])->andWhere(['>=', 'create_time', $lastmonth_start])->andWhere(['<=', 'create_time', $lastmonth_end])->count();
         $wx_lastmonth_bound_count = \app\models\MUser::find()->joinWith('openidBindMobiles')->andWhere(['belongto' => $office->office_id, 'subscribe' => 1])->andWhere(['>=', 'wx_user.create_time', $lastmonth_start])->andWhere(['<=', 'wx_user.create_time', $lastmonth_end])->andWhere(['wx_openid_bind_mobile.mobile' => null])->count();
         $wx_lastmonth_bound_count = $wx_lastmonth_count - $wx_lastmonth_bound_count;
         //            $wx_lastweek_count = \app\models\MUser::find()->andWhere(['scene_pid' => $office->getSceneids(), 'subscribe' => 1])
         //                    ->andWhere(['>=', 'wx_user.create_time', $lastweek_start])
         //                    ->andWhere(['<=', 'wx_user.create_time', $lastweek_end])
         //                    ->count();
         //            $wx_lastweek_bound_count = \app\models\MUser::find()->joinWith('openidBindMobiles')
         //                    ->andWhere(['scene_pid' => $office->getSceneids(), 'subscribe' => 1])
         //                    ->andWhere(['>=', 'wx_user.create_time', $lastweek_start])
         //                    ->andWhere(['<=', 'wx_user.create_time', $lastweek_end])
         //                    ->andWhere(['wx_openid_bind_mobile.mobile' => null])
         //                    ->count();
         $wx_lastweek_count = \app\models\MUser::find()->andWhere(['belongto' => $office->office_id, 'subscribe' => 1])->andWhere(['>=', 'wx_user.create_time', $thismonth_start])->andWhere(['<=', 'wx_user.create_time', $thismonth_end])->count();
         $wx_lastweek_bound_count = \app\models\MUser::find()->joinWith('openidBindMobiles')->andWhere(['belongto' => $office->office_id, 'subscribe' => 1])->andWhere(['>=', 'wx_user.create_time', $thismonth_start])->andWhere(['<=', 'wx_user.create_time', $thismonth_end])->andWhere(['wx_openid_bind_mobile.mobile' => null])->count();
         $wx_lastweek_bound_count = $wx_lastweek_count - $wx_lastweek_bound_count;
         $customer_count = \app\models\Custom::find()->where(['office_id' => $office->office_id])->count();
         $customer_bound_count = \app\models\Custom::find()->joinWith('openidBindMobile')->where(['office_id' => $office->office_id])->andWhere(['wx_openid_bind_mobile.mobile' => null])->count();
         $customer_bound_count = $customer_count - $customer_bound_count;
         $customer_lastmonth_bound_count = \app\models\Custom::find()->joinWith('openidBindMobile.user')->where(['office_id' => $office->office_id])->andWhere(['not', ['wx_openid_bind_mobile.mobile' => null]])->andWhere(['>=', 'wx_user.create_time', $lastmonth_start])->andWhere(['<=', 'wx_user.create_time', $lastmonth_end])->count();
         $customer_lastweek_bound_count = \app\models\Custom::find()->joinWith('openidBindMobile.user')->where(['office_id' => $office->office_id])->andWhere(['not', ['wx_openid_bind_mobile.mobile' => null]])->andWhere(['>=', 'wx_user.create_time', $thismonth_start])->andWhere(['<=', 'wx_user.create_time', $thismonth_end])->count();
         fprintf($fh, "%s", $office->title . ", " . $wx_count . ", " . $wx_bound_count . ", " . $wx_bound_thismonth_count . ", " . $wx_lastmonth_count . ", " . $wx_lastmonth_bound_count . ", " . $wx_lastweek_count . ", " . $wx_lastweek_bound_count . ", " . $customer_count . ", " . $customer_bound_count . ", " . $customer_lastmonth_bound_count . ", " . $customer_lastweek_bound_count . ", " . $order_count . PHP_EOL);
     }
     fclose($fh);
 }
Exemple #3
0
 public function actionOfficecustomstat()
 {
     $offices = MOffice::findAll(['gh_id' => 'gh_03a74ac96138']);
     $rows = [];
     $custom_count = [];
     foreach ($offices as $office) {
         //$row = [];
         $row['office_id'] = $office->office_id;
         $row['office_title'] = $office->title;
         $custom = Custom::findOne(['office_id' => $office->office_id]);
         if ($custom !== null) {
             $custom_counts = Custom::find()->select('*, count(*) as c')->where('office_id=:office_id', [':office_id' => $office->office_id])->groupBy(['office_id'])->orderBy('office_id')->asArray()->all();
             foreach ($custom_counts as $custom_count) {
                 $row['custom_count'] = $custom_count['c'];
             }
         } else {
             continue;
         }
         $rows[] = $row;
     }
     //print_r($custom_count);
     //U::W("####################################");
     //U::W($rows);
     //U::W($custom_count);
     $filter = new \app\models\FiltersForm();
     $filter->unsetAttributes();
     if (isset($_GET['FiltersForm'])) {
         $filter->setAttributes($_GET['FiltersForm'], false);
     }
     $rows = $filter->filterArrayData($rows);
     $dataProvider = new ArrayDataProvider(['allModels' => $rows, 'sort' => ['attributes' => ['office_id', 'office_title', 'custom_count'], 'defaultOrder' => ['custom_count' => SORT_DESC]], 'pagination' => ['pageSize' => 50]]);
     return $this->render('officecustomstat', ['dataProvider' => $dataProvider, 'filter' => $filter]);
 }
Exemple #4
0
 public static function getOfficeScoreTopByMonth($gh_id, $month)
 {
     $key = __METHOD__ . "{$gh_id}-{$month}";
     $value = Yii::$app->cache->get($key);
     if ($value !== false) {
         return $value;
     }
     $offices = MOffice::findAll(['gh_id' => $gh_id]);
     $rows = [];
     foreach ($offices as $office) {
         $row = [];
         $row['office_id'] = $office->office_id;
         $row['scene_id'] = $office->scene_id;
         $row['title'] = $office->title;
         $row['is_jingxiaoshang'] = $office->is_jingxiaoshang;
         $row['cnt_office'] = $office->getScoreByMonth($month);
         $row['cnt_staffs'] = $office->getScoreOfAllStaffsByMonth($month);
         $row['cnt_sum'] = $row['cnt_office'] + $row['cnt_staffs'];
         $rows[] = $row;
     }
     Yii::$app->cache->set($key, $rows, YII_DEBUG ? 10 : 12 * 3600);
     return $rows;
 }