审查视图

app/index/controller/FormController.php 24.1 KB
王晓刚 authored
1 2 3 4 5 6 7 8 9 10 11
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/25
 * Time: 19:57
 */

namespace app\index\controller;

王晓刚 authored
12
use app\index\model\CollocationModel;
王晓刚 authored
13 14 15
use app\index\model\OrderInfoModel;
use app\index\model\OrderModel;
use app\index\model\OrderRenewModel;
王晓刚 authored
16 17 18
use app\index\model\PayMethodModel;
use app\index\model\InsuranceCompanyModel;
use app\index\model\PageHtmlModel;
王晓刚 authored
19
use app\index\model\SubjoinInsuranceModel;
王晓刚 authored
20
use app\index\model\UserModel;
王晓刚 authored
21
use app\index\server\FormServer;
王晓刚 authored
22 23
use cmf\controller\WeChatBaseController;
王晓刚 authored
24
use EasyWeChat\Foundation\Application;
王晓刚 authored
25 26 27 28 29 30 31 32 33 34
use think\Db;
use think\Validate;

//我要托管
class FormController extends WeChatBaseController
{
    //授权
    function _initialize()
    {
        //判断用户是否微信浏览器打开
王晓刚 authored
35
        $this->isWechat();
王晓刚 authored
36
        //判断是否手机端
王晓刚 authored
37
//        $this->isMobile();
王晓刚 authored
38 39 40 41 42 43 44 45
        //微信授权
        parent::_initialize();
        $this->checkWeChatUserLogin();
        //阻止拉黑用户
        $this->ban();
    }
    //进入我要托管页面
    public function index(){
王晓刚 authored
46 47 48 49 50 51 52
        $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;
王晓刚 authored
53
        $jssdk = $js->config(['chooseImage', 'uploadImage', 'previewImage'], $debug = false, $beta = false, $json = true);
王晓刚 authored
54
        //判断用户是否注册手机号
王晓刚 authored
55
        $isRegister = $this->isRegister();
王晓刚 authored
56
        if(empty($isRegister)){
王晓刚 authored
57
            return $this->redirect('user_register_mobile/index');//注册手机号页面
王晓刚 authored
58 59
        }
        //判断用户是否填写问卷调查
王晓刚 authored
60 61
        $isQuestion = $this->isQuestion();
        if(empty($isQuestion)){
王晓刚 authored
62
            return $this->redirect('question/index');//问卷调查页面
王晓刚 authored
63 64 65 66 67 68 69 70 71 72
        }
        $PageHtmlModel = new PageHtmlModel();
        $page_html1 = $PageHtmlModel->findData(array('id'=>2));//顶部图片
        $page_html2 = $PageHtmlModel->findData(array('id'=>3));//上传说明
        $InsuranceCompanyModel = new InsuranceCompanyModel();
        $insurance_company = $InsuranceCompanyModel->selectData();//保险公司
        $PayMethodModel = new PayMethodModel();
        $pay_method = $PayMethodModel->selectData();//缴费方式
        $this->assign(
            array(
王晓刚 authored
73
                'jssdk'=>$jssdk,
王晓刚 authored
74 75 76 77 78 79
                'page_html1'=>$page_html1,
                'page_html2'=>$page_html2,
                'insurance_company'=>$insurance_company,
                'pay_method'=>$pay_method,
            )
        );
王晓刚 authored
80
        return $this->fetch();
王晓刚 authored
81
    }
王晓刚 authored
82
    //创建保险
王晓刚 authored
83 84 85 86 87 88 89 90 91
    public function add_post(){
        $user_id = cmf_get_current_user_id();
        $param = $this->request->param();
        //主险
        $validate = new Validate([
            'insurance_company_id' => 'require',
            'product_name' => 'require',
            'insurance_type_id' => 'require',
            'insurance_price' => 'require',
王晓刚 authored
92 93
//            'payment_time_type' => 'require',
            'payment_time' => 'require',
王晓刚 authored
94 95
            'pay_method_id' => 'require',
            'pay_method_price' => 'require',
王晓刚 authored
96
            'guarantee_deadline_time' => 'require',
王晓刚 authored
97 98 99 100 101 102 103
            'insurance_num' => 'require',
            'application' => 'require',
            'insurer' => 'require',
            'relation' => 'require',
            'insurer_birthday' => 'require',
            'insurer_time' => 'require',
            'take_time' => 'require',
王晓刚 authored
104
//            'insure_time' => 'require',
王晓刚 authored
105
            'remit' => 'require',
106
            'recommend' => 'require',
王晓刚 authored
107 108 109 110 111 112
        ]);
        $validate->message([
            'insurance_company_id' => '请选择保险公司!',
            'product_name' => '产品名称不能为空!',
            'insurance_type_id' => '请选择保险类型!',
            'insurance_price' => '保险金额不能为空!',
王晓刚 authored
113 114
//            'payment_time_type' => '请选择缴费期限类型!',
            'payment_time' => '请选择缴费期限!',
王晓刚 authored
115 116
            'pay_method_id' => '缴费方式不能为空!',
            'pay_method_price' => '期缴保费不能为空!',
王晓刚 authored
117
            'guarantee_deadline_time' => '请选择保障期限!',
王晓刚 authored
118 119 120 121 122 123 124
            'insurance_num' => '保险单号不能为空!',
            'application' => '投保人不能为空!',
            'insurer' => '被保人不能为空!',
            'relation' => '与被保人关系!',
            'insurer_birthday' => '请选择被保人生日!',
            'insurer_time' => '请选择投保日期!',
            'take_time' => '请选择合同生效日期!',
王晓刚 authored
125
//            'insure_time' => '请选择保险时间!',
王晓刚 authored
126
            'remit' => '请选择投保人豁免!',
127
            'recommend' => '请选择平台是否推荐!'
王晓刚 authored
128
        ]);
王晓刚 authored
129
        if (!$validate->check($param)) {
王晓刚 authored
130 131
            $this->error($validate->getError());
        }
王晓刚 authored
132 133
        $images = [];
        if(!empty($param['imgs'])){
王晓刚 authored
134
王晓刚 authored
135
            $images = explode(',',$param['imgs']);
王晓刚 authored
136
        }
王晓刚 authored
137
        $array1 = [
王晓刚 authored
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
            'insurance_company_id' => $param['insurance_company_id'],
            'product_name' => $param['product_name'],
            'insurance_type_id' => $param['insurance_type_id'],
            'insurance_price' => $param['insurance_price'],
//            'payment_time_type' => $param['payment_time_type'],
//            'payment_time_id' => $param['payment_time_id'] ? $param['payment_time_id'] : null,
            'payment_time' => $param['payment_time'] ? $param['payment_time'] : null,
            'pay_method_id' => $param['pay_method_id'],
            'pay_method_price' => $param['pay_method_price'],
            'guarantee_deadline_time' => $param['guarantee_deadline_time'],
            'insurance_num' => $param['insurance_num'],
            'application' => $param['application'],
            'insurer' => $param['insurer'],
            'relation' => $param['relation'],
            'insurer_birthday' => $param['insurer_birthday'],
            'insurer_time' => strtotime($param['insurer_time']),
王晓刚 authored
154
            'take_time' => strtotime($param['take_time']),
王晓刚 authored
155
//            'insure_time' => $param['insure_time'],
王晓刚 authored
156 157 158 159
            'remit' => $param['remit'],
            'remark' => !empty($param['remark']) ? $param['remark'] : null,
            'agent_name' => !empty($param['agent_name']) ? $param['agent_name'] : null,
            'agent_phone' => !empty($param['agent_phone']) ? $param['agent_phone'] : null,
王晓刚 authored
160
            'create_time' => time(),
161
            'expire_time' => strtotime($param['take_time'])+$param['payment_time']*365*24*60*60,
王晓刚 authored
162
            'user_id' => $user_id,
王晓刚 authored
163
            'image' => !empty($images) ? json_encode($images) : null,
164
            'recommend' => $param['recommend'],
王晓刚 authored
165 166 167 168 169 170 171 172 173 174 175
        ];
        //开启事务
        Db::startTrans();
        $result1 = Db::name('collocation')->insertGetId($array1);
        if(empty($result1)){
            Db::rollback();
            $arr['code'] = 40000;
            $arr['msg'] = "主险添加失败!";
            return json_encode($arr);
        }
        //附加险
王晓刚 authored
176
        if(!empty($param['subjoin_product_name_arr'])){
王晓刚 authored
177
            $param['subjoin_insurance_type_id_arr'] = explode(',',$param['subjoin_insurance_type_id_arr']);
王晓刚 authored
178 179
            $param['subjoin_product_name_arr'] = explode(',',$param['subjoin_product_name_arr']);
            $param['subjoin_price_arr'] = explode(',',$param['subjoin_price_arr']);
王晓刚 authored
180
            //$param['subjoin_time_arr'] = explode(',',$param['subjoin_time_arr']);
王晓刚 authored
181 182 183 184 185 186 187 188 189
            $param['payment_time_arr'] = explode(',',$param['payment_time_arr']);
            $param['subjoin_pay_method_price_arr'] = explode(',',$param['subjoin_pay_method_price_arr']);
            $param['subjoin_guarantee_deadline_time_arr'] = explode(',',$param['subjoin_guarantee_deadline_time_arr']);
            $array2 = [];
            foreach($param['subjoin_product_name_arr'] as $key => $value){
                $data = [
                    'subjoin_product_name' => $value,
                    'insurance_type_id' => $param['subjoin_insurance_type_id_arr'][$key] ? $param['subjoin_insurance_type_id_arr'][$key] : null,
                    'subjoin_price' => $param['subjoin_price_arr'][$key] ? $param['subjoin_price_arr'][$key] : null,
王晓刚 authored
190
//                    'subjoin_time' => $param['subjoin_time_arr'][$key] ? $param['subjoin_time_arr'][$key] : null,
王晓刚 authored
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
                    'payment_time' => $param['payment_time_arr'][$key] ? $param['payment_time_arr'][$key] : null,
                    'subjoin_pay_method_price' => $param['subjoin_pay_method_price_arr'][$key] ? $param['subjoin_pay_method_price_arr'][$key] : null,
                    'subjoin_guarantee_deadline_time'=>$param['subjoin_guarantee_deadline_time_arr'][$key] ? $param['subjoin_guarantee_deadline_time_arr'][$key] : null,
                    'user_id' => $user_id,
                    'collocation_id' => $result1,
                    'create_time' => time(),
                ];
                array_push($array2, $data);
            }
            $result2 = Db::name('subjoin_insurance')->insertAll($array2);
            if(empty($result2)){
                Db::rollback();
                $arr['code'] = 40000;
                $arr['msg'] = "附加险添加失败!";
            }
王晓刚 authored
206
        }
王晓刚 authored
207 208 209 210
        Db::commit();
        $arr['code'] = 20000;
        $arr['msg'] = "附加险添加成功!";
        $arr['data'] = $result1;
王晓刚 authored
211 212 213
        return json_encode($arr);

    }
王晓刚 authored
214
    public function edit(){
王晓刚 authored
215 216 217 218 219 220 221 222
        $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);
王晓刚 authored
223 224
        $id = $this->request->param('id');
        $user_id = cmf_get_current_user_id();
王晓刚 authored
225 226
        $collocationModel = new CollocationModel();
        $data = $collocationModel->findData(array('c.id'=>$id,'c.user_id'=>$user_id));
王晓刚 authored
227
        $subjoinInsuranceModel = new SubjoinInsuranceModel();
王晓刚 authored
228
        $subjoin = $subjoinInsuranceModel->selectData2(array('collocation_id'=>$data['id']));
王晓刚 authored
229 230 231 232 233 234
        $PageHtmlModel = new PageHtmlModel();
        $page_html2 = $PageHtmlModel->findData(array('id'=>3));//上传说明
        $InsuranceCompanyModel = new InsuranceCompanyModel();
        $insurance_company = $InsuranceCompanyModel->selectData();//保险公司
        $PayMethodModel = new PayMethodModel();
        $pay_method = $PayMethodModel->selectData();//缴费方式
王晓刚 authored
235 236 237
        $this->assign(
            array(
                'data'=>$data,
王晓刚 authored
238 239 240
                'page_html2'=>$page_html2,
                'insurance_company'=>$insurance_company,
                'pay_method'=>$pay_method,
王晓刚 authored
241
                'jssdk'=>$jssdk,
王晓刚 authored
242
                'subjoin'=>$subjoin,
王晓刚 authored
243 244 245 246
            )
        );
        return $this->fetch();
    }
王晓刚 authored
247 248 249 250
    //更改订单
    public function edit_post(){
        $user_id = cmf_get_current_user_id();
        $param = $this->request->param();
王晓刚 authored
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
        //清空所有该主险下的附加险
        $subjoinInsuranceModel = new SubjoinInsuranceModel();
        $subjoinInsuranceModel->deleteData(array('collocation_id'=>$param['id'],'user_id'=>$user_id));
        $array1 = [
            'insurance_company_id' => $param['insurance_company_id'],
            'product_name' => $param['product_name'],
            'insurance_type_id' => $param['insurance_type_id'],
            'insurance_price' => $param['insurance_price'],
            'payment_time' => $param['payment_time'] ? $param['payment_time'] : null,
            'pay_method_id' => $param['pay_method_id'],
            'pay_method_price' => $param['pay_method_price'],
            'guarantee_deadline_time' => $param['guarantee_deadline_time'],
            'insurance_num' => $param['insurance_num'],
            'application' => $param['application'],
            'insurer' => $param['insurer'],
            'relation' => $param['relation'],
            'insurer_birthday' => $param['insurer_birthday'],
王晓刚 authored
268
            'insurer_time' => strtotime($param['insurer_time']),
王晓刚 authored
269
            'take_time' => strtotime($param['take_time']),
王晓刚 authored
270
//            'insure_time' => $param['insure_time'],
王晓刚 authored
271 272 273 274
            'remit' => $param['remit'],
            'remark' => !empty($param['remark']) ? $param['remark'] : null,
            'agent_name' => !empty($param['agent_name']) ? $param['agent_name'] : null,
            'agent_phone' => !empty($param['agent_phone']) ? $param['agent_phone'] : null,
王晓刚 authored
275
            'expire_time' => strtotime($param['take_time'])+$param['payment_time']*365*24*60*60,
王晓刚 authored
276 277 278 279
            'image' => !empty($param['imgs']) ? json_encode($param['imgs']) : null,
        ];
        //更新主险
        $result1 = Db::name('collocation')->where(array('user_id'=>$user_id,'id'=>$param['id']))->update($array1);
王晓刚 authored
280 281 282 283 284 285 286 287
        //新增附加险
        if(!empty($param['subjoin_product_name_arr'])){
            $array2 = [];
            foreach($param['subjoin_product_name_arr'] as $key => $value){
                $data = [
                    'subjoin_product_name' => $value,
                    'insurance_type_id' => $param['subjoin_insurance_type_id_arr'][$key] ? $param['subjoin_insurance_type_id_arr'][$key] : null,
                    'subjoin_price' => $param['subjoin_price_arr'][$key] ? $param['subjoin_price_arr'][$key] : null,
王晓刚 authored
288
                    //'subjoin_time' => $param['subjoin_time_arr'][$key] ? $param['subjoin_time_arr'][$key] : null,
王晓刚 authored
289 290 291 292 293 294 295 296
                    'payment_time' => $param['payment_time_arr'][$key] ? $param['payment_time_arr'][$key] : null,
                    'subjoin_pay_method_price' => $param['subjoin_pay_method_price_arr'][$key] ? $param['subjoin_pay_method_price_arr'][$key] : null,
                    'subjoin_guarantee_deadline_time'=>$param['subjoin_guarantee_deadline_time_arr'][$key] ? $param['subjoin_guarantee_deadline_time_arr'][$key] : null,
                    'user_id' => $user_id,
                    'collocation_id' => $param['id'],
                    'create_time' => time(),
                ];
                array_push($array2, $data);
王晓刚 authored
297
                $result2 = Db::name('subjoin_insurance')->insertAll($array2);
王晓刚 authored
298 299
            }
        }
王晓刚 authored
300
        $send = Db::name('send')->where(array('user_id'=>$user_id,'collocation_id'=>$param['id']))->find();
王晓刚 authored
301
        Db::name('send')->where(array('user_id'=>$user_id,'collocation_id'=>$param['id']))->delete();
王晓刚 authored
302 303 304 305 306
        $data4 = [];
        $payment_time = $param['payment_time'];
        for($i=0;$i<$payment_time;$i++){
            if($array1['expire_time']-($i*365*24*60*60)-(30*24*60*60)>time()){
                $data3['user_id'] = $user_id;
王晓刚 authored
307
                $data3['order_id'] = $send['order_id'];
王晓刚 authored
308 309 310
                $data3['collocation_id'] = $param['id'];
                $data3['time'] = $array1['expire_time']-($i*365*24*60*60)-(30*24*60*60);
                $data4[] = $data3;
王晓刚 authored
311 312 313
            }else{
                $data3['time'] = $param['payment_time'];
                $data4[] = $data3;
王晓刚 authored
314 315
            }
        }
王晓刚 authored
316 317
        $array3 = array('order_expire_time'=>$array1['expire_time'],'order_about_time'=>$data4[count($data4)-1]['time']);
        $a = Db::name('order')->where(array('collocation_id'=>$param['id'],'user_id'=>$user_id))->update($array3);
王晓刚 authored
318 319 320
        $arr['code'] = 20000;
        $arr['msg'] = '更新成功!';
        return json_encode($arr);
王晓刚 authored
321
    }
王晓刚 authored
322
    //保单详情页
王晓刚 authored
323
    public function info(){
王晓刚 authored
324
        $param = $this->request->param();
王晓刚 authored
325
        $collocationModel = new CollocationModel();
王晓刚 authored
326
        //主险
王晓刚 authored
327
        $data = $collocationModel->findData(array('id'=>$param['id']));
王晓刚 authored
328 329
        $formServer = new FormServer();
        //附加险
王晓刚 authored
330
        $data = $formServer->getSubjoinInsurance($data);
王晓刚 authored
331 332 333 334 335 336
        $this->assign(
            array(
                'data'=>$data,
            )
        );
    }
王晓刚 authored
337 338 339 340 341 342 343 344 345 346 347
    //创建订单
    public function create_order(){
        $user_id = cmf_get_current_user_id();
        $param = $this->request->param();
        if($param['type'] == 1){
            //免费
            $data1['status'] = 1;
        }else if($param['type'] == 2){
            //付费
            $data1['status'] = 2;
        }else{
王晓刚 authored
348
            $data1['status'] = [];
王晓刚 authored
349 350
            $this->error('参数错误!','');
        }
王晓刚 authored
351
        $collocationModel = new CollocationModel();
王晓刚 authored
352 353 354 355 356 357
        if($data1['status'] == 2){
            //判断是否需要再付费
            //支付逻辑:支付一次可以添加20张保单,10个不相同的被保险人
            $order_num = Db::name('order_num')->where('user_id',$user_id)->count();
            $count_order = $this->count_order();
            $insurer = $collocationModel->insurerData(array('user_id'=>$user_id),"insurer");
王晓刚 authored
358
王晓刚 authored
359
            if(empty($order_num)){
王晓刚 authored
360 361
                $data1['status'] = 2;
            }else{
王晓刚 authored
362 363 364 365 366 367
                if($count_order >= $order_num*20 || count($insurer) > $order_num*10){
                    $data1['status'] = 2;
                }else{
                    //不需付费
                    $data1['status'] = 3;
                }
王晓刚 authored
368 369
            }
        }
王晓刚 authored
370
        $total = Db::name('total')->where('id',1)->find();
王晓刚 authored
371
        $collocation = $collocationModel->findData(array('c.id'=>$param['collocation_id']));
王晓刚 authored
372 373
        $data1['num'] = cmf_get_order_sn();
        $data1['user_id'] = $user_id;
王晓刚 authored
374
        $data1['collocation_id'] = $param['collocation_id'];
王晓刚 authored
375
        $data1['total'] = $total['total'];
王晓刚 authored
376
        $data1['create_time'] = time();
王晓刚 authored
377
        if($data1['status'] == 1 || $data1['status'] == 3){
王晓刚 authored
378
            $data1['order_expire_time'] = $collocation['expire_time'];
王晓刚 authored
379
            $data1['order_about_time'] = $collocation['expire_time']-30*24*60*60;
王晓刚 authored
380
        }else{
王晓刚 authored
381
            $data1['order_about_time'] = null;
王晓刚 authored
382
        }
王晓刚 authored
383 384 385 386 387 388 389
        $orderModel = new OrderModel();
        //开启事务
        $orderModel->startTrans();
        $result1 = $orderModel->insertData($data1);
        if(empty($result1)){
            //回滚
            $orderModel->rollback();
王晓刚 authored
390
            $arr['code'] = 40000;
王晓刚 authored
391 392 393 394 395 396 397 398 399 400 401
            $arr['msg'] = '主订单表添加失败!';
            return json_encode($arr);
        }
        $data2['order_id'] = $result1;
        $data2['collocation_id'] = $param['collocation_id'];
        $data2['create_time'] = time();
        $orderInfoModel = new OrderInfoModel();
        $result2 = $orderInfoModel->insertData($data2);
        if(empty($result2)){
            //回滚
            $orderModel->rollback();
王晓刚 authored
402
            $arr['code'] = 40000;
王晓刚 authored
403 404 405
            $arr['msg'] = '副订单表添加失败!';
            return json_encode($arr);
        }
王晓刚 authored
406 407 408
        //添加消息发送
        if($data1['status'] == 1 || $data1['status'] == 3) {
            $data4 = [];
王晓刚 authored
409 410 411 412 413 414 415 416
            $payment_time = $collocation['payment_time'];
            for($i=0;$i<$payment_time;$i++){
                if($collocation['expire_time']-($i*365*24*60*60)-(30*24*60*60)>time()){
                    $data3['user_id'] = $user_id;
                    $data3['order_id'] = $result1;
                    $data3['collocation_id'] = $collocation['id'];
                    $data3['time'] = $collocation['expire_time']-($i*365*24*60*60)-(30*24*60*60);
                    $data4[] = $data3;
王晓刚 authored
417 418 419
                }else{
                    $data3['time'] = $collocation['expire_time']-(30*24*60*60);
                    $data4[] = $data3;
王晓刚 authored
420
                }
王晓刚 authored
421 422
            }
            Db::name('send')->insertAll($data4);
王晓刚 authored
423
            $update['order_expire_time']=$collocation['expire_time'];
王晓刚 authored
424
            $update['order_about_time']=$data4[count($data4)-1]['time'];
王晓刚 authored
425
            $update['order_expire_time2']=time()+(365*24*60*60);
王晓刚 authored
426
            Db::name('order')->where('id',$result1)->update($update);
王晓刚 authored
427
        }
王晓刚 authored
428
        $orderModel->commit();
王晓刚 authored
429 430 431
        //推送模板消息
        if($data1['status'] == 1 || $data1['status'] == 3){
            $templateId = 'rQSM5XqM4cJEua6nsJC4IGuLfIOYvkNOVKVABILc8Ro';
王晓刚 authored
432
            $data2 = array(
王晓刚 authored
433 434 435 436
                'first'=>"尊敬的用户,您的保单即将生效",
                'keyword1'=>$collocation['insurance_num'],
                'keyword2'=>$collocation['product_name'],
                'keyword3'=>$collocation['insurer'],
王晓刚 authored
437
                'keyword4'=>date('Y-m-d',$collocation['take_time'])."至".date('Y-m-d',$collocation['expire_time']),
王晓刚 authored
438 439
                'remark'=>"立即查看保单详情",
            );
王晓刚 authored
440
            $url = url('me_guarantee/guarantee_info',array('id'=>$result2),'',true);
王晓刚 authored
441
            $user1 = Db::name('third_party_user')->where('user_id',$collocation['user_id'])->find();
王晓刚 authored
442
            $user = Db::name('user')->where('id',$user_id)->find();
王晓刚 authored
443
            $this->template($templateId,$data2,$url,$user1['openid']);
王晓刚 authored
444 445
            //短信通知
            $data = array(
王晓刚 authored
446
                'content' 	=> "【橙象保险】尊敬的用户您的保单即将生效,保单号为$collocation[insurance_num]。",//短信内容
王晓刚 authored
447 448 449 450 451 452 453 454 455 456
                'mobile' 	=> $user['mobile'],//手机号码
                'productid' => '887361',//产品id
                'xh'		=> ''//小号
            );
            $result = send_sms($data);
            if(substr($result,0,strpos($result,',')) != "1"){
                $arr['code'] = 40000;
                $arr['msg'] = '短信接口出错';
                return json_encode($arr);
            }
王晓刚 authored
457
        }
王晓刚 authored
458 459 460
        $arr['code'] = 20000;
        $arr['msg'] = '操作成功!';
        $arr['data'] = $result1;//返回主订单id
王晓刚 authored
461
        $arr['status'] = $data1['status'];
王晓刚 authored
462 463 464 465 466 467
        return json_encode($arr);
    }
    //创建续费订单
    public function create_order_renew(){
        $user_id = cmf_get_current_user_id();
        $param = $this->request->param();
王晓刚 authored
468 469
        //查询当前订单号
        $orderInfoModel = new OrderInfoModel();
王晓刚 authored
470 471
        $order_info = $orderInfoModel->findData2(array('collocation_id'=>$param['id']));
        if(empty($order_info)){
王晓刚 authored
472 473 474 475
            $arr['code'] = 40000;
            $arr['msg'] = "未查询到订单";
            return json_encode($arr);
        }
王晓刚 authored
476 477
        //判断当前订单是否为当收费
        $orderModel = new OrderModel();
王晓刚 authored
478
        $order = $orderModel->findData(array('id'=>$order_info['order_id'],'user_id'=>$user_id));
王晓刚 authored
479
        if(empty($order)){
王晓刚 authored
480 481
            $arr['code'] = 40000;
            $arr['msg'] = '未查询到当前订单!';
王晓刚 authored
482 483 484
            return json_encode($arr);
        }
        if($order['status'] == 1){
王晓刚 authored
485
            $arr['code'] = 20001;
王晓刚 authored
486 487 488
            $arr['msg'] = '当前订单为免费!';
            return json_encode($arr);
        }
王晓刚 authored
489
        $total = Db::name('total')->where('id',2)->find();
王晓刚 authored
490 491
        $data['num'] = cmf_get_order_sn();
        $data['user_id'] = $user_id;
王晓刚 authored
492
        $data['total'] = $total['total'];
王晓刚 authored
493 494 495 496 497 498
        $data['status'] = 1;
        $data['order_id'] = $order['id'];
        $data['create_time'] = time();
        $orderRenewModel = new OrderRenewModel();
        $result = $orderRenewModel->insertData($data);
        if(empty($result)){
王晓刚 authored
499
            $arr['code'] = 40000;
王晓刚 authored
500 501 502 503 504
            $arr['msg'] = '创建续费订单失败!';
            return json_encode($arr);
        }
        $arr['code'] = 20000;
        $arr['msg'] = '创建续费订单成功';
王晓刚 authored
505
        $arr['data'] = $result;
王晓刚 authored
506 507
        return json_encode($arr);
    }
王晓刚 authored
508 509 510 511 512 513
    //进入下单页面
    public function cost(){
        $user_id = cmf_get_current_user_id();
        $userModel = new UserModel();
        $user = $userModel->findUserData(array('id'=>$user_id));
        $param = $this->request->param();
王晓刚 authored
514
        $param['imgs'] = str_replace('*', '/', $param['imgs']);
王晓刚 authored
515 516 517 518 519 520 521
        if($param['insurer'] == $user['name']){
            //显示免费
            $type = 1;
        }else{
            //只显示付费
            $type = 2;
        }
王晓刚 authored
522 523 524
        $pageHtmlModel = new PageHtmlModel();
        $page_html1 = $pageHtmlModel->findData(array('id'=>5));
        $page_html2 = $pageHtmlModel->findData(array('id'=>6));
王晓刚 authored
525 526 527
        $this->assign(
            array(
                'type'=>$type,
王晓刚 authored
528
                'param'=>$param,
王晓刚 authored
529 530
                'page_html1'=>$page_html1,
                'page_html2'=>$page_html2,
王晓刚 authored
531 532 533 534
            )
        );
        return $this->fetch();
    }
王晓刚 authored
535 536 537
    //获取一个用户有多少个保单
    public function count_order(){
        $user_id = cmf_get_current_user_id();
王晓刚 authored
538 539 540
        $where['user_id'] = ['eq',$user_id];
        $where['status'] = ['eq',3];
        $result = Db::name('order')->where($where)->count();
王晓刚 authored
541 542
        return $result;
    }
王晓刚 authored
543
}