作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

业绩看板

... ... @@ -29,6 +29,16 @@ class Dashboard extends Backend
$endTime = strtotime($datetimerange[1]);
}
$store_ids = array_filter($store_ids);
// 门店管理员只能看到自己这家店的数据
$store_list_where = [];
$group_id_arr = array_column($this->auth->getGroups(), 'group_id');
if(!in_array(1,$group_id_arr) && in_array(2,$group_id_arr)){
$store_id = \app\admin\model\Admin::where('id',$this->auth->id)->value('store_id');
$store_ids = [$store_id];
$store_list_where['id'] = $store_id;
}
$this->model = new \app\admin\model\Order;
//订单数量
$where = [];
... ... @@ -119,7 +129,7 @@ class Dashboard extends Backend
}else{
$this->view->assign($data);
}
$store_list = \app\admin\model\Store::order('weigh desc')->column('id,store_name');
$store_list = \app\admin\model\Store::where($store_list_where)->order('weigh desc')->column('id,store_name');
$this->view->assign('store_list',$store_list);
return $this->view->fetch();
}
... ... @@ -142,6 +152,14 @@ class Dashboard extends Backend
];
$this->model = new \app\admin\model\Order;
$store_list = db('store')->select();
// 门店管理员只能看到自己这家店的数据
$group_id_arr = array_column($this->auth->getGroups(), 'group_id');
if(!in_array(1,$group_id_arr) && in_array(2,$group_id_arr)){
$store_id = \app\admin\model\Admin::where('id',$this->auth->id)->value('store_id');
$store_list = db('store')->where('id',$store_id)->select();
}
$package_list = db('package')->select();
$dataList = [];
foreach ($store_list as $k => $v) {
... ... @@ -199,57 +217,61 @@ class Dashboard extends Backend
];
$dataList[] = $list;
}
if(in_array(1,$group_id_arr) || !in_array(2,$group_id_arr)){
//总计
$list1 = [];
foreach ($package_list as $key => $value) {
$data['store_id'] = 0;
$data['store_name'] = '总计';
$data['package_name'] = $value['package_name'];
$data['count1'] = $this->model
->alias('o')
->join('order_package op','op.order_id = o.id')
->whereTime('o.createtime', 'today')
->where('op.package_id', $value['id'])
->where('o.status', '>', '0')
->count(); //已付款订单数量
$data['sum1'] = $this->model
->alias('o')
->join('order_package op','op.order_id = o.id')
->whereTime('o.createtime', 'today')
->where('op.package_id', $value['id'])
->where('o.status', '>', '0')
->sum('o.order_price'); //已付款订单总金额
$data['count2'] = $this->model
->alias('o')
->join('order_package op','op.order_id = o.id')
->whereTime('o.createtime', 'today')
->where('op.package_id', $value['id'])
->where('o.status', '0')
->count(); //未付款订单数量
$data['sum2'] = $this->model
->alias('o')
->join('order_package op','op.order_id = o.id')
->whereTime('o.createtime', 'today')
->where('op.package_id', $value['id'])
->where('o.status', '0')
->sum('o.order_price'); //未付款订单总金额
$data['count'] = $data['count1'] + $data['count2']; //订单总数量
$data['sum'] = $data['sum1'] + $data['sum2']; //订单总金额
$list1[] = $data;
}
//总计
$list1 = [];
foreach ($package_list as $key => $value) {
$data['store_id'] = 0;
$data['store_name'] = '总计';
$data['package_name'] = $value['package_name'];
$data['count1'] = $this->model
->alias('o')
->join('order_package op','op.order_id = o.id')
->whereTime('o.createtime', 'today')
->where('op.package_id', $value['id'])
->where('o.status', '>', '0')
->count(); //已付款订单数量
$data['sum1'] = $this->model
->alias('o')
->join('order_package op','op.order_id = o.id')
->whereTime('o.createtime', 'today')
->where('op.package_id', $value['id'])
->where('o.status', '>', '0')
->sum('o.order_price'); //已付款订单总金额
$data['count2'] = $this->model
->alias('o')
->join('order_package op','op.order_id = o.id')
->whereTime('o.createtime', 'today')
->where('op.package_id', $value['id'])
->where('o.status', '0')
->count(); //未付款订单数量
$data['sum2'] = $this->model
->alias('o')
->join('order_package op','op.order_id = o.id')
->whereTime('o.createtime', 'today')
->where('op.package_id', $value['id'])
->where('o.status', '0')
->sum('o.order_price'); //未付款订单总金额
$data['count'] = $data['count1'] + $data['count2']; //订单总数量
$data['sum'] = $data['sum1'] + $data['sum2']; //订单总金额
$list1[] = $data;
$list1[] = [
'store_id' => 0,
'store_name' => '总计',
'package_name' => '小计',
'count' => array_sum(array_column($list1, 'count')),
'sum' => array_sum(array_column($list1, 'sum')),
'count1' => array_sum(array_column($list1, 'count1')),
'sum1' => array_sum(array_column($list1, 'sum1')),
'count2' => array_sum(array_column($list1, 'count2')),
'sum2' => array_sum(array_column($list1, 'sum2')),
];
$dataList[] = $list1;
}
$list1[] = [
'store_id' => 0,
'store_name' => '总计',
'package_name' => '小计',
'count' => array_sum(array_column($list1, 'count')),
'sum' => array_sum(array_column($list1, 'sum')),
'count1' => array_sum(array_column($list1, 'count1')),
'sum1' => array_sum(array_column($list1, 'sum1')),
'count2' => array_sum(array_column($list1, 'count2')),
'sum2' => array_sum(array_column($list1, 'sum2')),
];
$dataList[] = $list1;
$newList = array_reduce($dataList, 'array_merge', array());
$this->exportExcel('订单列表-' . date('Y-m-d H:i:s'), $expCellName, $newList);
... ...