LoadController.php
11.1 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?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(){
//查询所有在托管中的保单
$orderInfoModel = new OrderInfoModel();
$time = time();
// if($type == 1){
// $where['o.status'] = ['eq',3];
// $where['o.order_expire_time2'] = ['>',$time];
// $where['o.order_about_time'] = array(array('<',$time),array('>',$time-30*24*60*60));
// $whereor = "o.status = 1 and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60)." and o.order_expire_time2 > $time";
$data = $orderInfoModel->selectData1();
foreach($data as $key1 => $vo) {
if ($vo['status'] == 3 && $vo['order_about_time'] < time() && ($vo['order_about_time'] + 30 * 24 * 60 * 60) > time() || ($vo['status'] == 1 && $vo['order_about_time'] < time() && ($vo['order_about_time'] + 30 * 24 * 60 * 60) > time())) {
//判断是否已经发送
$send_vice = Db::name('send_vice')->where(array('order_id'=>$vo['o_id'],'collocation_id'=>$vo['id'],'time'=>$vo['order_about_time'],'type'=>1))->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(), 'type' => 1));
}else{
echo "无需再次发送!";
}
} else if (($vo['status'] == 1 && $vo['order_expire_time2'] > time()) || ($vo['status'] == 3 && $vo['order_expire_time2'] > time())) {
if(($vo['order_about_time'] + 30 * 24 * 60 * 60) < time()){
if(($vo['order_about_time']+365*24*60*60)<$vo['order_expire_time']){
Db::name('order')->where(['id' => $vo['o_id']])->setInc('order_about_time', 365 * 24 * 60 * 60);
}
}
} else if ($vo['status'] == 2) {
//判断是否已经发送
$send_vice = Db::name('send_vice')->where(array('order_id'=>$vo['o_id'],'collocation_id'=>$vo['id'],'time'=>$vo['order_expire_time2'],'type'=>2))->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]。";
$this->note($content,$user2['mobile']);
Db::name('send_vice')->insert(array('order_id' => $vo['o_id'], 'collocation_id' => $vo['id'], 'time' => $vo['order_expire_time2'], 'user_id' => $vo['user_id'], 'create_time' => time(), 'type' => 2));
}else{
echo "无需再次发送!";
}
} else {
$send_vice = Db::name('send_vice')->where(array('order_id'=>$vo['o_id'],'collocation_id'=>$vo['id'],'time'=>$vo['order_expire_time2'],'type'=>2))->find();
if(empty($send_vice)) {
//短信
$user2 = Db::name('user')->where('id', $vo['user_id'])->find();
$content = "【橙象保单】尊敬的用户,您有一份保单已经失效,保险单号$vo[insurance_num]。";
$this->note($content, $user2['mobile']);
Db::name('send_vice')->insert(array('order_id' => $vo['o_id'], 'collocation_id' => $vo['id'], 'time' => $vo['order_expire_time2'], 'user_id' => $vo['user_id'], 'create_time' => time(), 'type' => 2));
}else{
echo "无需再次发送!";
}
}
}
// 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'],'type'=>1))->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(),'type'=>1));
// //Db::name('order')->where(['id'=>$vo['o_id']])->setInc('order_about_time',30*24*60*60);
// echo ($vo['order_about_time']+30*24*60*60)."@@@";
// if(($vo['order_about_time']+30*24*60*60)<time()){
// echo ($vo['order_about_time']+30*24*60*60)."@@@@";
// if(($vo['order_about_time']+365*24*60*60)<$vo['order_expire_time']){
// echo ($vo['order_about_time']+30*24*60*60)."@@@@@";
// Db::name('order')->where(['id'=>$vo['o_id']])->setInc('order_about_time',365*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];
// $where = [];
// $whereor = "(o.status = 1 and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.status = 3 and o.order_about_time < ".($time-24*30*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'],'type'=>2))->find();
//// if(empty($send_vice)){
//// //短信
//// $user2 = Db::name('user')->where('id',$vo['user_id'])->find();
//// $content = "【橙象保单】尊敬的用户,您有一份保单已经失效,保险单号$vo[insurance_num]。";
//// $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(),'type'=>2));
//// }
//// }
// }
}
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 '接口出错!';
}
}
}