优惠券订单及其他脚本

recall_user_message.php 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'conf.class.php';
  4. require_once 'SendMsg.class.php';
  5. /**
  6. * 召回潜在用户
  7. */
  8. #设置时区
  9. date_default_timezone_set('PRC');
  10. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  11. $etime = date("Y-m-d H:i:s",strtotime('-1 day'));
  12. $stime = date("Y-m-d H:i:s",strtotime('-36 hour'));
  13. $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}'";
  14. $stmt = $_PDO->prepare($sql);
  15. $stmt->execute();
  16. $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
  17. $n = 0;
  18. $m = 0;
  19. $str = '';
  20. $fstr = '';
  21. echo "\n\nSQL:".$sql;
  22. if(!empty($result)){
  23. foreach($result as $k=>$v){
  24. $mobile = $v['phone'];
  25. $res = sendMsg($mobile);
  26. if($res && $res['code'] == 0){
  27. $n++;
  28. $str .= $mobile.'|';
  29. $inres = insertRecall( $v );
  30. }
  31. else{
  32. $m++;
  33. $fstr .= $mobile.'|';
  34. }
  35. }
  36. }
  37. echo "\n成功发送{$n}条,失败{$m}条";
  38. echo "\n成功:".trim($str,'|');
  39. echo "\n失败:".trim($fstr,'|');
  40. function sendMsg ($mobile){
  41. $params = array();
  42. $params['mobile'] = $mobile;
  43. $n = mt_rand(0,1);
  44. //阿里测试
  45. $params['SignName'] = '猎豆优选';
  46. $params['tpl_id'] = 'SMS_152805117';
  47. $result = SendMsg::AliSendMsg($params);
  48. return $result;
  49. //天瑞测试
  50. /*
  51. $params['SignName'] = '猎豆优选';
  52. $params['tpl_id'] = '30290';
  53. //$params['extra']['code'] = '111256';
  54. //$params['extra']['minutes'] = 2;
  55. $result = SendMsg::TruiSendMsg($params);
  56. var_dump($result);exit;
  57. //云片测试
  58. $params['tpl_id'] = '2619986';
  59. //$params['extra']['code'] = '9000';
  60. //$params['extra']['minutes'] = 2;
  61. $params['extra'] = array();
  62. $result = SendMsg::YpianSendMsg($params);
  63. print_r($result);
  64. return $result;
  65. */
  66. }
  67. function insertRecall($userInfo){
  68. $user_id = $userInfo['id'];
  69. $nick = $userInfo['nickname'];
  70. $phone = $userInfo['phone'];
  71. $regist_at = $userInfo['regist_at'];
  72. $today_date = date("Y-m-d");
  73. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  74. $sql = "insert into `user_recall_log` (user_id, nickname, phone, regist_at, today_date) values ({$user_id},'{$nick}', '{$phone}','{$regist_at}','{$today_date}')";
  75. $stmt = $_PDO->prepare($sql);
  76. $stmt->execute();
  77. return $_PDO->lastinsertid();
  78. }