feat: 修改了WorkbenchController和相关的模型类,优化了仓库统计功能,增加了门店仓库总库存的统计方法。
This commit is contained in:
parent
cf1d6db00a
commit
a0814641c8
@ -239,14 +239,16 @@ class WorkbenchController extends BaseAdminController
|
||||
/**
|
||||
* 实时商品统计
|
||||
*/
|
||||
public function product_order(){
|
||||
public function product_order()
|
||||
{
|
||||
return $this->dataLists(new StoreOrderCartInfoGroupLists());
|
||||
}
|
||||
|
||||
/**
|
||||
* 月销售商品统计
|
||||
*/
|
||||
public function product_month_order(){
|
||||
public function product_month_order()
|
||||
{
|
||||
return $this->dataLists(new StoreOrderCartInfoGroupMonthLists());
|
||||
}
|
||||
/**
|
||||
@ -271,9 +273,10 @@ class WorkbenchController extends BaseAdminController
|
||||
return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
|
||||
}
|
||||
}
|
||||
//-------------------------------统计仓库---------------------------------------//
|
||||
|
||||
/**
|
||||
* 统计仓库
|
||||
* 统计仓库头
|
||||
* @return array
|
||||
*/
|
||||
public function total_warehouse()
|
||||
@ -283,12 +286,22 @@ class WorkbenchController extends BaseAdminController
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计仓库
|
||||
* 统计仓库列表
|
||||
* @return array
|
||||
*/
|
||||
public function warehouse_list()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -66,12 +66,12 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
|
||||
->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(b.stock) FROM `la_store_branch_product` b WHERE b.product_id=p.id) AS store_stock,
|
||||
(SELECT SUM(w.nums) FROM `la_warehouse_product_storege` w WHERE w.product_id=p.id) 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.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=0) AS total_outstanding_amount')
|
||||
(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 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 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 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 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 AND wp.delete_time IS NULL) AS total_outstanding_amount')
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
// 计算总库存
|
||||
|
@ -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_cart_info\StoreOrderCartInfo;
|
||||
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\UserVisit;
|
||||
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_product\WarehouseProduct;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
@ -103,4 +105,34 @@ class WarehouseLogic extends BaseLogic
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class StoreOrderLogic extends BaseLogic
|
||||
$v['uid'] = $params['user_id'];
|
||||
$v['store_id'] = $params['store_id'];
|
||||
$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']);
|
||||
$res = CartLogic::add($v);
|
||||
$cartId[] = $res['id'];
|
||||
@ -56,7 +56,7 @@ class StoreOrderLogic extends BaseLogic
|
||||
return false;
|
||||
} else {
|
||||
$arr = [
|
||||
'warehouse_id' => 1,
|
||||
'warehouse_id' => $params['warehouse_id']??-1,
|
||||
'store_id' => $params['store_id'],
|
||||
'supplier_id' => 0,
|
||||
'code' => getNewOrderId('PS'),
|
||||
@ -69,23 +69,21 @@ class StoreOrderLogic extends BaseLogic
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$data = [
|
||||
'warehouse_id' => 1,
|
||||
'warehouse_id' => $params['warehouse_id']??-1,
|
||||
'product_id' => $v['product_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'nums' => $v['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $params['admin_id'],
|
||||
];
|
||||
$storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
if ($arr['stock'] == 0) {
|
||||
StoreProductLogic::ordinary($arr, $params['store_id'], $params['admin_id'], $storeProduct);
|
||||
} else {
|
||||
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
|
||||
$storeProduct = StoreBranchProduct::where('id', $v['id'])->findOrEmpty()->toArray();
|
||||
if ($v['stock']>0) {
|
||||
$data['total_price'] = bcmul($v['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$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();
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class WarehouseProductLogic extends BaseLogic
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function add(array $params)
|
||||
public static function add(array $params,$type=1)
|
||||
{
|
||||
// Db::startTrans();
|
||||
try {
|
||||
@ -55,13 +55,15 @@ class WarehouseProductLogic extends BaseLogic
|
||||
}
|
||||
$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();
|
||||
}
|
||||
} else {
|
||||
$after_nums = $storege['nums'] + $params['nums'];
|
||||
if($type==1){
|
||||
WarehouseProductStorege::where('id', $storege['id'])->inc('nums', $params['nums'])->update();
|
||||
}
|
||||
}
|
||||
$before_nums = $storege['nums'];
|
||||
} else {
|
||||
$after_nums=$params['nums'];
|
||||
|
@ -23,6 +23,8 @@ use support\Log;
|
||||
use think\facade\Db;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
use function DI\get;
|
||||
|
||||
class OrderController extends BaseApiController
|
||||
{
|
||||
public $notNeedLogin = ['refund_reason'];
|
||||
@ -134,7 +136,7 @@ class OrderController extends BaseApiController
|
||||
public function createOrder()
|
||||
{
|
||||
$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');
|
||||
$addressId = (int)$this->request->post('address_id');
|
||||
$auth_code = $this->request->post('auth_code'); //微信支付条码
|
||||
@ -145,7 +147,13 @@ class OrderController extends BaseApiController
|
||||
if (count($cartId) > 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();
|
||||
if ($pay_type == PayEnum::PURCHASE_FUNDS || $pay_type == PayEnum::BALANCE_PAY) {
|
||||
if (!isset($params['password'])) {
|
||||
|
@ -257,6 +257,7 @@ class OrderLogic extends BaseLogic
|
||||
$alert = '当前时间超过配送截止时间16:00,若下单,物品送达时间为' . date('Y-m-d', strtotime($currentDate . '+2 days'));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
d($e);
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user