添加:积分商品兑换后减少豆豆积分

This commit is contained in:
wuhui_zzw 2023-12-29 19:17:26 +08:00
parent d51539a452
commit 4032070510
2 changed files with 63 additions and 51 deletions

View File

@ -3,6 +3,7 @@
namespace app\common\repositories\store\order; namespace app\common\repositories\store\order;
use app\common\dao\store\order\StoreOrderDao; use app\common\dao\store\order\StoreOrderDao;
use app\common\model\store\platformCommission\LegumesLog;
use app\common\repositories\store\coupon\StoreCouponUserRepository; use app\common\repositories\store\coupon\StoreCouponUserRepository;
use app\common\repositories\store\product\ProductAssistSkuRepository; use app\common\repositories\store\product\ProductAssistSkuRepository;
use app\common\repositories\store\product\ProductAttrValueRepository; use app\common\repositories\store\product\ProductAttrValueRepository;
@ -15,8 +16,10 @@ use app\common\repositories\user\IntegralRepository;
use app\common\repositories\user\UserAddressRepository; use app\common\repositories\user\UserAddressRepository;
use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserMerchantRepository; use app\common\repositories\user\UserMerchantRepository;
use app\jobs\store\platformCommission\UseLegumesIntegralJob;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\facade\Db; use think\facade\Db;
use think\facade\Queue;
class PointsOrderCreateRepository class PointsOrderCreateRepository
{ {
@ -147,8 +150,13 @@ class PointsOrderCreateRepository
$cart['cost'] = $total_cost; $cart['cost'] = $total_cost;
} }
// 判断:当前商户积分是否充足 // 判断:当前商户积分是否充足
$holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数 // $holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数
if($holdMerIntegral < $total_integral) throw new ValidateException("积分不足,剩余{$holdMerIntegral}商户积分"); // if($holdMerIntegral < $total_integral) throw new ValidateException("积分不足,剩余{$holdMerIntegral}商户积分");
$legumesModel = (new LegumesLog())->where('uid', (int)$user->uid)->where('status', 1);
$totalGetIntegral = $legumesModel->sum('get_integral');// 总获取积分
$totalUseIntegral = $legumesModel->sum('use_integral');// 总已使用积分
$hold_legumes_integral = (float)sprintf("%.2f",$totalGetIntegral - $totalUseIntegral);// 持有可使用积分
if($hold_legumes_integral < $total_integral) throw new ValidateException("积分不足,剩余{$hold_legumes_integral}可用积分");
unset($cart); unset($cart);
if (count($merchantCartList) > 1 || count($merchantCart['list']) > 1) { if (count($merchantCartList) > 1 || count($merchantCart['list']) > 1) {
@ -200,39 +208,40 @@ class PointsOrderCreateRepository
foreach ($merchantCartList as $k => $merchantCart) { foreach ($merchantCartList as $k => $merchantCart) {
//整理订单数据 //整理订单数据
$_order = [ $_order = [
'cartInfo' => $merchantCart, 'cartInfo' => $merchantCart,
'activity_type' => $order_type, 'activity_type' => $order_type,
'commission_rate' => 0, 'commission_rate' => 0,
'order_type' => $order_type, 'order_type' => $order_type,
'is_virtual' => $order_model, 'is_virtual' => $order_model,
'extension_one' => $total_extension_one ?? 0, 'extension_one' => $total_extension_one ?? 0,
'extension_two' => $total_extension_two ?? 0, 'extension_two' => $total_extension_two ?? 0,
'order_sn' => $make->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER) . ($k + 1), 'order_sn' => $make->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER).($k + 1),
'uid' => $user->uid, 'uid' => $user->uid,
'spread_uid' => $spreadUid ?? 0, 'spread_uid' => $spreadUid ?? 0,
'top_uid' => $topUid ?? 0, 'top_uid' => $topUid ?? 0,
'is_selfbuy' => $isSelfBuy ?? 0, 'is_selfbuy' => $isSelfBuy ?? 0,
'real_name' => $address['real_name'] ?? '', 'real_name' => $address['real_name'] ?? '',
'user_phone' => $address['phone'] ?? '', 'user_phone' => $address['phone'] ?? '',
'user_address' => $user_address, 'user_address' => $user_address,
'cart_id' => implode(',', array_column($merchantCart['list'], 'cart_id')), 'cart_id' => implode(',',array_column($merchantCart['list'],'cart_id')),
'total_num' => $merchantCart['order']['total_num'], 'total_num' => $merchantCart['order']['total_num'],
'total_price' => $merchantCart['order']['total_price'], 'total_price' => $merchantCart['order']['total_price'],
'total_postage' => 0, 'total_postage' => 0,
'pay_postage' => 0, 'pay_postage' => 0,
'svip_discount' => 0, 'svip_discount' => 0,
'pay_price' => $merchantCart['order']['pay_price'], 'pay_price' => $merchantCart['order']['pay_price'],
'integral' => $merchantCart['order']['total_integral'], 'integral' => $merchantCart['order']['total_integral'],
'integral_price' => 0, 'integral_price' => 0,
'give_integral' => 0, 'give_integral' => 0,
'mer_id' => $merchantCart['mer_id'], 'mer_id' => $merchantCart['mer_id'],
'cost' => $merchantCart['order']['total_cost'], 'cost' => $merchantCart['order']['total_cost'],
'order_extend' => count($extend) ? json_encode($extend, JSON_UNESCAPED_UNICODE) : '', 'order_extend' => count($extend) ? json_encode($extend,JSON_UNESCAPED_UNICODE) : '',
'coupon_id' => '', 'coupon_id' => '',
'mark' => $mark, 'mark' => $mark,
'coupon_price' => 0, 'coupon_price' => 0,
'platform_coupon_price' => 0, 'platform_coupon_price' => 0,
'pay_type' => $pay_type 'pay_type' => $pay_type,
'use_legumes_integral' => $merchantCart['order']['total_integral'],
]; ];
$orderList[] = $_order; $orderList[] = $_order;
$totalCost = bcadd($totalCost, $_order['cost'], 2); $totalCost = bcadd($totalCost, $_order['cost'], 2);
@ -335,23 +344,23 @@ class PointsOrderCreateRepository
$groupOrder = $storeGroupOrderRepository->create($groupOrder); $groupOrder = $storeGroupOrderRepository->create($groupOrder);
// 减少积分 // 减少积分
if ($groupOrder['integral'] > 0) { if ($groupOrder['integral'] > 0) {
foreach ($_orderList as $k => $order) { // foreach ($_orderList as $k => $order) {
foreach ($order['cartInfo']['list'] as $cart) { // foreach ($order['cartInfo']['list'] as $cart) {
// 减少对应的商户积分 // // 减少对应的商户积分
app()->make(IntegralRepository::class)->changeIntegral((int)$user['uid'],(int)$cart->mer_id,(float)sprintf("%.2f",0 - (int)$cart->integral)); // app()->make(IntegralRepository::class)->changeIntegral((int)$user['uid'],(int)$cart->mer_id,(float)sprintf("%.2f",0 - (int)$cart->integral));
} // }
} // }
// 减少总持有积分 // 减少总持有积分
$user->integral = bcsub($user->integral, $groupOrder['integral'], 0); // $user->integral = bcsub($user->integral, $groupOrder['integral'], 0);
$userBillRepository->decBill($user['uid'],'integral','points_order',[ // $userBillRepository->decBill($user['uid'],'integral','points_order',[
'link_id' => $groupOrder['group_order_id'], // 'link_id' => $groupOrder['group_order_id'],
'status' => 1, // 'status' => 1,
'title' => '积分商城兑换商品', // 'title' => '积分商城兑换商品',
'number' => $groupOrder['integral'], // 'number' => $groupOrder['integral'],
'mark' => '积分商城兑换商品使用商户积分'.floatval($groupOrder['integral']), // 'mark' => '积分商城兑换商品使用商户积分'.floatval($groupOrder['integral']),
'balance' => $user->integral // 'balance' => $user->integral
]); // ]);
$user->save(); // $user->save();
} }
foreach ($_orderList as $k => $order) { foreach ($_orderList as $k => $order) {
@ -408,6 +417,10 @@ class PointsOrderCreateRepository
'nickname' => $user->nickname, 'nickname' => $user->nickname,
'user_type' => $storeOrderStatusRepository::U_TYPE_USER, 'user_type' => $storeOrderStatusRepository::U_TYPE_USER,
]; ];
// 减少豆豆积分
Queue::push(UseLegumesIntegralJob::class,[
'order_id' => $_order->order_id
]);
} }
$storeOrderStatusRepository->batchCreateLog($orderStatus); $storeOrderStatusRepository->batchCreateLog($orderStatus);

View File

@ -1439,7 +1439,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
// 修改:用户持有的豆豆积分 // 修改:用户持有的豆豆积分
if((float)$order['use_legumes_integral'] > 0) { if((float)$order['use_legumes_integral'] > 0) {
// 推广员佣金结算
Queue::push(UseLegumesIntegralJob::class,[ Queue::push(UseLegumesIntegralJob::class,[
'order_id' => $_order->order_id 'order_id' => $_order->order_id
]); ]);