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; } } }