diff --git a/admin/controllers/receiver/orderv2/Orders.php b/admin/controllers/receiver/orderv2/Orders.php index 6092b89a..f9b84f3e 100644 --- a/admin/controllers/receiver/orderv2/Orders.php +++ b/admin/controllers/receiver/orderv2/Orders.php @@ -125,6 +125,73 @@ class Orders extends HD_Controller return $this->show_view($result['view'], true); } + public function lists_aggs(){ + # http://admin.dev.liche.cn/#/receiver/orderv2/orders/lists_aggs?today_start=2021-12-01&today_end=2022-06-06&total_start=2021-12-01&title_today=start 2021-12-01&title_ding_today=当日订单&title_piao_today=当日开票 + $today_start = date('Y-m-d 00:00:00'); + $today_end = date('Y-m-d 00:00:00', strtotime('+1 day')); + $total_start = date('Y-m-01 00:00:00'); + $total_end = date('Y-m-01 00:00:00', strtotime('+1 month')); + $title_today = date('m月d日'); + $title_ding_today = '当日订单'; + $title_ding = '月累计订单'; + $title_piao_today = '当日开票'; + $title_piao = '月累计开票'; + + $params = $this->input->get(); + $params['today_start'] && $today_start = $params['today_start']; + $params['today_end'] && $today_end = $params['today_end']; + $params['total_start'] && $total_start = $params['total_start']; + $params['total_end'] && $total_end = $params['total_end']; + $params['title_today'] && $title_today = $params['title_today']; + $params['title_ding_today'] && $title_ding_today = $params['title_ding_today']; + $params['title_ding'] && $title_ding = $params['title_ding']; + $params['title_piao_today'] && $title_piao_today = $params['title_piao_today']; + $params['title_piao'] && $title_piao = $params['title_piao']; + + $data = $this->orders_v2_entity->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=true); + $biz_aggs = $data['biz_aggs']; + $indexs = $data['indexs']; + $img_path = $data['img_path'] ? $data['img_path'] : ''; + $img_path_ding = $data['img_path_ding'] ? $data['img_path_ding'] : ''; + $img_path_piao = $data['img_path_piao'] ? $data['img_path_piao'] : ''; + + if ($export = $params['export']){ + if (!$biz_aggs){ + echo 'no data';exit(); + } + array_unshift($biz_aggs, $indexs); + $this->load->library('excel'); + #$filename = "lists_aggs_" . date('YmdHis'); + $filename = "lists_aggs"; + if ($export == 'csv'){ + return $this->excel->out_csv($biz_aggs, $indexs, $filename); + } + if ($export == 'image' || $export == 'img'){ + if ($img_path){ + echo '
'; + if ($img_path_ding) echo '
'; + if ($img_path_piao) echo '
'; + exit(); + $http = $_SERVER['HTTPS'] ? 'https://' : 'http://'; + $img_url = $http.$_SERVER['HTTP_HOST'].'/'.$img_path; + echo '';exit(); + } + return $this->excel->out_csv($biz_aggs, $indexs, $filename); + } + return $this->excel->out($biz_aggs, $indexs, $filename); + } + + #var_dump($indexs);var_dump($biz_aggs[0]); + $this->data['_title'] = '小狸播报'; + $this->data['fieldAry'] = $indexs; + $this->data['lists'] = $biz_aggs; + $this->data['img_path'] = $img_path; + $this->data['img_path_ding'] = $img_path_ding; + $this->data['img_path_piao'] = $img_path_piao; + return $this->show_view('receiver/orderv2/lists_aggs', true); + } + public function get() { $id = $this->input->get('id'); diff --git a/admin/views/receiver/orderv2/lists_aggs.php b/admin/views/receiver/orderv2/lists_aggs.php new file mode 100644 index 00000000..17137ab6 --- /dev/null +++ b/admin/views/receiver/orderv2/lists_aggs.php @@ -0,0 +1,81 @@ + + +
+ + +
+ + + + $v) { ?> + + + + + + + style="background-color: #8a6d3b" + style="background-color: #abd8f2" + > + $val) { ?> + + + + + +
style="width: 200px" >
style="background-color: #9b1a0e" + style="background-color: #9b1a0e" + >
+ + +
+ + + + + + + +
+ +
+
+ diff --git a/api/controllers/plan/Order.php b/api/controllers/plan/Order.php index 4d19854c..82928a23 100644 --- a/api/controllers/plan/Order.php +++ b/api/controllers/plan/Order.php @@ -413,4 +413,146 @@ class Order extends CI_Controller{ $left = $count-$size; echo "剩余:{$left}"; } + + /** + * 获取飞书 tenant_access_token + * @param $app_id + * @param $app_secret + * @return string + */ + private function get_tenant_access_token($app_id="cli_a2483b8493fc500d", $app_secret="iO6Egjw09xZ6SJVaNVOUxqClAW8YXnXD"){ + # https://open.feishu.cn/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM + # https://open.feishu.cn/document/ukTMukTMukTM/ukDNz4SO0MjL5QzM/auth-v3/auth/tenant_access_token_internal + if (!$app_id || !$app_secret){ + return null; + } + $redis = &load_cache('redis'); + $redisKey = 'feishu_app_id_'.$app_id; + $tenant_access_token = $redis->get($redisKey); + if ($tenant_access_token){ + return $tenant_access_token; + } + + $url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"; + $data = array("app_id"=>$app_id, "app_secret"=>$app_secret); + $this->load->library('mycurl'); + $res = $this->mycurl->httpPost($url, $data, $type='is_json'); + $result = json_decode($res, true); + if ($result && $result['code'] == 0 && $tenant_access_token = $result['tenant_access_token']){ + $expire = $result['expire'] ? $result['expire'] - 100 : 3600; + $redis->save($redisKey, $tenant_access_token, $expire); + } + return $tenant_access_token; + } + + /** + * 获取飞书上传图片的image_key + * @param $img_path + * @return string + */ + private function get_upload_image_key($img_path='temp/c01.jpg'){ + $image_key = ''; + $tenant_access_token = $this->get_tenant_access_token(); + if (!$tenant_access_token){ + return $image_key; + #echo "no tenant_access_token";exit(); + } + + $url = "https://open.feishu.cn/open-apis/im/v1/images"; + $header = ["Authorization: Bearer ".$tenant_access_token, "Content-Type: multipart/form-data"]; + $file_path = $img_path; + $arr = explode('/', $img_path); + $postname = array_slice($arr, -1)[0]; #var_dump($arr[count($arr) - 1]); + #$data = ['image_type="message"', "image=@'".$file_path."'"]; + #$data = ["image_type='message'", "image=@'".realpath($file_path)."'"]; + $data = ["image_type"=>"message", "image"=>curl_file_create(realpath($file_path), 'image/jpeg', $postname)]; + $this->load->library('mycurl'); + $this->mycurl->setHeaders($header); + $res = $this->mycurl->httpPost($url, $data, $type='is_file', $file_path); + $result = json_decode($res, true); + $result && $result['code'] == 0 && $result['data'] && $image_key = $result['data']['image_key']; + return $image_key; + } + + /** + * Notes:向飞书发送小狸播报 + * https://liche-api-dev.xiaoyu.com/plan/order/send_aggs_biz_ding_piao_rpt?sd=1&test=1 + * https://api.liche.cn/plan/order/send_aggs_biz_ding_piao_rpt + */ + public function send_aggs_biz_ding_piao_rpt(){ + $params = $this->input->get(); + $hour = date('H.i'); + if ( !($hour == 17.50 || $hour == 22.00 || $params['sd'])) { + return false; + } + + $today_start = $today_end = $total_start = $total_end = $title_today = $title_ding_today = $title_ding = $title_piao_today = $title_piao = ''; + if ($params['test']){ + $today_start = "2021-12-01 00:00:00"; + $today_end = date('Y-m-d 00:00:00', strtotime('+1 day')); + $today_end = '2022-06-06'; + $total_start = "2021-12-01 00:00:00"; + $total_end = date('Y-m-01 00:00:00', strtotime('+1 month')); + $title_today = date('m月d日'); + $title_ding_today = '当日订单'; + $title_ding = '月累计订单'; + $title_piao_today = '当日开票'; + $title_piao = '月累计开票'; + } + + $this->load->library('receiver/orders_v2_entity'); + $data = $this->orders_v2_entity->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=true); + if (!$data || !$data['biz_aggs']){ + echo 'no data';exit(); + } + $img_path = $data['img_path'] ? $data['img_path'] : ''; + $img_path_ding = $data['img_path_ding'] ? $data['img_path_ding'] : ''; + $img_path_piao = $data['img_path_piao'] ? $data['img_path_piao'] : ''; + if (!$img_path && !$img_path_ding && !$img_path_piao ){ + echo '执行结果:没有生成图片'; exit(); + } + + $img_path_arr = array(); + #if ($img_path) echo '';echo '
'; + if ($img_path_ding){ + echo '';echo '
'; + $img_path_arr[] = $img_path_ding; + } + if ($img_path_piao){ + echo '';echo '
'; + $img_path_arr[] = $img_path_piao; + } + + # https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN + # 测试图片 img_ecffc3b9-8f14-400f-a014-05eca1a4310g {"StatusCode":0,"StatusMessage":"success"} + $res = array(); + foreach ($img_path_arr as $img_path){ + $image_key = $this->get_upload_image_key($img_path); + if (!$image_key){ + echo "执行结果:$img_path 没有生成 image_key
"; + continue; + } + else{ + echo "执行结果:$img_path 生成 image_key:$image_key
"; + } + + $this->load->library('qyrobot', array('test'=>1)); + $msg = [ + "msg_type" => "image", + "content" => [ + "image_key" => $image_key, + ] + ]; + $res_send = $this->qyrobot->send_fb($msg); + $res[] = $res_send; + } + + $res['img_path'] = $img_path; + $res['image_key'] = $image_key; + if ($params['sd']) { + echo "执行结果:
"; + echo json_encode($res, JSON_UNESCAPED_UNICODE); + } + } } diff --git a/api/controllers/plan/Plan.php b/api/controllers/plan/Plan.php index 3b55e406..9707a7bc 100644 --- a/api/controllers/plan/Plan.php +++ b/api/controllers/plan/Plan.php @@ -50,6 +50,7 @@ class Plan extends CI_Controller $plan[] = array('url' => base_url(array('plan', 'biz', 'merge')), 'interval' => 20); //合并结算 $plan[] = array('url' => base_url(array('plan', 'order', 'up_old_status')), 'interval' => 30); //更新旧订单状态 $plan[] = array('url' => base_url(array('plan', 'order', 'out_time')), 'interval' => 10); //未支付订单过期 + $plan[] = array('url' => base_url(array('plan', 'order', 'send_aggs_biz_ding_piao_rpt')), 'interval' => 1); //向飞书发送小狸播报 // $plan[] = array('url' => base_url(array('plan', 'syt', 'subscribemsg')), 'interval' => 1); //私域通模板消息 $plan[] = array('url' => base_url(array('plan', 'syt', 'syn_polyv')), 'interval' => 60); //私域通直播间数据同步 diff --git a/common/libraries/receiver/Orders_v2_entity.php b/common/libraries/receiver/Orders_v2_entity.php index 0eedc8de..056ca640 100644 --- a/common/libraries/receiver/Orders_v2_entity.php +++ b/common/libraries/receiver/Orders_v2_entity.php @@ -801,4 +801,847 @@ class Orders_v2_entity{ 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 + "; + 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(); + } + + /** + * 按“商家”下定+开票统计 + * @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, 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, 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(); + } + + /** + * 商家下定+开票统计 + * @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 + * @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){ + !$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_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'))); + + # 生成品牌对应的车系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); + + # 生成表头 + $indexs_total = array(); + $indexs_total[] = 'doc_ding'; + $indexs_total[] = 'doc_piao'; + $arr1 = array('biz_name'=>$title_today, 'doc_ding_today'=>$title_ding_today); + /*foreach ($brand_names as $k => $v){ + foreach ($v as $k1 => $v1){ + $arr1[$k.'_'.$v1.'_ding_today'] = $k.'_'.$v1; + } + $arr1[$k.'_ding_today'] = $k; + }*/ + $arr1 = array_merge($arr1, array('doc_ding'=>$title_ding)); + foreach ($series_names as $k => $v){ + foreach ($v as $k1 => $v1){ + $arr1[$k.'_'.$v1.'_ding'] = $k.'_'.$v1; + } + $arr1[$k.'_ding'] = $k; + $indexs_total[] = $k.'_ding'; + } + $arr3 = array('doc_piao_today'=>$title_piao_today); + /*foreach ($brand_names as $k => $v){ + foreach ($v as $k1 => $v1){ + $arr3[$k.'_'.$v1.'_piao_today'] = $k.'_'.$v1; + } + $arr3[$k.'_piao_today'] = $k; + }*/ + $arr3 = array_merge($arr3, array('doc_piao'=>$title_piao)); + foreach ($series_names as $k => $v){ + foreach ($v as $k1 => $v1){ + $arr3[$k.'_'.$v1.'_piao'] = $k.'_'.$v1; + } + $arr3[$k.'_piao'] = $k; + $indexs_total[] = $k.'_piao'; + } + $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] = $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; + $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; + } + + 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; + $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; + } + } + + $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].')' : ''; + $arr1 = array('biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>$biz_type_name.'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : ''); + foreach ($brand_names as $k2 => $v2){ + # 生成车系列 + 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] : ''; + } + + # 生成车型列 + $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){ + 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] : ''; + } + + $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){ + 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] : ''; + } + + $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){ + 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] : ''; + } + + $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); + } + + # 最后一个小计 + $biz_type_ary = $this->ci->biz_model->type_ary(); + $biz_type_name = $biz_type_ary[$biz_type] ? '('.$biz_type_ary[$biz_type].')' : ''; + $arr1 = array('biz_type'=>$biz_type, 'biz_id'=>'', 'biz_name'=>$biz_type_name.'小计', 'doc_ding_today'=>$doc_ding_today ? $doc_ding_today : '', 'doc_ding'=>$doc_ding ? $doc_ding : ''); + foreach ($brand_names as $k2 => $v2){ + 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] : ''; + } + + $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){ + 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] : ''; + } + + $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){ + 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] : ''; + } + + $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){ + 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] : ''; + } + + $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 = $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; + } + } + 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]; + } + } + #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); + } + + // 商家下定+开票统计 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_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 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'); + } + + #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' => 14,//中间字体大小 + 'text_size_big' => 16,//加大字体大小 + 'row_hight' => 30,//每行数据行高 + 'filed_id_width' => 60,//序号列的宽度 + 'filed_name_width' => 200,//玩家名称的宽度 + '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 + $base['table_header'] = array_merge(array('序号'), array_values($indexs)); + $column = count($base['table_header']); + $column_data = $column - 2; + $offset_arr = array(50, 180); + for ($i=0; $i<$column_data; $i++){ + $offset_arr[] = 88; + } + $base['column_text_offset_arr'] = $offset_arr; + $offset_arr = array(50, 180); + for ($i=1; $i<=$column_data; $i++){ + $offset_arr[] = 40; + } + $base['row_text_offset_arr'] = $offset_arr; + // $base替换end + + $base['img_width'] = $base['filed_id_width'] + $base['filed_name_width'] + $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 + $base['border'] + $base['filed_id_width'] + $base['filed_name_width'],//第二列边框线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_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; + } + imagettftext($img, $base['text_size'], 0, $x,$y , $color, $base['font_ulr'],$text );//写入表头文字 + } + //画表格横线 + 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; + 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 : ''; + } + } diff --git a/www/admin/static/fonts/msyh.ttc b/www/admin/static/fonts/msyh.ttc new file mode 100644 index 00000000..37c28de0 Binary files /dev/null and b/www/admin/static/fonts/msyh.ttc differ diff --git a/www/api/static/fonts/msyh.ttc b/www/api/static/fonts/msyh.ttc new file mode 100644 index 00000000..37c28de0 Binary files /dev/null and b/www/api/static/fonts/msyh.ttc differ diff --git a/www/api/temp/c01.jpg b/www/api/temp/c01.jpg new file mode 100644 index 00000000..6233811a Binary files /dev/null and b/www/api/temp/c01.jpg differ