164 lines
6.1 KiB
PHP
164 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
use app\common\model\Order as OrderModel;
|
|
use app\common\model\OrderList;
|
|
use app\admin\controller\Base;
|
|
use app\common\model\Category;
|
|
use app\common\model\Yushou;
|
|
use \think\Request;
|
|
use think\facade\View;
|
|
use app\common\model\Goods as GoodsModel;
|
|
use app\common\model\GoodsList;
|
|
use think\facade\Db;
|
|
use app\common\model\Shang;
|
|
|
|
class Statistics extends Base
|
|
{
|
|
|
|
/**
|
|
* 利润统计
|
|
*/
|
|
public function profit(Request $request)
|
|
{
|
|
$title = trim(input('get.title'));
|
|
$id = trim(input('get.goodId'));
|
|
$status = trim(input('get.status'));
|
|
$type = trim(input('get.type'));
|
|
$addtime = trim(input('get.addtime'));
|
|
|
|
$whe = array();
|
|
if ($title) {
|
|
$whe[] = ['title', 'like', '%' . $title . '%'];
|
|
}
|
|
if ($id) {
|
|
$whe[] = ['id', 'like', '%' . $id . '%'];
|
|
}
|
|
if ($status) {
|
|
$whe[] = ['status', '=', $status];
|
|
}
|
|
if ($type) {
|
|
$whe[] = ['type', '=', $type];
|
|
} else {
|
|
$whe[] = ['type', 'notIn', [4, 7]];
|
|
}
|
|
$field = "*";
|
|
$order = "id desc";
|
|
$data = GoodsModel::getList($whe, $field, $order, $this->page);
|
|
//订单收入:实际收入:出货价值:实际利润率:订单利润率:
|
|
$sum_dingdan = 0;
|
|
$sum_shiji = 0;
|
|
$sum_chuhuo = 0;
|
|
$sum_shijilirun = 0;
|
|
$sum_dingdanlirun = 0;
|
|
foreach ($data['list'] as &$value) {
|
|
$whe1 = array();
|
|
$whe2 = array();
|
|
$whe1[] = ['goods_id', '=', $value['id']];
|
|
$whe1[] = ['status', '=', 1];
|
|
|
|
if ($addtime) {
|
|
$time = explode(' - ', $addtime);
|
|
$start_time = strtotime($time[0]);
|
|
$end_time = strtotime($time[1]) - 1;
|
|
if ($start_time > $end_time) {
|
|
$this->err('开始时间不能大于结束时间');
|
|
}
|
|
$whe1[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
|
|
$whe2[] = ['addtime', 'BETWEEN', array($start_time, $end_time)];
|
|
}
|
|
|
|
$list1 = OrderModel::where($whe1)->select();
|
|
$count = count($list1);
|
|
// $price = $list1 -> count('price');
|
|
$numbers = $list1->toArray();
|
|
$count_price = array_sum(array_map(function ($price) {
|
|
return $price['price']; //支付金额 2
|
|
}, $numbers));
|
|
|
|
$count_yue = array_sum(array_map(function ($price) {
|
|
return $price['use_money']; //用户余额 2
|
|
}, $numbers));
|
|
|
|
$use_integral = array_sum(array_map(function ($price) {
|
|
return $price['use_integral']; //潮币抵扣 2
|
|
}, $numbers));
|
|
$use_score = array_sum(array_map(function ($price) {
|
|
return $price['use_score']; //积分抵扣 2
|
|
}, $numbers));
|
|
$use_coupon = array_sum(array_map(function ($price) {
|
|
return $price['use_coupon']; //优惠卷抵扣 2
|
|
}, $numbers));
|
|
$order_zhe_total = array_sum(array_map(function ($price) {
|
|
return $price['order_zhe_total']; //折扣后总金额 2
|
|
}, $numbers));
|
|
$order_total = array_sum(array_map(function ($price) {
|
|
return $price['order_total']; //实际总金额 2
|
|
}, $numbers));
|
|
|
|
if ($use_integral > 0) {
|
|
$use_integral = $use_integral / 100;
|
|
}
|
|
// 订单价值
|
|
|
|
$whe2[] = ['goods_id', '=', $value['id']];
|
|
|
|
$orderList = OrderList::where($whe2)->select();
|
|
$orderArray = $orderList->toArray();
|
|
|
|
$count_OrderList = count($orderList);
|
|
$goodslist_price = 0;
|
|
if ($count_OrderList > 0) {
|
|
$goodslist_price = array_sum(array_map(function ($goodslist) {
|
|
return $goodslist['goodslist_money']; //实际总金额 2
|
|
}, $orderArray));
|
|
}
|
|
$value['order_count'] = $count;
|
|
$value['count_price'] = $count_price;
|
|
$value['order_total'] = $order_total;
|
|
|
|
$value['count_yue'] = $count_yue;
|
|
$value['count_use_integral'] = $use_integral;
|
|
$value['count_use_score'] = $use_score;
|
|
$value['order_zhe_total'] = $order_zhe_total;
|
|
$value['count_use_coupon'] = $use_coupon;
|
|
$value['count_heji'] = $count_price + $count_yue + $use_integral + $use_score + $use_coupon;
|
|
$value['count_heji_yanzheng'] = $count_OrderList * $value['price'];
|
|
|
|
$value['count_OrderList'] = $count_OrderList;
|
|
$goodslist_price1 = round($goodslist_price, 2);
|
|
$value['goodslist_price'] = $goodslist_price1;
|
|
$value['lirun'] = round($order_zhe_total - $goodslist_price1, 2);
|
|
$count_heji_yanzheng = $count_OrderList * $value['price'];
|
|
$value['liruns'] = round($count_heji_yanzheng - $goodslist_price1, 2);
|
|
if ($goodslist_price1 == 0) {
|
|
$value['lirulv'] = 0;
|
|
$value['lirulvs'] = 0;
|
|
} else {
|
|
$value['lirulv'] = round(($order_zhe_total - $goodslist_price1) / $goodslist_price1 * 100, 2);
|
|
|
|
$value['lirulvs'] = round(($count_heji_yanzheng - $goodslist_price1) / $goodslist_price1 * 100, 2);
|
|
}
|
|
|
|
$sum_dingdan += $count_OrderList * $value['price'];
|
|
$sum_shiji += $order_zhe_total;
|
|
$sum_chuhuo +=$goodslist_price1;
|
|
$sum_shijilirun += $value['lirun'];
|
|
$sum_dingdanlirun += $value['liruns'];
|
|
}
|
|
View::assign('list', $data['list']);
|
|
View::assign('count', $data['count']);
|
|
View::assign('page', $data['page']);
|
|
|
|
View::assign('sum_dingdan', $sum_dingdan);
|
|
View::assign('sum_shiji', $sum_shiji);
|
|
View::assign('sum_chuhuo', $sum_chuhuo);
|
|
View::assign('sum_shijilirun', $sum_shijilirun);
|
|
View::assign('sum_dingdanlirun', $sum_dingdanlirun);
|
|
return View::fetch("Statistics/profit");
|
|
|
|
}
|
|
|
|
|
|
}
|