LoadController.php
4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/1/28
* Time: 15:41
*/
namespace app\index\controller;
use app\index\model\OrderInfoModel;
use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;
class LoadController extends HomeBaseController
{
public function index(){
$type = $this->request->param('type');
if(!$type){
$arr['code'] = 40001;
$arr['msg'] = '缺点参数!';
return json_encode($arr);
}
//查询所有在托管中的保单
$orderInfoModel = new OrderInfoModel();
$time = time();
if($type == 1){
$where['o.status'] = ['eq',3];
$where['o.order_about_time'] = array(array('<',$time),array('>',$time-30*24*60*60));//array(array('gt',1),array('lt',10))
$whereor = "o.status = 1 and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60);
$data = $orderInfoModel->selectData1($where,$whereor);
dump($data);
foreach($data as $key1 => $vo){
//判断是否已经发送
$send_vice = Db::name('send_vice')->where(array('order_id'=>$vo['o_id'],'collocation_id'=>$vo['id'],'time'=>$vo['order_about_time']))->find();
if(empty($send_vice)){
//模板消息
$templateId = '83NoWJ74UmI-DY_FwrDrTBx1iysu9__6fosB-eMFm78';
$data1 = array(
'first'=>"尊敬的用户,您有一份保单即将到期需要续费,请在保障截止日期前完成续保,否则保单将失效",
'keyword1'=>$vo['insurer'],
'keyword2'=>$vo['product_name'],
'keyword3'=>$vo['insurance_num'],
'keyword4'=>date('Y-m-d',$vo['order_about_time']+30*24*60*60),
'remark'=>"请在保障期间内续费",
);
$url = url('/index/all_guarantee/guarantee_info',array('id'=>$vo['o_id']),'',true);
$user1 = Db::name('third_party_user')->where('user_id',$vo['user_id'])->find();
$this->template($templateId,$data1,$url,$user1['openid']);
//短信
$user2 = Db::name('user')->where('id',$vo['user_id'])->find();
$content = "【橙象保单】尊敬的用户,您有一份保单即将到期需要续费,请在保障截止日期前完成续保,否则保单将失效,保险单号$vo[insurance_num],请在".date('Y月m日d',$vo['order_about_time']+30*24*60*60)."之前续费。";
$this->note($content,$user2['mobile']);
Db::name('send_vice')->insert(array('order_id'=>$vo['o_id'],'collocation_id'=>$vo['id'],'time'=>$vo['order_about_time'],'user_id'=>$vo['user_id'],'create_time'=>time()));
Db::name('order')->where(['id'=>$vo['o_id']])->setInc('order_about_time',30*24*60*60);
}
}
}else if($type == 2){
//$data['status'] eq 2 || $data['order_expire_time'] lt time() || ($data['order_about_time']+24*30*60*60) lt time()
$where['o.status'] = ['eq',2];
$whereor = "o.status = 1 and o.order_expire_time < $time and o.order_about_time < ".($time-24*30*60*60)." or o.status = 3 and o.order_expire_time < $time or o.status = 3 and o.order_about_time < ".($time-24*30*60*60);
$data = $orderInfoModel->selectData1($where,$whereor);
dump($data);
}
}
public function template($templateId,$data,$url=null,$openid){
$options=config('wechat_config');
$app = new Application($options);
$notice = $app->notice;
if(empty($url)){
$notice->uses($templateId)->andData($data)->andReceiver($openid)->send();
}else{
$notice->uses($templateId)->withUrl($url)->andData($data)->andReceiver($openid)->send();
}
}
public function note($content,$mobile){
$data = array(
'content' => $content,//短信内容
'mobile' => $mobile,//手机号码
'productid' => '887361',//产品id
'xh' => ''//小号
);
$result = send_sms($data);
if(substr($result,0,strpos($result,',')) == "1"){
echo '发送成功!';
}else{
echo '接口出错!';
}
}
}