feat: 修改了WorkbenchController和相关的模型类,优化了仓库统计功能,增加了门店仓库总库存的统计方法。

This commit is contained in:
mkm 2024-08-23 13:46:25 +08:00
parent cf1d6db00a
commit a0814641c8
7 changed files with 123 additions and 69 deletions

View File

@ -52,13 +52,13 @@ class WorkbenchController extends BaseAdminController
public function store_index() public function store_index()
{ {
$params = $this->request->get(); $params = $this->request->get();
if(!isset($params['store_id']) ||$params['store_id']==''){ if (!isset($params['store_id']) || $params['store_id'] == '') {
$params['store_id'] =0; $params['store_id'] = 0;
} }
if(!isset($params['start_time']) ||$params['start_time']==''){ if (!isset($params['start_time']) || $params['start_time'] == '') {
$time=explode('-', $this->getDay('')); $time = explode('-', $this->getDay(''));
$params['start_time'] =$time[0]; $params['start_time'] = $time[0];
$params['end_time'] =$time[1]; $params['end_time'] = $time[1];
} }
$result = LogicWorkbenchLogic::index($params); $result = LogicWorkbenchLogic::index($params);
@ -102,24 +102,24 @@ class WorkbenchController extends BaseAdminController
public function get_trend() public function get_trend()
{ {
$dates = []; $dates = [];
$date=$this->request->get('date',''); $date = $this->request->get('date', '');
$days=31; $days = 31;
if($date){ if ($date) {
$arr=explode('-', $date); $arr = explode('-', $date);
if($arr[0]==$arr[1]){ if ($arr[0] == $arr[1]) {
$date = new DateTime($arr[0]); $date = new DateTime($arr[0]);
$dates[] = $date->format("Y-m-d"); $dates[] = $date->format("Y-m-d");
}else{ } else {
$datetime_start = new DateTime($arr[0]); $datetime_start = new DateTime($arr[0]);
$datetime_end = new DateTime($arr[1]); $datetime_end = new DateTime($arr[1]);
$days = $datetime_start->diff($datetime_end)->days; $days = $datetime_start->diff($datetime_end)->days;
for ($i = 0; $i <= $days; $i++) { for ($i = 0; $i <= $days; $i++) {
$date = new DateTime($datetime_start->format('Y-m-d')); $date = new DateTime($datetime_start->format('Y-m-d'));
$date->modify('+' . $i . ' days'); $date->modify('+' . $i . ' days');
$dates[] = $date->format('Y-m-d'); $dates[] = $date->format('Y-m-d');
}
} }
} } else {
}else{
$today = new DateTime(); $today = new DateTime();
$thirtyDaysAgo = new DateTime($today->format('Y-m-d')); $thirtyDaysAgo = new DateTime($today->format('Y-m-d'));
$thirtyDaysAgo->modify('-30 days'); $thirtyDaysAgo->modify('-30 days');
@ -166,10 +166,10 @@ class WorkbenchController extends BaseAdminController
*/ */
public function get_product_ranking() public function get_product_ranking()
{ {
$date=$this->request->get('date',''); $date = $this->request->get('date', '');
$where['create_time'] = $this->getDay($date); $where['create_time'] = $this->getDay($date);
$data=(new ProductStatisticLogic())->get_product_ranking($where); $data = (new ProductStatisticLogic())->get_product_ranking($where);
return $this->success('',$data); return $this->success('', $data);
} }
//-------------------------------用户统计---------------------------------------// //-------------------------------用户统计---------------------------------------//
@ -179,13 +179,13 @@ class WorkbenchController extends BaseAdminController
*/ */
public function get_user_basic() public function get_user_basic()
{ {
$date=$this->request->get('date',''); $date = $this->request->get('date', '');
$store_id=$this->request->get('store_id'); $store_id = $this->request->get('store_id');
$where['create_time'] = $this->getDay($date); $where['create_time'] = $this->getDay($date);
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$data=(new UserStatisticLogic())->getBasic($where); $data = (new UserStatisticLogic())->getBasic($where);
return $this->data($data); return $this->data($data);
} }
@ -194,13 +194,13 @@ class WorkbenchController extends BaseAdminController
*/ */
public function get_user_trend() public function get_user_trend()
{ {
$date=$this->request->get('date',''); $date = $this->request->get('date', '');
$store_id=$this->request->get('store_id'); $store_id = $this->request->get('store_id');
$where['create_time'] = $this->getDay($date); $where['create_time'] = $this->getDay($date);
if($store_id){ if ($store_id) {
$where['store_id'] = $store_id; $where['store_id'] = $store_id;
} }
$data=(new UserStatisticLogic())->getTrend($where); $data = (new UserStatisticLogic())->getTrend($where);
return $this->data($data); return $this->data($data);
} }
@ -208,7 +208,7 @@ class WorkbenchController extends BaseAdminController
//当日订单金额 //当日订单金额
public function top_trade() public function top_trade()
{ {
$logic=(new TradeStatisticLogic()); $logic = (new TradeStatisticLogic());
$leftToday = $logic->getTopLeftTrade(['create_time' => 'today']); $leftToday = $logic->getTopLeftTrade(['create_time' => 'today']);
$leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']); $leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']);
$rightOne = $logic->getTopRightOneTrade(); $rightOne = $logic->getTopRightOneTrade();
@ -231,25 +231,27 @@ class WorkbenchController extends BaseAdminController
//交易趋势 //交易趋势
public function bottom_trade() public function bottom_trade()
{ {
$date=$this->request->get('date',''); $date = $this->request->get('date', '');
$data=(new TradeStatisticLogic())->getBottomTrade(['data'=>$this->getDay($date)]); $data = (new TradeStatisticLogic())->getBottomTrade(['data' => $this->getDay($date)]);
return $this->data($data); return $this->data($data);
} }
/** /**
* 实时商品统计 * 实时商品统计
*/ */
public function product_order(){ public function product_order()
{
return $this->dataLists(new StoreOrderCartInfoGroupLists()); return $this->dataLists(new StoreOrderCartInfoGroupLists());
} }
/** /**
* 月销售商品统计 * 月销售商品统计
*/ */
public function product_month_order(){ public function product_month_order()
{
return $this->dataLists(new StoreOrderCartInfoGroupMonthLists()); return $this->dataLists(new StoreOrderCartInfoGroupMonthLists());
} }
/** /**
* 格式化时间 * 格式化时间
* @param $time * @param $time
* @return string * @return string
@ -261,9 +263,9 @@ class WorkbenchController extends BaseAdminController
if (!$startTime && !$endTime) { if (!$startTime && !$endTime) {
return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time()); return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
} else { } else {
if($startTime==$endTime){ if ($startTime == $endTime) {
return $startTime . '-' . $endTime.' 23:59:59'; return $startTime . '-' . $endTime . ' 23:59:59';
}else{ } else {
return $startTime . '-' . $endTime; return $startTime . '-' . $endTime;
} }
} }
@ -271,24 +273,35 @@ class WorkbenchController extends BaseAdminController
return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time()); return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
} }
} }
//-------------------------------统计仓库---------------------------------------//
/** /**
* 统计仓库 * 统计仓库
* @return array * @return array
*/ */
public function total_warehouse() public function total_warehouse()
{ {
$data=WarehouseLogic::total_warehouse(); $data = WarehouseLogic::total_warehouse();
return $this->data($data); return $this->data($data);
} }
/** /**
* 统计仓库 * 统计仓库列表
* @return array * @return array
*/ */
public function warehouse_list() public function warehouse_list()
{ {
return $this->dataLists(new StoreProductLists()); return $this->dataLists(new StoreProductLists());
}
/**
* 统计门店仓库总库存
* @return array
*/
public function total_warehouse_list()
{
$parmas=$this->request->get();
$data =WarehouseLogic::total_warehouse_list($parmas,$parmas['type']??1);
return $this->data($data);
} }
} }

View File

@ -66,12 +66,12 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->field('p.id, p.store_name, p.image, ->field('p.id, p.store_name, p.image,
(SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1) AS sales, (SELECT SUM(c.cart_num) FROM `la_store_order_cart_info` c WHERE c.product_id=p.id AND c.is_pay=1 AND c.delete_time IS NULL) AS sales,
(SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id) AS store_stock, (SELECT SUM(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id AND b.delete_time IS NULL) AS store_stock,
(SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id) AS warehouse_stock, (SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id AND w.delete_time IS NULL) AS warehouse_stock,
(SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id) AS total_purchase, (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.delete_time IS NULL) AS total_purchase,
(SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=1) AS total_completed_amount, (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=1 AND wp.delete_time IS NULL) AS total_completed_amount,
(SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=0) AS total_outstanding_amount') (SELECT SUM(wp.total_price) FROM `la_warehouse_product` wp WHERE wp.product_id=p.id AND wp.is_pay=0 AND wp.delete_time IS NULL) AS total_outstanding_amount')
->select() ->select()
->each(function ($item) { ->each(function ($item) {
// 计算总库存 // 计算总库存

View File

@ -7,9 +7,11 @@ use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\user\UserVisit; use app\common\model\user\UserVisit;
use app\common\model\user_recharge\UserRecharge; use app\common\model\user_recharge\UserRecharge;
use app\common\model\warehouse\Warehouse;
use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_order\WarehouseOrder;
use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product\WarehouseProduct;
use app\common\model\warehouse_product_storege\WarehouseProductStorege; use app\common\model\warehouse_product_storege\WarehouseProductStorege;
@ -103,4 +105,34 @@ class WarehouseLogic extends BaseLogic
return $data; return $data;
} }
/**
* 统计门店仓库总库存
* @return array
*/
public static function total_warehouse_list($parmas,$type=1) {
if($type==1){
$list=StoreBranchProduct::where('stock','>',0)->where('product_id',$parmas['product_id'])
->select()->each(function ($item){
$item->system_store = SystemStore::where('id',$item['store_id'])->value('name');
$item->total_price = bcmul($item->purchase,$item->stock,2);
});
$count=StoreBranchProduct::where('stock','>',0)->where('product_id',$parmas['product_id'])
->count();
}else{
$list=WarehouseProductStorege::where('nums','>',0)->where('product_id',$parmas['product_id'])->select()->each(function ($item){
$item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name');
$find = StoreProduct::where('id',$item['product_id'])->find();
$item->store_name=$find['store_name'];
$item->image=$find['image'];
$item->purchase=$find['purchase'];
if($find['purchase']>0 && $item->nums>0){
$item->total_price = bcmul($find['purchase'],$item->nums,2);
}else{
$item->total_price = 0;
}
});
$count=WarehouseProductStorege::where('nums','>',0)->where('product_id',$parmas['product_id'])->count();
}
return ['lists'=>$list,'count'=>$count];
}
} }

View File

@ -42,7 +42,7 @@ class StoreOrderLogic extends BaseLogic
$v['uid'] = $params['user_id']; $v['uid'] = $params['user_id'];
$v['store_id'] = $params['store_id']; $v['store_id'] = $params['store_id'];
$v['cart_num'] = $v['stock']; $v['cart_num'] = $v['stock'];
StoreBranchProduct::where('id',$v['id'])->update(['price'=>$v['price'],'vip_price'=>$v['price'],'cost'=>$v['price'],'purchase'=>$v['purchase']]); StoreBranchProduct::where('id',$v['id'])->update(['price'=>$v['price'],'vip_price'=>$v['price'],'cost'=>$v['price'],'purchase'=>$v['price']]);
unset($v['id']); unset($v['id']);
$res = CartLogic::add($v); $res = CartLogic::add($v);
$cartId[] = $res['id']; $cartId[] = $res['id'];
@ -56,7 +56,7 @@ class StoreOrderLogic extends BaseLogic
return false; return false;
} else { } else {
$arr = [ $arr = [
'warehouse_id' => 1, 'warehouse_id' => $params['warehouse_id']??-1,
'store_id' => $params['store_id'], 'store_id' => $params['store_id'],
'supplier_id' => 0, 'supplier_id' => 0,
'code' => getNewOrderId('PS'), 'code' => getNewOrderId('PS'),
@ -69,23 +69,21 @@ class StoreOrderLogic extends BaseLogic
$res = WarehouseOrder::create($arr); $res = WarehouseOrder::create($arr);
foreach ($params['product_arr'] as $k => $v) { foreach ($params['product_arr'] as $k => $v) {
$data = [ $data = [
'warehouse_id' => 1, 'warehouse_id' => $params['warehouse_id']??-1,
'product_id' => $v['product_id'], 'product_id' => $v['product_id'],
'store_id' => $params['store_id'], 'store_id' => $params['store_id'],
'financial_pm' => 0, 'financial_pm' => 0,
'batch' => 1, 'batch' => 1,
'nums' => $arr['stock'], 'nums' => $v['stock'],
'status' => 1, 'status' => 1,
'admin_id' => $params['admin_id'], 'admin_id' => $params['admin_id'],
]; ];
$storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray(); $storeProduct = StoreBranchProduct::where('id', $v['id'])->findOrEmpty()->toArray();
if ($arr['stock'] == 0) { if ($v['stock']>0) {
StoreProductLogic::ordinary($arr, $params['store_id'], $params['admin_id'], $storeProduct); $data['total_price'] = bcmul($v['stock'], $storeProduct['purchase'], 2);
} else {
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
$data['purchase'] = $storeProduct['purchase']; $data['purchase'] = $storeProduct['purchase'];
$data['oid'] = $res['id']; $data['oid'] = $res['id'];
WarehouseProductLogic::add($data); WarehouseProductLogic::add($data,0);
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); $finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]); WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
} }

View File

@ -32,7 +32,7 @@ class WarehouseProductLogic extends BaseLogic
* @author admin * @author admin
* @date 2024/07/31 16:55 * @date 2024/07/31 16:55
*/ */
public static function add(array $params) public static function add(array $params,$type=1)
{ {
// Db::startTrans(); // Db::startTrans();
try { try {
@ -55,12 +55,14 @@ class WarehouseProductLogic extends BaseLogic
} }
$storeBranchProduct=StoreProductLogic::ordinary(['id'=>$params['product_id']],$params['store_id'], $params['admin_id'], $storeProduct); $storeBranchProduct=StoreProductLogic::ordinary(['id'=>$params['product_id']],$params['store_id'], $params['admin_id'], $storeProduct);
} }
if ($params['nums'] > 0) { if ($params['nums'] > 0&&$type==1) {
StoreBranchProduct::where('id', $storeBranchProduct['id'])->inc('stock',$params['nums'])->update(); StoreBranchProduct::where('id', $storeBranchProduct['id'])->inc('stock',$params['nums'])->update();
} }
} else { } else {
$after_nums = $storege['nums'] + $params['nums']; $after_nums = $storege['nums'] + $params['nums'];
WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update(); if($type==1){
WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update();
}
} }
$before_nums = $storege['nums']; $before_nums = $storege['nums'];
} else { } else {

View File

@ -23,6 +23,8 @@ use support\Log;
use think\facade\Db; use think\facade\Db;
use Webman\RedisQueue\Redis; use Webman\RedisQueue\Redis;
use function DI\get;
class OrderController extends BaseApiController class OrderController extends BaseApiController
{ {
public $notNeedLogin = ['refund_reason']; public $notNeedLogin = ['refund_reason'];
@ -134,7 +136,7 @@ class OrderController extends BaseApiController
public function createOrder() public function createOrder()
{ {
$cartId = (array)$this->request->post('cart_id', []); $cartId = (array)$this->request->post('cart_id', []);
$store_id = (array)$this->request->post('store_id', 0); $store_id =$this->request->post('store_id', 0);
$pay_type = (int)$this->request->post('pay_type'); $pay_type = (int)$this->request->post('pay_type');
$addressId = (int)$this->request->post('address_id'); $addressId = (int)$this->request->post('address_id');
$auth_code = $this->request->post('auth_code'); //微信支付条码 $auth_code = $this->request->post('auth_code'); //微信支付条码
@ -145,7 +147,13 @@ class OrderController extends BaseApiController
if (count($cartId) > 100) { if (count($cartId) > 100) {
return $this->fail('购物车商品不能超过100个'); return $this->fail('购物车商品不能超过100个');
} }
$store_arr=getenv('NO_STORE_ID');
if($store_arr){
$store_arr=explode(',',$store_arr);
if (in_array($store_id,$store_arr)){
return $this->fail('该门店不支持下单');
}
}
$user = User::where('id', $this->userId)->find(); $user = User::where('id', $this->userId)->find();
if ($pay_type == PayEnum::PURCHASE_FUNDS || $pay_type == PayEnum::BALANCE_PAY) { if ($pay_type == PayEnum::PURCHASE_FUNDS || $pay_type == PayEnum::BALANCE_PAY) {
if (!isset($params['password'])) { if (!isset($params['password'])) {

View File

@ -257,6 +257,7 @@ class OrderLogic extends BaseLogic
$alert = '当前时间超过配送截止时间16:00,若下单,物品送达时间为' . date('Y-m-d', strtotime($currentDate . '+2 days')); $alert = '当前时间超过配送截止时间16:00,若下单,物品送达时间为' . date('Y-m-d', strtotime($currentDate . '+2 days'));
} }
} catch (\Exception $e) { } catch (\Exception $e) {
d($e);
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }