Commit 397fb35f by 朱继来

Merge branch 'zjl_act_msg_20190911' into development

parents 02333f3f 9c8d5843
...@@ -247,4 +247,71 @@ class CronController extends Controller ...@@ -247,4 +247,71 @@ class CronController extends Controller
$RedisModel->set('api_lx_activity_user_rank', null); $RedisModel->set('api_lx_activity_user_rank', null);
} }
/**
* 推送新用户活动短信
*
* 条件:前一天注册,未下单的用户或下单未支付一笔订单的用户
*
* 推送时间:每天上午10点 (0 10 * * * /usr/bin/curl http://order.ichunt.net/act/useramoumt)
*/
public function sendActMsg()
{
$start_time = strtotime(date('Y-m-d', strtotime('-1 day'))); // 前一天0点
$last_time = strtotime(date('Y-m-d')) - 1; // 前一天23:59:59
$UserMainModel = new UserMainModel;
$OrderModel = new OrderModel;
// 获取前一天新注册用户
$user = $UserMainModel->where('is_type', 0)
->where('is_test', 0)
->whereBetween('create_time', [$start_time, $last_time])
->select('user_id', 'is_new')
->get()
->toArray();
if (empty($user)) return '未获取到新用户';
$user_send_msg = []; // 需要发送短信的用户ID集合
foreach ($user as $v) {
if ($v['is_new'] == 0) { // 未下单用户
$user_send_msg[] = $v['user_id'];
continue;
}
// 已下单用户,判断订单是否有支付
$count = $OrderModel->where('user_id', $v['user_id'])->where('status', '>', 2)->count();
if (!$count) $user_send_msg[] = $v['user_id']; // 不存在,则表示没有已付款的订单
}
if (empty($user_send_msg)) return '没有需要推送活动短信的用户';
//调用消息接口
$url = Config('website.api_domain').'msg/sendmessagebyauto';
$keyword = 'new_user_activity_msg';
$data['k1'] = time();
$data['k2'] = md5(md5($data['k1']).'fh6y5t4rr351d2c3bryi');
foreach ($user_send_msg as $uid) {
$userData = [
"keyword" => $keyword,
"pf" => 1,
"k1" => $data['k1'],
"k2" => $data['k2'],
'touser' => json_encode($uid),
];
$temp = json_decode(curlApi($url, $userData, "POST"), true);
if ($temp['err_code'] == 0) {
continue;
} else {
errorLog($temp['err_code'], $temp['err_msg'].',用户ID:'.$uid); // 消息推送失败记录
}
}
}
} }
\ No newline at end of file
...@@ -150,5 +150,6 @@ Route::group(['middleware' => 'api'], function () { ...@@ -150,5 +150,6 @@ Route::group(['middleware' => 'api'], function () {
Route::get('/act/useramount', 'CronController@userAmount'); // 活动统计用户实付金额 Route::get('/act/useramount', 'CronController@userAmount'); // 活动统计用户实付金额
Route::get('/act/clear', 'CronController@clearData'); // 清除活动统计用户表和缓存 Route::get('/act/clear', 'CronController@clearData'); // 清除活动统计用户表和缓存
Route::get ('/handle/paylog', 'SpecialController@handlePayLog'); // 处理支付记录 Route::get ('/handle/paylog', 'SpecialController@handlePayLog'); // 处理支付记录
Route::get('/act/sendactmsg', 'CronController@sendActMsg'); // 推送活动短信
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment