Merge branch 'develop'
This commit is contained in:
commit
505f542d44
47
app/common/model/system/supplychain/SupplyChainBorkerage.php
Normal file
47
app/common/model/system/supplychain/SupplyChainBorkerage.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\system\supplychain;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
// 供应链佣金记录表
|
||||
class SupplyChainBorkerage extends BaseModel
|
||||
{
|
||||
|
||||
// 设置当前模型的数据库连接
|
||||
protected $connection = 'nongke';
|
||||
protected $table = 'fa_supply_brokerage';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'fa_supply_brokerage';
|
||||
}
|
||||
|
||||
}
|
@ -17,6 +17,7 @@ use app\common\repositories\user\UserAddressRepository;
|
||||
use app\common\repositories\user\UserBillRepository;
|
||||
use app\common\repositories\user\UserMerchantRepository;
|
||||
use app\common\repositories\user\UserRepository;
|
||||
use app\common\model\system\supplychain\SupplyChainLinkMerchant;
|
||||
use app\validate\api\OrderVirtualFieldValidate;
|
||||
use app\validate\api\UserAddressValidate;
|
||||
use crmeb\jobs\SendSmsJob;
|
||||
@ -971,133 +972,232 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$cartIds = [];
|
||||
$orderList = [];
|
||||
$user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['detail']) : '';
|
||||
foreach ($merchantCartList as $k => $merchantCart) {
|
||||
$cost = 0;
|
||||
$total_extension_one = 0;
|
||||
$total_extension_two = 0;
|
||||
//计算佣金和赠送的优惠券
|
||||
foreach ($merchantCart['list'] as &$cart) {
|
||||
|
||||
$cartIds[] = $cart['cart_id'];
|
||||
$giveCouponIds = array_merge($giveCouponIds, $cart['product']['give_coupon_ids'] ?: []);
|
||||
$cart['cost'] = $cart['productAttr']['cost'];
|
||||
$cost = bcadd(bcmul($cart['cost'], $cart['cart_num'], 2), $cost, 2);
|
||||
$extension_one = 0;
|
||||
$extension_two = 0;
|
||||
if ($ex) {
|
||||
//预售订单
|
||||
if ($orderType == 2) {
|
||||
$_payPrice = $merchantCart['order']['pay_price'];
|
||||
$rate = $cart['productPresell']['presell_type'] == 2 ? bcdiv($cart['productPresellAttr']['down_price'], $cart['productPresellAttr']['presell_price'], 3) : 1;
|
||||
$one_price = $_payPrice > 0 ? bcdiv($_payPrice, $cart['cart_num'], 2) : 0;
|
||||
if ($spreadUid && $cart['productPresellAttr']['bc_extension_one'] > 0) {
|
||||
$org_extension = $cart['productPresellAttr']['bc_extension_one'];
|
||||
if ($spreadUser->brokerage_level > 0 && $spreadUser->brokerage && $spreadUser->brokerage->extension_one_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $spreadUser->brokerage->extension_one_rate, 2);
|
||||
// 验证下单来源,如果是普通来源,则执行分销推广佣金分配
|
||||
if($source == 2) // 普通商品
|
||||
{
|
||||
// 分销推广佣金
|
||||
foreach ($merchantCartList as $k => $merchantCart) {
|
||||
|
||||
$cost = 0;
|
||||
$total_extension_one = 0;
|
||||
$total_extension_two = 0;
|
||||
|
||||
//计算佣金和赠送的优惠券
|
||||
foreach ($merchantCart['list'] as &$cart) {
|
||||
|
||||
$cartIds[] = $cart['cart_id'];
|
||||
$giveCouponIds = array_merge($giveCouponIds, $cart['product']['give_coupon_ids'] ?: []);
|
||||
$cart['cost'] = $cart['productAttr']['cost'];
|
||||
$cost = bcadd(bcmul($cart['cost'], $cart['cart_num'], 2), $cost, 2);
|
||||
|
||||
$extension_one = 0; // 一级
|
||||
$extension_two = 0; // 二级
|
||||
|
||||
if ($ex) {
|
||||
|
||||
//预售订单
|
||||
if ($orderType == 2) {
|
||||
|
||||
// 实际支付金额
|
||||
$_payPrice = $merchantCart['order']['pay_price'];
|
||||
|
||||
$rate = $cart['productPresell']['presell_type'] == 2 ? bcdiv($cart['productPresellAttr']['down_price'], $cart['productPresellAttr']['presell_price'], 3) : 1;
|
||||
|
||||
$one_price = $_payPrice > 0 ? bcdiv($_payPrice, $cart['cart_num'], 2) : 0;
|
||||
if ($spreadUid && $cart['productPresellAttr']['bc_extension_one'] > 0) {
|
||||
$org_extension = $cart['productPresellAttr']['bc_extension_one'];
|
||||
if ($spreadUser->brokerage_level > 0 && $spreadUser->brokerage && $spreadUser->brokerage->extension_one_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $spreadUser->brokerage->extension_one_rate, 2);
|
||||
}
|
||||
$_extension_one = bcmul($rate, $org_extension, 3);
|
||||
$presell_extension_one = 0;
|
||||
if ($cart['true_price'] > 0) {
|
||||
$extension_one = bcmul(bcdiv($one_price, $cart['productPresellAttr']['down_price'], 3), $_extension_one, 2);
|
||||
}
|
||||
if ($rate < 1) {
|
||||
$presell_extension_one = bcmul(1 - $rate, $org_extension, 2);
|
||||
}
|
||||
$cart['final_extension_one'] = bcmul($extension_one, $cart['cart_num'], 2);
|
||||
$extension_one = bcadd($extension_one, $presell_extension_one, 2);
|
||||
$cart['presell_extension_one'] = bcmul($presell_extension_one, $cart['cart_num'], 2);
|
||||
}
|
||||
$_extension_one = bcmul($rate, $org_extension, 3);
|
||||
$presell_extension_one = 0;
|
||||
if ($cart['true_price'] > 0) {
|
||||
$extension_one = bcmul(bcdiv($one_price, $cart['productPresellAttr']['down_price'], 3), $_extension_one, 2);
|
||||
if ($topUid && $cart['productPresellAttr']['bc_extension_two'] > 0) {
|
||||
$org_extension = $cart['productPresellAttr']['bc_extension_two'];
|
||||
if ($topUser->brokerage_level > 0 && $topUser->brokerage && $topUser->brokerage->extension_two_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $topUser->brokerage->extension_two_rate, 2);
|
||||
}
|
||||
$_extension_two = bcmul($rate, $org_extension, 2);
|
||||
$presell_extension_two = 0;
|
||||
if ($cart['true_price'] > 0) {
|
||||
$extension_two = bcmul(bcdiv($one_price, $cart['productPresellAttr']['down_price'], 3), $_extension_two, 2);
|
||||
}
|
||||
if ($rate < 1) {
|
||||
$presell_extension_two = bcmul(1 - $rate, $org_extension, 2);
|
||||
}
|
||||
$cart['final_extension_two'] = bcmul($extension_two, $cart['cart_num'], 2);;
|
||||
$extension_two = bcadd($extension_two, $presell_extension_two, 2);
|
||||
$cart['presell_extension_two'] = bcmul($presell_extension_two, $cart['cart_num'], 2);
|
||||
}
|
||||
if ($rate < 1) {
|
||||
$presell_extension_one = bcmul(1 - $rate, $org_extension, 2);
|
||||
} else if (!$orderType) {
|
||||
if ($spreadUid && $cart['productAttr']['bc_extension_one'] > 0) {
|
||||
$org_extension = $cart['productAttr']['bc_extension_one'];
|
||||
if ($spreadUser->brokerage_level > 0 && $spreadUser->brokerage && $spreadUser->brokerage->extension_one_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $spreadUser->brokerage->extension_one_rate, 2);
|
||||
}
|
||||
$extension_one = $cart['true_price'] > 0 ? bcmul(bcdiv($cart['true_price'], $cart['total_price'], 3), $org_extension, 2) : 0;
|
||||
}
|
||||
$cart['final_extension_one'] = bcmul($extension_one, $cart['cart_num'], 2);
|
||||
$extension_one = bcadd($extension_one, $presell_extension_one, 2);
|
||||
$cart['presell_extension_one'] = bcmul($presell_extension_one, $cart['cart_num'], 2);
|
||||
}
|
||||
if ($topUid && $cart['productPresellAttr']['bc_extension_two'] > 0) {
|
||||
$org_extension = $cart['productPresellAttr']['bc_extension_two'];
|
||||
if ($topUser->brokerage_level > 0 && $topUser->brokerage && $topUser->brokerage->extension_two_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $topUser->brokerage->extension_two_rate, 2);
|
||||
if ($topUid && $cart['productAttr']['bc_extension_two'] > 0) {
|
||||
$org_extension = $cart['productAttr']['bc_extension_two'];
|
||||
if ($topUser->brokerage_level > 0 && $topUser->brokerage && $topUser->brokerage->extension_two_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $topUser->brokerage->extension_two_rate, 2);
|
||||
}
|
||||
$extension_two = $cart['true_price'] > 0 ? bcmul(bcdiv($cart['true_price'], $cart['total_price'], 3), $org_extension, 2) : 0;
|
||||
}
|
||||
$_extension_two = bcmul($rate, $org_extension, 2);
|
||||
$presell_extension_two = 0;
|
||||
if ($cart['true_price'] > 0) {
|
||||
$extension_two = bcmul(bcdiv($one_price, $cart['productPresellAttr']['down_price'], 3), $_extension_two, 2);
|
||||
}
|
||||
if ($rate < 1) {
|
||||
$presell_extension_two = bcmul(1 - $rate, $org_extension, 2);
|
||||
}
|
||||
$cart['final_extension_two'] = bcmul($extension_two, $cart['cart_num'], 2);;
|
||||
$extension_two = bcadd($extension_two, $presell_extension_two, 2);
|
||||
$cart['presell_extension_two'] = bcmul($presell_extension_two, $cart['cart_num'], 2);
|
||||
}
|
||||
} else if (!$orderType) {
|
||||
if ($spreadUid && $cart['productAttr']['bc_extension_one'] > 0) {
|
||||
$org_extension = $cart['productAttr']['bc_extension_one'];
|
||||
if ($spreadUser->brokerage_level > 0 && $spreadUser->brokerage && $spreadUser->brokerage->extension_one_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $spreadUser->brokerage->extension_one_rate, 2);
|
||||
}
|
||||
$extension_one = $cart['true_price'] > 0 ? bcmul(bcdiv($cart['true_price'], $cart['total_price'], 3), $org_extension, 2) : 0;
|
||||
}
|
||||
if ($topUid && $cart['productAttr']['bc_extension_two'] > 0) {
|
||||
$org_extension = $cart['productAttr']['bc_extension_two'];
|
||||
if ($topUser->brokerage_level > 0 && $topUser->brokerage && $topUser->brokerage->extension_two_rate > 0) {
|
||||
$org_extension = bcmul($org_extension, 1 + $topUser->brokerage->extension_two_rate, 2);
|
||||
}
|
||||
$extension_two = $cart['true_price'] > 0 ? bcmul(bcdiv($cart['true_price'], $cart['total_price'], 3), $org_extension, 2) : 0;
|
||||
}
|
||||
}
|
||||
$cart['extension_one'] = $extension_one;
|
||||
$cart['extension_two'] = $extension_two;
|
||||
$total_extension_one = bcadd($total_extension_one, bcmul($extension_one, $cart['cart_num'], 2), 2);
|
||||
$total_extension_two = bcadd($total_extension_two, bcmul($extension_two, $cart['cart_num'], 2), 2);
|
||||
|
||||
}
|
||||
unset($cart);
|
||||
|
||||
$rate = 0;
|
||||
if ($merchantCart['commission_rate'] > 0) {
|
||||
$rate = $merchantCart['commission_rate'];
|
||||
} else if (isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0) {
|
||||
$rate = bcmul($merchantCart['merchantCategory']['commission_rate'], 100, 4);
|
||||
}
|
||||
|
||||
//整理订单数据
|
||||
$_order = [
|
||||
'cartInfo' => $merchantCart,
|
||||
'activity_type' => $orderInfo['order_type'],
|
||||
'commission_rate' => (float)$rate,
|
||||
'order_type' => $merchantCart['order']['isTake'] ? 1 : 0,
|
||||
'is_virtual' => $order_model ? 1 : 0,
|
||||
'extension_one' => $total_extension_one,
|
||||
'extension_two' => $total_extension_two,
|
||||
'order_sn' => $this->getNewOrderId() . ($k + 1),
|
||||
'uid' => $uid,
|
||||
'spread_uid' => $spreadUid,
|
||||
'top_uid' => $topUid,
|
||||
'is_selfbuy' => $isSelfBuy,
|
||||
'real_name' => $merchantCart['order']['isTake'] ? $post['real_name'] : ($address['real_name'] ?? ''),
|
||||
'user_phone' => $merchantCart['order']['isTake'] ? $post['phone'] : ($address['phone'] ?? ''),
|
||||
'user_address' => $user_address,
|
||||
'cart_id' => implode(',', array_column($merchantCart['list'], 'cart_id')),
|
||||
'total_num' => $merchantCart['order']['total_num'],
|
||||
'total_price' => $merchantCart['order']['total_price'],
|
||||
'total_postage' => $merchantCart['order']['postage_price'],
|
||||
'pay_postage' => $merchantCart['order']['postage_price'],
|
||||
'svip_discount' => $merchantCart['order']['svip_discount'],
|
||||
'pay_price' => $merchantCart['order']['pay_price'],
|
||||
'integral' => $merchantCart['order']['total_integral'],
|
||||
'integral_price' => $merchantCart['order']['total_integral_price'],
|
||||
'give_integral' => $merchantCart['order']['total_give_integral'],
|
||||
'mer_id' => $merchantCart['mer_id'],
|
||||
'cost' => $cost,
|
||||
'order_extend' => count($extend) ? json_encode($extend, JSON_UNESCAPED_UNICODE) : '',
|
||||
'coupon_id' => implode(',', $merchantCart['order']['useCouponIds']),
|
||||
'mark' => $mark[$merchantCart['mer_id']] ?? '',
|
||||
'coupon_price' => bcadd($merchantCart['order']['coupon_price'], $merchantCart['order']['platform_coupon_price'], 2),
|
||||
'platform_coupon_price' => $merchantCart['order']['platform_coupon_price'],
|
||||
'pay_type' => $pay_type,
|
||||
'source' => $source, // 增加订单来源 1 小组采购 2 普同商品
|
||||
];
|
||||
$allUseCoupon = array_merge($allUseCoupon, $merchantCart['order']['useCouponIds']);
|
||||
$orderList[] = $_order;
|
||||
$totalPostage = bcadd($totalPostage, $_order['total_postage'], 2);
|
||||
$totalCost = bcadd($totalCost, $cost, 2);
|
||||
$totalNum += $merchantCart['order']['total_num'];
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是服务小组下单来源,则另行处理
|
||||
if($source == 1)
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* 开始处理小组服务佣金逻辑
|
||||
*
|
||||
*/
|
||||
foreach ($merchantCartList as $k => $merchantCart) {
|
||||
|
||||
$cost = 0;
|
||||
$extension_one = 0; // 一级
|
||||
$extension_two = 0; // 二级
|
||||
$cart['extension_one'] = $extension_one;
|
||||
$cart['extension_two'] = $extension_two;
|
||||
$total_extension_one = bcadd($total_extension_one, bcmul($extension_one, $cart['cart_num'], 2), 2);
|
||||
$total_extension_two = bcadd($total_extension_two, bcmul($extension_two, $cart['cart_num'], 2), 2);
|
||||
$cart['cost'] = $cost;
|
||||
|
||||
}
|
||||
unset($cart);
|
||||
// 开始计算------------------------------------------------------------
|
||||
|
||||
$rate = 0;
|
||||
if ($merchantCart['commission_rate'] > 0) {
|
||||
$rate = $merchantCart['commission_rate'];
|
||||
} else if (isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0) {
|
||||
$rate = bcmul($merchantCart['merchantCategory']['commission_rate'], 100, 4);
|
||||
// 实际支付金额
|
||||
$_payPrice = $merchantCart['order']['pay_price'];
|
||||
// 供应链关联
|
||||
$supplyChainLink = SupplyChainLinkMerchant::with('supplyChain')
|
||||
->where('eb_merchant_id', $merchantCart['mer_id'])
|
||||
->find();
|
||||
// 分润比例
|
||||
$shareRate = $supplyChainLink['supplyChain']['shareRate'];
|
||||
// 大约分润比例金额
|
||||
$makePrice = $_payPrice * $shareRate / 100;
|
||||
// 获取实际分润金额
|
||||
$rate = $supplyPrice = sprintf("%.2f", $makePrice);
|
||||
|
||||
// 计算结束------------------------------------------------------------
|
||||
|
||||
//整理订单数据
|
||||
$_order = [
|
||||
'cartInfo' => $merchantCart,
|
||||
'activity_type' => $orderInfo['order_type'],
|
||||
'commission_rate' => $rate,
|
||||
'order_type' => $merchantCart['order']['isTake'] ? 1 : 0,
|
||||
'is_virtual' => $order_model ? 1 : 0,
|
||||
'order_sn' => $this->getNewOrderId() . ($k + 1),
|
||||
'uid' => $uid,
|
||||
'spread_uid' => $spreadUid,
|
||||
'top_uid' => $topUid,
|
||||
'is_selfbuy' => $isSelfBuy,
|
||||
'real_name' => $merchantCart['order']['isTake'] ? $post['real_name'] : ($address['real_name'] ?? ''),
|
||||
'user_phone' => $merchantCart['order']['isTake'] ? $post['phone'] : ($address['phone'] ?? ''),
|
||||
'user_address' => $user_address,
|
||||
'cart_id' => implode(',', array_column($merchantCart['list'], 'cart_id')),
|
||||
'total_num' => $merchantCart['order']['total_num'],
|
||||
'total_price' => $merchantCart['order']['total_price'],
|
||||
'total_postage' => $merchantCart['order']['postage_price'],
|
||||
'pay_postage' => $merchantCart['order']['postage_price'],
|
||||
'svip_discount' => $merchantCart['order']['svip_discount'],
|
||||
'pay_price' => $merchantCart['order']['pay_price'],
|
||||
'integral' => $merchantCart['order']['total_integral'],
|
||||
'integral_price' => $merchantCart['order']['total_integral_price'],
|
||||
'give_integral' => $merchantCart['order']['total_give_integral'],
|
||||
'mer_id' => $merchantCart['mer_id'],
|
||||
'cost' => $cost,
|
||||
'order_extend' => count($extend) ? json_encode($extend, JSON_UNESCAPED_UNICODE) : '',
|
||||
'coupon_id' => implode(',', $merchantCart['order']['useCouponIds']),
|
||||
'mark' => $mark[$merchantCart['mer_id']] ?? '',
|
||||
'coupon_price' => bcadd($merchantCart['order']['coupon_price'], $merchantCart['order']['platform_coupon_price'], 2),
|
||||
'platform_coupon_price' => $merchantCart['order']['platform_coupon_price'],
|
||||
'pay_type' => $pay_type,
|
||||
'source' => $source, // 增加订单来源 1 小组采购 2 普同商品
|
||||
'supply_chain_rate' => $shareRate, // 供应链分润比例
|
||||
'supply_chain_price' => $supplyPrice, // 供应链分润金额
|
||||
];
|
||||
|
||||
$allUseCoupon = array_merge($allUseCoupon, $merchantCart['order']['useCouponIds']);
|
||||
$orderList[] = $_order;
|
||||
$totalPostage = bcadd($totalPostage, $_order['total_postage'], 2);
|
||||
$totalCost = bcadd($totalCost, $cost, 2);
|
||||
$totalNum += $merchantCart['order']['total_num'];
|
||||
|
||||
}
|
||||
|
||||
//整理订单数据
|
||||
$_order = [
|
||||
'cartInfo' => $merchantCart,
|
||||
'activity_type' => $orderInfo['order_type'],
|
||||
'commission_rate' => (float)$rate,
|
||||
'order_type' => $merchantCart['order']['isTake'] ? 1 : 0,
|
||||
'is_virtual' => $order_model ? 1 : 0,
|
||||
'extension_one' => $total_extension_one,
|
||||
'extension_two' => $total_extension_two,
|
||||
'order_sn' => $this->getNewOrderId() . ($k + 1),
|
||||
'uid' => $uid,
|
||||
'spread_uid' => $spreadUid,
|
||||
'top_uid' => $topUid,
|
||||
'is_selfbuy' => $isSelfBuy,
|
||||
'real_name' => $merchantCart['order']['isTake'] ? $post['real_name'] : ($address['real_name'] ?? ''),
|
||||
'user_phone' => $merchantCart['order']['isTake'] ? $post['phone'] : ($address['phone'] ?? ''),
|
||||
'user_address' => $user_address,
|
||||
'cart_id' => implode(',', array_column($merchantCart['list'], 'cart_id')),
|
||||
'total_num' => $merchantCart['order']['total_num'],
|
||||
'total_price' => $merchantCart['order']['total_price'],
|
||||
'total_postage' => $merchantCart['order']['postage_price'],
|
||||
'pay_postage' => $merchantCart['order']['postage_price'],
|
||||
'svip_discount' => $merchantCart['order']['svip_discount'],
|
||||
'pay_price' => $merchantCart['order']['pay_price'],
|
||||
'integral' => $merchantCart['order']['total_integral'],
|
||||
'integral_price' => $merchantCart['order']['total_integral_price'],
|
||||
'give_integral' => $merchantCart['order']['total_give_integral'],
|
||||
'mer_id' => $merchantCart['mer_id'],
|
||||
'cost' => $cost,
|
||||
'order_extend' => count($extend) ? json_encode($extend, JSON_UNESCAPED_UNICODE) : '',
|
||||
'coupon_id' => implode(',', $merchantCart['order']['useCouponIds']),
|
||||
'mark' => $mark[$merchantCart['mer_id']] ?? '',
|
||||
'coupon_price' => bcadd($merchantCart['order']['coupon_price'], $merchantCart['order']['platform_coupon_price'], 2),
|
||||
'platform_coupon_price' => $merchantCart['order']['platform_coupon_price'],
|
||||
'pay_type' => $pay_type,
|
||||
];
|
||||
$allUseCoupon = array_merge($allUseCoupon, $merchantCart['order']['useCouponIds']);
|
||||
$orderList[] = $_order;
|
||||
$totalPostage = bcadd($totalPostage, $_order['total_postage'], 2);
|
||||
$totalCost = bcadd($totalCost, $cost, 2);
|
||||
$totalNum += $merchantCart['order']['total_num'];
|
||||
}
|
||||
|
||||
$groupOrder = [
|
||||
'uid' => $uid,
|
||||
'group_order_sn' => count($orderList) === 1 ? $orderList[0]['order_sn'] : ($this->getNewOrderId() . '0'),
|
||||
@ -1185,8 +1285,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
]);
|
||||
}
|
||||
|
||||
\think\facade\Log::record($groupOrder);
|
||||
|
||||
//创建订单
|
||||
$groupOrder = $storeGroupOrderRepository->create($groupOrder);
|
||||
$bills = [];
|
||||
|
@ -39,6 +39,7 @@ use app\common\repositories\user\UserRepository;
|
||||
use crmeb\jobs\PayGiveCouponJob;
|
||||
use crmeb\jobs\SendSmsJob;
|
||||
use crmeb\jobs\UserBrokerageLevelJob;
|
||||
use crmeb\jobs\SupplyChainOrderBrokerAgeJob;
|
||||
use crmeb\services\CombinePayService;
|
||||
use crmeb\services\CrmebServeServices;
|
||||
use crmeb\services\ExpressService;
|
||||
@ -113,9 +114,10 @@ class StoreOrderRepository extends BaseRepository
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额支付
|
||||
* @param User $user
|
||||
* @param StoreGroupOrder $groupOrder
|
||||
* @return mixed
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
@ -125,20 +127,21 @@ class StoreOrderRepository extends BaseRepository
|
||||
throw new ValidateException('未开启余额支付');
|
||||
if ($user['now_money'] < $groupOrder['pay_price'])
|
||||
throw new ValidateException('余额不足,请更换支付方式');
|
||||
Db::transaction(function () use ($user, $groupOrder) {
|
||||
$user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2);
|
||||
$user->save();
|
||||
$userBillRepository = app()->make(UserBillRepository::class);
|
||||
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [
|
||||
'link_id' => $groupOrder['group_order_id'],
|
||||
'status' => 1,
|
||||
'title' => '购买商品',
|
||||
'number' => $groupOrder['pay_price'],
|
||||
'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品',
|
||||
'balance' => $user->now_money
|
||||
]);
|
||||
$this->paySuccess($groupOrder);
|
||||
});
|
||||
|
||||
Db::transaction(function () use ($user, $groupOrder) {
|
||||
$user->now_money = bcsub($user->now_money, $groupOrder['pay_price'], 2);
|
||||
$user->save();
|
||||
$userBillRepository = app()->make(UserBillRepository::class);
|
||||
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [
|
||||
'link_id' => $groupOrder['group_order_id'],
|
||||
'status' => 1,
|
||||
'title' => '购买商品',
|
||||
'number' => $groupOrder['pay_price'],
|
||||
'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品',
|
||||
'balance' => $user->now_money
|
||||
]);
|
||||
$this->paySuccess($groupOrder);
|
||||
});
|
||||
return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
||||
}
|
||||
|
||||
@ -383,8 +386,18 @@ class StoreOrderRepository extends BaseRepository
|
||||
$this->autoPrinter($order->order_id, $order->mer_id);
|
||||
}
|
||||
if ($groupOrder->user->spread_uid) {
|
||||
|
||||
// 来源检测,1 服务小组 2 普通商品
|
||||
if($order->source == 2)
|
||||
{
|
||||
\think\facade\Log::record('供应链佣金--开始');
|
||||
Queue::push(SupplyChainOrderBrokerAgeJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]);
|
||||
\think\facade\Log::record('供应链佣金---结束');
|
||||
}
|
||||
|
||||
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]);
|
||||
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_money', 'inc' => $groupOrder->pay_price]);
|
||||
|
||||
}
|
||||
app()->make(UserRepository::class)->update($groupOrder->uid, [
|
||||
'pay_count' => Db::raw('pay_count+' . count($groupOrder->orderList)),
|
||||
@ -631,6 +644,12 @@ class StoreOrderRepository extends BaseRepository
|
||||
*/
|
||||
public function computed(StoreOrder $order, User $user)
|
||||
{
|
||||
|
||||
// \think\facade\Log::record('收获开始~');
|
||||
// \think\facade\Log::record($order);
|
||||
// \think\facade\Log::record('收获结束~');
|
||||
// exit;
|
||||
|
||||
$userBillRepository = app()->make(UserBillRepository::class);
|
||||
if ($order->spread_uid) {
|
||||
$spreadUid = $order->spread_uid;
|
||||
@ -694,6 +713,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
*/
|
||||
public function takeAfter(StoreOrder $order, User $user)
|
||||
{
|
||||
|
||||
Db::transaction(function () use ($user, $order) {
|
||||
$this->computed($order, $user);
|
||||
//TODO 确认收货
|
||||
|
@ -59,6 +59,7 @@ class UserBrokerageRepository extends BaseRepository
|
||||
return $this->dao->search(['type' => $type])->order('brokerage_level ASC,create_time DESC')->select();
|
||||
}
|
||||
|
||||
// 推广分销分佣记录方法
|
||||
public function inc(User $user, $type, $inc)
|
||||
{
|
||||
$nextLevel = $this->getNextLevel($user->brokerage_level);
|
||||
@ -80,6 +81,29 @@ class UserBrokerageRepository extends BaseRepository
|
||||
|
||||
return $this->checkLevel($user, $nextLevel);
|
||||
}
|
||||
|
||||
// 供应链分润分佣记录方法
|
||||
public function supplyChain(User $user, $type, $inc)
|
||||
{
|
||||
$nextLevel = $this->getNextLevel($user->brokerage_level);
|
||||
if (!$nextLevel) return false;
|
||||
$make = app()->make(UserBillRepository::class);
|
||||
$bill = $make->getWhere(['uid' => $user->uid, 'link_id' => $nextLevel->user_brokerage_id, 'category' => 'sys_brokerage', 'type' => $type]);
|
||||
if ($bill) {
|
||||
$bill->number = bcadd($bill->number, $inc, 2);
|
||||
$bill->save();
|
||||
} else {
|
||||
$make->incBill($user->uid, 'sys_brokerage', $type, [
|
||||
'number' => $inc,
|
||||
'title' => $type,
|
||||
'balance' => 0,
|
||||
'status' => 0,
|
||||
'link_id' => $nextLevel->user_brokerage_id
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->checkLevel($user, $nextLevel);
|
||||
}
|
||||
|
||||
public function checkLevel(User $user, UserBrokerage $nextLevel)
|
||||
{
|
||||
|
@ -263,7 +263,6 @@ class StoreOrder extends BaseController
|
||||
$this->repository->paySuccess($groupOrder);
|
||||
return app('json')->status('success', '支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->repository->pay($type, $this->request->userInfo(), $groupOrder, $this->request->param('return_url'), $this->request->isApp());
|
||||
} catch (\Exception $e) {
|
||||
|
62
crmeb/jobs/SupplyChainOrderBrokerAgeJob.php
Normal file
62
crmeb/jobs/SupplyChainOrderBrokerAgeJob.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace crmeb\jobs;
|
||||
|
||||
|
||||
use app\common\repositories\user\UserBrokerageRepository;
|
||||
use app\common\repositories\user\UserRepository;
|
||||
use crmeb\interfaces\JobInterface;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
*
|
||||
* 供应链分佣队列
|
||||
*
|
||||
*/
|
||||
class SupplyChainOrderBrokerAgeJob implements JobInterface
|
||||
{
|
||||
public function fire($job, $data)
|
||||
{
|
||||
try {
|
||||
$user = app()->make(UserRepository::class)->get($data['uid']);
|
||||
|
||||
// 供应链服务小组一级返还给服务小组
|
||||
if ($user) {
|
||||
$flag = true;
|
||||
if ($data['type'] == 'spread_money') {
|
||||
$user->spread_pay_price = bcadd($user->spread_pay_price, $data['inc'], 2);
|
||||
} else if ($data['type'] == 'spread_pay_num') {
|
||||
$user->spread_pay_count = bcadd($user->spread_pay_count, $data['inc'], 0);
|
||||
} else {
|
||||
$flag = false;
|
||||
}
|
||||
if ($flag) {
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
|
||||
// 执行供应链佣金分账
|
||||
app()->make(UserBrokerageRepository::class)->inc($user, $data['type'], $data['inc']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::info('分销等级同步失败: ' . var_export($data, 1) . $e->getMessage());
|
||||
}
|
||||
$job->delete();
|
||||
|
||||
}
|
||||
|
||||
public function failed($data)
|
||||
{
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ class UserBrokerageLevelJob implements JobInterface
|
||||
{
|
||||
public function fire($job, $data)
|
||||
{
|
||||
|
||||
try {
|
||||
$user = app()->make(UserRepository::class)->get($data['uid']);
|
||||
if ($user) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user