diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 8a5bf80..f278dec 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -23,6 +23,7 @@ use crmeb\jobs\SendSmsJob; use crmeb\services\SwooleTaskService; use think\exception\ValidateException; use think\facade\Db; +use think\facade\Log; use think\facade\Queue; class StoreOrderCreateRepository extends StoreOrderRepository @@ -694,6 +695,46 @@ class StoreOrderCreateRepository extends StoreOrderRepository $coupon['checked'] = true; $flag = true; } + } else if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_STORE_PRODUCT) { + $_price = 0; + $_use_count = 0; + $flag2 = true; + $productIds = array(); + foreach ($coupon['product'] as $product){ + $productIds[] = $product->product_id; + } + $maxPriceProductId = 0; + foreach ($merchantCartList as $merchantCart) { + foreach ($merchantCart['list'] as $cart) { + if(in_array($cart['product_id'], $productIds)){ + if($_price < $cart['product']['price']){ + $_price = $cart['product']['price']; + $maxPriceProductId = $cart['product']['product_id']; + Log::info($_price); + } + $_use_count = 1; + $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_store' => $maxPriceProductId, + 'coupon_price' => $_price, + 'use_count' => $_use_count, + 'check' => function ($cart) use ($maxPriceProductId) { + return $cart['product_id'] == $maxPriceProductId; + } + ]; + $coupon['checked'] = true; + $flag = true; + } } } unset($coupon); diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index c7116f7..19ed07c 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -26,6 +26,8 @@ use app\common\repositories\store\product\SpuRepository; use app\common\repositories\store\shipping\ShippingTemplateRepository; use app\common\repositories\store\StoreCategoryRepository; use app\common\repositories\system\attachment\AttachmentRepository; +use app\common\repositories\system\config\ConfigClassifyRepository; +use app\common\repositories\system\config\ConfigValueRepository; use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserRelationRepository; use app\common\repositories\user\UserRepository; @@ -254,6 +256,17 @@ class MerchantRepository extends BaseRepository $userRepository->update($user['uid'], ['mer_id' => $merchant['mer_id']]); } + /** @var ConfigClassifyRepository $make */ + $make = app()->make(ConfigClassifyRepository::class); + $cid = $make->keyById("integral"); + if($cid){ + $children = array_column($make->children($cid, 'config_classify_id')->toArray(), 'config_classify_id'); + $children[] = $cid; + + $configValue = app()->make(ConfigValueRepository::class); + $configValue->save($children, array('mer_integral_rate' => 100, 'mer_integral_status' => '1'), $merchant['mer_id']); + } + return $merchant; }); } diff --git a/app/common/repositories/user/UserAssetsLogRepository.php b/app/common/repositories/user/UserAssetsLogRepository.php index 9f4e2dd..9f15a76 100644 --- a/app/common/repositories/user/UserAssetsLogRepository.php +++ b/app/common/repositories/user/UserAssetsLogRepository.php @@ -140,9 +140,11 @@ class UserAssetsLogRepository extends BaseRepository // 获取商品详情(奖励积分 $product = $this->productRepository->detail($orderProduct['product_id'], null); Log::info("product" . json_encode($product)); - $rate = floatval($orderProduct['total_price']) / floatval($orderProduct['product_price']) * 100; - if ($rate >= $product['cash_rate']) { - $base += $product['base']; + if($orderProduct['total_price']){ + $rate = floatval($orderProduct['product_price']) / floatval($orderProduct['total_price']) * 100; + if ($rate >= $product['cash_rate']) { + $base += $product['base'] * $orderProduct['product_num']; + } } } @@ -566,12 +568,13 @@ class UserAssetsLogRepository extends BaseRepository // 5. 本人使用的福利积分 if ($orderItem['integral']) { $consume = $welfare = $huitong = $contribution = 0; + $welfare = $orderItem['integral']; $log = array('uid' => $orderItem['uid'], 'asset_type' => self::ASSET_TYPE_WELFARE, 'type' => self::CHANGE_TYPE_ORDER, 'status' => self::STATUS_USED, 'order_id' => $orderItem['order_id'], - 'count' => $orderItem['integral'], + 'count' => -$orderItem['integral'], ); $this->addLog([$log]); $this->userAssetsRepository->orderEvent($orderItem['uid'], self::STATUS_USED, compact('consume', 'welfare', 'huitong', 'contribution')); @@ -630,9 +633,9 @@ class UserAssetsLogRepository extends BaseRepository $usedList = $this->_getOrderData($orderItem['order_id'], self::STATUS_USED); if ($usedList) { foreach ($usedList as $used) { - if ($used['welfare'] > 0) { + if ($used['welfare']) { $info = $this->userAssetsRepository->get($used['uid']); - $this->userAssetsRepository->update($used['uid'], array('welfare' => $info['welfare'] + $used['welfare'])); + $this->userAssetsRepository->update($used['uid'], array('welfare' => $info['welfare'] - $used['welfare'])); } } }