From a0814641c83b54430744e3606f24e1a4fb6675d4 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 23 Aug 2024 13:46:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=BA=86WorkbenchCon?= =?UTF-8?q?troller=E5=92=8C=E7=9B=B8=E5=85=B3=E7=9A=84=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E4=BC=98=E5=8C=96=E4=BA=86=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=E9=97=A8=E5=BA=97=E4=BB=93=E5=BA=93=E6=80=BB=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E7=9A=84=E7=BB=9F=E8=AE=A1=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/WorkbenchController.php | 107 ++++++++++-------- .../lists/statistics/StoreProductLists.php | 12 +- app/admin/logic/statistic/WarehouseLogic.php | 32 ++++++ .../logic/store_order/StoreOrderLogic.php | 18 ++- .../WarehouseProductLogic.php | 10 +- app/api/controller/order/OrderController.php | 12 +- app/api/logic/order/OrderLogic.php | 1 + 7 files changed, 123 insertions(+), 69 deletions(-) diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index afbd03c5..04744434 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -52,13 +52,13 @@ class WorkbenchController extends BaseAdminController public function store_index() { $params = $this->request->get(); - if(!isset($params['store_id']) ||$params['store_id']==''){ - $params['store_id'] =0; + if (!isset($params['store_id']) || $params['store_id'] == '') { + $params['store_id'] = 0; } - if(!isset($params['start_time']) ||$params['start_time']==''){ - $time=explode('-', $this->getDay('')); - $params['start_time'] =$time[0]; - $params['end_time'] =$time[1]; + if (!isset($params['start_time']) || $params['start_time'] == '') { + $time = explode('-', $this->getDay('')); + $params['start_time'] = $time[0]; + $params['end_time'] = $time[1]; } $result = LogicWorkbenchLogic::index($params); @@ -102,24 +102,24 @@ class WorkbenchController extends BaseAdminController public function get_trend() { $dates = []; - $date=$this->request->get('date',''); - $days=31; - if($date){ - $arr=explode('-', $date); - if($arr[0]==$arr[1]){ - $date = new DateTime($arr[0]); - $dates[] = $date->format("Y-m-d"); - }else{ - $datetime_start = new DateTime($arr[0]); - $datetime_end = new DateTime($arr[1]); - $days = $datetime_start->diff($datetime_end)->days; - for ($i = 0; $i <= $days; $i++) { - $date = new DateTime($datetime_start->format('Y-m-d')); - $date->modify('+' . $i . ' days'); - $dates[] = $date->format('Y-m-d'); + $date = $this->request->get('date', ''); + $days = 31; + if ($date) { + $arr = explode('-', $date); + if ($arr[0] == $arr[1]) { + $date = new DateTime($arr[0]); + $dates[] = $date->format("Y-m-d"); + } else { + $datetime_start = new DateTime($arr[0]); + $datetime_end = new DateTime($arr[1]); + $days = $datetime_start->diff($datetime_end)->days; + for ($i = 0; $i <= $days; $i++) { + $date = new DateTime($datetime_start->format('Y-m-d')); + $date->modify('+' . $i . ' days'); + $dates[] = $date->format('Y-m-d'); + } } - } - }else{ + } else { $today = new DateTime(); $thirtyDaysAgo = new DateTime($today->format('Y-m-d')); $thirtyDaysAgo->modify('-30 days'); @@ -166,10 +166,10 @@ class WorkbenchController extends BaseAdminController */ public function get_product_ranking() { - $date=$this->request->get('date',''); + $date = $this->request->get('date', ''); $where['create_time'] = $this->getDay($date); - $data=(new ProductStatisticLogic())->get_product_ranking($where); - return $this->success('',$data); + $data = (new ProductStatisticLogic())->get_product_ranking($where); + return $this->success('', $data); } //-------------------------------用户统计---------------------------------------// @@ -179,13 +179,13 @@ class WorkbenchController extends BaseAdminController */ public function get_user_basic() { - $date=$this->request->get('date',''); - $store_id=$this->request->get('store_id'); + $date = $this->request->get('date', ''); + $store_id = $this->request->get('store_id'); $where['create_time'] = $this->getDay($date); - if($store_id){ + if ($store_id) { $where['store_id'] = $store_id; } - $data=(new UserStatisticLogic())->getBasic($where); + $data = (new UserStatisticLogic())->getBasic($where); return $this->data($data); } @@ -194,13 +194,13 @@ class WorkbenchController extends BaseAdminController */ public function get_user_trend() { - $date=$this->request->get('date',''); - $store_id=$this->request->get('store_id'); + $date = $this->request->get('date', ''); + $store_id = $this->request->get('store_id'); $where['create_time'] = $this->getDay($date); - if($store_id){ + if ($store_id) { $where['store_id'] = $store_id; } - $data=(new UserStatisticLogic())->getTrend($where); + $data = (new UserStatisticLogic())->getTrend($where); return $this->data($data); } @@ -208,7 +208,7 @@ class WorkbenchController extends BaseAdminController //当日订单金额 public function top_trade() { - $logic=(new TradeStatisticLogic()); + $logic = (new TradeStatisticLogic()); $leftToday = $logic->getTopLeftTrade(['create_time' => 'today']); $leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']); $rightOne = $logic->getTopRightOneTrade(); @@ -231,25 +231,27 @@ class WorkbenchController extends BaseAdminController //交易趋势 public function bottom_trade() { - $date=$this->request->get('date',''); - $data=(new TradeStatisticLogic())->getBottomTrade(['data'=>$this->getDay($date)]); + $date = $this->request->get('date', ''); + $data = (new TradeStatisticLogic())->getBottomTrade(['data' => $this->getDay($date)]); return $this->data($data); } /** * 实时商品统计 */ - 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()); } - /** + /** * 格式化时间 * @param $time * @return string @@ -261,9 +263,9 @@ class WorkbenchController extends BaseAdminController if (!$startTime && !$endTime) { return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time()); } else { - if($startTime==$endTime){ - return $startTime . '-' . $endTime.' 23:59:59'; - }else{ + if ($startTime == $endTime) { + return $startTime . '-' . $endTime . ' 23:59:59'; + } else { 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 array */ public function total_warehouse() { - $data=WarehouseLogic::total_warehouse(); + $data = WarehouseLogic::total_warehouse(); return $this->data($data); } - /** - * 统计仓库 + /** + * 统计仓库列表 * @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); } } diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php index d5f04386..06350317 100644 --- a/app/admin/lists/statistics/StoreProductLists.php +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -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) { // 计算总库存 diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index d2ba2d0a..db036f8c 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -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]; + } } diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index 27a2bef8..79c5405e 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -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']]); } diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 5e1f6152..b063802b 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -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,12 +55,14 @@ 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']; - 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']; } else { diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 15211d3d..76b78848 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -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'])) { diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 1569872b..522dc374 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -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; }