审查视图

app/index/model/OrderInfoModel.php 6.4 KB
王晓刚 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/28
 * Time: 16:52
 */

namespace app\index\model;


use think\Model;
use think\Db;

class OrderInfoModel extends Model
{
王晓刚 authored
17
    public function findData($where){
王晓刚 authored
18
        $field = "c.*,i_c.thumbnail,i_c.insurance_company_name,o.order_expire_time,o.order_expire_time2,o.order_about_time,o.status,o.id o_id";
王晓刚 authored
19 20 21 22 23 24 25 26 27 28
        $data = $this
            ->alias('o_i')
            ->field($field)
            ->join('cmf_order o','o.id = o_i.order_id')
            ->join('cmf_collocation c','c.id = o_i.collocation_id')
            ->join('cmf_insurance_company i_c','c.insurance_company_id = i_c.id')
            ->where($where)
            ->find();
        return $data;
    }
王晓刚 authored
29
    public function selectData1($where1=null,$whereor=null){
王晓刚 authored
30
//        $where1['o.delete_time'] = ['eq',0];
王晓刚 authored
31
        //$where1['c.expire_time'] = ['>',time()];//判断保单是否还在缴费期限内
王晓刚 authored
32 33
        //$where1['o.order_expire_time'] = ['>',time()];//筛选出托管中状态
        //$where1['o.status'] = ['eq',3];//筛选出托管中状态
王晓刚 authored
34
        $field = "c.*,i_c.thumbnail,i_c.insurance_company_name,o.order_expire_time,o.order_about_time,o.status,o.id o_id,o.order_expire_time2";
王晓刚 authored
35 36 37 38 39
        $data = $this
            ->alias('o_i')
            ->field($field)
            ->join('cmf_order o','o.id = o_i.order_id')
            ->join('cmf_collocation c','c.id = o_i.collocation_id')
王晓刚 authored
40
            ->join('cmf_insurance_company i_c','c.insurance_company_id = i_c.id')
王晓刚 authored
41
            ->where($where1)
王晓刚 authored
42
            ->whereOr($whereor)
王晓刚 authored
43
            ->order('c.create_time','desc')
王晓刚 authored
44 45 46 47
//            ->fetchSql()
            ->select()->toArray();
//        echo $data;
//        exit();
王晓刚 authored
48 49
        return $data;
    }
王晓刚 authored
50
    public function selectData($where1,$whereor=null){
王晓刚 authored
51
        $time = time();
王晓刚 authored
52
        $where1['o.delete_time'] = ['eq',0];
王晓刚 authored
53
//        $where1['c.expire_time'] = ['>',time()];//判断保单是否还在缴费期限内
王晓刚 authored
54 55
//        $where1['o.order_expire_time'] = ['>',time()];//筛选出托管中状态
//        $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)];//筛选出托管中状态
王晓刚 authored
56
        //$where1['o.status'] = ['eq',3];//筛选出托管中状态
王晓刚 authored
57
        $field = "c.*,o.order_expire_time,o.status,o.order_about_time,o.order_expire_time2";
王晓刚 authored
58 59 60 61
        $data = $this
            ->alias('o_i')
            ->field($field)
            ->join('cmf_order o','o.id = o_i.order_id')
王晓刚 authored
62
            ->join('cmf_collocation c','c.id = o_i.collocation_id')
王晓刚 authored
63
            ->where($where1)
王晓刚 authored
64
            ->whereOr($whereor)
王晓刚 authored
65
            ->order('c.create_time','desc')
王晓刚 authored
66 67 68 69
//            ->fetchSql()
            ->select()->toArray();
//        echo $data;
//        exit();
王晓刚 authored
70 71 72 73
        $new_data = [];
        foreach($data as $k1=>$v1 ){
            $new_data[$v1['product_name']][] = $v1;
        }
王晓刚 authored
74
        //获取附加险的信息
王晓刚 authored
75 76 77 78 79 80
//        foreach($data as $key => $vo){
//            $where2['collocation_id'] = ['eq',$vo['id']];
//            $where2['delete_time'] = ['eq',0];
//            $subjoin_insurance = Db::name('subjoin_insurance')->where($where2)->select()->toArray();
//            $data[$key]['subjoin_insurance'] = $subjoin_insurance;
//        }
王晓刚 authored
81
        return $new_data;
王晓刚 authored
82 83 84 85
    }
    //在托管中状态的保单份数
    public function collocationCount($where){
        $where['o.delete_time'] = ['eq',0];
王晓刚 authored
86 87
        $where1['o.order_expire_time2'] = ['>',time()];//筛选出托管中状态
//        $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)];
王晓刚 authored
88
        $where1['o.status'] = ['in',[3,1]];
王晓刚 authored
89 90 91 92 93 94 95
        $field = "c.*";
        $data = $this
            ->alias('o_i')
            ->field($field)
            ->join('cmf_order o','o.id = o_i.order_id')
            ->join('cmf_collocation c','c.id = o_i.collocation_id')
            ->where($where)
王晓刚 authored
96
            ->where($where1)
王晓刚 authored
97
            ->count();
王晓刚 authored
98 99 100 101
        return $data;
    }
    public function peopleCount($where){
        $where['o.delete_time'] = ['eq',0];
王晓刚 authored
102 103 104
        $where1['o.order_expire_time'] = ['>',time()];//筛选出托管中状态
        $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)];
        $where1['o.status'] = ['in',[3,1]];
王晓刚 authored
105 106 107 108 109
        $field = "c.*";
        $data = $this
            ->alias('o_i')
            ->field($field)
            ->join('cmf_order o','o.id = o_i.order_id')
王晓刚 authored
110
            ->join('cmf_collocation c','c.id = o_i.collocation_id')
王晓刚 authored
111
            ->where($where)
王晓刚 authored
112
            ->where($where1)
王晓刚 authored
113
            ->group('c.insurer')
王晓刚 authored
114 115 116 117 118
            ->count();
        return $data;
    }
    public function totalSum($where){
        $where['o.delete_time'] = ['eq',0];
王晓刚 authored
119 120
        $where1['o.order_expire_time2'] = ['>',time()];//筛选出托管中状态
//        $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)];
王晓刚 authored
121
        $where1['o.status'] = ['in',[3,1]];
王晓刚 authored
122 123 124 125 126
        $field = "c.*";
        $data = $this
            ->alias('o_i')
            ->field($field)
            ->join('cmf_order o','o.id = o_i.order_id')
王晓刚 authored
127
            ->join('cmf_collocation c','c.id = o_i.collocation_id')
王晓刚 authored
128
            ->where($where)
王晓刚 authored
129
            ->where($where1)
王晓刚 authored
130
            ->sum('c.pay_method_price');
王晓刚 authored
131 132 133 134
        return $data;
    }
    public function subjoinSum($where){
        $where['o.delete_time'] = ['eq',0];
王晓刚 authored
135 136
        $where1['o.order_expire_time2'] = ['>',time()];//筛选出托管中状态
//        $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)];
王晓刚 authored
137
        $where1['o.status'] = ['in',[3,1]];
王晓刚 authored
138 139 140 141 142
        $field = "c.*";
        $data = $this
            ->alias('o_i')
            ->field($field)
            ->join('cmf_order o','o.id = o_i.order_id')
王晓刚 authored
143
            ->join('cmf_collocation c','c.id = o_i.collocation_id')
王晓刚 authored
144
            ->where($where)
王晓刚 authored
145
            ->where($where1)
王晓刚 authored
146
            ->order('c.create_time','desc')
王晓刚 authored
147 148 149
            ->select()->toArray();
        //获取附加险的信息
        foreach($data as $key => $vo){
王晓刚 authored
150
            $subjoin_insurance_sum = Db::name('subjoin_insurance')->where(array('collocation_id'=>$vo['id'],'delete_time'=>0))->sum('subjoin_pay_method_price');
王晓刚 authored
151 152 153 154 155 156 157 158 159
            $data[$key]['subjoin_insurance_sum'] = $subjoin_insurance_sum;
        }
        //计算附加险的保险之和
        $sum = 0;
        foreach($data as $key => $vo){
            $sum += $vo['subjoin_insurance_sum'];
        }
        return $sum;
    }
王晓刚 authored
160 161 162
    public function countInsuranceType(){

    }
王晓刚 authored
163 164 165 166
    public function insertData($data){
        $result = $this->insertGetId($data);
        return $result;
    }
王晓刚 authored
167 168 169 170
    public function findData2($where){
        $data = $this->where($where)->find();
        return $data;
    }
王晓刚 authored
171
}