|
|
@ -34,6 +34,7 @@ class Task extends Controller{ |
|
|
$out_point_log['change'] = -$out_point; |
|
|
$out_point_log['change'] = -$out_point; |
|
|
$out_point_log['type'] = 2; |
|
|
$out_point_log['type'] = 2; |
|
|
$out_point_log['in_point'] = $admin_point['in_point']; |
|
|
$out_point_log['in_point'] = $admin_point['in_point']; |
|
|
|
|
|
$out_point_log['after_point'] = $admin_point['in_point'] - $out_point; |
|
|
$out_point_log['active_id'] = 0; |
|
|
$out_point_log['active_id'] = 0; |
|
|
$out_point_log['active_name'] = ""; |
|
|
$out_point_log['active_name'] = ""; |
|
|
$out_point_log['money'] = 0; |
|
|
$out_point_log['money'] = 0; |
|
|
@ -46,6 +47,87 @@ class Task extends Controller{ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 定时任务 每日过期积分 |
|
|
|
|
|
public function sendWxMessage(){ |
|
|
|
|
|
|
|
|
|
|
|
$weixinInfo = config('weixin_info'); |
|
|
|
|
|
$weixinTemplate = config('weixin_templates'); |
|
|
|
|
|
$now = time(); |
|
|
|
|
|
$appid = $weixinInfo['appid']; |
|
|
|
|
|
$appsecret = $weixinInfo['appSecret']; |
|
|
|
|
|
|
|
|
|
|
|
$access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsecret}"; |
|
|
|
|
|
$access_token_json = $this->https_request($access_token_url,[]);//自定义函数 |
|
|
|
|
|
$access_token_array = json_decode($access_token_json,true);//对 JSON 格式的字符串进行解码,转换为 PHP 变量,自带函数 |
|
|
|
|
|
//获取access_token |
|
|
|
|
|
$access_token = $access_token_array['access_token'];//获取access_token对应的值 |
|
|
|
|
|
|
|
|
|
|
|
//待发送的积分消息 |
|
|
|
|
|
//获取所有的用户所有已到期的有剩余积分的数据 求和 |
|
|
|
|
|
$messages = Db::table('admin_point_message')->where(['status'=>0])->order("id desc")->limit(10)->select(); |
|
|
|
|
|
foreach ($messages as $message){ |
|
|
|
|
|
if(!$message['openid'] || !$weixinTemplate[$message['tempid']]){ |
|
|
|
|
|
$update = [ |
|
|
|
|
|
"status"=>-1 |
|
|
|
|
|
]; |
|
|
|
|
|
Db::table('admin_point_message')->where('id',$message['id'])->update($update); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$wxMessage = [ |
|
|
|
|
|
'touser' => $message['openid'], |
|
|
|
|
|
'template_id' => $weixinTemplate[$message['tempid']], |
|
|
|
|
|
"url" => 'http://jm.iiixo.com/', |
|
|
|
|
|
"data"=>[ |
|
|
|
|
|
"first"=>["value"=>"合肥金麓积分变动通知"], |
|
|
|
|
|
"keyword1"=>["value"=>$message['good_name']?$message['good_name']:"提货商品"], |
|
|
|
|
|
"keyword2"=>["value"=>$message['take_money']], |
|
|
|
|
|
"keyword3"=>["value"=>$message['out_point']], |
|
|
|
|
|
"keyword4"=>["value"=>$message['get_point']."(有效积分:".$message['point'].")"], |
|
|
|
|
|
// "keyword5"=>["value"=>$message['point']], |
|
|
|
|
|
"keyword5"=>["value"=>date("Y年m月d日 H:i",$message['take_time']?:$message['add_time'])], |
|
|
|
|
|
"remark"=>["value"=>$message['remark']], |
|
|
|
|
|
], |
|
|
|
|
|
]; |
|
|
|
|
|
$wxMessage = json_encode($wxMessage, JSON_UNESCAPED_UNICODE); |
|
|
|
|
|
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={$access_token}"; |
|
|
|
|
|
$res = $this->https_request($url,$wxMessage);//自定义函数 |
|
|
|
|
|
$result = json_decode($res,true);//对 JSON 格式的字符串进行解码,转换为 PHP 变量,自带函数 |
|
|
|
|
|
if($result['errcode'] == 0 ){ |
|
|
|
|
|
$update = [ |
|
|
|
|
|
"status"=>1, |
|
|
|
|
|
"send_time" => time(), |
|
|
|
|
|
]; |
|
|
|
|
|
}else{ |
|
|
|
|
|
$update = [ |
|
|
|
|
|
"status"=>-1, |
|
|
|
|
|
]; |
|
|
|
|
|
} |
|
|
|
|
|
Db::table('admin_point_message')->where('id',$message['id'])->update($update); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function https_request($url,$data)//自定义函数,访问url返回结果 |
|
|
|
|
|
{ |
|
|
|
|
|
$curl = curl_init(); |
|
|
|
|
|
curl_setopt($curl, CURLOPT_URL, $url); |
|
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); |
|
|
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); |
|
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
|
|
|
|
if (! empty($data)) { |
|
|
|
|
|
curl_setopt($curl, CURLOPT_POST, 1); |
|
|
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|
|
|
|
|
} |
|
|
|
|
|
$data = curl_exec($curl); |
|
|
|
|
|
if (curl_errno($curl)){ |
|
|
|
|
|
return 'ERROR'.curl_error($curl); |
|
|
|
|
|
} |
|
|
|
|
|
curl_close($curl); |
|
|
|
|
|
return $data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 定时任务 每日监测 |
|
|
// 定时任务 每日监测 |
|
|
public function autotask(){ |
|
|
public function autotask(){ |
|
|
|