/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Custom::find(); $query->joinWith('openidBindMobile'); $query->leftJoin('wx_user', 'wx_user.gh_id = wx_openid_bind_mobile.gh_id AND wx_user.openid = wx_openid_bind_mobile.openid'); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!Yii::$app->user->getIsAdmin()) { $this->office_id = Yii::$app->user->identity->office_id; $query->andFilterWhere(['office_id' => $this->office_id]); } if (!($this->load($params) && $this->validate())) { return $dataProvider; } if ($this->is_bind !== '') { if ($this->is_bind == 1) { //$query->andWhere('wx_openid_bind_mobile.mobile is not null'); $query->andWhere(['not', ['wx_openid_bind_mobile.mobile' => null]]); } else { $query->andWhere(['wx_openid_bind_mobile.mobile' => null]); } } $query->andFilterWhere(['custom_id' => $this->custom_id, 'is_vip' => $this->is_vip, 'office_id' => $this->office_id, 'vip_level_id' => $this->vip_level_id]); $query->andFilterWhere(['like', 'wx_custom.mobile', $this->mobile])->andFilterWhere(['like', 'name', $this->name]); if (trim($this->subscribe_time_start) !== '') { $query->andWhere('date(wx_user.create_time)>=:subscribe_time_start', [':subscribe_time_start' => $this->subscribe_time_start]); } if (trim($this->subscribe_time_end) !== '') { $query->andWhere('date(wx_user.create_time)<=:subscribe_time_end', [':subscribe_time_end' => $this->subscribe_time_end]); } return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = \app\models\Custom::find()->join('INNER JOIN', 'wx_openid_bind_mobile', 'wx_openid_bind_mobile.mobile = wx_custom.mobile')->join('INNER JOIN', 'wx_user', 'wx_openid_bind_mobile.gh_id = wx_user.gh_id and wx_openid_bind_mobile.openid = wx_user.openid')->where(['wx_user.subscribe' => 1])->orderBy(['wx_user.create_time' => SORT_DESC]); $dataProvider = new \yii\data\ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } if (!empty($this->page)) { $dataProvider->pagination->page = $this->page; } if (trim($this->gh_id) !== '') { $query->andWhere(['wx_user.gh_id' => $this->gh_id]); } $this->addCondition($query, 'office_id'); if (!empty($this->searchStr)) { $query->andWhere(['or', ['like', 'wx_custom.mobile', $this->searchStr], ['like', 'wx_custom.name', $this->searchStr]]); } return $dataProvider; }
?> "> <span class="badge badge-primary"><?php echo \app\models\MUser::getBoundWechatFanCount($wx_user->gh_id, $outlet->original_office_id); ?> </span> 门店发展用户 </a> </li> <li class="table-view-cell"> <a class="navigate-right" data-ignore="push" href="<?php echo \yii\helpers\Url::to(['client-customer-list', 'gh_id' => $wx_user->gh_id, 'openid' => $wx_user->openid, 'backwards' => true, 'ClientCustomerSearch' => ['gh_id' => $wx_user->gh_id, 'office_id' => $outlet->original_office_id]]); ?> "> <span class="badge badge-primary"><?php echo \app\models\Custom::getBoundCustomerCount($wx_user->gh_id, $outlet->original_office_id); ?> </span> 门店存量用户 </a> </li> </ul> </div> <div id="showQr" class="modal"> <header class="bar bar-nav"> <a class="icon icon-close pull-right" href="#showQr"></a> <h1 class="title"><?php echo $outlet->title; ?> 的推广二维码</h1>
public static function getNotBindVipCustoms($in_office) { $mobiles = OpenidBindMobile::getMobiles(); if ($in_office == '1') { $customs = Custom::find()->where(['mobile' => $mobiles])->andWhere("office_id > 0 AND is_vip = 1")->all(); } else { $customs = Custom::find()->where(['mobile' => $mobiles])->andWhere("office_id = 0 AND is_vip = 1")->all(); } return $customs; }
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]); }
public function actionClientCustomer($gh_id, $openid, $customer_id, $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]); $customer = \app\models\Custom::findOne(['custom_id' => $customer_id]); $this->layout = false; return $this->render('client-customer', ['wx_user' => $wx_user, 'backwards' => $backwards, 'customer' => $customer]); }
public function actionVipbind() { $in_office = Yii::$app->request->get('in_office', 0); $rows = Custom::getBindVipCustoms($in_office); $dataProvider = new ArrayDataProvider(['allModels' => $rows, 'sort' => [], 'pagination' => ['pageSize' => 50]]); if (isset($_GET['download'])) { $data = $rows; // \yii\helpers\ArrayHelper::multisort($data, 'cnt_sum', SORT_DESC); $date = date('Y-m-d-His'); $filename = Yii::$app->getRuntimePath() . "/vipbind-{$date}.csv"; $csv = new \app\models\ECSVExport($data); /* $attributes = ['office_id', 'scene_id', 'title', 'is_jingxiaoshang', 'cnt_office', 'cnt_staffs', 'cnt_sum']; $csv->setInclude($attributes); $csv->setHeaders(['office_id'=>'营业厅ID', 'scene_id'=>'推广码ID', 'title'=>'名称', 'is_jingxiaoshang'=>'类别', 'cnt_office'=>'部门推广人数', 'cnt_staffs'=>'部门员工推广人数', 'cnt_sum'=>'合计推广人数']); */ $csv->toCSV($filename); Yii::$app->response->sendFile($filename); return; } return $this->render('vipbind', ['dataProvider' => $dataProvider]); }
public function actionImportcustom() { $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'custom.txt'; $fh = fopen($file, "r"); $i = 0; while (!feof($fh)) { $line = fgets($fh); if (empty($line)) { continue; } $arr = explode("\t", $line); $arr[1] = iconv('GBK', 'UTF-8//IGNORE', $arr[1]); $arr[2] = iconv('GBK', 'UTF-8//IGNORE', $arr[2]); $mobile = trim($arr[0]); $name = trim($arr[1]); $office_title = trim($arr[2]); $office = MOffice::findOne(['gh_id' => 'gh_03a74ac96138', 'title' => $office_title]); if (empty($office)) { U::W(['office_title is invalid', $arr]); exit; } $custom = Custom::findOne(['mobile' => $mobile]); if (!empty($custom)) { //U::W("mobile=$mobile already exists"); //U::W($arr); } else { $custom = new Custom(); } $custom->mobile = $mobile; $custom->name = $name; $custom->office_id = $office->office_id; $custom->save(false); $i++; if ($i % 1000 == 1) { U::W($i); } } fclose($fh); }
public function getCustom() { return $this->hasOne(Custom::className(), ['mobile' => 'mobile']); }
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); }
public function getCustomer() { return $this->hasOne(Custom::className(), ['mobile' => 'mobile'])->viaTable('wx_openid_bind_mobile', ['gh_id' => 'gh_id', 'openid' => 'openid']); }