From eb20948bcb43edc78ea175ace216f2bec3e804b9 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Thu, 29 Feb 2024 17:01:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BA=BF=E4=B8=8B=E6=89=AB?= =?UTF-8?q?=E7=A0=81=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/store/order/StoreCart.php | 2 +- app/common/model/store/product/Product.php | 12 +++++++ .../order/StoreOrderCreateRepository.php | 26 +++++++++++++- .../store/product/ProductRepository.php | 10 ++++++ app/controller/api/store/order/ScanPay.php | 35 +++++++++++++++++++ app/controller/api/store/order/StoreCart.php | 6 +++- route/api.php | 1 + 7 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 app/controller/api/store/order/ScanPay.php diff --git a/app/common/model/store/order/StoreCart.php b/app/common/model/store/order/StoreCart.php index 083e8244..6c9ca574 100755 --- a/app/common/model/store/order/StoreCart.php +++ b/app/common/model/store/order/StoreCart.php @@ -182,7 +182,7 @@ class StoreCart extends BaseModel switch ($this->product_type) { case 0: //普通商品 - if ($this->product->product_type !== 0 || $this->product->is_show !== 1 || $this->productAttr->stock < $this->cart_num || $this->product->is_used !== 1) { + if (($this->product->product_type !== 0 || $this->product->is_show !== 1 || $this->productAttr->stock < $this->cart_num || $this->product->is_used !== 1) && !$this->product->isPickupCard()) { return false; } break; diff --git a/app/common/model/store/product/Product.php b/app/common/model/store/product/Product.php index 48fb0728..57a11f2b 100755 --- a/app/common/model/store/product/Product.php +++ b/app/common/model/store/product/Product.php @@ -601,4 +601,16 @@ class Product extends BaseModel return false; } + /** + * 判断是否为实物提货券 + * @return bool + */ + public function isPickupCard() + { + if (!empty($this->cate_id) && $this->cate_id == env('PICKUP_CARD_CATE_ID')) { + return true; + } + return false; + } + } diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index cb0fbb8e..18b07b03 100755 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -31,6 +31,7 @@ use crmeb\jobs\SendSmsJob; use crmeb\services\SwooleTaskService; use crmeb\utils\Curl; use think\exception\ValidateException; +use think\facade\Cache; use think\facade\Db; use think\facade\Queue; @@ -84,6 +85,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository $activityProductCount = 0; //判断是否是平台购物卡,购物卡不允许使用任何优惠券 $isPlatformCard = $merchantCartList[0]['list'][0]['product']->isPlatformCard(); + $isPickupCard = $merchantCartList[0]['list'][0]['product']->isPickupCard(); + if ($isPickupCard) { + $totalAmount = Cache::get('cart_id_' . $cartId[0]); + if (empty($totalAmount)) { + throw new ValidateException('数据已过期,请重新扫码下单'); + } + } if ($isPlatformCard) { $merchantTypeId = Merchant::where('uid', $uid)->value('type_id'); if (empty($merchantTypeId) || $merchantTypeId != 21) { @@ -267,7 +275,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $enabledCoupon = !($order_type && $order_type != 2); //只有预售和普通商品可以用优惠券 - if (!$enabledCoupon || $isPlatformCard) { + if (!$enabledCoupon || $isPlatformCard || $isPickupCard) { $merchantCart['coupon'] = []; } $svip_coupon_merge = merchantConfig($merchantCart['mer_id'], 'svip_coupon_merge'); @@ -293,12 +301,18 @@ class StoreOrderCreateRepository extends StoreOrderRepository $cart['productAttr']['stock'] = $cart['cart_num']; } $price = bcmul($cart['cart_num'], $realPrice, 2); + if ($isPickupCard && !empty($totalAmount)) { + $price = $totalAmount; + } $cart['total_price'] = $price; $cart['postage_price'] = 0; $cart['svip_discount'] = 0; $total_price = bcadd($total_price, $price, 2); $total_num += $cart['cart_num']; $_price = bcmul($cart['cart_num'], $this->cartByCouponPrice($cart), 2); + if ($isPickupCard && !empty($totalAmount)) { + $_price = $totalAmount; + } $cart['svip_coupon_merge'] = 1; if ($cart['productAttr']['show_svip_price'] && !$cart['product_type']) { $svip_discount = max(bcmul($cart['cart_num'], bcsub($cart['productAttr']['org_price'] ?? 0, $cart['productAttr']['price'], 2), 2), 0); @@ -470,6 +484,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository $orderProcurePrice = 0; foreach ($merchantCart['list'] as $_k => &$cart) { $cartTotalPrice = bcmul($this->cartByPrice($cart), $cart['cart_num'], 2); + if ($isPickupCard && !empty($totalAmount)) { + $cartTotalPrice = $totalAmount; + } $_cartTotalPrice = $cartTotalPrice; //单个商品实际支付金额 @@ -697,6 +714,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository } unset($merchantCart); $status = ($address || $order_model || $allow_no_address) ? ($noDeliver ? 'noDeliver' : 'finish') : 'noAddress'; + if ($isPickupCard) { + $status = 'finish'; + } $order = $merchantCartList; $consumption_money = $this->consumption_money; $order_price = $groupOrderPayPrice; @@ -831,6 +851,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository $total_extension_one = 0; $total_extension_two = 0; //计算佣金和赠送的优惠券 + $isPickupCard = $merchantCart['list'][0]['product']->isPickupCard(); foreach ($merchantCart['list'] as &$cart) { $cartIds[] = $cart['cart_id']; $giveCouponIds = array_merge($giveCouponIds, $cart['product']['give_coupon_ids'] ?: []); @@ -851,6 +872,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository } else if (isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0) { $rate = bcmul($merchantCart['merchantCategory']['commission_rate'], 100, 4); } + if ($isPickupCard) { + $rate = 0; + } $user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['village'] . $address['brigade'] . $address['detail']) : ''; $user_address_code = isset($address) ? ($address['province_code'] . ',' . $address['city_code'] . ',' . $address['district_code'] . ',' . $address['street_code'] . ',' . $address['village_code'] . ',' . $address['brigade_id']) : ''; //整理订单数据 diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 6df2b81e..7d157bdc 100755 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -115,6 +115,10 @@ class ProductRepository extends BaseRepository 'msg' => '被下架' ], ]; + + /** @var bool $force 忽略商品状态 */ + public $force = false; + /** * ProductRepository constructor. * @param dao $dao @@ -1206,6 +1210,9 @@ class ProductRepository extends BaseRepository 'mer_status' => 1, 'product_id' => $id ]; + if ($this->force === true) { + unset($where['is_show']); + } return $this->apiProductDetail($where, $product_type, null, $userInfo); } @@ -1955,6 +1962,9 @@ class ProductRepository extends BaseRepository { $cart = null; $where = $this->dao->productShow(); + if ($data['source'] == 999) { + unset($where['is_show']); + } $where['product_id'] = $data['product_id']; $where['product_type'] = $data['product_type']; unset($where['is_gift_bag']); diff --git a/app/controller/api/store/order/ScanPay.php b/app/controller/api/store/order/ScanPay.php new file mode 100644 index 00000000..2e7ef030 --- /dev/null +++ b/app/controller/api/store/order/ScanPay.php @@ -0,0 +1,35 @@ +request->get('mer_id'); + $cateId = env('PICKUP_CARD_CATE_ID'); + $product = Product::where('mer_id', $merId)->where('cate_id', $cateId)->find(); + if (empty($product)) { + return app('json')->fail('商品已下架'); + } + $param = $this->request->params(['type', ['product_type', 0]]); + /** @var ProductRepository $productRepo */ + $productRepo = app()->make(ProductRepository::class); + $productRepo->force = true; + $data = $productRepo->detail((int)$product['product_id'], $this->request->userInfo, $param['product_type']); + if (!$data){ + return app('json')->fail('商品已下架'); + } + return app('json')->success($data); + } + +} diff --git a/app/controller/api/store/order/StoreCart.php b/app/controller/api/store/order/StoreCart.php index c9588abb..a46a24fb 100755 --- a/app/controller/api/store/order/StoreCart.php +++ b/app/controller/api/store/order/StoreCart.php @@ -31,6 +31,7 @@ use crmeb\basic\BaseController; use app\validate\api\StoreCartValidate as validate; use app\common\repositories\store\order\StoreCartRepository as repository; use think\exception\ValidateException; +use think\facade\Cache; use think\facade\Log; class StoreCart extends BaseController @@ -142,6 +143,9 @@ class StoreCart extends BaseController } $cart = $storeCart = $this->repository->create($data); } + if (isset($data['total_amount'])) { + Cache::set('cart_id_' . $cart['cart_id'], $data['total_amount'], 600); + } event('user.cart', compact('user','storeCart')); return app('json')->success(['cart_id' => $cart['cart_id']]); } @@ -255,7 +259,7 @@ class StoreCart extends BaseController */ public function checkParams(validate $validate) { - $data = $this->request->params(['product_id','product_attr_unique','cart_num','is_new',['product_type',0],['group_buying_id',0],['spread_id',0], 'referer',['source',2]]); + $data = $this->request->params(['product_id','product_attr_unique','cart_num','is_new',['product_type',0],['group_buying_id',0],['spread_id',0], 'referer',['source',2], 'total_amount']); $validate->check($data); if ($data['spread_id']) { if ($data['spread_id'] !== $this->request->userInfo()->uid){ diff --git a/route/api.php b/route/api.php index df6a6d29..fa2bab8e 100755 --- a/route/api.php +++ b/route/api.php @@ -47,6 +47,7 @@ Route::group('api/', function () { //强制登录 Route::group(function () { + Route::get('scanPay/product', 'api.store.order.ScanPay/product'); Route::any('qrcode', 'api.user.User/qrcode'); Route::get('merchantRecord', 'api.user.User/merchantRecord');