模版消息推送完成
This commit is contained in:
parent
dfd284f255
commit
060fb1ae5c
|
|
@ -23,3 +23,31 @@ if (!function_exists('p')) {
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多维数组去重并重新索引
|
||||||
|
* @param array $array 待处理的多维数组
|
||||||
|
* @return array 去重后并重新索引的数组
|
||||||
|
*/
|
||||||
|
function uniqueMultidimensionalArray($array, $k = 'user_id') {
|
||||||
|
$unique = [];
|
||||||
|
$seenIds = []; // 用于记录已出现的user_id
|
||||||
|
|
||||||
|
foreach ($array as $item) {
|
||||||
|
// 确保子数组包含user_id字段
|
||||||
|
if (!isset($item[$k])) {
|
||||||
|
continue; // 跳过不包含user_id的子数组(可选:也可抛出异常)
|
||||||
|
}
|
||||||
|
|
||||||
|
$userId = $item[$k];
|
||||||
|
// 如果user_id未出现过,则保留该记录
|
||||||
|
if (!in_array($userId, $seenIds)) {
|
||||||
|
$seenIds[] = $userId;
|
||||||
|
$unique[] = $item;
|
||||||
|
}
|
||||||
|
// 已出现的user_id会被自动跳过(去重)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新索引数组(从0开始的连续数字键)
|
||||||
|
return array_values($unique);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace app\model;
|
||||||
// 消息推送
|
// 消息推送
|
||||||
use support\Log;
|
use support\Log;
|
||||||
use support\think\Db;
|
use support\think\Db;
|
||||||
|
use EasyWeChat\Factory;
|
||||||
|
|
||||||
class MessagePushTask
|
class MessagePushTask
|
||||||
{
|
{
|
||||||
|
|
@ -13,11 +14,70 @@ class MessagePushTask
|
||||||
// 查询任务
|
// 查询任务
|
||||||
$event_list = Db::name('tb_push_event')->where(['status' => 0])->select();
|
$event_list = Db::name('tb_push_event')->where(['status' => 0])->select();
|
||||||
if($event_list) {
|
if($event_list) {
|
||||||
foreach ($event_list as $k => $event) {
|
try {
|
||||||
$user_list = self::getPullInfoUser($event);
|
Db::startTrans();
|
||||||
|
foreach ($event_list as $k => $event) {
|
||||||
|
Db::name('tb_push_event')->where(['id' => $event['id']])->update(['status' => 1, 'start_time' => date('Y-m-d H:i:s')]);
|
||||||
|
$res = self::getPullInfoUser($event);
|
||||||
|
if($res) {
|
||||||
|
foreach ($res as $rk => &$rv) {
|
||||||
|
if(empty($rv['open_id'])) {
|
||||||
|
unset($res[$rk]);
|
||||||
|
}
|
||||||
|
$rv['push_event_id'] = $event['id'];
|
||||||
|
$rv['template_id'] = $event['template_id'];
|
||||||
|
$rv['keyword1'] = $event['keyword1'];
|
||||||
|
$rv['keyword2'] = $event['keyword2'];
|
||||||
|
$rv['keyword3'] = $event['keyword3'];
|
||||||
|
$rv['keyword4'] = $event['keyword4'];
|
||||||
|
$rv['keyword5'] = $event['keyword5'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_list = uniqueMultidimensionalArray($res);
|
||||||
|
// 需要接收推送的用户 准备发送
|
||||||
|
foreach ($user_list as $k => $user) {
|
||||||
|
$user_push_list_res_id = Db::name('tb_user_push_event')->insertGetId([
|
||||||
|
'push_event_id' => $user['push_event_id'],
|
||||||
|
'user_id' => $user['user_id'],
|
||||||
|
'create_time' => date("Y-m-d H:i:s"),
|
||||||
|
]);
|
||||||
|
if($user_push_list_res_id) {
|
||||||
|
$app = Factory::officialAccount([
|
||||||
|
'app_id' => config('cons.app_id'),
|
||||||
|
'secret' => config('cons.secret'),
|
||||||
|
'response_type' => 'array',
|
||||||
|
]);
|
||||||
|
$data = [
|
||||||
|
'thing2' => $user['keyword1'],
|
||||||
|
'amount3' => $user['keyword2'],
|
||||||
|
'time6' => $user['keyword3'],
|
||||||
|
];
|
||||||
|
// 正式推送
|
||||||
|
$push = $app->template_message->send([
|
||||||
|
'touser' => $user['open_id'],
|
||||||
|
'template_id' => $user['template_id'],
|
||||||
|
'data' => $data
|
||||||
|
]);
|
||||||
|
Log::info('用户-' . $user['user_id'] . ' 推送模版ID:'. $user['template_id'] .' 内容:' . json_encode($data, 256) . ' 推送结果:' . json_encode($push));
|
||||||
|
if($push['errcode'] == 0) {
|
||||||
|
Db::name('tb_user_push_event')->where(['id' => $user_push_list_res_id])->update(['update_time' => date("Y-m-d H:i:s"), 'status' => 1]);
|
||||||
|
}else {
|
||||||
|
Db::name('tb_user_push_event')->where(['id' => $user_push_list_res_id])->update(['update_time' => date("Y-m-d H:i:s"), 'status' => -1, 'error' => json_encode($push)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
Db::name('tb_push_event')->where(['id' => $event['id']])->update(['status' => 2, 'send_time' => date('Y-m-d H:i:s')]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
}catch (\Exception $e) {
|
||||||
|
Log::info('执行出错--' . $e->getMessage());
|
||||||
|
Db::rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Log::info('没有推送任务可执行');
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,10 +109,11 @@ class MessagePushTask
|
||||||
{
|
{
|
||||||
$user_num = [];
|
$user_num = [];
|
||||||
if($event['can_send_times'] > 0) {
|
if($event['can_send_times'] > 0) {
|
||||||
$user_num = Db::name('tb_user_push_event_num')->alias('upen')->where(['num', '>=', $event['can_send_times']])
|
$user_num = Db::name('tb_user_push_event_num')->alias('upen')->where('upen.num', '>=', $event['can_send_times'])
|
||||||
->join('tb_user_info u', 'upen.user_id = u.id')
|
->join('tb_user_info u', 'upen.user_id = u.id')
|
||||||
->field('upen.user_id as user_id, u.wechat_ac_open_id as open_id')
|
->field('upen.user_id as user_id, upen.open_id as open_id')
|
||||||
->column('open_id', 'user_id');
|
->select()
|
||||||
|
->toArray();
|
||||||
}
|
}
|
||||||
return $user_num;
|
return $user_num;
|
||||||
}
|
}
|
||||||
|
|
@ -64,26 +125,39 @@ class MessagePushTask
|
||||||
$data_arr = [];
|
$data_arr = [];
|
||||||
// 按照性别
|
// 按照性别
|
||||||
if(isset($event['gender']) && is_string($event['gender'])) {
|
if(isset($event['gender']) && is_string($event['gender'])) {
|
||||||
|
$gender_data_arr = [];
|
||||||
$gender_arr = explode(',', $event['gender']);
|
$gender_arr = explode(',', $event['gender']);
|
||||||
foreach ($gender_arr as $k => $gender) {
|
foreach ($gender_arr as $k => $gender) {
|
||||||
// 未知
|
// 未知
|
||||||
if($gender == 0) {
|
if($gender == 0) {
|
||||||
$data_arr[] = Db::name('tb_user_info')->whereNotIn('sex', [0,1])
|
$gender_data_res = Db::name('tb_user_info')->whereNotIn('sex', [0,1])
|
||||||
->field('user_id as user_id, wechat_ac_open_id as open_id')
|
->field('id as user_id, wechat_ac_open_id as open_id')
|
||||||
->column('open_id', 'user_id');
|
->select()
|
||||||
|
->toArray();
|
||||||
}
|
}
|
||||||
// 男
|
// 男
|
||||||
if($gender == 1) {
|
if($gender == 1) {
|
||||||
$data_arr[] = Db::name('tb_user_info')->where('sex', 1)
|
$gender_data_res = Db::name('tb_user_info')->where('sex', 1)
|
||||||
->field('user_id as user_id, wechat_ac_open_id as open_id')
|
->field('id as user_id, wechat_ac_open_id as open_id')
|
||||||
->column('open_id', 'user_id');
|
->select()
|
||||||
|
->toArray();
|
||||||
}
|
}
|
||||||
// 女
|
// 女
|
||||||
if($gender == 2) {
|
if($gender == 2) {
|
||||||
$data_arr[] = Db::name('tb_user_info')->where('sex', 0)
|
$gender_data_res = Db::name('tb_user_info')->where('sex', 0)
|
||||||
->field('user_id as user_id, wechat_ac_open_id as open_id')
|
->field('id as user_id, wechat_ac_open_id as open_id')
|
||||||
->column('open_id', 'user_id');
|
->select()
|
||||||
|
->toArray();
|
||||||
}
|
}
|
||||||
|
if($gender_data_arr) {
|
||||||
|
$gender_data_arr = array_merge($gender_data_arr, $gender_data_res);
|
||||||
|
}else {
|
||||||
|
$gender_data_arr = $gender_data_res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($gender_data_arr) {
|
||||||
|
$data_arr = array_merge($data_arr, $gender_data_arr);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,144 +165,247 @@ class MessagePushTask
|
||||||
// 按照下单次数
|
// 按照下单次数
|
||||||
if(isset($event['order_history']) && is_string($event['order_history'])) {
|
if(isset($event['order_history']) && is_string($event['order_history'])) {
|
||||||
$order_history_arr = explode(',', $event['order_history']);
|
$order_history_arr = explode(',', $event['order_history']);
|
||||||
|
$order_history_data_arr = [];
|
||||||
foreach ($order_history_arr as $k => $order_history) {
|
foreach ($order_history_arr as $k => $order_history) {
|
||||||
// 从未下单
|
// 从未下单
|
||||||
if($order_history == 0) {
|
if($order_history == 0) {
|
||||||
$data_arr[] = Db::name('tb_user_info')
|
$order_history_data_res = Db::name('tb_user_info')
|
||||||
->alias('u') // 用户表别名u
|
->alias('u') // 用户表别名u
|
||||||
->leftJoin('tb_order_info o', 'u.id = o.user_id')
|
->leftJoin('tb_order_info o', 'u.id = o.user_id')
|
||||||
->where('o.user_id', 'null')
|
->where('o.user_id', 'null')
|
||||||
|
->distinct()
|
||||||
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
||||||
->distinct(true)
|
->select()
|
||||||
->column('open_id', 'user_id');
|
->toArray();
|
||||||
}
|
}
|
||||||
// 下过1单
|
// 下过1单
|
||||||
if($order_history == 1) {
|
if($order_history == 1) {
|
||||||
$data_arr[] = Db::name('tb_user_info')
|
$order_history_data_res = Db::name('tb_user_info')
|
||||||
->alias('u')
|
->alias('u')
|
||||||
// 关联订单表,使用内连接确保只包含有订单的用户
|
// 关联订单表,使用内连接确保只包含有订单的用户
|
||||||
->innerJoin('tb_order_info o', 'u.id = o.user_id')
|
->join('tb_order_info o', 'u.id = o.user_id')
|
||||||
// 按用户ID分组
|
// 按用户ID分组
|
||||||
->group('u.id')
|
->group('u.id')
|
||||||
// 筛选出订单数量为1的用户
|
// 筛选出订单数量为1的用户
|
||||||
->having('COUNT(o.id) = 1')
|
->having('COUNT(o.id) = 1')
|
||||||
// 选择需要的用户字段,同时查询订单数量(可选)
|
// 选择需要的用户字段,同时查询订单数量(可选)
|
||||||
->field('u.id as user_id, u.wechat_ac_open_id as user_id')
|
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
||||||
->column('open_id', 'user_id');
|
->select()
|
||||||
|
->toArray();
|
||||||
}
|
}
|
||||||
// 下过2-5单
|
// 下过2-5单
|
||||||
if($order_history == 2) {
|
if($order_history == 2) {
|
||||||
$data_arr[] = Db::name('tb_user_info')
|
$order_history_data_res = Db::name('tb_user_info')
|
||||||
->alias('u')
|
->alias('u')
|
||||||
// 关联订单表,使用内连接确保只包含有订单的用户
|
// 关联订单表,使用内连接确保只包含有订单的用户
|
||||||
->innerJoin('tb_order_info o', 'u.id = o.user_id')
|
->join('tb_order_info o', 'u.id = o.user_id')
|
||||||
// 按用户ID分组
|
// 按用户ID分组
|
||||||
->group('u.id')
|
->group('u.id')
|
||||||
// 筛选出订单数量为1的用户
|
// 筛选出订单数量为1的用户
|
||||||
->having('COUNT(o.id) BETWEEN 2 AND 5')
|
->having('COUNT(o.id) BETWEEN 2 AND 5')
|
||||||
// 选择需要的用户字段,同时查询订单数量(可选)
|
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
||||||
->field('u.id as user_id, u.wechat_ac_open_id as user_id')
|
->select()
|
||||||
->column('open_id', 'user_id');
|
->toArray();
|
||||||
}
|
}
|
||||||
// 下过5单起
|
// 下过5单起
|
||||||
if($order_history == 3) {
|
if($order_history == 3) {
|
||||||
$data_arr[] = Db::name('tb_user_info')
|
$order_history_data_res = Db::name('tb_user_info')
|
||||||
->alias('u')
|
->alias('u')
|
||||||
// 关联订单表,使用内连接确保只包含有订单的用户
|
// 关联订单表,使用内连接确保只包含有订单的用户
|
||||||
->innerJoin('tb_order_info o', 'u.id = o.user_id')
|
->join('tb_order_info o', 'u.id = o.user_id')
|
||||||
// 按用户ID分组
|
// 按用户ID分组
|
||||||
->group('u.id')
|
->group('u.id')
|
||||||
// 筛选出订单数量为1的用户
|
// 筛选出订单数量为1的用户
|
||||||
->having('COUNT(o.id) >= 5')
|
->having('COUNT(o.id) >= 5')
|
||||||
// 选择需要的用户字段,同时查询订单数量(可选)
|
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
||||||
->field('u.id as user_id, u.wechat_ac_open_id as user_id')
|
->select()
|
||||||
->column('open_id', 'user_id');
|
->toArray();
|
||||||
}
|
}
|
||||||
|
if($order_history_data_arr) {
|
||||||
|
$order_history_data_arr = array_merge($order_history_data_arr, $order_history_data_res);
|
||||||
|
;
|
||||||
|
}else {
|
||||||
|
$order_history_data_arr = $order_history_data_res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($order_history_data_arr) {
|
||||||
|
$data_arr = array_merge($data_arr, $gender_data_arr);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按照下单时间 no
|
// 按照下单时间
|
||||||
if(isset($event['order_times']) && is_string($event['order_times'])) {
|
if(isset($event['order_times']) && is_string($event['order_times'])) {
|
||||||
$order_times_arr = explode(',', $event['order_times']);
|
$order_times_arr = explode(',', $event['order_times']);
|
||||||
|
$order_times_data_arr = [];
|
||||||
foreach ($order_times_arr as $k => $order_times) {
|
foreach ($order_times_arr as $k => $order_times) {
|
||||||
// 今天下过
|
// 今天下过
|
||||||
if($order_times == 0) {
|
if($order_times == 0) {
|
||||||
$data_arr[] = Db::name('tb_user_info')
|
$order_times_data_res = Db::name('tb_user_info')
|
||||||
->alias('u') // 用户表别名u
|
->alias('u') // 用户表别名u
|
||||||
->innerJoin('tb_order_info o', 'u.id = o.user_id')
|
->join('tb_order_info o', 'u.id = o.user_id')
|
||||||
->where('o.create_time', '>=', date('Y-m-d 00:00:00'))
|
->where('o.create_time', '>=', date('Y-m-d 00:00:00'))
|
||||||
->where('o.create_time', '<=', date('Y-m-d 23:59:59'))
|
->where('o.create_time', '<=', date('Y-m-d 23:59:59'))
|
||||||
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
||||||
->distinct(true)
|
->distinct()
|
||||||
->column('open_id', 'user_id');
|
->select()
|
||||||
|
->toArray();
|
||||||
}
|
}
|
||||||
// 昨天下过
|
// 昨天下过
|
||||||
if($order_times == 1) {
|
if($order_times == 1) {
|
||||||
$data_arr[] = Db::name('tb_user_info')
|
$order_times_data_res = Db::name('tb_user_info')
|
||||||
->alias('u')
|
->alias('u') // 用户表别名u
|
||||||
// 关联订单表,使用内连接确保只包含有订单的用户
|
->join('tb_order_info o', 'u.id = o.user_id')
|
||||||
->innerJoin('tb_order_info o', 'u.id = o.user_id')
|
->where('o.create_time', '>=', date('Y-m-d 00:00:00', strtotime('-1 day')))
|
||||||
// 按用户ID分组
|
->where('o.create_time', '<=', date('Y-m-d 23:59:59', strtotime('-1 day')))
|
||||||
->group('u.id')
|
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
||||||
// 筛选出订单数量为1的用户
|
->distinct()
|
||||||
->having('COUNT(o.id) = 1')
|
->select()
|
||||||
// 选择需要的用户字段,同时查询订单数量(可选)
|
->toArray();
|
||||||
->field('u.id as user_id, u.wechat_ac_open_id as user_id')
|
|
||||||
->column('open_id', 'user_id');
|
|
||||||
}
|
}
|
||||||
// 2周内没下过
|
// 2周内没下过
|
||||||
if($order_times == 2) {
|
if($order_times == 2) {
|
||||||
$data_arr[] = Db::name('tb_user_info')
|
$twoWeeksAgo = date('Y-m-d H:i:s', strtotime('-14 days'));
|
||||||
->alias('u')
|
$order_times_data_res = Db::name('tb_user_info')
|
||||||
// 关联订单表,使用内连接确保只包含有订单的用户
|
->alias('u') // 用户表别名u
|
||||||
->innerJoin('tb_order_info o', 'u.id = o.user_id')
|
// 左连接订单表,关联条件包含近两周内的订单
|
||||||
// 按用户ID分组
|
->leftJoin('tb_order_info o', 'u.id = o.user_id')
|
||||||
->group('u.id')
|
->where('o.create_time', '>=', $twoWeeksAgo)
|
||||||
// 筛选出订单数量为1的用户
|
->where('o.id', 'null')
|
||||||
->having('COUNT(o.id) BETWEEN 2 AND 5')
|
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
||||||
// 选择需要的用户字段,同时查询订单数量(可选)
|
->distinct()
|
||||||
->field('u.id as user_id, u.wechat_ac_open_id as user_id')
|
->select()
|
||||||
->column('open_id', 'user_id');
|
->toArray();
|
||||||
}
|
}
|
||||||
// 半个月-1个月没下过
|
// 半个月-1个月没下过
|
||||||
if($order_times == 3) {
|
if($order_times == 3) {
|
||||||
$data_arr[] = Db::name('tb_user_info')
|
$startTime = date('Y-m-d H:i:s', strtotime('-30 days'));
|
||||||
->alias('u')
|
$endTime = date('Y-m-d H:i:s', strtotime('-15 days'));
|
||||||
// 关联订单表,使用内连接确保只包含有订单的用户
|
$order_times_data_res = Db::name('tb_user_info')
|
||||||
->innerJoin('tb_order_info o', 'u.id = o.user_id')
|
->alias('u') // 用户表别名u
|
||||||
// 按用户ID分组
|
// 左连接订单表,关联条件包含近两周内的订单
|
||||||
|
->join('tb_order_info o', 'u.id = o.user_id')
|
||||||
|
// 按用户分组
|
||||||
->group('u.id')
|
->group('u.id')
|
||||||
// 筛选出订单数量为1的用户
|
// 筛选最后下单时间在30天前到15天前之间的用户
|
||||||
->having('COUNT(o.id) >= 5')
|
->having('MAX(o.create_time) >="'. $startTime .'" AND MAX(o.create_time) <= "' . $endTime . '"')
|
||||||
// 选择需要的用户字段,同时查询订单数量(可选)
|
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
||||||
->field('u.id as user_id, u.wechat_ac_open_id as user_id')
|
->select()
|
||||||
->column('open_id', 'user_id');
|
->toArray();
|
||||||
}
|
}
|
||||||
// 1个月以上没下过
|
// 1个月以上没下过
|
||||||
if($order_times == 4) {
|
if($order_times == 4) {
|
||||||
$data_arr[] = Db::name('tb_user_info')
|
$oneMonthAgo = date('Y-m-d H:i:s', strtotime('-30 days'));
|
||||||
->alias('u')
|
$order_times_data_res = Db::name('tb_user_info')
|
||||||
// 关联订单表,使用内连接确保只包含有订单的用户
|
->alias('u') // 用户表别名u
|
||||||
->innerJoin('tb_order_info o', 'u.id = o.user_id')
|
// 左连接订单表,关联条件包含近两周内的订单
|
||||||
// 按用户ID分组
|
->join('tb_order_info o', 'u.id = o.user_id')
|
||||||
|
// 按用户分组
|
||||||
->group('u.id')
|
->group('u.id')
|
||||||
// 筛选出订单数量为1的用户
|
// 筛选最后下单时间在1个月前及更早
|
||||||
->having('COUNT(o.id) >= 5')
|
->having('MAX(o.create_time) <= "' . $oneMonthAgo . '"')
|
||||||
// 选择需要的用户字段,同时查询订单数量(可选)
|
// ->field('u.id as user_id, u.wechat_ac_open_id as open_id, MAX(o.create_time) as last_order_time')
|
||||||
->field('u.id as user_id, u.wechat_ac_open_id as user_id')
|
->field('u.id as user_id, u.wechat_ac_open_id as open_id')
|
||||||
->column('open_id', 'user_id');
|
->select()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
if($order_times_data_arr) {
|
||||||
|
$order_times_data_arr = array_merge($order_times_data_arr, $order_times_data_res);
|
||||||
|
|
||||||
|
}else {
|
||||||
|
$order_times_data_arr = $order_times_data_res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($order_times_data_arr) {
|
||||||
|
$data_arr = array_merge($data_arr, $order_times_data_arr);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按照会员
|
||||||
|
if(isset($event['vip']) && is_string($event['vip'])) {
|
||||||
|
$vip_data_arr = [];
|
||||||
|
$vip_arr = explode(',', $event['vip']);
|
||||||
|
foreach ($vip_arr as $k => $vip) {
|
||||||
|
// 非会员
|
||||||
|
if($vip == 0) {
|
||||||
|
$vip_data_res = Db::name('tb_user_info')->whereNotIn('is_vip', 0)
|
||||||
|
->field('id as user_id, wechat_ac_open_id as open_id')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
// 会员
|
||||||
|
if($vip == 1) {
|
||||||
|
$vip_data_res = Db::name('tb_user_info')->where('is_vip', 1)
|
||||||
|
->field('id as user_id, wechat_ac_open_id as open_id')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($vip_data_arr) {
|
||||||
|
$vip_data_arr = array_merge($vip_data_arr, $vip_data_res);
|
||||||
|
|
||||||
|
}else {
|
||||||
|
$vip_data_arr = $vip_data_res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($vip_data_arr) {
|
||||||
|
$data_arr = array_merge($data_arr, $vip_data_arr);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按照手机号
|
||||||
|
if(isset($event['telphone']) && is_string($event['telphone'])) {
|
||||||
|
$telphone_data_arr = [];
|
||||||
|
$telphone_arr = explode(',', $event['telphone']);
|
||||||
|
foreach ($telphone_arr as $k => $telphone) {
|
||||||
|
// 非绑定
|
||||||
|
if($telphone == 0) {
|
||||||
|
$telphone_data_res = Db::name('tb_user_info')->where(function ($query) {
|
||||||
|
$query->where('phone', 'null') // 为 NULL
|
||||||
|
->whereOr('phone', ''); // 为空字符串
|
||||||
|
})
|
||||||
|
->field('id as user_id, wechat_ac_open_id as open_id')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
// 已绑定
|
||||||
|
if($telphone == 1) {
|
||||||
|
$telphone_data_res = Db::name('tb_user_info')->where('phone', '<>', '')
|
||||||
|
->field('id as user_id, wechat_ac_open_id as open_id')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
if($telphone_data_arr) {
|
||||||
|
$telphone_data_arr = array_merge($telphone_data_arr, $telphone_data_res);
|
||||||
|
|
||||||
|
}else {
|
||||||
|
$telphone_data_arr = $telphone_data_res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($telphone_data_arr) {
|
||||||
|
$data_arr = array_merge($data_arr, $telphone_data_arr);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $data_arr;
|
return $data_arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按照标签获取用户信息
|
// 按照标签获取用户信息
|
||||||
public static function getPullInfoUserToLabel($event)
|
public static function getPullInfoUserToLabel($event)
|
||||||
{
|
{
|
||||||
return [];
|
$data_arr = [];
|
||||||
|
$label = Db::name('tb_user_label')->whereIn('label_id', explode(',', $event['user_label']))
|
||||||
|
->distinct()
|
||||||
|
->column('user_id');
|
||||||
|
if($label) {
|
||||||
|
$data_arr = Db::name('tb_user_info')->whereIn('id', $label)
|
||||||
|
->field('id as user_id, wechat_ac_open_id as open_id')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
return $data_arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,11 @@ class MessagePushTask
|
||||||
|
|
||||||
|
|
||||||
// 每分钟执行 营销推送
|
// 每分钟执行 营销推送
|
||||||
new Crontab('1 * * * * *', function(){
|
// new Crontab('1 * * * * *', function(){
|
||||||
Log::info('营销推送开始执行---->');
|
// Log::info('营销推送开始执行---->');
|
||||||
\app\model\MessagePushTask::send_msg();
|
// \app\model\MessagePushTask::send_msg();
|
||||||
Log::info('营销推送执行结束---->');
|
// Log::info('营销推送执行结束---->');
|
||||||
});
|
// });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@
|
||||||
"webman/redis": "^2.1",
|
"webman/redis": "^2.1",
|
||||||
"illuminate/events": "^11.46",
|
"illuminate/events": "^11.46",
|
||||||
"webman/redis-queue": "^1.3",
|
"webman/redis-queue": "^1.3",
|
||||||
"workerman/crontab": "^1.0"
|
"workerman/crontab": "^1.0",
|
||||||
|
"overtrue/wechat": "~5.0"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-event": "For better performance. "
|
"ext-event": "For better performance. "
|
||||||
|
|
@ -56,5 +57,10 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"prefer-stable": true
|
"prefer-stable": true,
|
||||||
|
"config": {
|
||||||
|
"allow-plugins": {
|
||||||
|
"easywechat-composer/easywechat-composer": true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return [
|
||||||
|
'app_id' => 'wx1fb600d0f5ea6279', // 银收客czg
|
||||||
|
'secret' => 'b4c0534c9b5e6c84a7fe5c2078dff876',
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue