Files
tuiguangzhushou/extend/job/Test.php
2020-08-06 15:26:41 +08:00

54 lines
1.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace job;
use app\common\model\Member as MemberModel;
use app\common\service\Wechat as WechatService;
use cjango\Wechat;
use cjango\Wechat\Template;
use think\queue\Job;
class Test extends _Init
{
public function fire(Job $job, $data)
{
if ($job->attempts() > 3) {
$data['msg'] = '重试3次';
parent::writelog($job->getName(), $data, 0);
$job->delete();
} else {
$openid = $data['openid'] ?? '';
$type = $data['type'] ?? '';
$d_array = $data['d_array'] ?? '';
$url = $data['url'] ?? '';
$user = MemberModel::where('openid', $openid)->find();
if ($user) {
WechatService::instance();
$tpl_data = json_decode($d_array, true);
$res = Template::send($openid, $type, $tpl_data, $url);
if ($res) {
$data['msg'] = '发送成功';
parent::writelog($job->getName(), $data, 1);
$job->delete();
} else {
$data['msg'] = Wechat::error();
parent::writelog($job->getName(), $data, 0);
$job->delete();
}
} else {
$data['msg'] = '用户不存在';
parent::writelog($job->getName(), $data, 0);
$job->delete();
}
}
}
}