ci = & get_instance(); $this->ci->load->model('receiver/receiver_customers_model','customers_model'); $this->ci->load->model('receiver/order/receiver_orders_v2_model'); $this->ci->load->model('receiver/order/receiver_order_signs_model','signs_model'); $this->ci->load->model('receiver/order/receiver_order_deliverys_model','deliverys_model'); $this->ci->load->model('receiver/order/receiver_order_contracts_model'); $this->ci->load->model('receiver/receiver_service_package_model','package_model'); $this->ci->load->model('receiver/receiver_services_model','services_model'); $this->ci->load->model('sys/sys_city_model'); $this->ci->load->model("sys/sys_company_model"); $this->ci->load->model('apporder/order_purchase_model'); $this->ci->load->model('auto/auto_brand_model'); $this->ci->load->model('auto/auto_series_model'); $this->ci->load->model('auto/auto_attr_model'); $this->ci->load->model("items/items_model"); $this->ci->load->model("biz/biz_model"); $this->ci->load->model('app/liche/app_liche_orders_model'); } //创建意向金订单 public function c_intention($oid,$uid,$money){ $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); if(!$this->order_row){ return false; } $p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'pid'=>0,'status>='=>0]); $entrust_user = $this->entrust_user($oid); if(!$p_row){ $sid = create_order_no(350200,'liche'); $add_data = [ 'o_id' => $this->order_row['id'], 'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0, 'sid' => $sid, 'pid' => 0, 'brand_id' => $this->order_row['brand_id'], 's_id' => $this->order_row['s_id'], 'v_id' => $this->order_row['v_id'], 'cor_id' => $this->order_row['cor_id'], 'incor_id' => $this->order_row['incor_id'], 'c_time' => time() ]; $uid && $add_data['uid'] = $uid; $pid = $this->ci->app_liche_orders_model->add($add_data); }else{ $pid = $p_row['id']; } $res = false; $sub_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'type'=>4,'status>='=>0]); if($pid && !$sub_row){ //获取微信商户号 $companys = $this->get_biz_mchid($this->order_row['biz_id'],$this->order_row['brand_id'],$this->order_row['if_local_bill']); $sid = create_order_no(350200,'liche'); $sub_data = [ 'o_id' => $this->order_row['id'], 'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0, 'sid' => $sid, 'mch_id' => $companys['company']['wx_mchid'], 'company_id' => $companys['company']['id'], 'pid' => $pid, 'type' => 4, 'brand_id' => $this->order_row['brand_id'], 's_id' => $this->order_row['s_id'], 'v_id' => $this->order_row['v_id'], 'cor_id' => $this->order_row['cor_id'], 'incor_id' => $this->order_row['incor_id'], 'total_price' => $money, 'c_time' => time() ]; $uid && $sub_data['uid'] = $uid; $res = $this->ci->app_liche_orders_model->add($sub_data); } return $res; } /** * 获取商家微信商户号 * @param $biz_id int 商家id * @param $car_brand_id int 品牌id * @param $if_local_bill int 是否开具本地发票 * @return array ['company'=>[],'srv_company'=>[]] */ public function get_biz_mchid($biz_id,$car_brand_id=0,$if_local_bill=false){ $biz = $this->ci->biz_model->get(['id'=>$biz_id],'type,city_id,company_id,srv_company_id,car_brand_id'); $filed = 'id,wx_mchid,title,short,credit_code,wx_mchid,img_seal'; $brand_biz = $this->ci->biz_model->get(['city_id'=>$biz['city_id'],'type'=>1,'status'=>1,'car_brand_id'=>$car_brand_id],'type,city_id,company_id,srv_company_id'); if($brand_biz){ $where = [ "status" => 1, "id in ({$brand_biz['company_id']},{$brand_biz['srv_company_id']})" => null ]; $companys = $this->ci->sys_company_model->map('id','',$where,'','','',$filed); $company = $companys[$brand_biz['company_id']][0]; $srv_company = $companys[$brand_biz['srv_company_id']][0]; } $local_city = false; if(in_array($biz['city_id'],$this->local_bill_citys) && $if_local_bill){ //是否开具本地发票且在指定城市用本地城市 $local_city = true; } if(!$company || $local_city){ //获取城市销售公司 $company = $this->ci->sys_company_model->get(['city_id'=>$biz['city_id'],'type'=>1,'status'=>1],$filed); } if(!$srv_company || $local_city){ //获取城市服务公司 $srv_company = $this->ci->sys_company_model->get(['city_id'=>$biz['city_id'],'type'=>0,'status'=>1],$filed); } if(!$company){ //获取固定id销售公司 $company = $this->ci->sys_company_model->get(['id'=>1],$filed); } if(!$srv_company){ //获取固定id服务公司 $srv_company = $this->ci->sys_company_model->get(['id'=>4],$filed); } //跑零 用泉州销售公司 if($car_brand_id==5){ $company = $this->ci->sys_company_model->get(['id'=>2],$filed); } $data = [ 'company' => $company, 'srv_company' => $srv_company ]; return $data; } /** * 获取代办人用户信息 * @param $oid int 订单id * @return array */ public function entrust_user($oid){ $this->ci->load->model('app/liche/app_liche_users_model'); !$this->order_row && $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); if(!$this->order_row){ return []; } $user = $this->ci->app_liche_users_model->get(['mobile'=>$this->order_row['owner_mobile']]); return $user; } /** * 获取订单服务费 * @param $oid int 订单id * @param $res_type string 返回数据格式 * @param $is_fines int(0否 1是) 是否包含精品选装 * @return array|int|mixed */ public function order_srv_money($oid,$res_type = '',$is_fines=1){ if(!$this->order_row){ $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); } elseif ($this->order_row['id'] != $oid){ $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); } $money_json = json_decode($this->order_row['money_json'],true); $srv_price = 0; $list = []; //明细 $services = json_decode($this->order_row['srv_ids'],true); if($services){ $srv_ids = array_column($services,'id'); $ids = implode(',',$srv_ids); if($srv_ids){ $where["id in ($ids)"] = null; $rows = $this->ci->services_model->map('id','title',$where,'','','','id,title'); } foreach($services as $key=>$val){ if($val['key']!='price_insure'){ //保险费不收 $srv_price += $money_json[$val['key']]; $list[] = [ 'title' => $rows[$val['id']], 'key' => $val['key'], 'money' => $money_json[$val['key']] ]; } if($val['key']=='price_insure' && $res_type==1){ $list[] = [ 'title' => $rows[$val['id']], 'key' => $val['key'], 'money' => '由保险公司收取' ]; } } } if($this->order_row['if_fine']){ //选择精品包 $fine_price = $money_json['price_fine']; if($money_json['price_fine_discount']){ //优惠精品价格 $fine_price = $fine_price - $money_json['price_fine_discount']; } $srv_price += $fine_price; $list[] = [ 'title' => '精品尊享包', 'key' => 'price_fine_discount', 'money' => $fine_price ]; } if($is_fines){ $fines = json_decode($this->order_row['fines'],true); if($fines){ $price_fine_select = $money_json['price_fine_select'] ? $money_json['price_fine_select'] : 0; $list[] = [ 'title' => '精品选装', 'key' => 'price_fine_select', 'money' => $price_fine_select, ]; $srv_price += $price_fine_select; } } $result['total'] = $srv_price; $result['list'] = $list; return $res_type ? $result:$srv_price; } /** * 生成定金订单 * @param $oid int 订单id * @param $uid int 小程序用户id * @return bool */ public function add_book_order($oid,$uid){ $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); if(!$this->order_row){ return false; } $pay_money = $this->ci->app_liche_orders_model->get(['o_id'=>$oid,'type'=>4,'status>='=>0]); //意向金订单 $ht_money = $this->ci->app_liche_orders_model->sum('pay_price',['o_id'=>$oid,'type'=>6,'status>='=>0]); //后台添加车款 $money_json = json_decode($this->order_row['money_json'],true); $deposit_count = $this->ci->app_liche_orders_model->count(['o_id'=>$oid,'type'=>1,'status'=>1]); //定金已支付 $need_pay_money = $money_json['price_book'] - $pay_money['total_price'] - $ht_money['pay_price']; $res = false; //if($need_pay_money > 0 && !$deposit_count){ $payway = $this->order_row['payway']; $money_json = json_decode($this->order_row['money_json'], true); $deposit = $money_json['price_book']; $if_zero_firstpay = $payway == 0 && !$deposit ? 1 : 0; if($if_zero_firstpay || $need_pay_money > 0 && !$deposit_count){ $entrust_user = $this->entrust_user($this->order_row['id']); $p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'pid'=>0,'status>='=>0]); if(!$p_row){ $sid = create_order_no(350200,'liche'); $add_data = [ 'o_id' => $this->order_row['id'], 'sid' => $sid, 'pid' => 0, 'brand_id' => $this->order_row['brand_id'], 's_id' => $this->order_row['s_id'], 'v_id' => $this->order_row['v_id'], 'cor_id' => $this->order_row['cor_id'], 'incor_id' => $this->order_row['incor_id'], 'c_time' => time() ]; $uid && $add_data['uid'] = $uid; $entrust_user['id'] && $add_data['entrust_uid'] = $entrust_user['id']; $pid = $this->ci->app_liche_orders_model->add($add_data); }else{ $pid = $p_row['id']; } $sub_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'type'=>1,'status>='=>0]); $zero_firstpay_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'type'=>1,'status='=>1,'total_price'=>0.0, 'pay_price'=>0.0]); if($pid && !$sub_row || $pid && !$zero_firstpay_row && $if_zero_firstpay){ //获取微信商户号 $companys = $this->get_biz_mchid($this->order_row['biz_id'],$this->order_row['brand_id'],$this->order_row['if_local_bill']); if($this->order_row['biz_id']==63){ //零跑店 门店ID= 63,车款收款都用 id = 12 的公司 合同收款公司不变 $filed = 'id,wx_mchid,title,short,credit_code,wx_mchid,img_seal'; $companys['company'] = $this->ci->sys_company_model->get(['id'=>12],$filed); } $sid = create_order_no(350200,'liche'); $sub_data = [ 'o_id' => $this->order_row['id'], 'sid' => $sid, 'mch_id' => $companys['company']['wx_mchid'], 'company_id' => $companys['company']['id'], 'pid' => $pid, 'type' => 1, 'brand_id' => $this->order_row['brand_id'], 's_id' => $this->order_row['s_id'], 'v_id' => $this->order_row['v_id'], 'cor_id' => $this->order_row['cor_id'], 'incor_id' => $this->order_row['incor_id'], 'total_price' => $need_pay_money, 'c_time' => time() ]; $if_zero_firstpay && $sub_data['status'] = 1; // 0首付强制为已支付 $if_zero_firstpay && $sub_data['pay_time'] = date('Y-m-d H:i:s'); // 0首付强制支付时间 $if_zero_firstpay && $sub_data['total_price'] = 0; // 0首付强制total_price为0 $if_zero_firstpay && $sub_data['descrip'] = '零首付'; $entrust_user['id'] && $sub_data['entrust_uid'] = $entrust_user['id']; $uid && $sub_data['uid'] = $uid; $res = $this->ci->app_liche_orders_model->add($sub_data); $pay_count = $this->ci->app_liche_orders_model->count(['o_id'=>$this->order_row['id'],'status'=>1]); //0首付播报 if ($pay_count == 1 && $if_zero_firstpay && $res){ $this->ci->load->library('qyrobot'); $this->ci->qyrobot->deposit_notify_v3($oid); } } } return $res; } /** * 创建服务费和尾款 * @param $oid * @param $uid * @return bool */ public function add_order($oid,$uid){ $this->ci->load->helper('order'); $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); $p_row = $this->ci->app_liche_orders_model->get(['pid'=>0,'o_id'=>$oid,'status>='=>0],'id'); //父订单 if(!$this->order_row || !$p_row){ return false; } //获取微信商户号 $companys = $this->get_biz_mchid($this->order_row['biz_id'],$this->order_row['brand_id'],$this->order_row['if_local_bill']); if($this->order_row['biz_id']==63){ //零跑店 门店ID= 63,车款收款都用 id = 12 的公司 合同收款公司不变 $filed = 'id,wx_mchid,title,short,credit_code,wx_mchid,img_seal'; $companys['company'] = $this->ci->sys_company_model->get(['id'=>12],$filed); } $srv_money = $this->order_srv_money($oid); //服务费 $money_json = json_decode($this->order_row['money_json'],true); $total_price = $this->total_price($oid); if(!$this->order_row['payway'] && !$money_json['price_loan']){//按揭金额未填写首付 return false; } $to_srv_price = $srv_money; //后台添加车款 $pay_row = $this->ci->app_liche_orders_model->sum('pay_price',['status'=>1,'type'=>6,'o_id'=>$oid]); if($pay_row['pay_price']>=0 && $pay_row['pay_price']>=$money_json['price_book']){ if(!$this->order_row['payway']){ //按揭 $total_price = $total_price - $money_json['price_loan']; $money_json['price_loan0'] && $total_price -= $money_json['price_loan0']; // 首付按揭 } $to_com_price = $total_price - $pay_row['pay_price']; }else{ if($this->order_row['payway']){ //全款 $to_com_price = $total_price - $money_json['price_book']; }else{ //按揭 $to_com_price = $total_price-$money_json['price_loan'] - $money_json['price_book']; $money_json['price_loan0'] && $to_com_price -= $money_json['price_loan0']; // 首付按揭 } } $to_com_price = $to_com_price>0 ? $to_com_price : 0; $last_order = $this->ci->app_liche_orders_model->get(['status>='=>0,'type'=>3,'o_id'=>$oid]); $srv_order = $this->ci->app_liche_orders_model->get(['status>='=>0,'type'=>2,'o_id'=>$oid]); if($last_order && $srv_order){ //存在尾款订单 if($last_order['total_price']!=$to_com_price && $to_com_price>0){ $this->ci->app_liche_orders_model->update(['total_price'=>$to_com_price,'status'=>0],['id'=>$last_order['id']]); } return true; } $add_data = []; $entrust_user = $this->entrust_user($oid); if($to_srv_price>0 && !$this->ci->app_liche_orders_model->count(['o_id'=>$this->order_row['id'],'type'=>2,'status>='=>0])){ $order_type = 2; $sid = create_order_no(350200,'liche'); $add_data[] = [ 'o_id' => $this->order_row['id'], 'uid' => $uid ? $uid : 0, 'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0, 'sid' => $sid, 'mch_id' => $companys['srv_company']['wx_mchid'], 'company_id' => $companys['srv_company']['id'], 'pid' => $p_row['id'], 'brand_id' => $this->order_row['brand_id'], 's_id' => $this->order_row['s_id'], 'v_id' => $this->order_row['v_id'], 'cor_id' => $this->order_row['cor_id'], 'incor_id' => $this->order_row['incor_id'], 'total_price' => $to_srv_price, 'type' => $order_type, 'c_time' => time() ]; } if($to_com_price>0 && !$this->ci->app_liche_orders_model->count(['o_id'=>$this->order_row['id'],'type'=>3,'status>='=>0])){ $book_order = $this->ci->app_liche_orders_model->get(['status>='=>0,'type'=>1,'o_id'=>$oid]); $book_order['mch_id'] && $companys['company']['wx_mchid'] = $book_order['mch_id']; $book_order['company_id'] && $companys['company']['id'] = $book_order['company_id']; $order_type = 3; $sid = create_order_no(350200,'liche'); $add_data[] = [ 'o_id' => $this->order_row['id'], 'uid' => $uid ? $uid : 0, 'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0, 'sid' => $sid, 'mch_id' => $companys['company']['wx_mchid'], 'company_id' => $companys['company']['id'], 'pid' => $p_row['id'], 'brand_id' => $this->order_row['brand_id'], 's_id' => $this->order_row['s_id'], 'v_id' => $this->order_row['v_id'], 'cor_id' => $this->order_row['cor_id'], 'incor_id' => $this->order_row['incor_id'], 'total_price' => $to_com_price, 'type' => $order_type, 'c_time' => time() ]; } $result = false; if($add_data){ $result = $this->ci->app_liche_orders_model->add_batch($add_data); } return $result; } /** * 计算订单应收金额 * @param $oid int 订单id * @param $srv_price boolean 是否包含服务费 * @param $price_loan boolean 是否包含按揭(230220 成本-应收款不要扣掉按揭部分) * @return float */ public function recevable_price($oid,$srv_price=true,$price_loan=true){ $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); if(!$this->order_row){ return false; } $money_json = json_decode($this->order_row['money_json'],true); $total_price = $this->total_price($oid); if($srv_price){ $srv_money = $this->order_srv_money($oid); $recevable_price = $total_price + $srv_money; }else{ $recevable_price = $total_price; } if($price_loan && !$this->order_row['payway']){ //按揭 $recevable_price -= $money_json['price_loan']; $money_json['price_loan0'] && $recevable_price -= $money_json['price_loan0']; // 首付按揭 } return $recevable_price; } /** * 计算订单总售价 * @param int $oid 订单id * @param string $money_json * @return float */ public function total_price($oid,$money_json=''){ if(!$money_json){ $order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid],'money_json'); if(!$order_row){ return false; } $money_json = json_decode($order_row['money_json'],true); }else{ $money_json = json_decode($money_json,true); } $total_price = $money_json['price_car']; if($money_json['price_discount']){ $total_price -= $money_json['price_discount']; } if($money_json['price_color']){ $total_price += $money_json['price_color']; } if($money_json['price_coplus']){ $total_price += $money_json['price_coplus']; } if($money_json['price_options']){ $total_price += $money_json['price_options']; } return $total_price ? $total_price : 0; } /** * 修改完订单信息后操作 * @param array() $new_data 修改后的数据 * @param array() $row 修改前数据 */ public function edit_order($new_data,$row,$user_info=[]){ //更新购车订单车辆信息 $up_data = [ 'brand_id' => $new_data['brand_id'], 's_id' => $new_data['s_id'], 'v_id' => $new_data['v_id'], 'cor_id' => $new_data['cor_id'], 'incor_id' => $new_data['incor_id'], ]; $this->ci->app_liche_orders_model->update($up_data,['o_id'=>$row['id']]); //删除未支付订单 $this->ci->app_liche_orders_model->delete(['o_id'=>$row['id'],'status'=>0,'pid!='=>0]); $payway = $new_data['payway']; $money_json = json_decode($new_data['money_json'],true); $deposit = $money_json['price_book']; $if_zero_firstpay = $payway == 0 && !$deposit ? 1 : 0; if (!$if_zero_firstpay){ //删除已支付的零首付订单 $this->ci->app_liche_orders_model->update(array('status'=>-1), ['o_id'=>$row['id'],'type'=>1,'status'=>1,'descrip'=>'零首付']); } $userinfo = $this->ci->app_liche_users_model->get(['mobile'=>$row['mobile']],'id'); if(!$this->ci->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>1,'status'=>1])){ //不存在定金订单 $pay_row= $this->ci->app_liche_orders_model->sum('pay_price',['o_id'=>$row['id'],'type'=>6,'status'=>1]);//后台添加车款 //if($pay_row['pay_price']<$money_json['price_book']){ if($if_zero_firstpay || $pay_row['pay_price']<$money_json['price_book']){ $int_order = $this->ci->app_liche_orders_model->get(['o_id'=>$row['id'],'type'=>4,'status'=>1]); //意向金订单 //if($int_order['pay_price']==$money_json['price_book']){ //意向金订单转支付订单、推送并且生成pfd //意向金小于定金的,怎么处理? (暂不处理) if($int_order && $int_order['pay_price']>=$money_json['price_book']){ //意向金订单转支付订单、推送并且生成pfd $this->ci->app_liche_orders_model->update(['type'=>1],['id'=>$int_order['id']]); $this->ci->receiver_orders_v2_model->update(['order_time'=>date('Y-m-d H:i:s')],['id'=>$row['id']]); //生成pdf $this->create_pdf($row['id']); $this->ci->load->library('qyrobot'); $this->ci->qyrobot->deposit_notify_v3($row['id']); //0首付下需要补记录 if ($if_zero_firstpay){ $this->add_book_order($row['id'],$userinfo['id']); } }else{ $this->add_book_order($row['id'],$userinfo['id']); } } } $this->add_order($row['id'],$userinfo['id']); //合同重新生成 $need_del_con = false; if($this->ci->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type in (0,1)'=>null])){ $need_del_con = true; } if($new_data['if_local_bill']!=$row['if_local_bill']){ $need_del_con = true; } if($need_del_con){ $this->ci->receiver_order_contracts_model->delete(['o_id'=>$row['id'],'type in (0,1)'=>null]); } $is_pay = $this->ci->app_liche_orders_model->count(['o_id'=>$row['id'],'type!='=>4,'status'=>1]); if($is_pay && ($new_data['brand_id']!=$row['brand_id'] || $new_data['s_id']!=$row['s_id'] || $new_data['v_id']!=$row['v_id']) || $new_data['cor_id']!=$row['cor_id'] || $new_data['incor_id'] != $row['incor_id'] ){ //存在已支付订单并且修改车型 写日志 $where = [ "lc_auto_series.id in ({$new_data['s_id']},{$row['s_id']})" => null ]; $brand = $this->ci->auto_series_model->select_brand($where); foreach ($brand as $key=>$value) { $brand[$value['id']] = $value; } $ids = [$new_data['v_id'],$row['v_id'],$new_data['cor_id'],$row['cor_id'],$new_data['incor_id'],$new_data['incor_id']]; $ids_str = implode(',',$ids); $where = [ "id in ({$ids_str})" => null ]; $attr = $this->ci->auto_attr_model->map('id','title',$where); $old_title = "{$brand[$row['s_id']]['b_name']}-{$brand[$row['s_id']]['name']}-{$attr[$row['v_id']]}-{$attr[$row['cor_id']]}-{$attr[$row['incor_id']]}"; $new_title = "{$brand[$new_data['s_id']]['b_name']}-{$brand[$new_data['s_id']]['name']}-{$attr[$new_data['v_id']]}-{$attr[$new_data['cor_id']]}-{$attr[$row['incor_id']]}"; $content = "车型由 {$old_title} 变更为 {$new_title}"; $this->ci->load->library('receiver/orders_entity'); $this->ci->orders_entity->add_log($row['id'],$user_info['uid'],$user_info['uname'],$content); //短信通知 $params = [ 'sid' => $row['sid']."({$row['owner_name']})", 'car_a' => $old_title, 'car_b' => $new_title, ]; $this->send_msg('SMS_241355543',$params); } } /** * 生成pdf文件 * @param $oid * @throws Exception */ public function create_pdf($oid){ $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); if(!$this->order_row ){ return ['code'=>0,'msg'=>'参数错误']; } if($this->ci->receiver_order_contracts_model->count(['o_id'=>$oid,'status'=>1])){ return ['code'=>1,'msg'=>'操作成功']; } $need_sign = false; if($this->order_row['brand_id'] == 1){ //除了东风,其他品牌都不用生成 购车协议 // $biz = $this->ci->biz_model->get(['id'=>$this->order_row['biz_id']],'city_id'); // $need_sign = $biz['city_id'] == '350900' ? true : false; $need_sign = true; } $fill_info = $this->pdf_data($this->order_row); $this->ci->load->library('pdftk'); if($need_sign) { $fill_data = [ 'sid' => $this->order_row['sid'], 'give_time' => $fill_info['give_time'], 'date' => $fill_info['now_day'], 'company' => $fill_info['companys']['company']['title'], 'name' => $fill_info['name'], 'owner_name' => $fill_info['owner_name'], 'owner_mobile' => $fill_info['owner_mobile'], 'identify_type' => $fill_info['identify_type'], 'identify' => $fill_info['identify'], 'address' => $fill_info['address'], 'version' => $fill_info['version'], 'color' => $fill_info['color'], 'incolor' => $fill_info['incolor'], 'price_car' => $fill_info['price_car'], 'price_discount' => $fill_info['price_discount'], 'price_finance' => $fill_info['price_finance'], 'recevable_price' => $fill_info['recevable_price'], 'price_book' => $fill_info['price_book'], 'last_price' => $fill_info['last_price'], ]; //2022-12-23至2023-01-01使用 car_tpl_tmp.pdf $pdf_path = time()>strtotime('2023-01-01 00:00:00') ? 'pdf/car_tpl.pdf' : 'pdf/car_tpl_temp.pdf'; if ($fill_info['sa']) { $fill_data['sa'] = $fill_info['sa']; $pdf_path = 'pdf/car_sa_tpl.pdf'; } $save_path = "pdf/{$this->order_row['sid']}/car.pdf"; $req = $this->ci->pdftk->esign_fill_pdf($pdf_path, $save_path, $fill_data); if (!$req['code']) { return ['code' => 0, 'msg' => $req['msg']]; } $add_data[] = [ 'o_id' => $this->order_row['id'], 'cid' => 0, 'file' => $req['data']['file_path'] ? $req['data']['file_path'] : '', 'type' => 0, 'status' => 1, 'c_time' => time() ]; } if($this->order_row['srv_ids']){ $fill_data = [ 'sid' => $this->order_row['sid'], 'date' => $fill_info['now_day'], 'company' => $fill_info['companys']['srv_company']['title'], 'name' => $fill_info['name'], 'mobile' => $this->order_row['owner_mobile'], 'owner_name' => $fill_info['owner_name'], 'owner_mobile' => $fill_info['owner_mobile'], 'service_str' => implode(' ',$fill_info['services']), ]; $pdf_path = 'pdf/agent_tpl.pdf'; $save_path = "pdf/{$this->order_row['sid']}/service.pdf"; $res = $this->ci->pdftk->esign_fill_pdf($pdf_path,$save_path,$fill_data); if($res['code']){ $add_data[] = [ 'o_id' => $this->order_row['id'], 'cid' => 0, 'file' => $res['data']['file_path'] ? $res['data']['file_path'] : '', 'type' => 1, 'status' => 1, 'c_time' => time() ]; } } $res = $this->ci->receiver_order_contracts_model->add_batch($add_data); if($res){ //更新交付时间 $car_json = json_decode($this->order_row['car_json'],true); $over_time = date('Y-m-d H:i:s',time()+$car_json['delivery_day']*24*60*60); //交付截止时间 $this->ci->receiver_orders_v2_model->update(['over_time'=>$over_time],['id'=> $this->order_row['id']]); return ['code'=>1,'msg'=>'操作成功']; }else{ return ['code'=>0,'msg'=>'操作失败']; } } /** * 获取填充内容 * @param $row * @param $type * @return mixed */ public function pdf_data($row,$type=0){ if(!$row){ return false; } $this->ci->load->model('auto/auto_business_model'); $info_json = json_decode($row['info_json'],true); $business_id = $info_json['business_id'] ? $info_json['business_id'] : 0; $data = []; $biz = $this->ci->biz_model->get(['id'=>$row['biz_id']]); //车辆信息 $money_json = json_decode($row['money_json'],true); $money_json['price_discount'] && $row['price'] = $row['price'] - $money_json['price_discount']; $brand = $this->ci->auto_brand_model->get(['id'=>$row['brand_id']],'name'); $series = $this->ci->auto_series_model->get(['id'=>$row['s_id']],'name'); $version = $this->ci->auto_attr_model->get(['id'=>$row['v_id']],'title'); $color = $this->ci->auto_attr_model->get(['id'=>$row['cor_id']],'title'); $incolor = $this->ci->auto_attr_model->get(['id'=>$row['incor_id']],'title'); $_version = $version['title'] ? $version['title'] : ''; $data['version'] = "{$brand['name']} {$series['name']} $_version"; $data['color'] = $color['title'] ? $color['title'] : ''; $data['incolor'] = $incolor['title'] ? $incolor['title'] : ''; $business_row = $this->ci->auto_business_model->get(['id'=>$business_id]); if($business_row){ $data['give_time'] = $business_row['delivery_day']; }else{ if($row['s_id']==24) { //零跑T03 $data['give_time'] = 60; }elseif($row['s_id']==25) { //零跑C11 $data['give_time'] = 120; }else{ //其它车型 $data['give_time'] = 45; } } $data['price_car'] = number_format($money_json['price_car']+$money_json['price_color']+$money_json['price_coplus'],2); $data['price_discount'] = number_format($money_json['price_discount'],2); $data['price_book'] = number_format($money_json['price_book'],2); $data['recevable_price'] = number_format($this->total_price($row['id']),2); $data['last_price'] = number_format($this->total_price($row['id']) - $money_json['price_book'],2); $data['address'] = $info_json['c_address'] ? $info_json['c_address'] : ''; $data['name'] = $row['name']; if($row['main_type']){ $data['identify_type'] = '营业执照' ; $data['identify'] = $info_json['c_credit']; $data['owner_name'] = $info_json['c_company']; $data['owner_mobile'] = $row['mobile']; }else{ $data['identify_type'] = '身份证'; $data['identify'] = $info_json['c_owner_cardid']; $data['owner_name'] = $row['owner_name']; $data['owner_mobile'] = $row['owner_mobile']; } $data['now_day'] = date('Y-m-d'); $data['companys'] = $this->get_biz_mchid($row['biz_id'],$row['brand_id'],$row['if_local_bill']); if($type==1){ $items = $this->ci->items_model->get(['id'=>$row['item_id']],'vin'); $delivery = $this->ci->deliverys_model->get(['o_id'=>$row['id']],'info,tool,remark'); $data['vin'] = $items['vin']; $data['delivery'] = $delivery; } $data['sa'] = ''; if($biz['type']==1){ $this->ci->load->model('receiver/order/receiver_order_datas_model'); $order_data = $this->ci->receiver_order_datas_model->get(['o_id'=>$row['id']]); $order_data['sa'] && $data['sa'] = $order_data['sa']; } if(!$type){ $services = []; $srv_arr = json_decode($row['srv_ids'],true); if(is_array($srv_arr)){ $srv_ids = array_column($srv_arr,'id'); $srv_ids_str = implode(',',$srv_ids); if($row['srv_ids'] && $srv_ids_str){ $service_rows = $this->ci->services_model->select(["id in ({$srv_ids_str})"=>null],'','','','id,title,field_name'); foreach($service_rows as $key=>$val){ $field_arr = explode('.',$val['field_name']); if(isset($money_json[$field_arr[1]])){ //保险费不收 $money = $field_arr[1]=='price_insure' ? '由保险公司收取' : $money_json[$field_arr[1]]; is_numeric($money) && $money = number_format($money,2); $services[] = $val['title'].': '.$money; } } } } if($row['if_fine']){ //选择精品包 $fine_price = $money_json['price_fine_discount'] ? $money_json['price_fine'] - $money_json['price_fine_discount'] : $money_json['price_fine']; $services[] = '精品尊享包: '.number_format($fine_price,2); } if($row['fines']){ $fines = json_decode($row['fines'],true); $split = $fine_title_price = $fine_title = ''; foreach($fines as $key=>$val){ $fine_title = $fine_title.$split.$val['txt'].$split; $price = $val['price']>0 ? number_format(floatval($val['price']),2) : '赠送'; $fine_title_price = $fine_title_price.$split."{$val['txt']}:{$price}"; $split = ' '; } $services[] = '精品选装: '.number_format($money_json['price_fine_select'],2)."($fine_title_price)"; } $srv_price = $this->order_srv_money($row['id']); $services[] = '实际支付(元): '.number_format($srv_price,2); $data['services'] = $services; } return $data; } //小程序支付图片 public function pay_img($oid){ $this->ci->load->model('app/app_model', 'mdApp'); $wxconfig = $this->ci->mdApp->appConfig()[1]['wx']; $img = self::API_PAY_IMG; if ($wxconfig) { $this->ci->load->library("hd_wechat", $wxconfig); $width = '430px'; $path = "pages/mine/carOrder/index"; $scene = $oid; $filename = "{$this->ci->mdApp->appConfig()[1]['app_key']}/" . substr(md5($path.'?id='.$oid), 8, 16); $result = $this->ci->hd_wechat->qrcode($filename,$scene,$path,$width); if($result['url']){ $img = http_host_com('api').'/'.$result['url']; } } return $img; } /** * 订单改变发送消息 * @param $sid * @param $info * @return void */ public function send_msg($template,$params){ /** * 模板内容 SMS_241360549 * 叮~小爱同学,订单 ${sid} 信息发生变化。车主信息由 ${owner_a} 变更为 ${owner_b},请知悉~ * 模板内容 SMS_241355543 * 叮~小爱同学,订单 ${sid} 信息发生变化。客户订购车型由 ${car_a} 变更为 ${car_b},请知悉~ */ return ''; if(!template || !$params){ return ''; } $mobile_lists = ['18950000118','13860199646']; !is_product() && $mobile_lists = ['18350451617']; //测试 foreach ($mobile_lists as $val){ send_alisms(array('mobile' => $val, 'template' => $template, 'param' => $params)); } } /** * 按“商家-品牌”下定统计 * @param $today_start * @param $today_end * @param $total_start * @param $total_end * @return array */ public function aggs_biz_brand_ding($today_start='', $today_end='', $total_start='', $total_end=''){ if (!$today_start || !$today_end || !$total_start || !$total_end){ return array(); } # biz_type(已下订) $sql = " SELECT b.type as biz_type, o.biz_id, o.brand_id,ab.`name` as brand_name, o.s_id, s.`name` as series_name, count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today, count(o.id) as doc_ding FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '0' AND `status` in (1,2) GROUP BY o_id HAVING count(status) >= 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id left join lc_auto_brand ab on o.brand_id = ab.id left join lc_auto_series s on o.s_id = s.id WHERE o.`status` >= 0 AND o.order_time >= '$total_start' AND o.order_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 group by b.type, o.biz_id, o.brand_id, ab.`name`, o.s_id, s.`name` order by b.type, o.biz_id, o.brand_id, o.s_id "; # 只统计品牌店,合伙店,代理店,其中代理店按城市(已下订) $sql = " SELECT b.type as biz_type, if(b.type in (3), b.city_id, o.biz_id) as biz_id, o.brand_id,ab.`name` as brand_name, o.s_id, s.`name` as series_name, count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today, count(o.id) as doc_ding FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '0' AND `status` in (1,2) GROUP BY o_id HAVING count(status) >= 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id left join lc_auto_brand ab on o.brand_id = ab.id left join lc_auto_series s on o.s_id = s.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.order_time >= '$total_start' AND o.order_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 AND b.type in (1, 2, 3) group by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, ab.`name`, o.s_id, s.`name` order by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, o.s_id "; # 只统计品牌店,合伙店,代理店,其中代理店按城市(全部) $sql = " SELECT b.type as biz_type, if(b.type in (3), b.city_id, o.biz_id) as biz_id, o.brand_id, if(ab.`name` is null, '-', ab.`name`) as brand_name, o.s_id, if(s.`name` is null, '-', s.`name`) as series_name, count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today, count(o.id) as doc_ding FROM lc_receiver_orders_v2 o left join lc_biz b on o.biz_id = b.id left join lc_auto_brand ab on o.brand_id = ab.id left join lc_auto_series s on o.s_id = s.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.order_time >= '$total_start' AND o.order_time < '$total_end' AND b.type in (1, 2, 3) group by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, ab.`name`, o.s_id, s.`name` order by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, o.s_id "; return $this->ci->db->query($sql)->result_array(); } public function aggs_biz_brand_ding_cityid($today_start='', $today_end='', $total_start='', $total_end=''){ if (!$today_start || !$today_end || !$total_start || !$total_end){ return array(); } $sql = " SELECT b.city_id as biz_type, case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end as biz_id, o.brand_id, if(ab.`name` is null, '-', ab.`name`) as brand_name, o.s_id, if(s.`name` is null, '-', s.`name`) as series_name, count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today, count(o.id) as doc_ding FROM lc_receiver_orders_v2 o left join lc_biz b on o.biz_id = b.id left join lc_auto_brand ab on o.brand_id = ab.id left join lc_auto_series s on o.s_id = s.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.order_time >= '$total_start' AND o.order_time < '$total_end' AND b.type in (1, 2, 3) group by b.city_id, case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end, o.brand_id, ab.`name`, o.s_id, s.`name` order by b.city_id, FIELD(b.type,1,2,3), case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end, o.brand_id, o.s_id "; return $this->ci->db->query($sql)->result_array(); } /** * 按“商家-品牌”开票统计 * @param $today_start * @param $today_end * @param $total_start * @param $total_end * @return array */ public function aggs_biz_brand_piao($today_start='', $today_end='', $total_start='', $total_end=''){ if (!$today_start || !$today_end || !$total_start || !$total_end){ return array(); } # biz_type $sql = " SELECT b.type as biz_type, o.biz_id, o.brand_id, ab.`name` as brand_name, o.s_id, s.`name` as series_name, count(if(o.bill_time >= '$today_start' AND o.bill_time < '$today_end', o.id, null)) as doc_piao_today, count(o.id) as doc_piao FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '3' AND `status` in (1,2) GROUP BY o_id HAVING count(status) = 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id left join lc_auto_brand ab on o.brand_id = ab.id left join lc_auto_series s on o.s_id = s.id WHERE o.`status` >= 0 AND o.bill_time >= '$total_start' AND o.bill_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 group by b.type, o.biz_id, o.brand_id, ab.`name`, o.s_id, s.`name` order by b.type, o.biz_id, o.brand_id, o.s_id "; # 只统计品牌店,合伙店,代理店,其中代理店按城市 $sql = " SELECT b.type as biz_type, if(b.type in (3), b.city_id, o.biz_id) as biz_id, o.brand_id, ab.`name` as brand_name, o.s_id, s.`name` as series_name, count(if(o.bill_time >= '$today_start' AND o.bill_time < '$today_end', o.id, null)) as doc_piao_today, count(o.id) as doc_piao FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '3' AND `status` in (1,2) GROUP BY o_id HAVING count(status) = 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id left join lc_auto_brand ab on o.brand_id = ab.id left join lc_auto_series s on o.s_id = s.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.bill_time >= '$total_start' AND o.bill_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 AND b.type in (1, 2, 3) group by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, ab.`name`, o.s_id, s.`name` order by b.type, if(b.type in (3), b.city_id, o.biz_id), o.brand_id, o.s_id "; return $this->ci->db->query($sql)->result_array(); } public function aggs_biz_brand_piao_cityid($today_start='', $today_end='', $total_start='', $total_end=''){ if (!$today_start || !$today_end || !$total_start || !$total_end){ return array(); } $sql = " SELECT b.city_id as biz_type, case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end as biz_id, o.brand_id, ab.`name` as brand_name, o.s_id, s.`name` as series_name, count(if(o.bill_time >= '$today_start' AND o.bill_time < '$today_end', o.id, null)) as doc_piao_today, count(o.id) as doc_piao FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '3' AND `status` in (1,2) GROUP BY o_id HAVING count(status) = 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id left join lc_auto_brand ab on o.brand_id = ab.id left join lc_auto_series s on o.s_id = s.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.bill_time >= '$total_start' AND o.bill_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 AND b.type in (1, 2, 3) group by b.city_id, case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end, o.brand_id, ab.`name`, o.s_id, s.`name` order by b.city_id, FIELD(b.type,1,2,3), case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end, o.brand_id, o.s_id "; return $this->ci->db->query($sql)->result_array(); } /** * 按“商家”下定+开票统计 * @param $today_start * @param $today_end * @param $total_start * @param $total_end * @return array */ public function aggs_biz_ding_piao($today_start='', $today_end='', $total_start='', $total_end=''){ if (!$today_start || !$today_end || !$total_start || !$total_end){ return array(); } # biz_type $sql = " select biz_type, biz_id, biz_name, if(sum(doc_ding_today)=0,null,sum(doc_ding_today)) as doc_ding_today, if(sum(doc_ding)=0,null,sum(doc_ding)) as doc_ding, if(sum(doc_piao_today)=0,null,sum(doc_piao_today)) as doc_piao_today, if(sum(doc_piao)=0,null,sum(doc_piao)) as doc_piao from ( SELECT b.type as biz_type, o.biz_id, b.biz_name, count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today, count(o.id) as doc_ding, null as doc_piao_today, null as doc_piao FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '0' AND `status` in (1,2) GROUP BY o_id HAVING count(status) >= 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id WHERE o.`status` >= 0 AND o.order_time >= '$total_start' AND o.order_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 group by b.type, o.biz_id, b.biz_name union all SELECT b.type as biz_type, o.biz_id, b.biz_name, null as doc_ding_today, null as doc_ding, count(if(o.bill_time >= '$today_start' AND o.bill_time < '$today_end', o.id, null)) as doc_piao_today, count(o.id) as doc_piao FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '3' AND `status` in (1,2) GROUP BY o_id HAVING count(status) = 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id WHERE o.`status` >= 0 AND o.bill_time >= '$total_start' AND o.bill_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 group by b.type, o.biz_id, b.biz_name ) u group by biz_type, biz_id, biz_name order by biz_type, biz_id "; # 只统计品牌店,合伙店,代理店,其中代理店按城市 $sql = " select biz_type, biz_id, biz_name, if(sum(doc_ding_today)=0,null,sum(doc_ding_today)) as doc_ding_today, if(sum(doc_ding)=0,null,sum(doc_ding)) as doc_ding, if(sum(doc_piao_today)=0,null,sum(doc_piao_today)) as doc_piao_today, if(sum(doc_piao)=0,null,sum(doc_piao)) as doc_piao from ( SELECT b.type as biz_type, if(b.type in (3), b.city_id, o.biz_id) as biz_id, if(b.type in (3), if(c.`name` is null, b.city_id, replace(concat(c.`name`, '渠道'), '市渠道', '渠道')), b.biz_name) as biz_name, count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today, count(o.id) as doc_ding, null as doc_piao_today, null as doc_piao FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '0' AND `status` in (1,2) GROUP BY o_id HAVING count(status) >= 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.order_time >= '$total_start' AND o.order_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 AND b.type in (1, 2, 3) group by b.type, if(b.type in (3), b.city_id, o.biz_id), if(b.type in (3), if(c.`name` is null, b.city_id, c.`name`), b.biz_name) union all SELECT b.type as biz_type, if(b.type in (3), b.city_id, o.biz_id) as biz_id, if(b.type in (3), if(c.`name` is null, b.city_id, replace(concat(c.`name`, '渠道'), '市渠道', '渠道')), b.biz_name) as biz_name, null as doc_ding_today, null as doc_ding, count(if(o.bill_time >= '$today_start' AND o.bill_time < '$today_end', o.id, null)) as doc_piao_today, count(o.id) as doc_piao FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '3' AND `status` in (1,2) GROUP BY o_id HAVING count(status) = 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.bill_time >= '$total_start' AND o.bill_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 AND b.type in (1, 2, 3) group by b.type, if(b.type in (3), b.city_id, o.biz_id), if(b.type in (3), if(c.`name` is null, b.city_id, c.`name`), b.biz_name) ) u group by biz_type, biz_id, biz_name order by biz_type, biz_id "; # 只统计品牌店,合伙店,代理店,其中代理店按城市(全部) $sql = " select biz_type, biz_id, biz_name, if(sum(doc_ding_today)=0,null,sum(doc_ding_today)) as doc_ding_today, if(sum(doc_ding)=0,null,sum(doc_ding)) as doc_ding, if(sum(doc_piao_today)=0,null,sum(doc_piao_today)) as doc_piao_today, if(sum(doc_piao)=0,null,sum(doc_piao)) as doc_piao from ( SELECT b.type as biz_type, if(b.type in (3), b.city_id, o.biz_id) as biz_id, if(b.type in (3), if(c.`name` is null, b.city_id, replace(concat(c.`name`, '渠道'), '市渠道', '渠道')), b.biz_name) as biz_name, count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today, count(o.id) as doc_ding, null as doc_piao_today, null as doc_piao FROM lc_receiver_orders_v2 o left join lc_biz b on o.biz_id = b.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.order_time >= '$total_start' AND o.order_time < '$total_end' AND b.type in (1, 2, 3) group by b.type, if(b.type in (3), b.city_id, o.biz_id), if(b.type in (3), if(c.`name` is null, b.city_id, c.`name`), b.biz_name) union all SELECT b.type as biz_type, if(b.type in (3), b.city_id, o.biz_id) as biz_id, if(b.type in (3), if(c.`name` is null, b.city_id, replace(concat(c.`name`, '渠道'), '市渠道', '渠道')), b.biz_name) as biz_name, null as doc_ding_today, null as doc_ding, count(if(o.bill_time >= '$today_start' AND o.bill_time < '$today_end', o.id, null)) as doc_piao_today, count(o.id) as doc_piao FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '3' AND `status` in (1,2) GROUP BY o_id HAVING count(status) = 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.bill_time >= '$total_start' AND o.bill_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 AND b.type in (1, 2, 3) group by b.type, if(b.type in (3), b.city_id, o.biz_id), if(b.type in (3), if(c.`name` is null, b.city_id, c.`name`), b.biz_name) ) u group by biz_type, biz_id, biz_name order by biz_type, biz_id "; return $this->ci->db->query($sql)->result_array(); } public function aggs_biz_ding_piao_cityid($today_start='', $today_end='', $total_start='', $total_end=''){ if (!$today_start || !$today_end || !$total_start || !$total_end){ return array(); } $sql = " select biz_type, city_name, biz_id, biz_name, if(sum(doc_ding_today)=0,null,sum(doc_ding_today)) as doc_ding_today, if(sum(doc_ding)=0,null,sum(doc_ding)) as doc_ding, if(sum(doc_piao_today)=0,null,sum(doc_piao_today)) as doc_piao_today, if(sum(doc_piao)=0,null,sum(doc_piao)) as doc_piao from ( SELECT b.city_id as biz_type, c.`name` as city_name, case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end as biz_id, case when b.type=2 then '合伙店' when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then '东风店渠道'when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then '哪吒店渠道' when b.type=3 then '渠道店' else b.biz_name end as biz_name, count(if(o.order_time >= '$today_start' AND o.order_time < '$today_end', o.id, null)) as doc_ding_today, count(o.id) as doc_ding, null as doc_piao_today, null as doc_piao FROM lc_receiver_orders_v2 o left join lc_biz b on o.biz_id = b.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.order_time >= '$total_start' AND o.order_time < '$total_end' AND b.type in (1, 2, 3) group by b.city_id, c.`name`, case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end, case when b.type=2 then '合伙店' when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then '东风店渠道'when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then '哪吒店渠道' when b.type=3 then '渠道店' else b.biz_name end union all SELECT b.city_id as biz_type, c.`name` as city_name, case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end as biz_id, case when b.type=2 then '合伙店' when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then '东风店渠道'when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then '哪吒店渠道' when b.type=3 then '渠道店' else b.biz_name end as biz_name, null as doc_ding_today, null as doc_ding, count(if(o.bill_time >= '$today_start' AND o.bill_time < '$today_end', o.id, null)) as doc_piao_today, count(o.id) as doc_piao FROM lc_receiver_orders_v2 o JOIN (select o_id from lc_receiver_order_status where pid_status = '3' AND `status` in (1,2) GROUP BY o_id HAVING count(status) = 1 ) os ON os.o_id = o.id left join lc_biz b on o.biz_id = b.id left join lc_sys_city c on b.city_id = c.city_id WHERE o.`status` >= 0 AND o.bill_time >= '$total_start' AND o.bill_time < '$total_end' AND o.brand_id > 0 AND o.`status` <> 2 AND b.type in (1, 2, 3) group by b.city_id, c.`name`, case when b.type = 2 then b.type when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then b.type when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then 4 when b.type = 3 then b.type else o.biz_id end, case when b.type=2 then '合伙店' when b.type = 3 and b.city_id = 350200 and b.id in (73,78,110,171) then '东风店渠道'when b.type = 3 and b.city_id = 350200 and b.id not in (73,78,110,171) then '哪吒店渠道' when b.type=3 then '渠道店' else b.biz_name end ) u group by biz_type, city_name, biz_id, biz_name order by biz_type, biz_id desc "; return $this->ci->db->query($sql)->result_array(); } /** * 商家下定+开票统计:按店铺类型,品牌拆分为系列,支持订单与开票独立图片 * @param $today_start * @param $today_end * @param $total_start * @param $total_end * @param $title_today * @param $title_ding_today * @param $title_ding * @param $title_piao_today * @param $title_piao * @param $create_table_image * @param $title * @return array */ public function aggs_biz_ding_piao_rpt($today_start='', $today_end='', $total_start='', $total_end='', $title_today='', $title_ding_today='', $title_ding='', $title_piao_today='', $title_piao='', $create_table_image=false, $title='区域') { !$today_start && $today_start = date('Y-m-d 00:00:00'); !$today_end && $today_end = date('Y-m-d 00:00:00', strtotime('+1 day')); !$total_start && $total_start = date('Y-m-01 00:00:00'); !$total_end && $total_end = date('Y-m-01 00:00:00', strtotime('+1 month')); //!$title_today && $title_today = date('m月d日'); !$title_today && $title_today = '来源'; !$title_ding_today && $title_ding_today = '当日订单'; !$title_ding && $title_ding = '月累计订单'; !$title_piao_today && $title_piao_today = '当日开票'; !$title_piao && $title_piao = '月累计开票'; $ding = $this->aggs_biz_brand_ding_cityid($today_start, $today_end, $total_start, $total_end); $piao = $this->aggs_biz_brand_piao_cityid($today_start, $today_end, $total_start, $total_end); $biz = $this->aggs_biz_ding_piao_cityid($today_start, $today_end, $total_start, $total_end); #var_dump($today_start);var_dump($today_end);var_dump($total_start);var_dump($total_end);var_dump($ding); var_dump($piao);var_dump($biz); if (!$biz) { return array(); } # 生成品牌arr $brand_names = array_unique(array_merge(array_column($ding, 'brand_name'), array_column($piao, 'brand_name'))); sort($brand_names); # 生成品牌对应的车系arr $series_names = array(); foreach ($ding as $k => $v) { $series_name = $v['series_name']; $key = $v['brand_name']; if (!$series_names[$key]) { $series_names[$key][] = $series_name; continue; } if (!in_array($series_name, $series_names[$key])) { $series_names[$key][] = $series_name; } } foreach ($piao as $k => $v) { $series_name = $v['series_name']; $key = $v['brand_name']; if (!$series_names[$key]) { $series_names[$key][] = $series_name; continue; } if (!in_array($series_name, $series_names[$key])) { $series_names[$key][] = $series_name; } } #var_dump($brand_names); var_dump($series_names); #$series_name 先完成排序,再生成表头与数据列 $series_names_ = array(); foreach ($brand_names as $brand_name){ $v = $series_names[$brand_name]; sort($v); $series_names_[$brand_name] = $v; } $series_names = $series_names_; # 生成表头 $indexs_total = array(); $indexs_total[] = 'doc_ding'; $indexs_total[] = 'doc_piao'; $arr1 = array('city_name'=>$title, 'biz_name'=>$title_today, 'doc_ding_today'=>$title_ding_today); $arr1 = array_merge($arr1, array('doc_ding'=>$title_ding)); foreach ($series_names as $k => $v){ $indexs_total[] = $k.'_ding'; $arr1[$k.'_ding'] = $k; # 品牌在系列前 foreach ($v as $k1 => $v1){ #$arr1[$k.'_'.$v1.'_ding'] = $k.'_'.$v1; $arr1[$k.'_'.$v1.'_ding'] = ' '.$v1; # 系列简写 } } $arr3 = array('doc_piao_today'=>$title_piao_today); $arr3 = array_merge($arr3, array('doc_piao'=>$title_piao)); foreach ($series_names as $k => $v){ $indexs_total[] = $k.'_piao'; $arr3[$k.'_piao'] = $k; # 品牌在系列前 foreach ($v as $k1 => $v1){ #$arr3[$k.'_'.$v1.'_piao'] = $k.'_'.$v1; $arr3[$k.'_'.$v1.'_piao'] = ' '.$v1; # 系列简写 } } $indexs = array_merge($arr1, $arr3); #var_dump($indexs); # $ding, $piao 行转kv,生成xj小记与hj合计: 1 _1_东风EV_doc_ding 7; 1 _东风EV_doc_ding 9; 东风EV_doc_ding 9 $kv = array(); foreach (array_merge($ding, $piao) as $k => $v){ $key_ding = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_doc_ding'; $key_ding_xj = $v['biz_type'].'_'.$v['brand_name'].'_doc_ding'; $key_ding_hj = $v['brand_name'].'_doc_ding'; $key_ding_series = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_ding'; $key_ding_series_xj = $v['biz_type'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_ding'; $key_ding_series_hj = $v['brand_name'].'_'.$v['series_name'].'_doc_ding'; $key_piao = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_doc_piao'; $key_piao_xj = $v['biz_type'].'_'.$v['brand_name'].'_doc_piao'; $key_piao_hj = $v['brand_name'].'_doc_piao'; $key_piao_series = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_piao'; $key_piao_series_xj = $v['biz_type'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_piao'; $key_piao_series_hj = $v['brand_name'].'_'.$v['series_name'].'_doc_piao'; if ($temp = intval($v['doc_ding'])){ $kv[$key_ding_series] = $temp; $kv[$key_ding_series_xj] = $kv[$key_ding_series_xj] ? $kv[$key_ding_series_xj] + $temp: $temp; $kv[$key_ding_series_hj] = $kv[$key_ding_series_hj] ? $kv[$key_ding_series_hj] + $temp: $temp; $kv[$key_ding] = $kv[$key_ding] ? $kv[$key_ding] + $temp: $temp; $kv[$key_ding_xj] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] + $temp: $temp; $kv[$key_ding_hj] = $kv[$key_ding_hj] ? $kv[$key_ding_hj] + $temp: $temp; } if ($temp = intval($v['doc_piao'])){ $kv[$key_piao_series] = $temp; $kv[$key_piao_series_xj] = $kv[$key_piao_series_xj] ? $kv[$key_piao_series_xj] + $temp: $temp; $kv[$key_piao_series_hj] = $kv[$key_piao_series_hj] ? $kv[$key_piao_series_hj] + $temp: $temp; $kv[$key_piao] = $kv[$key_piao] ? $kv[$key_piao] + $temp: $temp; $kv[$key_piao_xj] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] + $temp: $temp; $kv[$key_piao_hj] = $kv[$key_piao_hj] ? $kv[$key_piao_hj] + $temp: $temp; } } $biz_type = $city_name = $biz_id = $biz_name = null; $doc_ding_today = $doc_ding = $doc_piao_today = $doc_piao = 0; $doc_ding_today_ = $doc_ding_ = $doc_piao_today_ = $doc_piao_ = 0; $biz_aggs = array(); foreach ($biz as $k1 => $v1){ !$biz_type && $biz_type = $v1['biz_type']; !$city_name && $city_name = $v1['city_name']; $biz_id = $v1['biz_id']; $biz_name = $v1['biz_name']; $doc_ding_today_ += $v1['doc_ding_today'] ? $v1['doc_ding_today'] : 0; $doc_ding_ += $v1['doc_ding'] ? $v1['doc_ding'] : 0; $doc_piao_today_ += $v1['doc_piao_today'] ? $v1['doc_piao_today'] : 0; $doc_piao_ += $v1['doc_piao'] ? $v1['doc_piao'] : 0; if ($biz_type <> $v1['biz_type']){ #$biz_type_ary = $this->ci->biz_model->type_ary(); #$biz_type_name = $biz_type_ary[$biz_type] ? '('.$biz_type_ary[$biz_type].')' : ''; # 'biz_name'=>$biz_type_name.'小计' $arr1 = array('city_name'=>'', 'biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : ''); foreach ($brand_names as $k2 => $v2){ # 生成车型列 $key_ding_xj = $biz_type.'_'.$v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] : ''; # 生成车系列 foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_ding'; $arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series_xj] ? $kv[$key_ding_series_xj] : ''; } } $arr3 = array('doc_piao_today'=>$doc_piao_today ? $doc_piao_today : '', 'doc_piao'=>$doc_piao ? $doc_piao : ''); foreach ($brand_names as $k2 => $v2){ $key_piao_xj = $biz_type.'_'.$v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_piao_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_piao'; $arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_piao_series_xj] ? $kv[$key_piao_series_xj] : ''; } } $biz_aggs[] = array_merge($arr1, $arr3); $biz_type = $v1['biz_type']; $city_name = $v1['city_name']; $doc_ding_today = $doc_ding = $doc_piao_today = $doc_piao = 0; } $doc_ding_today += $v1['doc_ding_today'] ? $v1['doc_ding_today'] : 0; $doc_ding += $v1['doc_ding'] ? $v1['doc_ding'] : 0; $doc_piao_today += $v1['doc_piao_today'] ? $v1['doc_piao_today'] : 0; $doc_piao += $v1['doc_piao'] ? $v1['doc_piao'] : 0; $arr1 = array('city_name'=>$city_name, 'biz_type'=>$biz_type, 'biz_id'=>$biz_id, 'biz_name'=>$biz_name, 'doc_ding_today'=>$v1['doc_ding_today'] ? $v1['doc_ding_today'] : '', 'doc_ding'=>$v1['doc_ding'] ? $v1['doc_ding'] : ''); foreach ($brand_names as $k2 => $v2){ $key_ding = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding] ? $kv[$key_ding] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_'.$vs.'_doc_ding'; $arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series] ? $kv[$key_ding_series] : ''; } } $arr3 = array('doc_piao_today'=>$v1['doc_piao_today'] ? $v1['doc_piao_today'] : '', 'doc_piao'=>$v1['doc_piao'] ? $v1['doc_piao'] : ''); foreach ($brand_names as $k2 => $v2){ $key_piao = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao] ? $kv[$key_piao] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_piao_series = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_'.$vs.'_doc_piao'; $arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_piao_series] ? $kv[$key_piao_series] : ''; } } $biz_aggs[] = array_merge($arr1, $arr3); } # 最后一个小计 #$biz_type_ary = $this->ci->biz_model->type_ary(); #$biz_type_name = $biz_type_ary[$biz_type] ? '('.$biz_type_ary[$biz_type].')' : ''; # 'biz_name'=>$biz_type_name.'小计' $arr1 = array('city_name'=>'', 'biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : ''); foreach ($brand_names as $k2 => $v2){ $key_ding_xj = $biz_type.'_'.$v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_ding'; $arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series_xj] ? $kv[$key_ding_series_xj] : ''; } } $arr3 = array('doc_piao_today'=>$doc_piao_today ? $doc_piao_today : '', 'doc_piao'=>$doc_piao ? $doc_piao : ''); foreach ($brand_names as $k2 => $v2){ $key_piao_xj = $biz_type.'_'.$v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_piao_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_piao'; $arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_piao_series_xj] ? $kv[$key_piao_series_xj] : ''; } } $biz_aggs[] = array_merge($arr1, $arr3); # 合计 $arr1 = array('city_name'=>'', 'biz_type'=>'', 'biz_id'=>'', 'biz_name'=>'合计', 'doc_ding_today'=>$doc_ding_today_ ? $doc_ding_today_ : '', 'doc_ding'=>$doc_ding_ ? $doc_ding_ : ''); foreach ($brand_names as $k2 => $v2){ $key_ding_hj = $v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding_hj] ? $kv[$key_ding_hj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series_hj = $v2.'_'.$vs.'_doc_ding'; $arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series_hj] ? $kv[$key_ding_series_hj] : ''; } } $arr3 = array('doc_piao_today'=>$doc_piao_today_ ? $doc_piao_today_ : '', 'doc_piao'=>$doc_piao_ ? $doc_piao_ : ''); foreach ($brand_names as $k2 => $v2){ $key_piao_hj = $v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao_hj] ? $kv[$key_piao_hj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series_hj = $v2.'_'.$vs.'_doc_piao'; $arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_ding_series_hj] ? $kv[$key_ding_series_hj] : ''; } } $biz_aggs[] = array_merge($arr1, $arr3);#var_dump($indexs);var_dump($biz_aggs); $img_path = $img_path_ding = $img_path_piao = ''; if ($create_table_image){ $data = $biz_aggs; foreach ($data as $k => $v){ unset($data[$k]['biz_type']); unset($data[$k]['biz_id']); $data[$k]['biz_name'] = mb_strlen ($data[$k]['biz_name']) > 9 ? mb_substr($data[$k]['biz_name'], 0, 9).'..' : $data[$k]['biz_name']; } $data_ding = $data_piao = $data; foreach ($data_ding as $k => $v){ foreach ($data_ding[$k] as $kd => $vd){ if (strpos($kd,'_piao') !== false){ unset($data_ding[$k][$kd]); } } } foreach ($data_ding as $k => $v){ foreach ($data_ding[$k] as $kd => $vd){ if (strpos($kd,'_ding') !== false){ unset($data_piao[$k][$kd]); } } } $index_img = $indexs; $index_img_ding = $index_img_piao = array(); foreach ($index_img as $k => $v){ #$k != 'biz_name' && $index_img[$k] = mb_strlen ($v) > 8 ? mb_substr($v, -8, 8) : $v; if ($k != 'biz_name'){ /*if (strpos($k,'_') !== false){ $index_img[$k] = mb_strlen ($v) > 8 ? mb_substr($v, 0, 2).'..'.mb_substr(array_slice(explode('_', $v), -1)[0], -5, 5) : str_replace('_', ' ', $v); } else{ $index_img[$k] = mb_strlen ($v) > 5 ? mb_substr($v, 0, 5) : $v; }*/ $index_img[$k] = $v; # 讲话车系后直接显示全部 } if (strpos($k,'_ding') !== false){ $index_img_ding[$k] = $index_img[$k]; } elseif (strpos($k,'_piao') !== false){ $index_img_piao[$k] = $index_img[$k]; } else{ $index_img_ding[$k] = $index_img[$k]; $index_img_piao[$k] = $index_img[$k]; } } # 去掉空列与空行 $this->clear_null_column_line($biz_aggs, $indexs); $this->clear_null_column_line($data, $index_img); $this->clear_null_column_line($data_ding, $index_img_ding); $this->clear_null_column_line($data_piao, $index_img_piao); #var_dump($data_piao);var_dump('
');var_dump($index_img_piao);var_dump('
');var_dump($indexs_total); #var_dump($biz_aggs[0]);var_dump($data[0]);var_dump($index_img);var_dump($data_ding[0]);var_dump($index_img_ding);var_dump($data_piao[0]);var_dump($index_img_piao);; $img_path = $this->create_table_image($data, $index_img, $indexs_total, '小狸播报', 'aggs_biz_rpt.png'); $img_path_ding = $this->create_table_image($data_ding, $index_img_ding, $indexs_total, '小狸播报 - 订单', 'aggs_biz_rpt_ding.png'); $img_path_piao = $this->create_table_image($data_piao, $index_img_piao, $indexs_total, '小狸播报 - 开票', 'aggs_biz_rpt_piao.png'); } return array('biz_aggs'=>$biz_aggs, 'indexs'=>$indexs, 'img_path'=>$img_path, 'img_path_ding'=>$img_path_ding, 'img_path_piao'=>$img_path_piao, 'brand_names'=>$brand_names, 'series_names'=>$series_names); } // 商家下定+开票统计 simple:按店铺类型,拆分品牌的系列 public function aggs_biz_ding_piao_rpt_series($today_start='', $today_end='', $total_start='', $total_end='', $title_today='', $title_ding_today='', $title_ding='', $title_piao_today='', $title_piao='', $create_table_image=false){ !$today_start && $today_start = date('Y-m-d 00:00:00'); !$today_end && $today_end = date('Y-m-d 00:00:00', strtotime('+1 day')); !$total_start && $total_start = date('Y-m-01 00:00:00'); !$total_end && $total_end = date('Y-m-01 00:00:00', strtotime('+1 month')); //!$title_today && $title_today = date('m月d日'); !$title_today && $title_today = '来源'; !$title_ding_today && $title_ding_today = '当日订单'; !$title_ding && $title_ding = '月累计订单'; !$title_piao_today && $title_piao_today = '当日开票'; !$title_piao && $title_piao = '月累计开票'; $ding = $this->aggs_biz_brand_ding($today_start, $today_end, $total_start, $total_end); $piao = $this->aggs_biz_brand_piao($today_start, $today_end, $total_start, $total_end); $biz = $this->aggs_biz_ding_piao($today_start, $today_end, $total_start, $total_end); #var_dump($today_start);var_dump($today_end);var_dump($total_start);var_dump($total_end);var_dump($ding); var_dump($piao);var_dump($biz); if (!$biz){ return array(); } # 生成品牌arr $brand_names = array_unique(array_merge(array_column($ding, 'brand_name'), array_column($piao, 'brand_name'))); sort($brand_names); # 生成品牌对应的车系arr $series_names = array(); foreach ($ding as $k => $v){ $series_name = $v['series_name']; $key = $v['brand_name']; if (!$series_names[$key]){ $series_names[$key][] = $series_name; continue; } if (!in_array($series_name, $series_names[$key])){ $series_names[$key][] = $series_name; } } foreach ($piao as $k => $v){ $series_name = $v['series_name']; $key = $v['brand_name']; if (!$series_names[$key]){ $series_names[$key][] = $series_name; continue; } if (!in_array($series_name, $series_names[$key])){ $series_names[$key][] = $series_name; } } #var_dump($brand_names); var_dump($series_names); #$series_name 先完成排序,再生成表头与数据列 $series_names_ = array(); foreach ($brand_names as $brand_name){ $v = $series_names[$brand_name]; sort($v); $series_names_[$brand_name] = $v; } $series_names = $series_names_; # 生成表头 $indexs_total = array(); $indexs_total[] = 'doc_ding'; $indexs_total[] = 'doc_piao'; $arr1 = array('biz_name'=>$title_today, 'doc_ding_today'=>$title_ding_today); $arr1 = array_merge($arr1, array('doc_ding'=>$title_ding)); foreach ($series_names as $k => $v){ $indexs_total[] = $k.'_ding'; $arr1[$k.'_ding'] = $k; # 品牌在系列前 foreach ($v as $k1 => $v1){ #$arr1[$k.'_'.$v1.'_ding'] = $k.'_'.$v1; $arr1[$k.'_'.$v1.'_ding'] = ' '.$v1; # 系列简写 } } $arr3 = array('doc_piao_today'=>$title_piao_today); $arr3 = array_merge($arr3, array('doc_piao'=>$title_piao)); foreach ($series_names as $k => $v){ $indexs_total[] = $k.'_piao'; $arr3[$k.'_piao'] = $k; # 品牌在系列前 foreach ($v as $k1 => $v1){ #$arr3[$k.'_'.$v1.'_piao'] = $k.'_'.$v1; $arr3[$k.'_'.$v1.'_piao'] = ' '.$v1; # 系列简写 } } $indexs = array_merge($arr1, $arr3); #var_dump($indexs); # $ding, $piao 行转kv,生成xj小记与hj合计: 1 _1_东风EV_doc_ding 7; 1 _东风EV_doc_ding 9; 东风EV_doc_ding 9 $kv = array(); foreach (array_merge($ding, $piao) as $k => $v){ $key_ding = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_doc_ding'; $key_ding_xj = $v['biz_type'].'_'.$v['brand_name'].'_doc_ding'; $key_ding_hj = $v['brand_name'].'_doc_ding'; $key_ding_series = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_ding'; $key_ding_series_xj = $v['biz_type'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_ding'; $key_ding_series_hj = $v['brand_name'].'_'.$v['series_name'].'_doc_ding'; $key_piao = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_doc_piao'; $key_piao_xj = $v['biz_type'].'_'.$v['brand_name'].'_doc_piao'; $key_piao_hj = $v['brand_name'].'_doc_piao'; $key_piao_series = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_piao'; $key_piao_series_xj = $v['biz_type'].'_'.$v['brand_name'].'_'.$v['series_name'].'_doc_piao'; $key_piao_series_hj = $v['brand_name'].'_'.$v['series_name'].'_doc_piao'; if ($temp = intval($v['doc_ding'])){ $kv[$key_ding_series] = $temp; $kv[$key_ding_series_xj] = $kv[$key_ding_series_xj] ? $kv[$key_ding_series_xj] + $temp: $temp; $kv[$key_ding_series_hj] = $kv[$key_ding_series_hj] ? $kv[$key_ding_series_hj] + $temp: $temp; $kv[$key_ding] = $kv[$key_ding] ? $kv[$key_ding] + $temp: $temp; $kv[$key_ding_xj] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] + $temp: $temp; $kv[$key_ding_hj] = $kv[$key_ding_hj] ? $kv[$key_ding_hj] + $temp: $temp; } if ($temp = intval($v['doc_piao'])){ $kv[$key_piao_series] = $temp; $kv[$key_piao_series_xj] = $kv[$key_piao_series_xj] ? $kv[$key_piao_series_xj] + $temp: $temp; $kv[$key_piao_series_hj] = $kv[$key_piao_series_hj] ? $kv[$key_piao_series_hj] + $temp: $temp; $kv[$key_piao] = $kv[$key_piao] ? $kv[$key_piao] + $temp: $temp; $kv[$key_piao_xj] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] + $temp: $temp; $kv[$key_piao_hj] = $kv[$key_piao_hj] ? $kv[$key_piao_hj] + $temp: $temp; } } $biz_type = $biz_id = $biz_name = null; $doc_ding_today = $doc_ding = $doc_piao_today = $doc_piao = 0; $doc_ding_today_ = $doc_ding_ = $doc_piao_today_ = $doc_piao_ = 0; $biz_aggs = array(); foreach ($biz as $k1 => $v1){ !$biz_type && $biz_type = $v1['biz_type']; $biz_id = $v1['biz_id']; $biz_name = $v1['biz_name']; $doc_ding_today_ += $v1['doc_ding_today'] ? $v1['doc_ding_today'] : 0; $doc_ding_ += $v1['doc_ding'] ? $v1['doc_ding'] : 0; $doc_piao_today_ += $v1['doc_piao_today'] ? $v1['doc_piao_today'] : 0; $doc_piao_ += $v1['doc_piao'] ? $v1['doc_piao'] : 0; if ($biz_type <> $v1['biz_type']){ #$biz_type_ary = $this->ci->biz_model->type_ary(); #$biz_type_name = $biz_type_ary[$biz_type] ? '('.$biz_type_ary[$biz_type].')' : ''; # 'biz_name'=>$biz_type_name.'小计' $arr1 = array('biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : ''); foreach ($brand_names as $k2 => $v2){ # 生成车型列 $key_ding_xj = $biz_type.'_'.$v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] : ''; # 生成车系列 foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_ding'; $arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series_xj] ? $kv[$key_ding_series_xj] : ''; } } $arr3 = array('doc_piao_today'=>$doc_piao_today ? $doc_piao_today : '', 'doc_piao'=>$doc_piao ? $doc_piao : ''); foreach ($brand_names as $k2 => $v2){ $key_piao_xj = $biz_type.'_'.$v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_piao_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_piao'; $arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_piao_series_xj] ? $kv[$key_piao_series_xj] : ''; } } $biz_aggs[] = array_merge($arr1, $arr3); $biz_type = $v1['biz_type']; $doc_ding_today = $doc_ding = $doc_piao_today = $doc_piao = 0; } $doc_ding_today += $v1['doc_ding_today'] ? $v1['doc_ding_today'] : 0; $doc_ding += $v1['doc_ding'] ? $v1['doc_ding'] : 0; $doc_piao_today += $v1['doc_piao_today'] ? $v1['doc_piao_today'] : 0; $doc_piao += $v1['doc_piao'] ? $v1['doc_piao'] : 0; $arr1 = array('biz_type'=>$biz_type, 'biz_id'=>$biz_id, 'biz_name'=>$biz_name, 'doc_ding_today'=>$v1['doc_ding_today'] ? $v1['doc_ding_today'] : '', 'doc_ding'=>$v1['doc_ding'] ? $v1['doc_ding'] : ''); foreach ($brand_names as $k2 => $v2){ $key_ding = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding] ? $kv[$key_ding] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_'.$vs.'_doc_ding'; $arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series] ? $kv[$key_ding_series] : ''; } } $arr3 = array('doc_piao_today'=>$v1['doc_piao_today'] ? $v1['doc_piao_today'] : '', 'doc_piao'=>$v1['doc_piao'] ? $v1['doc_piao'] : ''); foreach ($brand_names as $k2 => $v2){ $key_piao = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao] ? $kv[$key_piao] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_piao_series = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_'.$vs.'_doc_piao'; $arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_piao_series] ? $kv[$key_piao_series] : ''; } } $biz_aggs[] = array_merge($arr1, $arr3); } # 最后一个小计 #$biz_type_ary = $this->ci->biz_model->type_ary(); #$biz_type_name = $biz_type_ary[$biz_type] ? '('.$biz_type_ary[$biz_type].')' : ''; # 'biz_name'=>$biz_type_name.'小计' $arr1 = array('biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : ''); foreach ($brand_names as $k2 => $v2){ $key_ding_xj = $biz_type.'_'.$v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_ding'; $arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series_xj] ? $kv[$key_ding_series_xj] : ''; } } $arr3 = array('doc_piao_today'=>$doc_piao_today ? $doc_piao_today : '', 'doc_piao'=>$doc_piao ? $doc_piao : ''); foreach ($brand_names as $k2 => $v2){ $key_piao_xj = $biz_type.'_'.$v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_piao_series_xj = $biz_type.'_'.$v2.'_'.$vs.'_doc_piao'; $arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_piao_series_xj] ? $kv[$key_piao_series_xj] : ''; } } $biz_aggs[] = array_merge($arr1, $arr3); # 合计 $arr1 = array('biz_type'=>'', 'biz_id'=>'', 'biz_name'=>'合计', 'doc_ding_today'=>$doc_ding_today_ ? $doc_ding_today_ : '', 'doc_ding'=>$doc_ding_ ? $doc_ding_ : ''); foreach ($brand_names as $k2 => $v2){ $key_ding_hj = $v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding_hj] ? $kv[$key_ding_hj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series_hj = $v2.'_'.$vs.'_doc_ding'; $arr1[$v2.'_'.$vs.'_ding'] = $kv[$key_ding_series_hj] ? $kv[$key_ding_series_hj] : ''; } } $arr3 = array('doc_piao_today'=>$doc_piao_today_ ? $doc_piao_today_ : '', 'doc_piao'=>$doc_piao_ ? $doc_piao_ : ''); foreach ($brand_names as $k2 => $v2){ $key_piao_hj = $v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao_hj] ? $kv[$key_piao_hj] : ''; foreach ($series_names[$v2] as $ks => $vs){ $key_ding_series_hj = $v2.'_'.$vs.'_doc_piao'; $arr3[$v2.'_'.$vs.'_piao'] = $kv[$key_ding_series_hj] ? $kv[$key_ding_series_hj] : ''; } } $biz_aggs[] = array_merge($arr1, $arr3);#var_dump($indexs);var_dump($biz_aggs); $img_path = $img_path_ding = $img_path_piao = ''; if ($create_table_image){ $data = $biz_aggs; foreach ($data as $k => $v){ unset($data[$k]['biz_type']); unset($data[$k]['biz_id']); $data[$k]['biz_name'] = mb_strlen ($data[$k]['biz_name']) > 9 ? mb_substr($data[$k]['biz_name'], 0, 9).'..' : $data[$k]['biz_name']; } $data_ding = $data_piao = $data; foreach ($data_ding as $k => $v){ foreach ($data_ding[$k] as $kd => $vd){ if (strpos($kd,'_piao') !== false){ unset($data_ding[$k][$kd]); } } } foreach ($data_ding as $k => $v){ foreach ($data_ding[$k] as $kd => $vd){ if (strpos($kd,'_ding') !== false){ unset($data_piao[$k][$kd]); } } } $index_img = $indexs; $index_img_ding = $index_img_piao = array(); foreach ($index_img as $k => $v){ #$k != 'biz_name' && $index_img[$k] = mb_strlen ($v) > 8 ? mb_substr($v, -8, 8) : $v; if ($k != 'biz_name'){ /*if (strpos($k,'_') !== false){ $index_img[$k] = mb_strlen ($v) > 8 ? mb_substr($v, 0, 2).'..'.mb_substr(array_slice(explode('_', $v), -1)[0], -5, 5) : str_replace('_', ' ', $v); } else{ $index_img[$k] = mb_strlen ($v) > 5 ? mb_substr($v, 0, 5) : $v; }*/ $index_img[$k] = $v; # 讲话车系后直接显示全部 } if (strpos($k,'_ding') !== false){ $index_img_ding[$k] = $index_img[$k]; } elseif (strpos($k,'_piao') !== false){ $index_img_piao[$k] = $index_img[$k]; } else{ $index_img_ding[$k] = $index_img[$k]; $index_img_piao[$k] = $index_img[$k]; } } # 去掉空列与空行 $this->clear_null_column_line($biz_aggs, $indexs); $this->clear_null_column_line($data, $index_img); $this->clear_null_column_line($data_ding, $index_img_ding); $this->clear_null_column_line($data_piao, $index_img_piao); #var_dump($data_piao);var_dump('
');var_dump($index_img_piao);var_dump('
');var_dump($indexs_total); #var_dump($biz_aggs[0]);var_dump($data[0]);var_dump($index_img);var_dump($data_ding[0]);var_dump($index_img_ding);var_dump($data_piao[0]);var_dump($index_img_piao);; $img_path = $this->create_table_image($data, $index_img, $indexs_total, '小狸播报', 'aggs_biz_rpt.png'); $img_path_ding = $this->create_table_image($data_ding, $index_img_ding, $indexs_total, '小狸播报 - 订单', 'aggs_biz_rpt_ding.png'); $img_path_piao = $this->create_table_image($data_piao, $index_img_piao, $indexs_total, '小狸播报 - 开票', 'aggs_biz_rpt_piao.png'); } return array('biz_aggs'=>$biz_aggs, 'indexs'=>$indexs, 'img_path'=>$img_path, 'img_path_ding'=>$img_path_ding, 'img_path_piao'=>$img_path_piao, 'brand_names'=>$brand_names, 'series_names'=>$series_names); } // 商家下定+开票统计 simple:按店铺类型,只拆分品牌列 public function aggs_biz_ding_piao_rpt_simple($today_start='', $today_end='', $total_start='', $total_end='', $title_today='', $title_ding_today='', $title_ding='', $title_piao_today='', $title_piao='', $create_table_image=false){ !$today_start && $today_start = date('Y-m-d 00:00:00'); !$today_end && $today_end = date('Y-m-d 00:00:00', strtotime('+1 day')); !$total_start && $total_start = date('Y-m-01 00:00:00'); !$total_end && $total_end = date('Y-m-01 00:00:00', strtotime('+1 month')); //!$title_today && $title_today = date('m月d日'); !$title_today && $title_today = '来源'; !$title_ding_today && $title_ding_today = '当日订单'; !$title_ding && $title_ding = '月累计订单'; !$title_piao_today && $title_piao_today = '当日开票'; !$title_piao && $title_piao = '月累计开票'; $ding = $this->aggs_biz_brand_ding($today_start, $today_end, $total_start, $total_end); $piao = $this->aggs_biz_brand_piao($today_start, $today_end, $total_start, $total_end); $biz = $this->aggs_biz_ding_piao($today_start, $today_end, $total_start, $total_end); #var_dump($today_start);var_dump($today_end);var_dump($total_start);var_dump($total_end);var_dump($ding); var_dump($piao);var_dump($biz); if (!$biz){ return array(); } $brand_names = array_unique(array_merge(array_column($ding, 'brand_name'), array_column($piao, 'brand_name')));#var_dump($brand_names); $arr1 = array('biz_name'=>$title_today, 'doc_ding_today'=>$title_ding_today, 'doc_ding'=>$title_ding); foreach ($brand_names as $k => $v){ $arr1[$v.'_ding'] = $v; } $arr3 = array('doc_piao_today'=>$title_piao_today, 'doc_piao'=>$title_piao); foreach ($brand_names as $k => $v){ $arr3[$v.'_piao'] = $v; } $indexs = array_merge($arr1, $arr3); # $ding, $piao 行转kv,生成xj小记与hj合计: 1 _1_东风EV_doc_ding 7; 1 _东风EV_doc_ding 9; 东风EV_doc_ding 9 $kv = array(); foreach (array_merge($ding, $piao) as $k => $v){ $key_ding = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_doc_ding'; $key_ding_xj = $v['biz_type'].'_'.$v['brand_name'].'_doc_ding'; $key_ding_hj = $v['brand_name'].'_doc_ding'; $key_piao = $v['biz_type'].'_'.$v['biz_id'].'_'.$v['brand_name'].'_doc_piao'; $key_piao_xj = $v['biz_type'].'_'.$v['brand_name'].'_doc_piao'; $key_piao_hj = $v['brand_name'].'_doc_piao'; if ($temp = intval($v['doc_ding'])){ $kv[$key_ding] = $temp; $kv[$key_ding_xj] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] + $temp: $temp; $kv[$key_ding_hj] = $kv[$key_ding_hj] ? $kv[$key_ding_hj] + $temp: $temp; } if ($temp = intval($v['doc_piao'])){ $kv[$key_piao] = $temp; $kv[$key_piao_xj] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] + $temp: $temp; $kv[$key_piao_hj] = $kv[$key_piao_hj] ? $kv[$key_piao_hj] + $temp: $temp; } } $biz_type = $biz_id = $biz_name = null; $doc_ding_today = $doc_ding = $doc_piao_today = $doc_piao = 0; $doc_ding_today_ = $doc_ding_ = $doc_piao_today_ = $doc_piao_ = 0; $biz_aggs = array(); foreach ($biz as $k1 => $v1){ !$biz_type && $biz_type = $v1['biz_type']; $biz_id = $v1['biz_id']; $biz_name = $v1['biz_name']; $doc_ding_today_ += $v1['doc_ding_today'] ? $v1['doc_ding_today'] : 0; $doc_ding_ += $v1['doc_ding'] ? $v1['doc_ding'] : 0; $doc_piao_today_ += $v1['doc_piao_today'] ? $v1['doc_piao_today'] : 0; $doc_piao_ += $v1['doc_piao'] ? $v1['doc_piao'] : 0; if ($biz_type <> $v1['biz_type']){ $arr1 = array('biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : ''); foreach ($brand_names as $k2 => $v2){ $key_ding_xj = $biz_type.'_'.$v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] : ''; } $arr3 = array('doc_piao_today'=>$doc_piao_today ? $doc_piao_today : '', 'doc_piao'=>$doc_piao ? $doc_piao : ''); foreach ($brand_names as $k2 => $v2){ $key_piao_xj = $biz_type.'_'.$v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] : ''; } $biz_aggs[] = array_merge($arr1, $arr3); $biz_type = $v1['biz_type']; $doc_ding_today = $doc_ding = $doc_piao_today = $doc_piao = 0; } $doc_ding_today += $v1['doc_ding_today'] ? $v1['doc_ding_today'] : 0; $doc_ding += $v1['doc_ding'] ? $v1['doc_ding'] : 0; $doc_piao_today += $v1['doc_piao_today'] ? $v1['doc_piao_today'] : 0; $doc_piao += $v1['doc_piao'] ? $v1['doc_piao'] : 0; $arr1 = array('biz_type'=>$biz_type, 'biz_id'=>$biz_id, 'biz_name'=>$biz_name, 'doc_ding_today'=>$v1['doc_ding_today'] ? $v1['doc_ding_today'] : '', 'doc_ding'=>$v1['doc_ding'] ? $v1['doc_ding'] : ''); foreach ($brand_names as $k2 => $v2){ $key_ding = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding] ? $kv[$key_ding] : ''; } $arr3 = array('doc_piao_today'=>$v1['doc_piao_today'] ? $v1['doc_piao_today'] : '', 'doc_piao'=>$v1['doc_piao'] ? $v1['doc_piao'] : ''); foreach ($brand_names as $k2 => $v2){ $key_piao = $v1['biz_type'].'_'.$v1['biz_id'].'_'.$v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao] ? $kv[$key_piao] : ''; } $biz_aggs[] = array_merge($arr1, $arr3); } # 最后一个小计 $arr1 = array('biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : ''); foreach ($brand_names as $k2 => $v2){ $key_ding_xj = $biz_type.'_'.$v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding_xj] ? $kv[$key_ding_xj] : ''; } $arr3 = array('doc_piao_today'=>$doc_piao_today ? $doc_piao_today : '', 'doc_piao'=>$doc_piao ? $doc_piao : ''); foreach ($brand_names as $k2 => $v2){ $key_piao_xj = $biz_type.'_'.$v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao_xj] ? $kv[$key_piao_xj] : ''; } $biz_aggs[] = array_merge($arr1, $arr3); # 合计 $arr1 = array('biz_type'=>'', 'biz_id'=>'', 'biz_name'=>'合计', 'doc_ding_today'=>$doc_ding_today_ ? $doc_ding_today_ : '', 'doc_ding'=>$doc_ding_ ? $doc_ding_ : ''); foreach ($brand_names as $k2 => $v2){ $key_ding_hj = $v2.'_doc_ding'; $arr1[$v2.'_ding'] = $kv[$key_ding_hj] ? $kv[$key_ding_hj] : ''; } $arr3 = array('doc_piao_today'=>$doc_piao_today_ ? $doc_piao_today_ : '', 'doc_piao'=>$doc_piao_ ? $doc_piao_ : ''); foreach ($brand_names as $k2 => $v2){ $key_piao_hj = $v2.'_doc_piao'; $arr3[$v2.'_piao'] = $kv[$key_piao_hj] ? $kv[$key_piao_hj] : ''; } $biz_aggs[] = array_merge($arr1, $arr3);#var_dump($indexs);var_dump($biz_aggs); $img_path = ''; if ($create_table_image){ $data = $biz_aggs; foreach ($data as $k => $v){ unset($data[$k]['biz_type']); unset($data[$k]['biz_id']); $data[$k]['biz_name'] = mb_strlen ($data[$k]['biz_name']) > 9 ? mb_substr($data[$k]['biz_name'], 0, 9).'..' : $data[$k]['biz_name']; } $index_img = $indexs; foreach ($index_img as $k => $v){ $k != 'biz_name' && $index_img[$k] = mb_strlen ($v) > 5 ? mb_substr($v, 0, 5) : $v; } $img_path = $this->create_table_image($data, $index_img, $indexs_total=array(),'小狸播报', 'aggs_biz_rpt.png'); } return array('biz_aggs'=>$biz_aggs, 'indexs'=>$indexs, 'img_path'=>$img_path); } private function clear_null_column_line(&$data, &$indexs, $index_ignore_column=array('biz_type', 'city_name', 'biz_id', 'biz_name', 'doc_ding_today', 'doc_ding', 'doc_piao_today', 'doc_piao'), $index_ignore_line=array('biz_type', 'city_name', 'biz_id', 'biz_name')){ # $biz_aggs去掉除列(biz_type, biz_id, biz_name, doc_ding_today, doc_ding, doc_piao_today, doc_piao)外为空的空列 + $indexs 去掉列名 $columns = array(); foreach ($data as $k => $v){ foreach ($v as $kd => $vd){ if (in_array($kd, $index_ignore_column)){ continue; } if ($columns[$kd]){ continue; } !$columns[$kd] && $columns[$kd] = $vd ? 1 : 0; } } #var_dump($data[0]);var_dump('
');var_dump($indexs);var_dump('
');var_dump($columns); foreach ($columns as $k => $v){ if ($v){ continue; } foreach ($data as $kd => $vd){ unset($data[$kd][$k]); } unset($indexs[$k]); } # $biz_aggs去掉除列(biz_type, biz_id, biz_name)外为空的空行 foreach ($data as $k => $v){ $null_flag = true; foreach ($v as $kd => $kv){ if (in_array($kd, $index_ignore_line)){ continue; } if ($kv){ $null_flag = false; break; } } if ($null_flag){ unset($data[$k]); } } } private function create_table_image($data=array(), $indexs=array(), $indexs_total=array(), $title='', $file_name='aggs_biz_rpt.png'){ # https://blog.csdn.net/mao__ge/article/details/107414956 /*if (!$data){ $data = array();//生成演示数据 for ($i = 0; $i < 10; $i++) { $data[] = array( 'nice_name' => '测试名' . $i, 'zhuang' => 100, 'xian' => 50, 'he' => '', 'zhuang_dui' => 500, 'xian_dui' => intval(5000 / ($i + 1)), 'xian_li' => 30, ); } $data[0]['nice_name'] = '这个名字比较长哦123'; } if (!$indexs){ $indexs = array('nice_name'=>'昵称', 'zhuang'=>'数据1', 'xian'=>'数据2', 'he'=>'数据3', 'zhuang_dui'=>'数据4', 'xian_dui'=>'数据5', 'xian_li'=>'数据6'); }*/ if (!$data || !$indexs){ return ''; } #date_default_timezone_set('PRC'); $params = array( 'row' => count($data)+1,//数据的行数 'file_name' => $file_name, 'title' => $title, 'table_time' => date('Y-m-d H:i:s'), 'data' => $data ); $base = array( 'border' => 10,//图片外边框 'file_path' => 'temp/',//图片保存路径 'title_height' => 30,//报表名称高度 'title_font_size' =>16,//报表名称字体大小 'font_ulr' => realpath('./static/fonts/msyh.ttc'),//字体文件路径 'text_size' => 12,//正文字体大小 'text_size_middle' => 12,//中间字体大小 14 'text_size_big' => 12,//加大字体大小 16 'row_hight' => 30,//每行数据行高 'filed_id_width' => 60,//序号列的宽度 'filed_name_width' => 140,//玩家名称的宽度 'filed_name_columns' => 1, //非数据列数据,也可传参数来控制 'filed_data_width' => 90,//数据列的宽度 'table_header' => array('序号', '昵称', '数据1', '数据2', '数据3', '数据4', '数据5', '数据6'),//表头文字 'column_text_offset_arr' => array(50, 180, 70, 70, 70, 70, 70, 70),//表头文字左偏移量 'row_text_offset_arr' => array(50, 180, 60, 60, 60, 60, 60, 60),//数据列文字左偏移量 ); // $base替换start if (in_array('city_name', array_keys($indexs))) { $base['filed_name_columns'] = 2; } $base['table_header'] = array_merge(array('序号'), array_values($indexs)); $column = count($base['table_header']); $offset_arr_left = array(50); # 序号列 for ($i=0; $i<$base['filed_name_columns']; $i++){ $offset_arr_left[] = 120; //230427:与filed_name_width一起,各减60 } $offset_arr = array(); $column_data = $column - $base['filed_name_columns'] -1; for ($i=0; $i<$column_data; $i++){ $offset_arr[] = 88; } $base['column_text_offset_arr'] = array_merge($offset_arr_left, $offset_arr); $offset_arr = array(); for ($i=0; $i<$column_data; $i++){ $offset_arr[] = 40; } $base['row_text_offset_arr'] = array_merge($offset_arr_left, $offset_arr); #var_dump(array_keys($indexs));var_dump('
');var_dump($base['column_text_offset_arr']);var_dump('
');var_dump($base['row_text_offset_arr']);var_dump('
'); // $base替换end $base['img_width'] = $base['filed_id_width'] + $base['filed_name_width'] * $base['filed_name_columns'] + $base['filed_data_width'] * $column_data + $base['border'] * 2;//图片宽度 $base['img_height'] = $params['row'] * $base['row_hight'] + $base['border'] * 2 + $base['title_height'];//图片高度 $border_top = $base['border'] + $base['title_height'];//表格顶部高度 $border_bottom = $base['img_height'] - $base['border'];//表格底部高度 // $base['column_x_arr'] 动态计算 $base['column_x_arr'] = array( $base['border'] + $base['filed_id_width'],//第一列边框线x轴像素 70/2+10 ); for ($i=1; $i<=$base['filed_name_columns']; $i++){ $base['column_x_arr'][] = $base['border'] + $base['filed_id_width'] + $base['filed_name_width'] * $i; //第二列边框线x轴像素 190 } for ($i=1; $i<=$column_data; $i++){ $base['column_x_arr'][] = $base['border'] + $base['filed_id_width'] + $base['filed_name_width'] * $base['filed_name_columns'] + $base['filed_data_width'] * $i; } $img = imagecreatetruecolor($base['img_width'], $base['img_height']);//创建指定尺寸图片 $bg_color = imagecolorallocate($img, 255, 255, 255);//设定图片背景色 $text_coler = imagecolorallocate($img, 0, 0, 0);//设定文字颜色 $border_coler = imagecolorallocate($img, 0, 0, 0);//设定边框颜色 $white_coler = imagecolorallocate($img, 255, 255, 255);//设定边框颜色 $red_coler = imagecolorallocate($img, 255, 0, 0); $green_coler = imagecolorallocate($img, 0, 255, 0); $blue_coler = imagecolorallocate($img, 0, 0, 255); $origin_coler = imagecolorallocate($img, 255, 97, 0); imagefill($img, 0, 0, $bg_color);//填充图片背景色 //先填充一个黑色的大块背景 imagefilledrectangle($img, $base['border'], $base['border'] + $base['title_height'], $base['img_width'] - $base['border'], $base['img_height'] - $base['border'], $border_coler);//画矩形 //再填充一个小两个像素的 背景色区域,形成一个两个像素的外边框 imagefilledrectangle($img, $base['border'] + 2, $base['border'] + $base['title_height'] + 2, $base['img_width'] - $base['border'] - 2, $base['img_height'] - $base['border'] - 2, $bg_color);//画矩形 //画表格纵线 及 写入表头文字 foreach ($base['column_x_arr'] as $key => $x) { imageline($img, $x, $border_top, $x, $border_bottom, $border_coler);//画纵线 $x = $x - $base['column_text_offset_arr'][$key] + 1; $y = $border_top + $base['row_hight'] - 8; $text = $base['table_header'][$key]; #imagettftext($img, $base['text_size'], 0, $x,$y , $text_coler, $base['font_ulr'],$text );//写入表头文字 $color = $text_coler; if (in_array($text.'_ding', $indexs_total) || in_array($text.'_piao', $indexs_total) || $text == $indexs['doc_ding'] || $text == $indexs['doc_piao']){ $color = $blue_coler; } $offset_ext = in_array($text, array('序号')) || mb_strlen($text) > 4 ? 0 : 10 * (5 - mb_strlen($text)); imagettftext($img, $base['text_size'], 0, $x + $offset_ext, $y, $color, $base['font_ulr'], $text );//写入表头文字 } //画表格横线 $text = 0; foreach ($params['data'] as $key => $item) { $border_top += $base['row_hight']; imageline($img, $base['border'], $border_top, $base['img_width'] - $base['border'], $border_top, $border_coler); $x = $base['column_x_arr'][0] - $base['row_text_offset_arr'][0]; $y = $border_top + $base['row_hight'] - 10; #$text = $key + 1; $text ++; # 防止$key跳空 imagettftext($img, $base['text_size'], 0, $x, $y, $text_coler, $base['font_ulr'], $text);//写入序号 $sub = 0; /*foreach ($item as $value) { $sub++; $offset = $base['row_text_offset_arr'][$sub]; if ($value && intval($value) && intval($value) > 9){ $offset = $offset + (strlen(strval($value)) - 1) * 10; } imagettftext($img, $base['text_size'], 0, $base['column_x_arr'][$sub] - $offset, $border_top + $base['row_hight'] - 10, $text_coler, $base['font_ulr'], $value);//写入data数据 }*/ $size = $coclor = $size_set = null; foreach ($item as $key => $value) { $sub++; $offset = $base['row_text_offset_arr'][$sub]; if ($value && intval($value) && intval($value) > 9){ $offset = $offset + (strlen(strval($value)) - 1) * 10; } if (strpos($value,'小计') !== false){ $size = $base['text_size_big']; $coclor = $blue_coler; $size_set = true; } if (strpos($value,'合计') !== false){ $size = $base['text_size_big']; $coclor = $red_coler; $size_set = true; } !$size_set && $size = $base['text_size']; !$size_set && $coclor = $text_coler; /*if (!$size_set && $indexs_total && in_array($key, $indexs_total)){ $size = $base['text_size_middle']; $coclor = $origin_coler; }*/ /*if (!$size_set){ if ($indexs_total && in_array($key, $indexs_total)){ $size = $base['text_size_big']; $coclor = $origin_coler; } else{ $size = $base['text_size']; $coclor = $text_coler; } }*/ imagettftext($img, $size, 0, $base['column_x_arr'][$sub] - $offset, $border_top + $base['row_hight'] - 10, $coclor, $base['font_ulr'], $value);//写入data数据 } } //计算标题写入起始位置 $title_fout_box = imagettfbbox($base['title_font_size'], 0, $base['font_ulr'], $params['title']);//imagettfbbox() 返回一个含有 8 个单元的数组表示了文本外框的四个角: $title_fout_width = $title_fout_box[2] - $title_fout_box[0];//右下角 X 位置 - 左下角 X 位置 为文字宽度 $title_fout_height = $title_fout_box[1] - $title_fout_box[7];//左下角 Y 位置- 左上角 Y 位置 为文字高度 //居中写入标题 imagettftext($img, $base['title_font_size'], 0, ($base['img_width'] - $title_fout_width) / 2, $base['title_height'], $text_coler, $base['font_ulr'], $params['title']); //写入制表时间 imagettftext($img, $base['text_size'], 0, $base['border'], $base['title_height'], $text_coler, $base['font_ulr'], '时间:' . $params['table_time']); $save_path = $base['file_path'] . $params['file_name']; if (!is_dir($base['file_path']))//判断存储路径是否存在,不存在则创建 { mkdir($base['file_path'], 0777, true);//可创建多级目录 } $res = imagepng($img, $save_path);//输出图片,输出png使用imagepng方法,输出gif使用imagegif方法 //echo ''; return $res ? $save_path : ''; } }