checkDatabaseToSeeIfJobNeedToBeDone($data);
if (!$isJobStillNeedToBeDone) {
$job->delete();
return;
}
if (isset($data['doName']) && $data['doName']) {
$doName = $data['doName'];
$isJobDone = $this->$doName($data);
} else
$isJobDone = $this->doPinkJob($data);
if ($isJobDone) {
// 如果任务执行成功, 记得删除任务
$job->delete();
//print("Hello Job has been done and deleted"."\n");
} else {
if ($job->attempts() > 3) {
//通过这个方法可以检查这个任务已经重试了几次了
// print("Hello Job has been retried more than 3 times!"."\n");
$job->delete();
// 也可以重新发布这个任务
//print("Hello Job will be availabe again after 2s."."\n");
//$job->release(2); //$delay为延迟时间,表示该任务延迟2秒后再执行
}
}
}
/**
* 有些消息在到达消费者时,可能已经不再需要执行了
* @param array|mixed $data 发布任务时自定义的数据
* @return boolean 任务执行的结果
*/
private function checkDatabaseToSeeIfJobNeedToBeDone($data)
{
return true;
}
/**
* 根据消息中的数据进行实际的业务处理...
*/
private function doPinkJob($data)
{
$pink_id = $data['pinkInfo']['pink_id'];
if ($pink_id) {
$pink_info = \app\wap\model\store\StorePink::where(['id' => $pink_id, 'k_id' => 0, 'status' => 1])->find();
if ($pink_info ? $pink_info = $pink_info->toArray() : []) {
list($pinkAll, $pinkT, $count, $idAll) = \app\wap\model\store\StorePink::getPinkMemberAndPinkK($pink_info);
\app\wap\model\store\StorePink::PinkFail($pink_info['uid'], $idAll, $pinkAll, $pinkT, $count, 1, [], true, true);
}
}
return true;
}
private function doLiveStudioJob($data)
{
$item = $data['pinkInfo'];
if ($item) {
if ($item['pay_type'] == 1 && $item['member_pay_type'] == 1) {
$orderList = \app\wap\model\store\StoreOrder::where(['cart_id' => $item['special_id'], 'type' => 0])->column("uid");
} elseif ($item['pay_type'] == 1 && $item['member_pay_type'] == 0) {
$order = \app\wap\model\store\StoreOrder::where(['cart_id' => $item['special_id'], 'type' => 0])->column("uid");
$user = \app\wap\model\user\User::where('is_h5user', 0)->where('level', 1)->column("uid");
$orderList = array_merge($order, $user);
} else {
$orderList = \app\wap\model\user\User::where('is_h5user', 0)->column("uid");
}
if (count($orderList) <= 0) return true;
$site_url = \service\SystemConfigService::get('site_url');
$orderList = array_unique($orderList);
foreach ($orderList as $k => $v) {
if ($openId = \app\wap\model\user\WechatUser::where('uid', $v)->value('openid')) {
$wechat_notification_message = \service\SystemConfigService::get('wechat_notification_message');
if ($wechat_notification_message == 1) {
\service\WechatTemplateService::sendTemplate($openId, \service\WechatTemplateService::LIVE_START_NOTICE, [
'first' => '叮!直播马上开始啦,精彩不容错过!',
'keyword1' => $item['live_title'],
'keyword2' => $item['start_play_time'],
'remark' => '直播间通道'
], $site_url . \think\Url::build('wap/special/details', ['id' => $item['special_id']]));
} else {
$data['thing5']['value'] = $item['live_title'];
$data['time2']['value'] = $item['start_play_time'];
\app\wap\model\routine\RoutineTemplate::sendBroadcastReminder($data, $v, $site_url . \think\Url::build('wap/special/details', ['id' => $item['special_id']]));
}
}
$dat['title'] = $item['live_title'];
\app\wap\model\wap\SmsTemplate::sendSms($v, $dat, 'LIVE_START_NOTICE');
}
}
return true;
}
}