From c97602e31832d93610660248898763815930a1bc Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 13 Mar 2024 11:43:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81=E6=89=B9?= =?UTF-8?q?=E5=8F=91=E4=BB=B7=E6=A0=BC=EF=BC=8C=E8=B0=83=E6=95=B4=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=B4=A6=E5=8F=B7=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/order/StoreCartDao.php | 4 +-- .../dao/system/merchant/MerchantTypeDao.php | 6 ++++ app/common/middleware/UserTokenMiddleware.php | 2 ++ app/common/model/system/merchant/Merchant.php | 9 +++++ app/common/model/user/User.php | 10 ++++++ .../order/StoreOrderCreateRepository.php | 10 ++++-- .../store/order/StoreOrderRepository.php | 10 ++++-- .../merchant/MerchantTypeRepository.php | 4 +-- app/controller/api/Auth.php | 36 ++++++++++--------- .../api/store/merchant/MerchantIntention.php | 2 +- 10 files changed, 66 insertions(+), 27 deletions(-) diff --git a/app/common/dao/store/order/StoreCartDao.php b/app/common/dao/store/order/StoreCartDao.php index dd3daa6c..26944a5f 100644 --- a/app/common/dao/store/order/StoreCartDao.php +++ b/app/common/dao/store/order/StoreCartDao.php @@ -101,11 +101,11 @@ class StoreCartDao extends BaseDao } }, 'productAttr' => function (Relation $query) { - $query->field('value_id,image,extension_one,extension_two,product_id,stock,price,unique,sku,volume,weight,ot_price,cost,svip_price') + $query->field('value_id,image,extension_one,extension_two,product_id,stock,price,unique,sku,volume,weight,ot_price,cost,svip_price,wholesale_price') ->append(['bc_extension_one', 'bc_extension_two']); }, 'merchant' => function (Relation $query) use ($uid) { - $query->field('mer_id,mer_name,mer_state,mer_avatar,delivery_way,commission_rate,category_id') + $query->field('mer_id,mer_name,mer_state,mer_avatar,delivery_way,commission_rate,category_id,wholesale') ->with([ 'coupon' => function ($query) use ($uid) { $query->where('uid', $uid); diff --git a/app/common/dao/system/merchant/MerchantTypeDao.php b/app/common/dao/system/merchant/MerchantTypeDao.php index 8d69652c..ff18607d 100644 --- a/app/common/dao/system/merchant/MerchantTypeDao.php +++ b/app/common/dao/system/merchant/MerchantTypeDao.php @@ -28,6 +28,12 @@ class MerchantTypeDao extends BaseDao public function search(array $where = []) { return MerchantType::getDB() + ->when(isset($where['is_allow_apply']) && $where['is_allow_apply'] !== '',function($query) use($where){ + $query->where('is_allow_apply', $where['is_allow_apply']); + }) + ->when(isset($where['is_search_display']) && $where['is_search_display'] !== '',function($query) use($where){ + $query->where('is_search_display', $where['is_search_display']); + }) ->when(isset($where['mer_type_id']) && $where['mer_type_id'] !== '',function($query) use($where){ $query->where('mer_type_id',$where['mer_type_id']); }); diff --git a/app/common/middleware/UserTokenMiddleware.php b/app/common/middleware/UserTokenMiddleware.php index bc0e6250..fb2fc66e 100644 --- a/app/common/middleware/UserTokenMiddleware.php +++ b/app/common/middleware/UserTokenMiddleware.php @@ -65,6 +65,8 @@ class UserTokenMiddleware extends BaseMiddleware throw new AuthException('用户不存在'); if (!$user['status']) throw new AuthException('用户已被禁用'); + if ($user['status'] == -1) + throw new AuthException('当前账号已合并,请重新登录'); if ($user['cancel_time']) throw new AuthException('用户不存在'); diff --git a/app/common/model/system/merchant/Merchant.php b/app/common/model/system/merchant/Merchant.php index efca6f6a..7422a975 100644 --- a/app/common/model/system/merchant/Merchant.php +++ b/app/common/model/system/merchant/Merchant.php @@ -288,4 +288,13 @@ class Merchant extends BaseModel return null; } + /** + * 判断是否为批发商 + * @return bool + */ + public function isWholeSale() + { + return $this->wholesale == 1; + } + } diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index a357f57a..e207142f 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -16,6 +16,7 @@ namespace app\common\model\user; use app\common\model\BaseModel; use app\common\model\store\service\StoreService; +use app\common\model\system\merchant\Merchant; use app\common\model\wechat\WechatUser; use app\common\repositories\store\coupon\StoreCouponUserRepository; use app\common\repositories\store\order\StoreGroupOrderRepository; @@ -377,4 +378,13 @@ class User extends BaseModel return $value; } + /** + * 获取商户id + * @return mixed + */ + public function getMerId() + { + return Merchant::where('uid', $this->uid)->value('mer_id'); + } + } diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 2e8e6662..ddc6fba8 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -78,8 +78,12 @@ class StoreOrderCreateRepository extends StoreOrderRepository $order_total_postage = 0; $orderDeliveryStatus = true; $order_svip_discount = 0; + //下单用户关联的商户id + $merId = $user->getMerId(); // 循环计算每个店铺的订单数据 foreach ($merchantCartList as &$merchantCart) { + //用户关联了商户id且下单店铺支持批发 + $isWholeSale = $merchantCart['wholesale'] == 1 && $merId > 0; $postageRule = []; $total_price = 0; $total_num = 0; @@ -195,13 +199,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository throw new ValidateException('购买商品数必须大于0'); } $svip_discount = 0; - $price = bcmul($cart['cart_num'], $this->cartByPrice($cart), 2); + $price = bcmul($cart['cart_num'], $this->cartByPrice($cart, $isWholeSale), 2); $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); + $_price = bcmul($cart['cart_num'], $this->cartByCouponPrice($cart, $isWholeSale), 2); $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); @@ -462,7 +466,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository //计算单个商品实际支付金额 foreach ($merchantCart['list'] as $_k => &$cart) { - $cartTotalPrice = bcmul($this->cartByPrice($cart), $cart['cart_num'], 2); + $cartTotalPrice = bcmul($this->cartByPrice($cart, $isWholeSale), $cart['cart_num'], 2); $_cartTotalPrice = $cartTotalPrice; if (!$cart['product_type'] && $cartTotalPrice > 0) { if (isset($productCouponRate[$cart['product_id']])) { diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index a8960366..bdbe7256 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -497,8 +497,11 @@ class StoreOrderRepository extends BaseRepository } } - public function cartByPrice($cart) + public function cartByPrice($cart, $isWholesale = false) { + if ($isWholesale) { + return $cart['productAttr']['wholesale_price']; + } if ($cart['product_type'] == '2') { return $cart['productPresellAttr']['presell_price']; } else if ($cart['product_type'] == '3') { @@ -510,8 +513,11 @@ class StoreOrderRepository extends BaseRepository } } - public function cartByCouponPrice($cart) + public function cartByCouponPrice($cart, $isWholesale = false) { + if ($isWholesale) { + return $cart['productAttr']['wholesale_price']; + } if ($cart['product_type'] == '2') { return $cart['productPresellAttr']['final_price']; } else if ($cart['product_type'] == '1') { diff --git a/app/common/repositories/system/merchant/MerchantTypeRepository.php b/app/common/repositories/system/merchant/MerchantTypeRepository.php index 31af8fae..0695a11d 100644 --- a/app/common/repositories/system/merchant/MerchantTypeRepository.php +++ b/app/common/repositories/system/merchant/MerchantTypeRepository.php @@ -44,9 +44,9 @@ class MerchantTypeRepository extends BaseRepository return compact('count', 'list'); } - public function getSelect() + public function getSelect($where = []) { - $query = $this->search([])->field('mer_type_id,type_name'); + $query = $this->search($where)->field('mer_type_id,type_name'); return $query->select()->toArray(); } diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index f79c70d7..13ece6a2 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -813,28 +813,12 @@ class Auth extends BaseController if (!empty($user)) { Db::startTrans(); try { - StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreOrderProduct::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - UserBill::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - FinancialRecord::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); - UserAddress::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreCouponUser::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreCouponDetail::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreRefundOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - UserRecharge::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - StoreOrderStatus::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); - if ($user->now_money > 0) { - $user->now_money = 0; - $targetUser->now_money = bcadd($targetUser->now_money, $user->now_money, 2); - $targetUser->save(); - } $merchant = Merchant::where('uid', $targetUser['uid'])->find(); if (!empty($merchant)) { $orders = StoreOrder::with(['refundOrder' => function(Query $query) { $query->where('status', '<>', -1)->field('order_id,refund_price'); }])->where('uid', $user['uid']) - ->whereIn('status', [0, 1, 2, 3, 9, 10]) + ->whereIn('status', [2, 3]) ->field('order_id,uid,total_price') ->select()->toArray(); $purchaseAmount = 0; @@ -850,7 +834,25 @@ class Auth extends BaseController $merchant->save(); } } + StoreGroupOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrderProduct::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + UserBill::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + FinancialRecord::where('user_id', $user['uid'])->update(['user_id' => $targetUser['uid']]); + UserAddress::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreCouponUser::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreCouponDetail::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreRefundOrder::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + UserRecharge::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + StoreOrderStatus::where('uid', $user['uid'])->update(['uid' => $targetUser['uid']]); + if ($user->now_money > 0) { + $targetUser->now_money = bcadd($targetUser->now_money, $user->now_money, 2); + $user->now_money = 0; + $targetUser->save(); + } $user->wechat_user_id = 0; + $user->account = 'uid_' . $targetUser['uid']; + $user->status = -1; $user->save(); Db::commit(); } catch (\Throwable $e) { diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index 19f3fe8c..3d80d359 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -366,7 +366,7 @@ class MerchantIntention extends BaseController public function typeLst() { - $lst = app()->make(MerchantTypeRepository::class)->getSelect(); + $lst = app()->make(MerchantTypeRepository::class)->getSelect(['is_allow_apply' => 1, 'is_search_display' => 1]); return app('json')->success($lst); } }