<?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 { public function findData($where){ $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"; $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; } public function selectData1($where1=null,$whereor=null){ // $where1['o.delete_time'] = ['eq',0]; //$where1['c.expire_time'] = ['>',time()];//判断保单是否还在缴费期限内 //$where1['o.order_expire_time'] = ['>',time()];//筛选出托管中状态 //$where1['o.status'] = ['eq',3];//筛选出托管中状态 $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"; $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($where1) ->whereOr($whereor) ->order('c.create_time','desc') // ->fetchSql() ->select()->toArray(); // echo $data; // exit(); return $data; } public function selectData($where1,$whereor=null){ $time = time(); $where1['o.delete_time'] = ['eq',0]; // $where1['c.expire_time'] = ['>',time()];//判断保单是否还在缴费期限内 // $where1['o.order_expire_time'] = ['>',time()];//筛选出托管中状态 // $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)];//筛选出托管中状态 //$where1['o.status'] = ['eq',3];//筛选出托管中状态 $field = "c.*,o.order_expire_time,o.status,o.order_about_time,o.order_expire_time2"; $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($where1) ->whereOr($whereor) ->order('c.create_time','desc') // ->fetchSql() ->select()->toArray(); // echo $data; // exit(); $new_data = []; foreach($data as $k1=>$v1 ){ $new_data[$v1['product_name']][] = $v1; } //获取附加险的信息 // 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; // } return $new_data; } //在托管中状态的保单份数 public function collocationCount($where){ $where['o.delete_time'] = ['eq',0]; $where1['o.order_expire_time2'] = ['>',time()];//筛选出托管中状态 // $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)]; $where1['o.status'] = ['in',[3,1]]; $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) ->where($where1) ->count(); return $data; } public function peopleCount($where){ $where['o.delete_time'] = ['eq',0]; $where1['o.order_expire_time'] = ['>',time()];//筛选出托管中状态 $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)]; $where1['o.status'] = ['in',[3,1]]; $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) ->where($where1) ->group('c.insurer') ->count(); return $data; } public function totalSum($where){ $where['o.delete_time'] = ['eq',0]; $where1['o.order_expire_time2'] = ['>',time()];//筛选出托管中状态 // $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)]; $where1['o.status'] = ['in',[3,1]]; $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) ->where($where1) ->sum('c.pay_method_price'); return $data; } public function subjoinSum($where){ $where['o.delete_time'] = ['eq',0]; $where1['o.order_expire_time2'] = ['>',time()];//筛选出托管中状态 // $where1['o.order_about_time'] = ['>',(time()-30*24*60*60)]; $where1['o.status'] = ['in',[3,1]]; $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) ->where($where1) ->order('c.create_time','desc') ->select()->toArray(); //获取附加险的信息 foreach($data as $key => $vo){ $subjoin_insurance_sum = Db::name('subjoin_insurance')->where(array('collocation_id'=>$vo['id'],'delete_time'=>0))->sum('subjoin_pay_method_price'); $data[$key]['subjoin_insurance_sum'] = $subjoin_insurance_sum; } //计算附加险的保险之和 $sum = 0; foreach($data as $key => $vo){ $sum += $vo['subjoin_insurance_sum']; } return $sum; } public function countInsuranceType(){ } public function insertData($data){ $result = $this->insertGetId($data); return $result; } public function findData2($where){ $data = $this->where($where)->find(); return $data; } }