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; } } }
protected function onScan() { $this->saveAccessLogAll(); $openid = $this->getRequest('FromUserName'); $gh_id = $this->getRequest('ToUserName'); $Event = $this->getRequest('Event'); $EventKey = $this->getRequest('EventKey'); if (!empty($EventKey)) { $Ticket = $this->getRequest('Ticket'); $scene_pid = $EventKey; // U::yjhu_W("EventKey=$EventKey, scene_pid=$scene_pid"); if ($scene_pid > 100000) { $real_sceneid = $scene_pid - 100000; $sceneid_mobile = SceneidMobile::getModelBySceneId($real_sceneid); if (!empty($sceneid_mobile)) { // U::yjhu_W($sceneid_mobile); $openid_bind_mobile = OpenidBindMobile::findOne(['gh_id' => $gh_id, 'mobile' => $sceneid_mobile->mobile]); if (empty($openid_bind_mobile)) { $openid_bind_mobile = new OpenidBindMobile(); $openid_bind_mobile->gh_id = $gh_id; $openid_bind_mobile->openid = $openid; $openid_bind_mobile->mobile = $sceneid_mobile->mobile; $openid_bind_mobile->save(false); // U::yjhu_W($openid_bind_mobile); U::yjhu_W($sceneid_mobile->mobile . '扫码绑定至' . $gh_id . ' ' . $openid); SmsMarketingLog::member($sceneid_mobile->mobile); $user = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); $url = \yii\helpers\Url::to(['wap/hyzx1', 'gh_id' => $gh_id, 'openid' => $openid], true); $respText = $user->nickname . ', 您已成功绑定手机号码' . $sceneid_mobile->mobile . ', 成为襄阳联通微信平台会员,直接点击进入<a href="' . $url . '">会员中心</a>!'; RedpackLog::sendRedpack($gh_id, $openid, $sceneid_mobile->mobile); return $this->responseText($respText); } else { $user = MUser::findOne(['gh_id' => $gh_id, 'openid' => $openid]); $respText = $user->nickname . ', ' . $sceneid_mobile->mobile . '已绑定!'; return $this->responseText($respText); } } } } return Wechat::NO_RESP; }