multi-store/app/admin/logic/statistic/WarehouseLogic.php

127 lines
4.8 KiB
PHP

<?php
namespace app\admin\logic\statistic;
use app\common\logic\BaseLogic;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct;
use app\common\model\user\User;
use app\common\model\user\UserVisit;
use app\common\model\user_recharge\UserRecharge;
use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
use Exception;
/**
* Class 仓库统计
* @package app\services\statistic
*/
class WarehouseLogic extends BaseLogic
{
public static function total_warehouse()
{
$topData[] = [
'title' => '总采购金额',
'desc' => '平台采购商品总支付金额',
'total_money' => WarehouseOrder::sum('total_price'),
'value' => [],
'type' => 1,
];
$topData[] = [
'title' => '已结算金额',
'desc' => '平台支付给供应商的金额',
'total_money' => WarehouseOrder::sum('completed_amount'),
'value' => [],
'type' => 1,
];
$topData[] = [
'title' => '未结算金额',
'desc' => '平台未支付给供应商的金额',
'total_money' => WarehouseOrder::sum('outstanding_amount'),
'value' => [],
'type' => 1,
];
$store_stock_1 = StoreBranchProduct::where('stock','>',0)->sum('stock');
$store_stock_2 = WarehouseProductStorege::where('nums','>',0)->sum('nums');
$topData[] = [
'title' => '总商品库存',
'desc' => '平台统计商品总库存、含门店仓库',
'total_money' => bcadd($store_stock_1,$store_stock_2,2),
'cash_title' => 0,
'value' => [],
'type' => 1,
];
$topData[] = [
'title' => '总仓库库存',
'desc' => '平台统计仓库库存',
'total_money' => WarehouseProductStorege::sum('nums'),
'cash_title' => 0,
'value' => [],
'type' => 1,
];
$topData[] = [
'title' => '海吉星仓库库存',
'desc' => '平台统计海吉星仓库库存',
'total_money' => WarehouseProductStorege::where('warehouse_id',1)->sum('nums'),
'cash_title' => 0,
'value' => [],
'type' => 1,
];
$topData[] = [
'title' => '泸县集采集配库存',
'desc' => '平台统计泸县集采集配库存',
'total_money' => WarehouseProductStorege::where('warehouse_id',2)->sum('nums'),
'cash_title' => 0,
'value' => [],
'type' => 1,
];
$topData[] = [
'title' => '总门店库存',
'desc' => '平台统计门店库存',
'total_money' => StoreBranchProduct::sum('stock'),
'cash_title' => 0,
'value' => [],
'type' => 1,
];
$data['series'] = [];
foreach ($topData as $k => $v) {
// $data['x'] = $Chain['out']['x'];
$data['series'][$k]['name'] = $v['title'];
$data['series'][$k]['desc'] = $v['desc'];
$data['series'][$k]['total_value'] = $v['total_money'];
$data['series'][$k]['total_money'] = $v['cash_title'] ?? '';
$data['series'][$k]['type'] = $v['type'];
}
return $data;
}
public static function warehouse_list()
{
$list = StoreProduct::where('is_show', 1)
->field('id,store_name,image')
->select()->each(function ($item) {
// $item->sales = StoreOrderCartInfo::where('product_id', $item['id'])->where('is_pay',1)->sum('cart_num');
// $store_stock = StoreBranchProduct::where('product_id', $item['id'])->sum('stock');
// $warehouse_stock = WarehouseProductStorege::where('product_id', $item['id'])->sum('nums');
// $item->store_stock=$store_stock;
// $item->warehouse_stock=$warehouse_stock;
// $item->total_stock=$store_stock+$warehouse_stock;
// $item->total_purchase=WarehouseProduct::where('product_id', $item['id'])->sum('total_price');
// $item->total_completed_amount=WarehouseProduct::where('product_id', $item['id'])->where('is_pay',1)->sum('total_price');
// $item->total_outstanding_amount=WarehouseProduct::where('product_id', $item['id'])->where('is_pay',0)->sum('total_price');
// sum(branch_product.stock) as store_stock,sum(w_p.total_price) as total_purchase,
})->toArray();
return $list;
}
}