Merge branch 'dev' of https://gitea.lihaink.cn/mkm/shop-new into dev
This commit is contained in:
commit
27c86f1a8d
@ -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);
|
||||
|
@ -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']);
|
||||
});
|
||||
|
@ -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('用户不存在');
|
||||
|
||||
|
@ -288,4 +288,13 @@ class Merchant extends BaseModel
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为批发商
|
||||
* @return bool
|
||||
*/
|
||||
public function isWholeSale()
|
||||
{
|
||||
return $this->wholesale == 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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']])) {
|
||||
|
@ -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') {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user