Commit 4f73eb15 by 朱继来

Merge branch 'master' of http://119.23.72.7/zhujilai/Order into zjl_perm_20191022

parents e3dabe64 b3206861
......@@ -266,52 +266,83 @@ class CronController extends Controller
$user = $UserMainModel->where('is_type', 0)
->where('is_test', 0)
->whereBetween('create_time', [$start_time, $last_time])
->select('user_id', 'is_new')
->select('user_id', 'is_new', 'create_time')
->get()
->toArray();
if (empty($user)) return '未获取到新用户';
$user_send_msg = []; // 需要发送短信的用户ID集合
$crm_params = []; // 推送到crm用户集合
foreach ($user as $v) {
foreach ($user as $k=>$v) {
if ($v['is_new'] == 0) { // 未下单用户
$user_send_msg[] = $v['user_id'];
$user_send_msg[$k]['user_id'] = $v['user_id'];
$user_send_msg[$k]['create_time'] = $v['create_time'];
$crm_params[$k]['user_id'] = $v['user_id'];
$crm_params[$k]['is_create_order'] = 0;
continue;
}
// 已下单用户,判断订单是否有支付
$count = $OrderModel->where('user_id', $v['user_id'])->where('status', '>', 2)->count();
if (!$count) $user_send_msg[] = $v['user_id']; // 不存在,则表示没有已付款的订单
if (!$count) { // 不存在,则表示没有已付款的订单
$user_send_msg[$k]['user_id'] = $v['user_id'];
$user_send_msg[$k]['create_time'] = $v['create_time'];
}
$crm_params[$k]['user_id'] = $v['user_id'];
$crm_params[$k]['is_create_order'] = 1; // 标记已下单
}
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) {
foreach ($user_send_msg as $msg) {
// 判断用户注册时间
$time = time() - $msg['create_time'];
$reg_day = intval(ceil($time / 86400));
switch ($reg_day) {
case 1: $keyword = 'new_user_activity_msg_1'; break;
case 3: $keyword = 'new_user_activity_msg_3'; break;
case 7: $keyword = 'new_user_activity_msg_7'; break;
case 15: $keyword = 'new_user_activity_msg_15'; break;
default : $keyword = ''; break;
}
if (!$keyword) continue;
$userData = [
"keyword" => $keyword,
"pf" => 1,
"k1" => $data['k1'],
"k2" => $data['k2'],
'touser' => json_encode($uid),
'touser' => json_encode($msg['user_id']),
];
$temp = json_decode(curlApi($url, $userData, "POST"), true);
if ($temp['err_code'] == 0) {
continue;
} else {
errorLog($temp['err_code'], $temp['err_msg'].',用户ID:'.$uid); // 消息推送失败记录
}
if (empty($temp) || $temp['err_code'] != 0) errorLog(10001, '消息推送失败记录,用户ID:'.$uid);
continue;
}
// 推送到crm
$crm_url = Config('website.crm_domain').'/api/notifyNewUser';
$crm_header = array('api-key: crm a1b2c3d4e5f6g7h8i9jk');
$res = json_decode(curlApi($crm_url, $crm_params, "POST", false, $crm_header), true);
if (!$res || $res['err_code'] != 0) errorLog(10002, '新用户推送到crm失败 '.$res['err_msg']);
}
}
\ No newline at end of file
......@@ -80,4 +80,7 @@ return [
// 订单微服务
'order_api_domain' => 'http://orderapi.liexin.com',
// crm
'crm_domain' => 'http://lcrm.liexin.net',
];
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