diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 9d0dbe6e..5f465430 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -107,14 +107,14 @@ class StoreOrderCreateRepository extends StoreOrderRepository } if ($address) { if ($cart['source'] == 0) { - $userAddressCode = ($address['province_code'] ?? '') . ',' . ($address['city_code'] ?? '') . ',' . ($address['district_code'] ?? '') . ',' . ($address['street_code'] ?? '') . ',' . ($address['village_code'] ?? '') . ',' . ($address['brigade_id'] ?? 0); - $getUrl = env('LOGISTICS_HOST_URL') . '/api/hasCourier?user_address_code=' . $userAddressCode; - $client = new \GuzzleHttp\Client(); - $response = $client->request('GET', $getUrl); - $courierData = json_decode($response->getBody(), true); - if (empty($courierData['code']) || $courierData['code'] != 1) { - throw new ValidateException('该收货区域未设置快递员'); - } + // $userAddressCode = ($address['province_code'] ?? '') . ',' . ($address['city_code'] ?? '') . ',' . ($address['district_code'] ?? '') . ',' . ($address['street_code'] ?? '') . ',' . ($address['village_code'] ?? '') . ',' . ($address['brigade_id'] ?? 0); + // $getUrl = env('LOGISTICS_HOST_URL') . '/api/hasCourier?user_address_code=' . $userAddressCode; + // $client = new \GuzzleHttp\Client(); + // $response = $client->request('GET', $getUrl); + // $courierData = json_decode($response->getBody(), true); + // if (empty($courierData['code']) || $courierData['code'] != 1) { + // throw new ValidateException('该收货区域未设置快递员'); + // } } } } @@ -479,165 +479,26 @@ class StoreOrderCreateRepository extends StoreOrderRepository } } unset($merchantCart); - - $usePlatformCouponId = 0; - $total_platform_coupon_price = 0; - //计算平台券优惠金额 // if ($total_true_price > 0) { $StoreCouponUser = app()->make(StoreCouponUserRepository::class); $platformCoupon = $StoreCouponUser->validUserPlatformCoupon($uid); - if ($enabledPlatformCoupon && count($platformCoupon)) { - - $catePriceLst = []; - $storePriceLst = []; - $_cartNum = 0; - - foreach ($merchantCartList as &$merchantCart) { - if ($merchantCart['order']['true_price'] <= 0) continue; - foreach ($merchantCart['list'] as &$cart) { - $_cartNum++; - if ($cart['product']['cate_id']) { - if (!isset($catePriceLst[$cart['product']['cate_id']])) { - $catePriceLst[$cart['product']['cate_id']] = ['price' => 0, 'cart' => []]; - } - $catePriceLst[$cart['product']['cate_id']]['price'] = bcadd($catePriceLst[$cart['product']['cate_id']]['price'], $cart['true_price']); - $catePriceLst[$cart['product']['cate_id']]['cart'][] = &$cart; - } - } - unset($cart); - $storePriceLst[$merchantCart['mer_id']] = [ - 'price' => $merchantCart['order']['true_price'], - 'num' => count($merchantCart['list']) - ]; - } - unset($merchantCart); - $flag = false; - $platformCouponRate = null; - - foreach ($platformCoupon as &$coupon) { - $coupon['checked'] = false; - //通用券 - if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_ALL) { - $coupon['disabled'] = $total_true_price <= 0 || $coupon['use_min_price'] > $total_true_price; - if (!$platformCouponRate && !$coupon['disabled'] && !$flag && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) { - $platformCouponRate = [ - 'id' => $coupon['coupon_user_id'], - 'type' => $coupon['coupon']['type'], - 'price' => $total_true_price, - 'coupon_price' => $coupon['coupon_price'], - 'use_count' => $_cartNum, - 'check' => function ($cart) { - return true; - } - ]; - $coupon['checked'] = true; - $flag = true; - } - //品类券 - } else if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_CATE) { - $_price = 0; - $_use_count = 0; - $cateIds = $coupon['product']->column('product_id'); - $allCateIds = array_unique(array_merge(app()->make(StoreCategoryRepository::class)->allChildren($cateIds), $cateIds)); - $flag2 = true; - foreach ($allCateIds as $cateId) { - if (isset($catePriceLst[$cateId])) { - $_price = bcadd($catePriceLst[$cateId]['price'], $_price, 2); - $_use_count += count($catePriceLst[$cateId]['cart']); - $flag2 = false; - } - } - $coupon['disabled'] = $flag2 || $coupon['use_min_price'] > $_price; - //品类券可用 - if (!$platformCouponRate && !$coupon['disabled'] && !$flag && !$flag2 && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) { - $platformCouponRate = [ - 'id' => $coupon['coupon_user_id'], - 'type' => $coupon['coupon']['type'], - 'price' => $_price, - 'use_cate' => $allCateIds, - 'coupon_price' => $coupon['coupon_price'], - 'use_count' => $_use_count, - 'check' => function ($cart) use ($allCateIds) { - return in_array($cart['product']['cate_id'], $allCateIds); - } - ]; - $coupon['checked'] = true; - $flag = true; - } - //跨店券 - } else if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_STORE) { - $_price = 0; - $_use_count = 0; - $flag2 = true; - foreach ($coupon['product'] as $item) { - $merId = $item['product_id']; - if (isset($storePriceLst[$merId])) { - $_price = bcadd($storePriceLst[$merId]['price'], $_price, 2); - $_use_count += $storePriceLst[$merId]['num']; - $flag2 = false; - } - } - $coupon['disabled'] = $flag2 || $coupon['use_min_price'] > $_price; - //店铺券可用 - if (!$platformCouponRate && !$coupon['disabled'] && !$flag && !$flag2 && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) { - $_merIds = $coupon['product']->column('product_id'); - $platformCouponRate = [ - 'id' => $coupon['coupon_user_id'], - 'type' => $coupon['coupon']['type'], - 'price' => $_price, - 'use_store' => $_merIds, - 'coupon_price' => $coupon['coupon_price'], - 'use_count' => $_use_count, - 'check' => function ($cart) use ($_merIds) { - return in_array($cart['mer_id'], $_merIds); - } - ]; - $coupon['checked'] = true; - $flag = true; - } - } - } - unset($coupon); + $platformConsumption=[]; + //消费金 + if ($source == 103) { + $ConsumptionWhere = [ + 'uid' => $uid, + 'start_time' => date('Y-m-d H:i:s'), + 'status' => 0, + 'is_fail' => 0 + ]; + $platformConsumption = Db::name('store_consumption_user')->where($ConsumptionWhere)->limit(100)->order('create_time', 'desc')->select(); } // } $usePlatformCouponId = 0; $total_platform_coupon_price = 0; - //计算平台优惠券 - if (isset($platformCouponRate)) { - $_coupon_price = $platformCouponRate['coupon_price']; - foreach ($merchantCartList as &$merchantCart) { - $_ids = array_column($merchantCart['list'], 'cart_id'); - usort($merchantCart['list'], function ($a, $b) { - return $a['true_price'] > $b['true_price'] ? 1 : -1; - }); - $_price = 0; - foreach ($merchantCart['list'] as &$cart) { - if ($cart['true_price'] <= 0 || !$platformCouponRate['check']($cart)) continue; - if ($platformCouponRate['use_count'] === 1) { - $couponPrice = min($platformCouponRate['coupon_price'], $cart['true_price']); - } else { - $couponPrice = min(max(0.01, bcmul($_coupon_price, bcdiv($cart['true_price'], $platformCouponRate['price'], 6), 2)), $cart['true_price']); - } - $platformCouponRate['coupon_price'] = bcsub($platformCouponRate['coupon_price'], $couponPrice, 2); - $cart['true_price'] = bcsub($cart['true_price'], $couponPrice, 2); - $cart['platform_coupon_price'] = $couponPrice; - $platformCouponRate['use_count']--; - $_price = bcadd($couponPrice, $_price, 2); - } - unset($cart); - $merchantCart['order']['platform_coupon_price'] = $_price; - $merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], $_price, 2); - $total_platform_coupon_price = bcadd($total_platform_coupon_price, $_price, 2); - usort($merchantCart['list'], function ($a, $b) use ($_ids) { - return array_search($a['cart_id'], $_ids) > array_search($b['cart_id'], $_ids) ? 1 : -1; - }); - } - $usePlatformCouponId = $platformCouponRate['id']; - unset($merchantCart); - } //积分配置 $sysIntegralConfig = systemConfig(['integral_money', 'integral_status', 'integral_order_rate']); $merIntegralFlag = false;