market_statistics_111

This commit is contained in:
dengbw
2023-01-11 16:20:30 +08:00
committed by lccsw
parent a0c146860b
commit 376d84953b
3 changed files with 360 additions and 25 deletions
+114
View File
@@ -125,6 +125,120 @@ class Stock extends HD_Controller
$this->show_view('items/stock/lists', true);
}
public function get_month()
{
$params = $this->input->get();
$type_ary = $this->mdBiz->type_ary();
$params['type'] = $params['type'] ? $params['type'] : '';
$typeStr = '1,2,3';//品牌 合伙 代理
$typeAry = [];
foreach ($type_ary as $k => $v) {
if (strstr($typeStr . ',', $k . ',')) {
$typeAry[$k] = $v;
}
}
$biz = $res_biz = $dateMonths = [];
if ($params['type'] || $params['biz_id'] || $params['city_id']) {
$start_date = date('Y-m', strtotime("-11 month"));//取最近12个月
$end_date = date('Y-m');
$date_months = $this->dateMonths($start_date, $end_date);
rsort($date_months);
foreach ($date_months as $v) {
$firstDay = $v . '-01' . ' 00:00:00';
$lastDay = date('Y-m-d', strtotime("$firstDay +1 month -1 day"));
$dateMonths[] = ['name' => $v, 'firstDay' => $v . '-01', 'lastDay' => $lastDay];
}
$type = $params['type'] ? $params['type'] : $typeStr;
$where_biz['status'] = 1;
$where_biz["type in({$type})"] = null;
if ($params['biz_id']) {
$where_biz['id'] = $params['biz_id'];
} else {
$params['city_id'] && $where_biz['city_id'] = $params['city_id'];
$params['county_id'] && $where_biz['county_id'] = $params['county_id'];
}
$res_biz = $this->mdBiz->select($where_biz, 'id desc', 0, 0, 'id,biz_name');
foreach ($res_biz as $v) {
$months = [];
foreach ($dateMonths as $v2) {
$data = $v2['firstDay'] . '/' . $v2['lastDay'];
$months[] = ['name' => $v2['name'], 'data' => $data];
}
$biz[] = ['biz_name' => $v['biz_name'], 'months' => $months];
}
}
!$params['city_id'] && $params['city_id'] = '';
!$params['county_id'] && $params['county_id'] = '';
!$params['biz_id'] && $params['biz_id'] = '';
$showData['typeAry'] = $typeAry;
$showData['typeStr'] = $typeStr;
$this->data['showData'] = $showData;
$this->data['biz'] = $biz;
$this->data['params'] = $params;
$this->data['_title'] = "库存统计";
$this->show_view('items/stock/get_month', true);
}
/**
* Notes:计算出两个日期之间的月份
* Created on: 2022/8/9 14:38
* Created by: dengbw
* @param $start_date [开始日期,如2022-03]
* @param $end_date [结束日期,如2022-12]
* @param string $explode [年份和月份之间分隔符,此例为 - ]
* @param bool $addOne [算取完之后最后是否加一月,用于算取时间戳用]
* @return array [返回是两个月份之间所有月份字符串]
*/
private function dateMonths($start_date, $end_date, $explode = '-', $addOne = false)
{
//判断两个时间是不是需要调换顺序
$start_int = strtotime($start_date);
$end_int = strtotime($end_date);
if ($start_int > $end_int) {
$tmp = $start_date;
$start_date = $end_date;
$end_date = $tmp;
}
//结束时间月份+1,如果是13则为新年的一月份
$start_arr = explode($explode, $start_date);
$start_year = intval($start_arr[0]);
$start_month = intval($start_arr[1]);
$end_arr = explode($explode, $end_date);
$end_year = intval($end_arr[0]);
$end_month = intval($end_arr[1]);
$data = array();
$data[] = $start_date;
$tmp_month = $start_month;
$tmp_year = $start_year;
//如果起止不相等,一直循环
while (!(($tmp_month == $end_month) && ($tmp_year == $end_year))) {
$tmp_month++;
//超过十二月份,到新年的一月份
if ($tmp_month > 12) {
$tmp_month = 1;
$tmp_year++;
}
$data[] = $tmp_year . $explode . str_pad($tmp_month, 2, '0', STR_PAD_LEFT);
}
if ($addOne == true) {
$tmp_month++;
//超过十二月份,到新年的一月份
if ($tmp_month > 12) {
$tmp_month = 1;
$tmp_year++;
}
$data[] = $tmp_year . $explode . str_pad($tmp_month, 2, '0', STR_PAD_LEFT);
}
return $data;
}
public function get()
{
+198
View File
@@ -0,0 +1,198 @@
<div class="coms-table-wrap mt10">
<form id="vue-app" class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="items/stock/get_month">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w60">门店:</label>
<div class="am-para-inline w120">
<select title="类型" name="type" v-model="params.type" @change="setType">
<option value="">选择类型</option>
<option v-for="(v,i) in showData.typeAry" :value="i">{{v}}</option>
</select>
</div>
</div>
<div class="am-form-group fl">
<div class="am-para-inline w120">
<select title="城市" name="city_id" v-model="params.city_id">
<option value="">选择城市</option>
<option :value="v.id" v-for="(v,i) in cityAry">{{v.name}}</option>
</select>
</div>
</div>
<div class="am-form-group fl">
<div class="am-para-inline w120">
<select title="行政区" name="county_id" v-model="params.county_id" @change="set_county">
<option value="">选择行政区</option>
<option :value="v.id" v-for="(v,i) in countyAry">{{v.name}}</option>
</select>
</div>
</div>
<div class="am-form-group fl">
<div class="am-para-inline w200">
<select title="门店" name="biz_id" v-model="params.biz_id">
<option value="">选择门店</option>
<option :value="v.id" v-for="(v,i) in bizAry">{{v.title}}</option>
</select>
</div>
</div>
<div class="am-form-group fl ml10">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
<div class="am-form-group fl ml10">
<button type="button" class="am-btn am-btn-success am-btn-sm w100" @click="reset">重置</button>
</div>
</div>
</div>
</form>
<div class="coms-table-bd">
<? if ($biz) {
foreach ($biz as $v) { ?>
<table class="am-table am-table-bordered" style="margin-top: 10px;">
<thead>
<tr>
<th colspan="10"><?= $v['biz_name'] ?></th>
</tr>
</thead>
<tbody>
<? foreach ($v['months'] as $v2) { ?>
<tr>
<td><?= $v2['name'] ?></td>
<td colspan="9" style="text-align:left;padding-left:15px;padding-right:15px;">
<?= $v2['data'] ?>
</td>
</tr>
<? } ?>
</tbody>
</table>
<? }
} ?>
</div>
</div>
<script>
$(function () {
vue_obj = new Vue({
el: '.coms-table-wrap',
data: {
params: {},
cityAry: [],//城市
countyAry: [],//行政区
bizAry: [],//门店
showData: {typeAry: [''], typeStr: ''},//显示数据
},
mounted: function () {
var vm = this;
vm.params = <?=json_encode($params)?>;
vm.showData = <?=json_encode($showData)?>;
vm.init_citys();
},
methods: {
init_citys: function () {
var vm = this;
$.ajax({
type: 'get',
url: '/common/area',
dataType: 'json',
data: {
id: '350',
key: 'city',
type: 1
},
success: function (response) {
if (response.code == 1) {
vm.cityAry = response.data;
}
}
});
},
set_county: function () {
var that = this;
that.bizAry = [];
that.params.biz_id = that.params.addr_id = '';
},
setType: function () {
var that = this;
that.params.city_id = '';
},
reset: function () {
var that = this;
that.params.city_id = '';
that.params.type = '';
}
},
watch: {
'params.city_id': function (nv, ov) {
var that = this;
if (nv == '') {
that.countyAry = [];
that.params.county_id = '';
} else {
if (nv.substring(0, 4) != that.params.county_id.substring(0, 4)) {
that.params.county_id = '';
}
$.ajax({
type: 'get',
url: '/common/area',
dataType: 'json',
data: {
id: nv,
key: 'county',
type: 1
},
success: function (response) {
if (response.code == 1) {
that.countyAry = response.data;
}
}
});
}
},
'params.county_id': function (nv, ov) {
var that = this;
if (nv == '') {
that.bizAry = [];
that.params.biz_id = that.params.addr_id = '';
} else {
let type = that.params.type ? that.params.type : that.showData.typeStr;
$.ajax({
type: 'post',
url: '/biz/store/store/json_lists',
dataType: 'json',
data: {
type: type,
city_id: that.params.city_id,
county_id: that.params.county_id,
status: 1
},
success: function (response) {
if (response.code == 1) {
that.bizAry = response.data.list;
var biz_id = '';
if (that.params.biz_id > 0 || that.params.biz_id == -1) {
for (var i in that.bizAry) {
if (that.params.biz_id == that.bizAry[i].id) {
biz_id = that.params.biz_id;
break;
}
}
}
that.params.biz_id = biz_id;
}
}
});
}
},
}
});
<?php page_script($pager) ?>
});
</script>
<style>
.td-left {
display: none;
position: absolute;
text-align: left;
margin-left: 15px;
margin-right: 15px;
}
</style>
@@ -147,9 +147,15 @@ class GroupsStatistics extends BaseController
if ($day) {//按天搜索
$createTimeStart = strtotime($day . ' 00:00:00');
$createTimeEnd = strtotime($day . ' 23:59:59');
$where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, "$levelId>" => 0, 'kpi' => $sort];
$where = $where_order = ['activityId' => $activityId, 'day' => $day, "$levelId>" => 0, 'itemId>' => 0];
$where_sort = ['activityId' => $activityId, 'day' => $day, "$levelId>" => 0, 'kpi' => $sort];
if ($sort == 'order') {
$itemId && $where['itemId'] = $itemId;
if ($itemId) {
$where['itemId'] = $itemId;
$where_order['itemId'] = $itemId;
}
} else {
$where = ['activityId' => $activityId, 'day' => $day, "$levelId>" => 0, 'kpi' => $sort];
}
$count = $this->mdSyliveActivityKpidata->count($where, $levelId);
if ($count) {
@@ -180,9 +186,7 @@ class GroupsStatistics extends BaseController
if ($sort == 'order') {
$orderTotal = $v['total'];
} else {
$where_order['kpi'] = 'order';
$where_order[$levelId] = $groupsId;
$itemId && $where_order['itemId'] = $itemId;
$orderTotal = $this->mdSyliveActivityKpidata->count($where_order);
}
$consultant = $this->mdSyliveActivityKpidata->count([$levelId => $groupsId, 'activityId' => $activityId], 'cfUserId');
@@ -207,7 +211,7 @@ class GroupsStatistics extends BaseController
}
} else {
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
$where = ['activityId' => $activityId, 'itemId' => $itemId, "$levelId>" => 0, 'kpi' => $sort];
$where = ['activityId' => $activityId, 'itemId' => $itemId, "$levelId>" => 0, 'itemId>' => 0];
$count = $this->mdSyliveActivityKpidata->count($where, 'bizId');
} else {
$where = ['activityId' => $activityId, 'status>=' => 0, 'groupsLevel' => $groupsLevel];
@@ -246,7 +250,7 @@ class GroupsStatistics extends BaseController
}
}
if ($sort != 'order' && $itemId) {//有商品id,区分订单
$order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', $levelId => $groupsId, 'itemId' => $itemId, 'activityId' => $activityId]);
$order = $this->mdSyliveActivityKpidata->count(['itemId>' => 0, $levelId => $groupsId, 'itemId' => $itemId, 'activityId' => $activityId]);
} else {
$order = $v['orderTotal'];
}
@@ -354,9 +358,9 @@ class GroupsStatistics extends BaseController
$left_subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'subscribe', 'createTime<' => $timeStart]);
$left_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'watch', $left_browse_where => null]);
if ($itemId) {
$left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId' => $itemId, 'kpi' => 'order', $left_browse_where => null]);
$left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId' => $itemId, 'itemId>' => 0, $left_browse_where => null]);
} else {
$left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'order', $left_browse_where => null]);
$left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId>' => 0, $left_browse_where => null]);
}
$left_subscribe_per = number_format_com($left_subscribe / $left_browse * 100, 1, '');
if ($left_watch) {
@@ -380,9 +384,9 @@ class GroupsStatistics extends BaseController
$right_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'browse', 'createTime>=' => $timeStart]);
$right_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'watch', $right_browse_where => null]);
if ($itemId) {
$right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId' => $itemId, 'kpi' => 'order', $right_browse_where => null]);
$right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId' => $itemId, 'itemId>' => 0, $right_browse_where => null]);
} else {
$right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'order', $right_browse_where => null]);
$right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId>' => 0, $right_browse_where => null]);
}
$right_watch_per = number_format_com($right_watch / $right_browse * 100, 1, '');
$right_order_per = number_format_com($right_order / $right_watch * 100, 1, '');
@@ -435,8 +439,13 @@ class GroupsStatistics extends BaseController
foreach ($times as $v2) {
$start = strtotime($v2['start']);
$end = strtotime($v2['end']);
$counts[] = $this->mdSyliveActivityKpidata->count(['kpi' => $v['value'], 'createTime >=' => $start,
'createTime <=' => $end, 'activityId' => $activityId]);
$where = ['createTime >=' => $start, 'createTime <=' => $end, 'activityId' => $activityId];
if ($v['value'] == 'order') {
$where['itemId>'] = 0;
} else {
$where['kpi'] = $v['value'];
}
$counts[] = $this->mdSyliveActivityKpidata->count($where);
}
$yAxisSeries[] = ['name' => $v['name'], 'type' => 'line', 'data' => $counts];
}
@@ -473,9 +482,16 @@ class GroupsStatistics extends BaseController
if ($day) {//按天搜索
$createTimeStart = strtotime($day . ' 00:00:00');
$createTimeEnd = strtotime($day . ' 23:59:59');
$where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, 'bizId>' => 0, 'kpi' => $sort];
$where_order = ['activityId' => $activityId, 'day' => $day, "bizId>" => 0, 'itemId>' => 0];
$where_sort = ['activityId' => $activityId, 'day' => $day, "bizId>" => 0, 'kpi' => $sort];
if ($sort == 'order') {
$itemId && $where['itemId'] = $itemId;
$where = ['activityId' => $activityId, 'day' => $day, "bizId>" => 0, 'itemId>' => 0];
if ($itemId) {
$where['itemId'] = $itemId;
$where_order['itemId'] = $itemId;
}
} else {
$where = ['activityId' => $activityId, 'day' => $day, "bizId>" => 0, 'kpi' => $sort];
}
$count = $this->mdSyliveActivityKpidata->count($where, 'bizId');
if ($count) {
@@ -527,9 +543,7 @@ class GroupsStatistics extends BaseController
if ($sort == 'order') {
$orderTotal = $v['total'];
} else {
$where_order['kpi'] = 'order';
$where_order['bizId'] = $bizId;
$itemId && $where_order['itemId'] = $itemId;
$orderTotal = $this->mdSyliveActivityKpidata->count($where_order);
}
$consultant = $this->mdSyliveActivityKpidata->count(['bizId' => $bizId, 'activityId' => $activityId], 'cfUserId');
@@ -554,7 +568,7 @@ class GroupsStatistics extends BaseController
}
} else {
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
$where = ['activityId' => $activityId, 'itemId' => $itemId, 'bizId>' => 0, 'kpi' => $sort];
$where = ['activityId' => $activityId, 'itemId' => $itemId, 'bizId>' => 0, 'itemId>' => 0];
$count = $this->mdSyliveActivityKpidata->count($where, 'bizId');
} else {
$where = ['activityId' => $activityId, 'status>=' => 0, 'ifBiz' => 1];
@@ -627,7 +641,7 @@ class GroupsStatistics extends BaseController
}
}
if ($sort != 'order' && $itemId) {//有商品id,区分订单
$order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'bizId' => $bizId, 'itemId' => $itemId, 'activityId' => $activityId]);
$order = $this->mdSyliveActivityKpidata->count(['itemId>' => 0, 'bizId' => $bizId, 'itemId' => $itemId, 'activityId' => $activityId]);
} else {
$order = $v['orderTotal'];
}
@@ -678,9 +692,16 @@ class GroupsStatistics extends BaseController
if ($day) {
$createTimeStart = strtotime($day . ' 00:00:00');
$createTimeEnd = strtotime($day . ' 23:59:59');
$where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, 'cfUserId>' => 0, 'kpi' => $sort];
$where_order = ['activityId' => $activityId, 'day' => $day, "cfUserId>" => 0, 'itemId>' => 0];
$where_sort = ['activityId' => $activityId, 'day' => $day, "cfUserId>" => 0, 'kpi' => $sort];
if ($sort == 'order') {
$itemId && $where['itemId'] = $itemId;
$where = ['activityId' => $activityId, 'day' => $day, "cfUserId>" => 0, 'itemId>' => 0];
if ($itemId) {
$where['itemId'] = $itemId;
$where_order['itemId'] = $itemId;
}
} else {
$where = ['activityId' => $activityId, 'day' => $day, "cfUserId>" => 0, 'kpi' => $sort];
}
$count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId');
if ($count) {
@@ -737,9 +758,7 @@ class GroupsStatistics extends BaseController
if ($sort == 'order') {
$order = $v['total'];
} else {
$where_order['kpi'] = 'order';
$where_order['cfUserId'] = $cfUserId;
$itemId && $where_order['itemId'] = $itemId;
$order = $this->mdSyliveActivityKpidata->count($where_order);
}
$livePV = $watchDuration = 0;
@@ -760,7 +779,7 @@ class GroupsStatistics extends BaseController
}
} else {
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
$where = ['activityId' => $activityId, 'itemId' => $itemId, 'cfUserId>' => 0, 'kpi' => $sort];
$where = ['activityId' => $activityId, 'itemId' => $itemId, 'cfUserId>' => 0, 'itemId>' => 0];
$count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId');
} else {
$where = ['activityId' => $activityId, 'status>=' => 0];
@@ -804,7 +823,7 @@ class GroupsStatistics extends BaseController
$map_groups[$v['bizId']] && $bizName = $map_groups[$v['bizId']];
$map_user[$cfUserId] && $consultantName = $map_user[$cfUserId];
if ($sort != 'order' && $itemId) {//有商品id,区分订单
$order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'cfUserId' => $cfUserId, 'itemId' => $itemId, 'activityId' => $activityId]);
$order = $this->mdSyliveActivityKpidata->count(['itemId>' => 0, 'cfUserId' => $cfUserId, 'itemId' => $itemId, 'activityId' => $activityId]);
} else {
$order = $v['orderTotal'];
}
@@ -880,7 +899,11 @@ class GroupsStatistics extends BaseController
$where['itemId'] = $itemId;
$count = $this->mdSyliveOrder->count($where, 'userId');
} else {
$where['kpi'] = $sort;
if ($sort == 'order') {
$where['itemId>'] = 0;
} else {
$where['kpi'] = $sort;
}
$count = $this->mdSyliveActivityKpidata->count($where, 'userId');
}
if ($count) {