添加线下扫码支付

This commit is contained in:
luofei 2024-02-29 17:01:17 +08:00
parent 6c4ce77c83
commit eb20948bcb
7 changed files with 89 additions and 3 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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']) : '';
//整理订单数据

View File

@ -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']);

View File

@ -0,0 +1,35 @@
<?php
namespace app\controller\api\store\order;
use app\common\model\store\product\Product;
use app\common\repositories\store\product\ProductRepository;
use crmeb\basic\BaseController;
/**
* Class ScanPay
* @package app\controller\api\store\ScanPay
*/
class ScanPay extends BaseController
{
public function product()
{
$merId = $this->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);
}
}

View File

@ -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){

View File

@ -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');