public static function run() { if (self::enable()) { self::sms('18971288549'); // warning self::sms('13545296480'); // warning $cnt = 1; // first round: 76+ customers $offset = 0; $limit = self::SINGLE_STEP_LIMIT; while (true) { $mobiles = MHd201509t5::find()->where(['tcnx' => 2])->orderBy('mobile DESC')->offset($offset)->limit($limit)->all(); foreach ($mobiles as $mobile) { $openid_bind_mobile = OpenidBindMobile::findOne(['gh_id' => MGh::GH_XIANGYANGUNICOM, 'mobile' => $mobile->mobile]); if (empty($openid_bind_mobile)) { $smslog = SmsMarketingLog::findOne(['mobile' => $mobile->mobile]); if (empty($smslog)) { self::sms($mobile->mobile); // $smslog = new SmsMarketingLog; // $smslog->mobile = $mobile->mobile; // $smslog->first_sendtime = time(); // $smslog->last_sendtime = time(); // $smslog->send_count = 1; // $smslog->save(false); $cnt++; if ($cnt > self::dailyLimit()) { return; } } } } $offset += $limit; } // 2nd round, 76- customers $offset = 0; $limit = self::SINGLE_STEP_LIMIT; while (true) { $mobiles = MHd201509t5::find()->where(['tcnx' => 1])->orderBy('mobile DESC')->offset($offset)->limit($limit)->all(); foreach ($mobiles as $mobile) { $openid_bind_mobile = OpenidBindMobile::findOne(['gh_id' => MGh::GH_XIANGYANGUNICOM, 'mobile' => $mobile->mobile]); if (empty($openid_bind_mobile)) { $smslog = SmsMarketingLog::findOne(['mobile' => $mobile->mobile]); if (empty($smslog)) { self::sms($mobile->mobile); // $smslog = new SmsMarketingLog; // $smslog->mobile = $mobile->mobile; // $smslog->first_sendtime = time(); // $smslog->last_sendtime = time(); // $smslog->send_count = 1; // $smslog->save(false); $cnt++; if ($cnt > self::dailyLimit()) { return; } } } } $offset += $limit; } // 3rd round, 76+ customers $offset = 0; $limit = self::SINGLE_STEP_LIMIT; $max_send_count = SmsMarketingLog::sendCountMax(); while (true) { $mobiles = MHd201509t5::find()->where(['tcnx' => 2])->orderBy('mobile DESC')->offset($offset)->limit($limit)->all(); foreach ($mobiles as $mobile) { $openid_bind_mobile = OpenidBindMobile::findOne(['gh_id' => MGh::GH_XIANGYANGUNICOM, 'mobile' => $mobile->mobile]); if (empty($openid_bind_mobile)) { $smslog = SmsMarketingLog::findOne(['mobile' => $mobile->mobile]); if (!empty($smslog) && $smslog->send_count < $max_send_count) { self::sms($mobile->mobile); // $smslog->send_count++; // $smslog->last_sendtime = time(); // $smslog->save(false); $cnt++; if ($cnt > self::dailyLimit()) { return; } } } } $offset += $limit; } // 4th round, 76- customers $offset = 0; $limit = self::SINGLE_STEP_LIMIT; $max_send_count = SmsMarketingLog::sendCountMax(); while (true) { $mobiles = MHd201509t5::find()->where(['tcnx' => 1])->orderBy('mobile DESC')->offset($offset)->limit($limit)->all(); foreach ($mobiles as $mobile) { $openid_bind_mobile = OpenidBindMobile::findOne(['gh_id' => MGh::GH_XIANGYANGUNICOM, 'mobile' => $mobile->mobile]); if (empty($openid_bind_mobile)) { $smslog = SmsMarketingLog::findOne(['mobile' => $mobile->mobile]); if (!empty($smslog) && $smslog->send_count < $max_send_count) { self::sms($mobile->mobile); // $smslog->send_count++; // $smslog->last_sendtime = time(); // $smslog->save(false); $cnt++; if ($cnt > self::dailyLimit()) { return; } } } } $offset += $limit; } } }
public function actionHd201509t6() { $this->layout = false; $gh_id = U::getSessionParam('gh_id'); $openid = U::getSessionParam('openid'); $wx_user = \app\models\MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); if (empty($wx_user) || $wx_user->subscribe === 0) { return $this->render('need_subscribe'); } $bindMobiles = \app\models\OpenidBindMobile::findOne(['gh_id' => $gh_id, 'openid' => $openid]); if (empty($bindMobiles)) { $url = \yii\helpers\Url::to(); \Yii::$app->getSession()->set('RETURN_URL', $url); return $this->redirect(['wap/addbindmobile', 'gh_id' => $gh_id, 'openid' => $openid]); } $hd201509t5 = \app\models\MHd201509t5::findOne(['mobile' => $bindMobiles->mobile]); if (empty($hd201509t5)) { //不在能充值的用户表中,表明是新用户 $tcnx_flag = 0; $yfzx = ""; $fsc = ""; } else { if ($hd201509t5->tcnx == 1) { //76元套餐以下 $tcnx_flag = 1; } else { $tcnx_flag = 2; } $yfzx = $hd201509t5->yfzx; $fsc = $hd201509t5->fsc; } $hd201509t6 = \app\models\MHd201509t6::findOne(['mobile' => $bindMobiles->mobile]); if (empty($hd201509t6)) { $hd201509t6 = new \app\models\MHd201509t6(); $hd201509t6->gh_id = $gh_id; $hd201509t6->openid = $openid; $hd201509t6->mobile = $bindMobiles->mobile; $hd201509t6->status = 0; $hd201509t6->yfzx = $yfzx; $hd201509t6->fsc = $fsc; $hd201509t6->tcnx = $tcnx_flag; $hd201509t6->hbme = 0; $hd201509t6->save(false); } return $this->render('hd201509t6', ['observer' => $wx_user, 'hd201509t6' => $hd201509t6]); }
public function actionImporthd201509t5() { $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'all-76.csv'; $fh = fopen($file, "r"); $i = 0; while (!feof($fh)) { $line = fgets($fh); if (empty($line)) { continue; } $arr = explode(",", $line); //18671071245,7南漳漳南营服中心,个客,2 $mobile = trim($arr[0]); $yfzx = trim($arr[1]); $fsc = trim($arr[2]); $tcnx = trim($arr[3]); //echo $mobile."\t".$yfzx."\t".$fsc."\t".$tcnx."\n"; $hd201509t5 = MHd201509t5::findOne(['mobile' => $mobile]); if (!empty($hd201509t5)) { //U::W("mobile=$mobile already exists"); //U::W($arr); } else { $hd201509t5 = new MHd201509t5(); } $hd201509t5->mobile = $mobile; $hd201509t5->yfzx = $yfzx; $hd201509t5->fsc = $fsc; $hd201509t5->tcnx = $tcnx; $hd201509t5->save(false); $i++; if ($i % 1000 == 1) { echo $i . "\n"; } } fclose($fh); }