MeGuaranteeController.php
13.2 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/1/4
* Time: 9:11
*/
namespace app\index\controller;
use app\index\model\CollocationModel;
use app\index\model\OrderInfoModel;
use app\index\model\PageHtmlModel;
use app\index\model\SubjoinInsuranceModel;
use app\index\model\UserModel;
use cmf\controller\WeChatBaseController;
use EasyWeChat\Foundation\Application;
//我的保单
class MeGuaranteeController extends WeChatBaseController
{
//授权
function _initialize()
{
//判断用户是否微信浏览器打开
//$this->isWechat();
//判断是否手机端
//$this->isMobile();
//微信授权
parent::_initialize();
$this->checkWeChatUserLogin();
//阻止拉黑用户
$this->ban();
}
public function index(){
$user_id = cmf_get_current_user_id();
$userModel = new UserModel();
$user = $userModel->findUserData(array('id'=>$user_id));
$collocationModel = new CollocationModel();
$no_collocation_count = $collocationModel->collocationCount(array('user_id'=>$user_id));//保单总数
$no_people_count = $collocationModel->peopleCount(array('user_id'=>$user_id));//被保人数
$no_main_total_sum = $collocationModel->totalSum(array('user_id'=>$user_id));//本年保险支出(主险)
$subjoinInsuranceModel = new SubjoinInsuranceModel();
$no_vice_total_sum = $subjoinInsuranceModel->subjoinSum(array('s.user_id'=>$user_id));//本年保险支出(附加险)
//已托管的保单信息
$orderInfoModel = new OrderInfoModel();
$yes_collocation_count = $orderInfoModel->collocationCount(array('c.user_id'=>$user_id));//托管中状态的保单份数
$yes_people_count = $orderInfoModel->peopleCount(array('c.user_id'=>$user_id));//托管中状态的被保人数
$yes_main_total_sum = $orderInfoModel->totalSum(array('c.user_id'=>$user_id));//托管中状态的本年保险支出(主险)
$yes_vice_total_sum = $orderInfoModel->subjoinSum(array('c.user_id'=>$user_id));//托管中状态的本年保险支出(附加险)
$insurer = $collocationModel->insurerData(array('user_id'=>$user_id),"insurer");//获取全部保险人
$collocation = $orderInfoModel->selectData(array('c.user_id'=>$user_id));//获取到在托管中状态的保单
//获取第一个被保人的默认信息
$collocation_data = $orderInfoModel->selectData1(array('c.user_id'=>$user_id,'c.insurer'=>!empty($insurer[0]['insurer']) ? $insurer[0]['insurer'] : null));
$pageHtmlModel = new PageHtmlModel();
$page_html = $pageHtmlModel->findData(array('id'=>4));
$this->assign(
array(
'user' => $user,
'no_collocation_count' => $no_collocation_count,
'no_people_count' => $no_people_count,
'no_total_sum' => $no_main_total_sum+$no_vice_total_sum,
'yes_collocation_count' => $yes_collocation_count,
'yes_people_count' => $yes_people_count,
'yes_total_sum' => $yes_main_total_sum+$yes_vice_total_sum,
'insurer' => $insurer,
'collocation_data' => $collocation_data,
'page_html'=>$page_html,
)
);
return $this->fetch();
}
public function guarantee_info(){
$options = [
'app_id' => config('wechat_config.app_id'),
'secret' => config('wechat_config.secret'),
'payment' => config('wechat_config.payment'),
];
$app = new Application($options);
$js = $app->js;
$jssdk = $js->config(['chooseImage', 'uploadImage', 'previewImage'], $debug = false, $beta = false, $json = true);
$id = $this->request->param('id');
$user_id = cmf_get_current_user_id();
$orderInfoModel = new OrderInfoModel();
$data = $orderInfoModel->findData(array('o.id'=>$id,'o.user_id'=>$user_id))->toArray();
$subjoinInsuranceModel = new SubjoinInsuranceModel();
$subjoin = $subjoinInsuranceModel->selectData2(array('collocation_id'=>$data['id']));
$this->assign(
array(
'jssdk'=>$jssdk,
'data'=>$data,
'subjoin'=>$subjoin,
)
);
return $this->fetch();
}
public function select_status(){
$param = $this->request->param();
if(!empty($param['application'])){
$where['c.application'] = ['eq',$param['application']];
}
if(!empty($param['agent_phone'])){
$where['c.agent_phone'] = ['eq',$param['agent_phone']];
}
$user_id = !empty($param['user_id']) ? $param['user_id'] : cmf_get_current_user_id();
$insurer = $param['insurer'];
$time = time();
// $where['c.insurer'] = ['eq',$insurer];
$where = [];
$whereor = '';
if(!empty($param['status'])){//0为全部1为托管中2为即将到期3为未托管
if($param['status'] == 1){
$where['o.status'] = ['eq',1];
$where['c.insurer'] = ['eq',$param['insurer']];
// $where['o.order_about_time'] = ['>',$time];
// $where['o.order_expire_time2'] = ['>',$time];
if(!empty($param['application']) && !empty($param['agent_phone'])){
$where['c.application'] = ['eq',$param['application']];
$where['c.agent_phone'] = ['eq',$param['agent_phone']];
$whereor = "o.status = 3 and o.order_expire_time2 > $time and c.application = "."'"."$param[application]"."'"." and c.agent_phone = $param[agent_phone] and c.insurer ="."'"."$insurer"."'";
}else if(!empty($param['application'])){
$where['c.application'] = ['eq',$param['application']];
$whereor = "o.status = 3 and o.order_expire_time2 > $time and c.application = "."'"."$param[application]"."'"." and c.insurer ="."'"."$insurer"."'";
}else if(!empty($param['agent_phone'])){
$where['c.agent_phone'] = ['eq',$param['agent_phone']];
$whereor = "o.status = 3 and o.order_expire_time2 > $time and c.agent_phone = $param[agent_phone] and c.insurer ="."'"."$insurer"."'";
}else{
$where['o.user_id'] = ['eq',$user_id];
$whereor = "o.user_id = $user_id and o.status = 3 and o.order_expire_time2 > ".$time." and c.insurer ="."'"."$insurer"."'";
}
}else if($param['status'] == 2){
$where['o.status'] = ['eq',3];
$where['c.insurer'] = ['eq',$param['insurer']];
$where['o.order_expire_time2'] = ['>',$time];
$where['o.order_about_time'] = array(array('<',$time),array('>',$time-30*24*60*60));//array(array('gt',1),array('lt',10))
if(!empty($param['application']) && !empty($param['agent_phone'])){
$where['c.application'] = ['eq',$param['application']];
$where['c.agent_phone'] = ['eq',$param['agent_phone']];
$whereor = "o.status = 1 and c.insurer = "."'".$insurer."'"." and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60)." and o.order_expire_time2 > $time and c.application = "."'"."$param[application]"."'"." and c.agent_phone = $param[agent_phone]";
}else if(!empty($param['application'])){
$where['c.application'] = ['eq',$param['application']];
$whereor = "o.status = 1 and c.insurer = "."'".$insurer."'"." and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60)." and o.order_expire_time2 > $time and c.application = "."'"."$param[application]"."'"."";
}else if(!empty($param['agent_phone'])){
$where['c.agent_phone'] = ['eq',$param['agent_phone']];
$whereor = "o.status = 1 and c.insurer = "."'".$insurer."'"." and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60)." and o.order_expire_time2 > $time and c.agent_phone = $param[agent_phone]";
}else{
$where['o.user_id'] = ['eq',$user_id];
$whereor = "o.user_id = $user_id and o.status = 1 and c.insurer = "."'".$insurer."'"." and o.order_about_time < $time and o.order_about_time > ".($time-30*24*60*60)." and o.order_expire_time2 > $time";
}
}else if($param['status'] == 3){
// $where['o.status'] = ['eq',2];
// $where['c.insurer'] = ['eq',$param['insurer']];
// $where['o.order_expire_time2'] = ['<',$time];
if(!empty($param['application']) && !empty($param['agent_phone'])){
$whereor = "(o.status = 3 and o.order_expire_time2 < $time and c.insurer ="."'"."$insurer"."'"." and c.application = "."'"."$param[application]"."'"." and c.agent_phone = $param[agent_phone])";
//$whereor = "(o.user_id = $user_id and o.status = 2 and o.delete_time = 0 and o.order_expire_time2 < $time) or (o.user_id = $user_id and o.status = 1 and c.insurer ="."'"."$insurer"."'"." and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and c.application = "."'"."$param[application]"."'"." and c.agent_phone = $param[agent_phone] and c.insurer ="."'"."$insurer"."'"."and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and o.order_about_time < ".($time-24*30*60*60)." and c.insurer ="."'"."$insurer"."'and o.delete_time = 0)";
}else if(!empty($param['application'])){
$whereor = "(o.status = 3 and o.order_expire_time2 < $time and c.insurer ="."'"."$insurer"."'"." and c.application = "."'"."$param[application]"."'".")";
// $whereor = "(o.user_id = $user_id and o.status = 2 and o.delete_time = 0 and o.order_expire_time2 < $time) or (o.user_id = $user_id and o.status = 1 and c.insurer ="."'"."$insurer"."'"." and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and c.application = "."'"."$param[application]"."'"." and c.insurer ="."'"."$insurer"."'"." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and o.order_about_time < ".($time-24*30*60*60)." and c.insurer ="."'"."$insurer"."' and o.delete_time = 0)";
}else if(!empty($param['agent_phone'])){
$whereor = "(o.status = 3 and o.order_expire_time2 < $time and c.insurer ="."'"."$insurer"."'"." and c.agent_phone = $param[agent_phone])";
// $whereor = "(o.user_id = $user_id and o.status = 2 and o.delete_time = 0 and o.order_expire_time2 < $time) or (o.user_id = $user_id and o.status = 1 and c.insurer ="."'"."$insurer"."'"." and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and c.agent_phone = $param[agent_phone] and c.insurer ="."'"."$insurer"."'"." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and o.order_about_time < ".($time-24*30*60*60)." and c.insurer ="."'"."$insurer"."'and o.delete_time = 0)";
}else{
$whereor = "(o.user_id = $user_id and o.status = 3 and o.order_expire_time2 < $time and c.insurer ="."'"."$insurer"."'".")";
// $whereor = "(o.user_id = $user_id and o.status = 2 and o.delete_time = 0 and o.order_expire_time2 < $time) or (o.user_id = $user_id and o.status = 1 and c.insurer ="."'"."$insurer"."'"." and o.order_about_time < ".($time-24*30*60*60)." and o.delete_time = 0) or (o.user_id = $user_id and o.status = 3 and o.order_about_time < ".($time-24*30*60*60)." and c.insurer ="."'"."$insurer"."')";
//$whereor = "(o.status = 2 and o.delete_time = 0) or (o.order_expire_time < $time ) or (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)." and o.delete_time = 0)";
}
}
}else{
if(!empty($param['application'])){
$where['c.application'] = ['eq',$param['application']];
}
if(!empty($param['agent_phone'])){
$where['c.agent_phone'] = ['eq',$param['agent_phone']];
}
if(empty($param['application']) || empty($param['agent_phone'])){
$where['o.user_id'] = ['eq',$user_id];
}
$where['c.insurer'] = ['eq',$insurer];
}
$orderInfoModel = new OrderInfoModel();
$data = $orderInfoModel->selectData1($where,$whereor);
$data = $this->dispose($data);
$arr['code'] = 20000;
$arr['msg'] = 'SUCCESS';
$arr['data'] = $data;
return json_encode($arr);
}
public function dispose($data){
foreach($data as $key => $vo){
$data[$key]['thumbnail'] = cmf_get_image_url($vo['thumbnail']);
if($vo['remit'] == 1){
$data[$key]['remit'] = '是';
}else if($vo['remit'] == 2){
$data[$key]['remit'] = '否';
}
$data[$key]['take_time'] = date('Y-m-d',$vo['take_time']);
$data[$key]['insurer_time'] = date('Y-m-d',$vo['insurer_time']);
}
return $data;
}
}