diff --git a/app/admin/controller/WorkbenchController.php b/app/admin/controller/WorkbenchController.php index 0ea9348bc..c6d88fa77 100644 --- a/app/admin/controller/WorkbenchController.php +++ b/app/admin/controller/WorkbenchController.php @@ -14,6 +14,7 @@ namespace app\admin\controller; +use app\admin\lists\statistics\StoreProductLists; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupLists; use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupMonthLists; use app\admin\logic\statistic\ProductStatisticLogic; @@ -51,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); @@ -101,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'); @@ -165,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); } //-------------------------------用户统计---------------------------------------// @@ -178,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); } @@ -193,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); } @@ -207,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(); @@ -230,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 @@ -260,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; } } @@ -270,24 +273,46 @@ 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() { - $data=WarehouseLogic::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); + } + + /** + * 统计门店仓库总库存 + * @return array + */ + public function total_warehouse_product_list() + { + $parmas=$this->request->get(); + $data =WarehouseLogic::total_warehouse_product_list($parmas,$parmas['type']??1); return $this->data($data); } } diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index 34977798c..092c9bb9a 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -56,11 +56,12 @@ class StoreOrderController extends BaseAdminController public function add() { $params = $this->request->post(); + $params['admin_id'] = $this->adminId; $result = StoreOrderLogic::add($params); if (StoreOrderLogic::hasError()) { return $this->fail(StoreOrderLogic::getError()); } else { - return $this->success('添加成功,请在30分钟内支付', [], 1, 1); + return $this->success('添加成功,该订单不会因为系统时间而删除', [], 1, 1); } } diff --git a/app/admin/controller/warehouse_order/WarehouseOrderController.php b/app/admin/controller/warehouse_order/WarehouseOrderController.php index c03ed4932..a37b3a32a 100644 --- a/app/admin/controller/warehouse_order/WarehouseOrderController.php +++ b/app/admin/controller/warehouse_order/WarehouseOrderController.php @@ -209,6 +209,7 @@ class WarehouseOrderController extends BaseAdminController public function export() { $id = $this->request->post('id'); + $type = $this->request->post('type'); $xlsx = new OrderDetail(); $order = WarehouseOrder::where('id', $id)->findOrEmpty(); $system_store = SystemStore::where('id', $order['store_id'])->value('name'); @@ -218,7 +219,12 @@ class WarehouseOrderController extends BaseAdminController $find = StoreProduct::where('id', $value->product_id)->find(); $value->store_name = $find['store_name'] ?? ''; $value->store_info = $find['store_info'] ?? ''; - $value->price = $value['purchase']; + if($type==2){ + $value->price = $find['price']; + $value->total_price=bcmul($find['price'],$value['nums'],2); + }else{ + $value->price = $value['purchase']; + } $value->cart_num = $value['nums']; if (!empty($find['unit'])) { $value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name'); diff --git a/app/admin/lists/statistics/StoreProductLists.php b/app/admin/lists/statistics/StoreProductLists.php new file mode 100644 index 000000000..06350317a --- /dev/null +++ b/app/admin/lists/statistics/StoreProductLists.php @@ -0,0 +1,145 @@ + ['cate_id', 'is_show', 'bar_code'], + '<=' => ['stock'], + '%like%' => ['store_name'], + ]; + } + + + /** + * @notes 获取商品列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function lists(): array + { + $class_all = $this->request->get('class_all'); + if ($class_all) { + //查3级别的 + $arr = Cate::where('pid', $class_all)->column('id'); + if ($arr) { + $arr2 = Cate::where('pid', 'in', $arr)->column('id'); + $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; + } else { + $this->searchWhere[] = ['cate_id', '=', $class_all]; + } + } + $list = StoreProduct::where($this->searchWhere) + ->alias('p') // 为 StoreProduct 表设置别名 + ->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 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) { + // 计算总库存 + $item->total_stock = $item->store_stock + $item->warehouse_stock; + $item->total_completed_amount=$item->total_completed_amount??0; + $item->warehouse_stock=$item->warehouse_stock??0; + $item->total_outstanding_amount=$item->total_outstanding_amount??0; + $item->total_purchase=$item->total_purchase??0; + }) + ->toArray(); + return $list; + } + + + /** + * @notes 获取商品列表数量 + * @return int + * @author likeadmin + * @date 2024/05/31 10:53 + */ + public function count(): int + { + $export=$this->request->get('export'); + if($export==1){ + $class_all = $this->request->get('class_all'); + if ($class_all) { + //查3级别的 + $arr = Cate::where('pid', $class_all)->column('id'); + if ($arr) { + $arr2 = Cate::where('pid', 'in', $arr)->column('id'); + $this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; + } else { + $this->searchWhere[] = ['cate_id', '=', $class_all]; + } + } + } + return StoreProduct::where($this->searchWhere)->count(); + } + + /** + * @notes 导出文件名 + * @return string + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setFileName(): string + { + return '商品列表'; + } + + + /** + * @notes 导出字段 + * @return string[] + * @author 乔峰 + * @date 2022/11/24 16:17 + */ + public function setExcelFields(): array + { + $data = [ + 'store_name' => '商品名称', + 'cate_name'=>'分类', + 'unit_name'=>'单位', + 'stock' => '库存', + 'purchase' => '采购价', + 'cost' => '商户', + 'price' => '零售', + ]; + return $data; + } +} diff --git a/app/admin/lists/store_extract/StoreExtractLists.php b/app/admin/lists/store_extract/StoreExtractLists.php index 6916faf7d..dbb2ec935 100644 --- a/app/admin/lists/store_extract/StoreExtractLists.php +++ b/app/admin/lists/store_extract/StoreExtractLists.php @@ -60,6 +60,7 @@ class StoreExtractLists extends BaseAdminDataLists implements ListsSearchInterfa } $user_ship=UserShip::where('id',$find['user_ship'])->value('title'); $item->nickname=$name.'('.$user_ship.')'; + // $item->id_card=$name.'('.$user_ship.')'; } }) ->toArray(); diff --git a/app/admin/lists/store_product/StoreProductLists.php b/app/admin/lists/store_product/StoreProductLists.php index 1502506b9..c4f4f50a5 100644 --- a/app/admin/lists/store_product/StoreProductLists.php +++ b/app/admin/lists/store_product/StoreProductLists.php @@ -129,6 +129,7 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa 'purchase' => '采购价', 'cost' => '商户', 'price' => '零售', + 'bar_code' => '条码', ]; return $data; } diff --git a/app/admin/lists/warehouse_product/WarehouseProductLists.php b/app/admin/lists/warehouse_product/WarehouseProductLists.php index 500e54e82..a301f6634 100644 --- a/app/admin/lists/warehouse_product/WarehouseProductLists.php +++ b/app/admin/lists/warehouse_product/WarehouseProductLists.php @@ -98,10 +98,11 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt $item->admin_name = ''; } if ($item->product_id) { - $find = StoreProduct::where('id', $item->product_id)->field('image,store_name')->find(); + $find = StoreProduct::where('id', $item->product_id)->field('price,image,store_name')->find(); if($find){ $item->store_name = $find->store_name . '|' . $item->product_id; $item->image = $find->image; + $item->price = $find->price; } } else { $item->store_name = ''; diff --git a/app/admin/logic/statistic/WarehouseLogic.php b/app/admin/logic/statistic/WarehouseLogic.php index a7ff4ec4e..23ec94f00 100644 --- a/app/admin/logic/statistic/WarehouseLogic.php +++ b/app/admin/logic/statistic/WarehouseLogic.php @@ -7,9 +7,12 @@ 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\supplier\Supplier; +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; @@ -47,13 +50,13 @@ class WarehouseLogic extends BaseLogic 'value' => [], 'type' => 1, ]; - $store_stock_1 = StoreBranchProduct::where('stock','>',0)->sum('stock'); - $store_stock_2 = WarehouseProductStorege::where('nums','>',0)->sum('nums'); + $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, + 'total_money' => bcadd($store_stock_1, $store_stock_2, 2), + 'cash_title' => 1, 'value' => [], 'type' => 1, ]; @@ -61,23 +64,23 @@ class WarehouseLogic extends BaseLogic 'title' => '总仓库库存', 'desc' => '平台统计仓库库存', 'total_money' => WarehouseProductStorege::sum('nums'), - 'cash_title' => 0, + 'cash_title' => 1, 'value' => [], 'type' => 1, ]; $topData[] = [ 'title' => '海吉星仓库库存', 'desc' => '平台统计海吉星仓库库存', - 'total_money' => WarehouseProductStorege::where('warehouse_id',1)->sum('nums'), - 'cash_title' => 0, + 'total_money' => WarehouseProductStorege::where('warehouse_id', 1)->sum('nums'), + 'cash_title' => 1, 'value' => [], 'type' => 1, ]; $topData[] = [ 'title' => '泸县集采集配库存', 'desc' => '平台统计泸县集采集配库存', - 'total_money' => WarehouseProductStorege::where('warehouse_id',2)->sum('nums'), - 'cash_title' => 0, + 'total_money' => WarehouseProductStorege::where('warehouse_id', 2)->sum('nums'), + 'cash_title' => 1, 'value' => [], 'type' => 1, ]; @@ -85,7 +88,7 @@ class WarehouseLogic extends BaseLogic 'title' => '总门店库存', 'desc' => '平台统计门店库存', 'total_money' => StoreBranchProduct::sum('stock'), - 'cash_title' => 0, + 'cash_title' => 1, 'value' => [], 'type' => 1, @@ -103,24 +106,77 @@ class WarehouseLogic extends BaseLogic 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; + /** + * 统计门店仓库总库存 + * @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]; + } + /** + * 统计商品采购总价 已结未结 + * @return array + */ + public static function total_warehouse_product_list($parmas,$type=1) { + $list=[]; + $count=0; + if($type==1){ + //总采购价 + $where=[['product_id','=',$parmas['product_id']],['nums','>',0],['financial_pm','=',1]]; + $list=WarehouseProduct::where($where)->select()->each(function ($item){ + $item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name'); + $item->supplier_name = Supplier::where('id',$item['supplier_id'])->value('mer_name'); + $find = StoreProduct::where('id',$item['product_id'])->find(); + $item->store_name=$find['store_name']; + $item->image=$find['image']; + }); + $count=WarehouseProduct::where($where)->count(); + }elseif($type==2){ + //已结算采购价 + $where=[['product_id','=',$parmas['product_id']],['nums','>',0],['financial_pm','=',1],['is_pay','=',1]]; + $list=WarehouseProduct::where($where)->select()->each(function ($item){ + $item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name'); + $item->supplier_name = Supplier::where('id',$item['supplier_id'])->value('mer_name'); + $find = StoreProduct::where('id',$item['product_id'])->find(); + $item->store_name=$find['store_name']; + $item->image=$find['image']; + }); + $count=WarehouseProduct::where($where)->count(); + }elseif($type==3){ + //未结算采购价 + $where=[['product_id','=',$parmas['product_id']],['nums','>',0],['financial_pm','=',1],['is_pay','=',0]]; + $list=WarehouseProduct::where($where)->select()->each(function ($item){ + $item->warehouse_name = Warehouse::where('id',$item['warehouse_id'])->value('name'); + $item->supplier_name = Supplier::where('id',$item['supplier_id'])->value('mer_name'); + $find = StoreProduct::where('id',$item['product_id'])->find(); + $item->store_name=$find['store_name']; + $item->image=$find['image']; + }); + $count=WarehouseProduct::where($where)->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 14af044d1..79c5405e7 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -2,14 +2,20 @@ namespace app\admin\logic\store_order; +use app\admin\logic\store_product\StoreProductLogic; +use app\admin\logic\warehouse_product\WarehouseProductLogic; use app\api\logic\order\CartLogic; use app\api\logic\order\OrderLogic; use app\common\enum\PayEnum; use app\common\model\store_order\StoreOrder; use app\common\logic\BaseLogic; use app\common\logic\PayNotifyLogic; +use app\common\model\store_branch_product\StoreBranchProduct; 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\warehouse_order\WarehouseOrder; +use app\common\model\warehouse_product\WarehouseProduct; use think\facade\Db; @@ -35,20 +41,54 @@ class StoreOrderLogic extends BaseLogic foreach ($params['product_arr'] as $k => $v) { $v['uid'] = $params['user_id']; $v['store_id'] = $params['store_id']; - $v['product_id'] = $v['id']; $v['cart_num'] = $v['stock']; + 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']; } $user = User::where('id', $params['user_id'])->find(); - $params['shipping_type'] = 2; + $params['shipping_type']=4; $params['pay_type'] = 7; $order = OrderLogic::createOrder($cartId, null, $user, $params); - if ($order != false) { - return true; - } else { - OrderLogic::getError(); + if (OrderLogic::hasError()) { + StoreOrderLogic::setError(OrderLogic::getError()); return false; + } else { + $arr = [ + 'warehouse_id' => $params['warehouse_id']??-1, + 'store_id' => $params['store_id'], + 'supplier_id' => 0, + 'code' => getNewOrderId('PS'), + 'admin_id' => $params['admin_id'], + 'financial_pm' => 0, + 'batch' => 0, + 'mark' => $mark ?? "", + ]; + $arr['delivery_time'] = time(); + $res = WarehouseOrder::create($arr); + foreach ($params['product_arr'] as $k => $v) { + $data = [ + 'warehouse_id' => $params['warehouse_id']??-1, + 'product_id' => $v['product_id'], + 'store_id' => $params['store_id'], + 'financial_pm' => 0, + 'batch' => 1, + 'nums' => $v['stock'], + 'status' => 1, + 'admin_id' => $params['admin_id'], + ]; + $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,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']]); + } + } + return true; } } diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 5e1f61526..b063802b3 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/IndexController.php b/app/api/controller/IndexController.php index 40542ea25..36c14354d 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -208,7 +208,7 @@ class IndexController extends BaseApiController public function config() { //处理返回最近的店铺 - $params=$this->request->get(); + $params = $this->request->get(); if ((isset($params['lat']) && $params['lat'] != '') && (isset($params['long']) && $params['long'] != '')) { $latitude = $params['lat']; $longitude = $params['long']; @@ -216,10 +216,15 @@ class IndexController extends BaseApiController $distanceSql = "SQRT(POW(69.1 * (latitude - {$latitude}), 2) + POW(69.1 * ({$longitude} - longitude) * COS(latitude / 57.3), 2))"; $find = SystemStore::field("id, name,abbreviation, {$distanceSql} AS distance") + ->where('is_show', '=', 1) ->where('latitude', '<>', '') ->where('longitude', '<>', '') ->order('distance', 'asc') // 根据距离排序 ->find(); + if (!$find) { + $store_id = getenv('STORE_ID') ?? 1; + $find = SystemStore::where('id', $store_id)->find(); + } } else { $store_id = getenv('STORE_ID') ?? 1; $find = SystemStore::where('id', $store_id)->find(); diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 15211d3d2..76b788483 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 548a82138..522dc374a 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; } @@ -340,32 +341,17 @@ class OrderLogic extends BaseLogic $order = StoreOrder::create($_order); $goods_list = $orderInfo['cart_list']; - $updateData = []; - $updateDataTwo = []; + foreach ($goods_list as $k => $v) { $goods_list[$k]['oid'] = $order->id; $goods_list[$k]['uid'] = $uid; $goods_list[$k]['cart_id'] = implode(',', $cartId); $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id - - $id = StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['store_id'])->value('id'); - if ($id) { - $updateData[] = [ - 'id' => $id, - 'sales' => ['inc', $v['cart_num']], - 'stock' => ['dec', $v['cart_num']], - ]; - } - $updateDataTwo[] = [ - 'id' => $v['product_id'], - 'sales' => ['inc', $v['cart_num']] - ]; } (new StoreOrderCartInfo())->saveAll($goods_list); $where = ['is_pay' => 0]; Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]); - (new StoreBranchProduct())->saveAll($updateData); - (new StoreProduct())->saveAll($updateDataTwo); + Db::commit(); return $order; } catch (\Exception $e) { diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 681993271..3b1a47d38 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -19,6 +19,7 @@ use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow; use app\common\model\store_finance_flow\StoreFinanceFlow; 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\store_product_log\StoreProductLog; use app\common\model\system_store\SystemStore; use app\common\model\user\User; @@ -324,7 +325,7 @@ class PayNotifyLogic extends BaseLogic StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); //处理财务流水退还 - (new StoreFinanceFlowLogic())->store_finance_back($orderSn,$order['store_id']); + (new StoreFinanceFlowLogic())->store_finance_back($orderSn, $order['store_id']); if (in_array($order['pay_type'], [PayEnum::BALANCE_PAY, PayEnum::PURCHASE_FUNDS])) { if ($order['pay_type'] == PayEnum::BALANCE_PAY) { //用户余额支付 $user = User::where('id', $order['uid'])->findOrEmpty(); @@ -358,7 +359,6 @@ class PayNotifyLogic extends BaseLogic $capitalFlowDao->userIncome('user_order_refund', 'system_back', $order['id'], $order['pay_price'], '', 1); self::addStock($order['id']); //微信 return true; - // self::afterPay($order,$extra['transaction_id']); } /** @@ -393,7 +393,7 @@ class PayNotifyLogic extends BaseLogic //增加数量 self::addStock($order['id']); StoreOrderCartInfo::where('oid', $order['id'])->update(['status' => OrderEnum::REFUND_STATUS_FINISH]); - (new StoreFinanceFlowLogic())->store_finance_back($orderSn,$order['store_id']); + (new StoreFinanceFlowLogic())->store_finance_back($orderSn, $order['store_id']); return true; } @@ -572,7 +572,25 @@ class PayNotifyLogic extends BaseLogic */ public static function afterPay($order, $transaction_id = 0) { + $updateData = []; + $updateDataTwo = []; StoreOrderCartInfo::where('oid', $order['id'])->update(['is_pay' => 1]); + $arr = StoreOrderCartInfo::where('oid', $order['id'])->field('id,oid,product_id,store_id,cart_num')->select(); + foreach ($arr as $k => $v) { + $updateData[] = [ + 'store_id' => $v['store_id'], + 'product_id' => $v['product_id'], + 'sales' => ['inc', $v['cart_num']], + 'stock' => ['dec', $v['cart_num']], + ]; + + $updateDataTwo[] = [ + 'id' => $v['product_id'], + 'sales' => ['inc', $v['cart_num']] + ]; + } + (new StoreBranchProduct())->saveAll($updateData); + (new StoreProduct())->saveAll($updateDataTwo); $financeLogic = new StoreFinanceFlowLogic(); $off_activity = Config::where('name', 'off_activity')->value('value'); $village_uid = 0; diff --git a/app/common/model/store_product/StoreProduct.php b/app/common/model/store_product/StoreProduct.php index 871b88caf..dc810fdda 100644 --- a/app/common/model/store_product/StoreProduct.php +++ b/app/common/model/store_product/StoreProduct.php @@ -5,7 +5,6 @@ namespace app\common\model\store_product; use app\common\model\BaseModel; use app\common\model\store_category\StoreCategory; -use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product_unit\StoreProductUnit; use think\model\concern\SoftDelete; diff --git a/process/Task.php b/process/Task.php index a08bae717..df537e071 100644 --- a/process/Task.php +++ b/process/Task.php @@ -23,7 +23,8 @@ class Task new Crontab('0 */10 * * * *', function () { $where = ['paid' => 0]; $where[] = ['create_time', '<', time() - 600]; // 10分钟前创建的订单 - // 删除10分钟未支付的订单 + $where[] = ['shipping_type', '<>',4]; + // 删除10分钟未支付的订单 $oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除 if ($oid) { StoreOrder::where('id', 'in', $oid)->update(['delete_time' => time()]);