12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- require_once 'DB_PDO.class.php';
- require_once 'conf.class.php';
- require_once 'SendMsg.class.php';
- /**
- * 召回潜在用户
- */
- #设置时区
- date_default_timezone_set('PRC');
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $etime = date("Y-m-d H:i:s",strtotime('-1 day'));
- $stime = date("Y-m-d H:i:s",strtotime('-36 hour'));
-
- $sql = "select DISTINCT u.phone,wx.nickname,u.id,ul.regist_at from users as u left join user_weixin wx on wx.user_id = u.id left join user_level ul on u.id=ul.user_id where wx.invite_code is null and left(wx.union_id,3) like 'ovn' and wx.user_id>0 and ul.parent_user_id is null and ul.regist_at < '{$etime}' and ul.regist_at >= '{$stime}'";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute();
- $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
- $n = 0;
- $m = 0;
- $str = '';
- $fstr = '';
- echo "\n\nSQL:".$sql;
- if(!empty($result)){
- foreach($result as $k=>$v){
- $mobile = $v['phone'];
- $res = sendMsg($mobile);
- if($res && $res['code'] == 0){
- $n++;
- $str .= $mobile.'|';
- $inres = insertRecall( $v );
- }
- else{
- $m++;
- $fstr .= $mobile.'|';
- }
- }
- }
- echo "\n成功发送{$n}条,失败{$m}条";
- echo "\n成功:".trim($str,'|');
- echo "\n失败:".trim($fstr,'|');
- function sendMsg ($mobile){
- $params = array();
- $params['mobile'] = $mobile;
- $n = mt_rand(0,1);
- //阿里测试
- $params['SignName'] = '猎豆优选';
- $params['tpl_id'] = 'SMS_152805117';
- $result = SendMsg::AliSendMsg($params);
- return $result;
- //天瑞测试
- /*
- $params['SignName'] = '猎豆优选';
- $params['tpl_id'] = '30290';
- //$params['extra']['code'] = '111256';
- //$params['extra']['minutes'] = 2;
- $result = SendMsg::TruiSendMsg($params);
- var_dump($result);exit;
- //云片测试
- $params['tpl_id'] = '2619986';
- //$params['extra']['code'] = '9000';
- //$params['extra']['minutes'] = 2;
- $params['extra'] = array();
- $result = SendMsg::YpianSendMsg($params);
- print_r($result);
- return $result;
- */
- }
- function insertRecall($userInfo){
- $user_id = $userInfo['id'];
- $nick = $userInfo['nickname'];
- $phone = $userInfo['phone'];
- $regist_at = $userInfo['regist_at'];
- $today_date = date("Y-m-d");
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $sql = "insert into `user_recall_log` (user_id, nickname, phone, regist_at, today_date) values ({$user_id},'{$nick}', '{$phone}','{$regist_at}','{$today_date}')";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute();
- return $_PDO->lastinsertid();
- }
|