160 lines
6.4 KiB
PHP
160 lines
6.4 KiB
PHP
<?php
|
|
defined('WXAPP_ITEMS') OR exit('No direct script access allowed');
|
|
ini_set('display_errors', 'On');
|
|
error_reporting(E_ERROR);
|
|
|
|
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
|
|
|
/**
|
|
* Notes:数据分析
|
|
* Created on: 2021/10/13 15:16
|
|
* Created by: dengbw
|
|
*/
|
|
class Statistics extends Wxapp
|
|
{
|
|
private $biz_id = 0;
|
|
private $cf_id = 24;//素材报名
|
|
|
|
function __construct($inputs, $app_key)
|
|
{
|
|
parent::__construct($inputs, $app_key);
|
|
$this->login_white = '';//
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg = array();//授权微信信息
|
|
$this->majia_white = array('get');//超级管理员披上马甲可操作权限
|
|
$this->load->model('app/material/Material_biz_statistics_model', 'mdBizStatistics');
|
|
$this->load->model('app/material/Material_template_model', 'mdTemplate');
|
|
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
|
|
$this->load->model("biz/biz_model", 'mdBiz');
|
|
$this->biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
|
|
$this->app_id == 1 && $this->app_id = 2;//获取狸车宝数据
|
|
}
|
|
|
|
/**
|
|
* Notes:数据分析首页
|
|
* Created on: 2021/10/12 11:47
|
|
* Created by: dengbw
|
|
* @return array
|
|
* @throws Exception
|
|
*/
|
|
protected function get()
|
|
{
|
|
if (!$this->biz_id) {
|
|
throw new Hd_exception('门店不存在!', API_CODE_FAIL);
|
|
}
|
|
$re_biz = $this->mdBiz->get(['id' => $this->biz_id, 'status' => 1]);
|
|
if (!$re_biz) {
|
|
return $this->show_json(SYS_CODE_FAIL, '门店不存在!');
|
|
}
|
|
$topic_list = array();
|
|
$where = ['a.status' => 1, 'b.app_id' => $this->app_id, 'b.biz_id' => $this->biz_id];
|
|
$this->mdTemplate->db->from('lc_material_template as a');
|
|
$this->mdTemplate->db->join('lc_material_biz as b', "b.t_id=a.id", 'left');
|
|
$this->mdTemplate->db->select('a.id, a.title,b.biz_id,b.app_id');
|
|
$this->mdTemplate->db->where($where);
|
|
$this->mdTemplate->db->order_by('a.id Desc');
|
|
$this->mdTemplate->db->limit(50);
|
|
$res = $this->mdTemplate->db->get()->result_array();
|
|
foreach ($res as $key => $value) {
|
|
$topic_list[] = array('id' => $value['id'], 'title' => $value['title']);
|
|
}
|
|
$this->data['title'] = '数据分析';
|
|
$this->data['biz_name'] = $re_biz['biz_name'];
|
|
$this->data['topic_list'] = $topic_list;
|
|
return $this->data;
|
|
}
|
|
|
|
/**
|
|
* Notes:累计数据
|
|
* Created on: 2021/10/13 14:51
|
|
* Created by: dengbw
|
|
* @return array
|
|
*/
|
|
protected function get_cal()
|
|
{
|
|
$day = $this->input_param('day');
|
|
$t_id = intval($this->input_param('t_id'));
|
|
$where_s = array('app_id' => $this->app_id, 'biz_id' => $this->biz_id);
|
|
$where_c = array('biz_id' => $this->biz_id, 'cf_id' => $this->cf_id, 'status >=' => 0);
|
|
$where_o = array('c.biz_id' => $this->biz_id, 'c.cf_id' => $this->cf_id, 'c.status >=' => 0);
|
|
if ($day) {
|
|
$where_s['day'] = $day;
|
|
$where_c['c_time>='] = strtotime($day . ' 00:00:00');
|
|
$where_c['c_time<='] = strtotime($day . ' 23:59:59');
|
|
$where_o['o.c_time>='] = strtotime($day . ' 00:00:00');
|
|
$where_o['o.c_time<='] = strtotime($day . ' 23:59:59');
|
|
}
|
|
if ($t_id) {
|
|
$where_s['t_id'] = $t_id;
|
|
$where_c['t_id '] = $t_id;
|
|
$where_o['c.t_id'] = $t_id;
|
|
}
|
|
$re_s = $this->mdBizStatistics->sum('browse_num', $where_s);
|
|
$count_c = $this->mdCustomers->count($where_c);
|
|
$count_o = $this->mdBizStatistics->count_order($where_o);
|
|
$data = [
|
|
['icon' => 'icon-liulan', 'name' => '浏览次数', 'value' => intval($re_s['browse_num'])],
|
|
['icon' => 'icon-baoming', 'name' => '报名客户', 'value' => $count_c],
|
|
['icon' => 'icon-dingdan', 'name' => '订单客户', 'value' => $count_o]
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Notes:图表
|
|
* Created on: 2021/10/13 10:59
|
|
* Created by: dengbw
|
|
* @return array
|
|
*/
|
|
protected function get_chart()
|
|
{
|
|
$xAxis = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
|
|
$year = date('Y');
|
|
$browse_data = $enroll_data = $orders_data = [];
|
|
$where_s = array('app_id' => $this->app_id, 'biz_id' => $this->biz_id);
|
|
$where_c = array('biz_id' => $this->biz_id, 'cf_id' => $this->cf_id, 'status >=' => 0);
|
|
$where_o = array('c.biz_id' => $this->biz_id, 'c.cf_id' => $this->cf_id, 'c.status >=' => 0);
|
|
foreach ($xAxis as $key => $value) {
|
|
$value < 10 && $value = '0' . $value;
|
|
$s_day = $year . '-' . $value . '-01';//第一天
|
|
$e_day = date('Y-m-d', strtotime("$s_day +1 month -1 day"));//最后一天
|
|
//浏览
|
|
$re_s = $this->mdBizStatistics->sum('browse_num', array_merge($where_s, array('day>=' => $s_day, 'day<=' => $e_day)));
|
|
$s_time = strtotime($s_day . ' 00:00:00');
|
|
$e_time = strtotime($e_day . ' 23:59:59');
|
|
//客户
|
|
$count_c = $this->mdCustomers->count(array_merge($where_c, array('c_time>=' => $s_time, 'c_time<=' => $e_time)));
|
|
//订单
|
|
$count_o = $this->mdBizStatistics->count_order(array_merge($where_o, array('o.c_time>=' => $s_time, 'o.c_time<=' => $e_time)));
|
|
$browse_data[] = intval($re_s['browse_num']);
|
|
$enroll_data[] = $count_c;
|
|
$orders_data[] = $count_o;
|
|
}
|
|
$data = [
|
|
'legend' => ["浏览", "客户", "订单"],
|
|
'xAxis' => $xAxis,
|
|
'series' => [
|
|
[
|
|
'name' => '浏览',
|
|
'type' => 'line',
|
|
'smooth' => true,
|
|
'data' => $browse_data,
|
|
],
|
|
[
|
|
'name' => '客户',
|
|
'type' => 'line',
|
|
'smooth' => true,
|
|
'data' => $enroll_data,
|
|
],
|
|
[
|
|
'name' => '订单',
|
|
'type' => 'line',
|
|
'smooth' => true,
|
|
'data' => $orders_data,
|
|
]
|
|
]
|
|
];
|
|
return $data;
|
|
}
|
|
} |