From 60f58e2e9c013df82745348c4f77c5d3e443c00d Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Thu, 11 Apr 2024 15:07:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E6=80=BB=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E8=AE=A2=E5=8D=95=E4=B8=8B=E5=8D=95=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/order/StoreCartDao.php | 2 +- app/common/model/store/Point.php | 2 + .../repositories/store/PointRepository.php | 15 +++ .../store/order/StoreCartRepository.php | 16 ++- .../order/StoreOrderCreateRepository.php | 97 ++++++++----------- .../store/product/ProductRepository.php | 13 +++ app/controller/admin/store/StoreProduct.php | 3 +- app/controller/api/store/order/StoreOrder.php | 3 +- 8 files changed, 89 insertions(+), 62 deletions(-) diff --git a/app/common/dao/store/order/StoreCartDao.php b/app/common/dao/store/order/StoreCartDao.php index 55003b1..19dab48 100644 --- a/app/common/dao/store/order/StoreCartDao.php +++ b/app/common/dao/store/order/StoreCartDao.php @@ -154,7 +154,7 @@ class StoreCartDao extends BaseDao } ]) ->whereIn('cart_id',$ids) - ->order('product_type DESC,cart_id DESC') + ->order('product_type DESC,mer_id ASC,cart_id DESC') ->select(); } diff --git a/app/common/model/store/Point.php b/app/common/model/store/Point.php index 045521a..6c18978 100644 --- a/app/common/model/store/Point.php +++ b/app/common/model/store/Point.php @@ -6,6 +6,8 @@ use app\common\model\BaseModel; class Point extends BaseModel{ + public $hidden = ['is_del']; + public static function tablePk(): string{ return 'id'; } diff --git a/app/common/repositories/store/PointRepository.php b/app/common/repositories/store/PointRepository.php index 021a90a..a40f0db 100644 --- a/app/common/repositories/store/PointRepository.php +++ b/app/common/repositories/store/PointRepository.php @@ -77,7 +77,22 @@ class PointRepository extends BaseRepository{ } + /** + * Common: 移动端获取总平台提货点配置信息 + * Author: wu-hui + * Time: 2024/04/11 10:14 + * @param int $useId + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getUseInfo(int $useId = 0):array{ + $list = $this->getSearchModel([])->withoutField('create_time,update_time')->select()->toArray(); + $config = $useId > 0 ? (array_column($list, null, 'id')[$useId] ?? []) : []; + return compact('list', 'config'); + } diff --git a/app/common/repositories/store/order/StoreCartRepository.php b/app/common/repositories/store/order/StoreCartRepository.php index efa5682..2acf7ca 100644 --- a/app/common/repositories/store/order/StoreCartRepository.php +++ b/app/common/repositories/store/order/StoreCartRepository.php @@ -11,6 +11,7 @@ use app\common\model\store\product\Product; use app\common\repositories\BaseRepository; use app\common\repositories\store\coupon\StoreCouponProductRepository; use app\common\repositories\store\coupon\StoreCouponRepository; +use app\common\repositories\store\PointRepository; use app\common\repositories\store\product\ProductRepository; use app\common\repositories\user\MemberinterestsRepository; use think\exception\ValidateException; @@ -48,7 +49,7 @@ class StoreCartRepository extends BaseRepository return $this->checkCartList($res, $user->uid, $user); } - public function checkCartList($res, $hasCoupon = 0, $user = null) + public function checkCartList($res, $hasCoupon = 0, $user = null,$points = []) { $arr = $fail = []; $product_make = app()->make(ProductRepository::class); @@ -60,14 +61,24 @@ class StoreCartRepository extends BaseRepository } else { //商户信息 if ($item['merchant']){ + // 商户存在 购买商户商品 $merchantData = $item['merchant']->append(['openReceipt'])->toArray(); } else { + // 商户不存在 购买总平台商品 $merchantData = [ 'mer_id' => 0, - 'delivery_way' => [1,2] + 'delivery_way' => $product_make->getPlatformDeliveryWay(), ]; + // 总平台 允许自提时 提货点信息处理 + if(in_array(1, $merchantData['delivery_way'])){ + $pointId = $points[$merchantData['mer_id']] ?? 0; + $deliveryWayInfo = app()->make(PointRepository::class)->getUseInfo((int)$pointId); + $merchantData['delivery_way_list'] = $deliveryWayInfo['list']; + $merchantData['config'] = $deliveryWayInfo['config']; + } } + unset($item['merchant']); $coupon_make = app()->make(StoreCouponRepository::class); if (!isset($arr[$item['mer_id']])) { @@ -89,6 +100,7 @@ class StoreCartRepository extends BaseRepository } } $list = array_values($arr); + return compact('list', 'fail'); } diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 8f5dcf7..3fd1530 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -38,7 +38,7 @@ use think\facade\{Cache,Db,Log,Queue}; class StoreOrderCreateRepository extends StoreOrderRepository{ /****** 原始版本 ************************************/ - public function v2CartIdByOrderInfo($user,array $cartId,array $takes = NULL,array $useCoupon = NULL,bool $useIntegral = FALSE,int $addressId = NULL,array $withGoods = [],$createOrder = FALSE){ + public function v2CartIdByOrderInfo($user,array $cartId,array $takes = NULL,array $points = NULL,array $useCoupon = NULL,bool $useIntegral = FALSE,int $addressId = NULL,array $withGoods = [],$createOrder = FALSE){ $uid = $user->uid; $userIntegral = $user->integral; $exchangeIntegral = $user->exchange_integral ?? 0;// 持有可用酒水卡积分 @@ -57,7 +57,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ //获取购物车信息 if($isWithGoods) $cartIbByData = $storeCartRepository->cartIbByData($cartId,0,$address,$withGoods); else $cartIbByData = $storeCartRepository->cartIbByData($cartId,$uid,$address); - $res = $storeCartRepository->checkCartList($cartIbByData,0,$user); + $res = $storeCartRepository->checkCartList($cartIbByData,0,$user,$points); $merchantCartList = $res['list']; $fail = $res['fail']; @@ -70,9 +70,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ throw new ValidateException('[已失效]'.mb_substr($fail[0]['product']['store_name'],0,10).'...'); } $svip_status = $user->is_svip > 0 && systemConfig('svip_switch_status') == '1'; - $svip_integral_rate = $svip_status ? app() - ->make(MemberinterestsRepository::class) - ->getSvipInterestVal(MemberinterestsRepository::HAS_TYPE_PAY) : 0; + $svip_integral_rate = $svip_status ? app()->make(MemberinterestsRepository::class)->getSvipInterestVal(MemberinterestsRepository::HAS_TYPE_PAY) : 0; //订单活动类型 $order_type = 0; //虚拟订单 @@ -148,22 +146,20 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $order_refund_switch = 0; //是否自提 $isTake = in_array($merchantCart['mer_id'],$takes ?? []); - $merTake = in_array('1',$merchantCart['delivery_way'],TRUE); - $merDelivery = (!$merchantCart['delivery_way'] || !count($merchantCart['delivery_way']) || in_array('2',$merchantCart['delivery_way'],TRUE)); + $merTake = in_array('1',$merchantCart['delivery_way']); + $merDelivery = (!$merchantCart['delivery_way'] || !count($merchantCart['delivery_way']) || in_array('2',$merchantCart['delivery_way'])); $_merTake = $merTake; $_merDelivery = $merDelivery; $deliveryStatus = TRUE; - if($createOrder && $isTake && !$merTake){ - $deliveryStatus = FALSE; - } + if($createOrder && $isTake && !$merTake) $deliveryStatus = FALSE; $product_cart = []; foreach($merchantCart['list'] as $k => $cart){ //获取订单类型, 活动商品单次只能购买一个 if($cart['product']['delivery_way']){ $delivery_way = explode(',',$cart['product']['delivery_way']); - $proTake = in_array('1',$delivery_way,TRUE); + $proTake = in_array('1',$delivery_way); $merTake = $merTake && $proTake; - $proDelivery = (!count($delivery_way) || in_array('2',$delivery_way,TRUE)); + $proDelivery = (!count($delivery_way) || in_array('2',$delivery_way)); $merDelivery = $merDelivery && $proDelivery; $merchantCart['list'][$k]['allow_take'] = $proTake; $merchantCart['list'][$k]['allow_delivery'] = $proDelivery; @@ -172,16 +168,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $merchantCart['list'][$k]['allow_take'] = $_merTake; $merchantCart['list'][$k]['allow_delivery'] = $_merDelivery; } - if($createOrder && $isTake && !$merTake){ - $deliveryStatus = FALSE; - } - } - if(!$merDelivery && !$merTake){ - $deliveryStatus = FALSE; - } - if($deliveryStatus && !$isTake && ($merDelivery || $merTake)){ - $isTake = $merDelivery ? 0 : 1; + if($createOrder && $isTake && !$merTake) $deliveryStatus = FALSE; } + if(!$merDelivery && !$merTake) $deliveryStatus = FALSE; + + if($deliveryStatus && !$isTake && ($merDelivery || $merTake)) $isTake = $merDelivery ? 0 : 1; + //加载商品数据 foreach($merchantCart['list'] as $cart){ //预售订单 @@ -514,9 +506,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ } unset($cart,$_k); $total_true_price = bcadd($_pay_price,$total_true_price,2); - if(count($merchantCartList) > 1 || count($merchantCart['list']) > 1){ - $orderDeliveryStatus = $orderDeliveryStatus && $deliveryStatus; - } + if(count($merchantCartList) > 1 || count($merchantCart['list']) > 1) $orderDeliveryStatus = $orderDeliveryStatus && $deliveryStatus; $merchantCart['order'] = [ 'true_price' => $_pay_price, 'platform_coupon_price' => 0, @@ -741,8 +731,15 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ 'mer_integral_status' => 0, ]; $allow_no_address = $allow_no_address && $merchantCart['order']['isTake']; - foreach($merchantCart['config'] as $config){ - $merchantCart['take'][$config['config_key']] = $config['value']; + // 提货点 总平台和商户兼容处理 + if($merchantCart['mer_id'] > 0){ + // 商户 + foreach($merchantCart['config'] as $config){ + $merchantCart['take'][$config['config_key']] = $config['value']; + } + }else{ + // 总平台 + $merchantCart['take'] = array_merge($merchantCart['take'], ($merchantCart['config'] ?? [])); } $merIntegralConfig = $merchantCart['take']; unset($merchantCart['config']); @@ -962,17 +959,11 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $uid = $user->uid; // $orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true); $orderInfo = Cache::get('order_create_cache'.$uid.'_'.$key); - if(!$orderInfo) throw new ValidateException('订单操作超时,请刷新页面'); - $order_model = $orderInfo['order_model']; $order_extend = $orderInfo['order_extend']; - if(!$orderInfo['order_delivery_status']){ - throw new ValidateException('部分商品配送方式不一致,请单独下单'); - } - if($orderInfo['order_price'] > 1000000){ - throw new ValidateException('支付金额超出最大限制'); - } + if(!$orderInfo['order_delivery_status']) throw new ValidateException('部分商品配送方式不一致,请单独下单'); + if($orderInfo['order_price'] > 1000000) throw new ValidateException('支付金额超出最大限制'); if($orderInfo['status'] == 'noDeliver') throw new ValidateException('部分商品不支持该区域'); if($orderInfo['status'] == 'noAddress') throw new ValidateException('请选择地址'); if(!$order_model && $orderInfo['allow_address']){ @@ -981,9 +972,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $extend = []; } elseif(count($order_extend)){ - $extend = app() - ->make(OrderVirtualFieldValidate::class) - ->load($order_extend,$extend); + $extend = app()->make(OrderVirtualFieldValidate::class)->load($order_extend,$extend); } else{ $extend = []; @@ -998,9 +987,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $cartSpread = 0; $hasTake = FALSE; foreach($merchantCartList as $merchantCart){ - if($merchantCart['order']['isTake']){ - $hasTake = TRUE; - } //检查发票状态 if(isset($receipt_data[$merchantCart['mer_id']]) && !$merchantCart['openReceipt']) throw new ValidateException('该店铺不支持开发票'); foreach($merchantCart['list'] as $cart){ @@ -1008,18 +994,15 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $cartSpread = $cart['spread_id']; } } + // 判断:订单配送方式为自提时 判断是否存在自提信息 + if($merchantCart['order']['isTake']) { + $hasTake = TRUE; + if(empty($merchantCart['take']['mer_take_name'])) throw new ValidateException('请选择有效的提货点!'); + } } - if($hasTake){ - app() - ->make(UserAddressValidate::class) - ->scene('take') - ->check($post); - } - if($cartSpread){ - app() - ->make(UserRepository::class) - ->bindSpread($user,$cartSpread); - } + + if($hasTake) app()->make(UserAddressValidate::class)->scene('take')->check($post); + if($cartSpread) app()->make(UserRepository::class)->bindSpread($user,$cartSpread); $isSelfBuy = $user->is_promoter && systemConfig('extension_self') ? 1 : 0; if($isSelfBuy){ $spreadUser = $user; @@ -1042,6 +1025,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ $cartIds = []; $orderList = []; foreach($merchantCartList as $k => $merchantCart){ + // 数据补齐 总平台商品订单可能存在部分数据不存在 + $merchantCart['commission_rate'] = $merchantCart['commission_rate'] ?? 0; + + $cost = 0; $total_extension_one = 0; $total_extension_two = 0; @@ -1118,12 +1105,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository{ } unset($cart); $rate = 0; - if($merchantCart['commission_rate'] > 0){ - $rate = $merchantCart['commission_rate']; - } - elseif(isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0){ - $rate = bcmul($merchantCart['merchantCategory']['commission_rate'],100,4); - } + if($merchantCart['commission_rate'] > 0) $rate = $merchantCart['commission_rate']; + elseif(isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0) $rate = bcmul($merchantCart['merchantCategory']['commission_rate'],100,4); $user_address = isset($address) ? ($address['province'].$address['city'].$address['district'].$address['street'].$address['detail']) : ''; //整理订单数据 $_order = [ diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 6581800..527521f 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -17,6 +17,7 @@ use app\common\repositories\store\order\StoreCartRepository; use app\common\repositories\store\order\StoreOrderProductRepository; use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\store\parameter\ParameterValueRepository; +use app\common\repositories\store\PointRepository; use app\common\repositories\store\StoreActivityRepository; use app\common\repositories\store\StoreSeckillActiveRepository; use app\common\repositories\store\StoreSeckillTimeRepository; @@ -2627,6 +2628,18 @@ class ProductRepository extends BaseRepository return compact('count', 'list'); } + /** + * Common: 获取总平台允许送货方式 + * Author: wu-hui + * Time: 2024/04/11 9:29 + * @return int[] + */ + public function getPlatformDeliveryWay():array{ + // 存在提货点 则允许自提和快递 不存在则仅允许快递 + $pointCount = (int)app()->make(PointRepository::class)->getSearchModel([])->count(); + if($pointCount > 0) return [1,2]; + else return [2]; + } diff --git a/app/controller/admin/store/StoreProduct.php b/app/controller/admin/store/StoreProduct.php index 460fa5b..073a0e2 100644 --- a/app/controller/admin/store/StoreProduct.php +++ b/app/controller/admin/store/StoreProduct.php @@ -4,6 +4,7 @@ namespace app\controller\admin\store; +use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\product\SpuRepository; use app\common\repositories\system\merchant\MerchantRepository; use think\App; @@ -310,7 +311,7 @@ class StoreProduct extends BaseController // $data['delivery_way'] = $this->request->merchant()->delivery_way ? $this->request->merchant()->delivery_way : [2]; // $data['is_audit'] = $this->request->merchant()->is_audit; $data['is_audit'] = 0; - $data['delivery_way'] = [1,2]; + $data['delivery_way'] = app()->make(ProductRepository::class)->getPlatformDeliveryWay(); return app('json')->success($data); } diff --git a/app/controller/api/store/order/StoreOrder.php b/app/controller/api/store/order/StoreOrder.php index 4b64fa0..8fe5209 100644 --- a/app/controller/api/store/order/StoreOrder.php +++ b/app/controller/api/store/order/StoreOrder.php @@ -54,6 +54,7 @@ class StoreOrder extends BaseController $addressId = (int)$this->request->param('address_id'); $couponIds = (array)$this->request->param('use_coupon', []); $takes = (array)$this->request->param('takes', []); + $points = (array)$this->request->param('points', []); // $usePlatformIntegral = (bool)$this->request->param('use_platform_integral', false); // $useMerIntegral = (bool)$this->request->param('use_mer_integral', false); $useIntegral = (bool)$this->request->param('use_integral', false); @@ -71,7 +72,7 @@ class StoreOrder extends BaseController if (!($count = count($cartId)) || $count != $cartCount) return app('json')->fail('数据无效'); // $orderInfo = $orderCreateRepository->v2CartIdByOrderInfo($user, $cartId, $takes, $couponIds, $usePlatformIntegral,$useMerIntegral, $addressId); - $orderInfo = $orderCreateRepository->v2CartIdByOrderInfo($user, $cartId, $takes, $couponIds, $useIntegral, $addressId, $withGoods); + $orderInfo = $orderCreateRepository->v2CartIdByOrderInfo($user, $cartId, $takes, $points, $couponIds, $useIntegral, $addressId, $withGoods); return app('json')->success($orderInfo); }