添加:积分商品兑换后减少豆豆积分
This commit is contained in:
parent
d51539a452
commit
4032070510
|
|
@ -3,6 +3,7 @@
|
|||
namespace app\common\repositories\store\order;
|
||||
|
||||
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\product\ProductAssistSkuRepository;
|
||||
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\UserBillRepository;
|
||||
use app\common\repositories\user\UserMerchantRepository;
|
||||
use app\jobs\store\platformCommission\UseLegumesIntegralJob;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Queue;
|
||||
|
||||
class PointsOrderCreateRepository
|
||||
{
|
||||
|
|
@ -147,8 +150,13 @@ class PointsOrderCreateRepository
|
|||
$cart['cost'] = $total_cost;
|
||||
}
|
||||
// 判断:当前商户积分是否充足
|
||||
$holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数
|
||||
if($holdMerIntegral < $total_integral) throw new ValidateException("积分不足,剩余{$holdMerIntegral}商户积分");
|
||||
// $holdMerIntegral = app()->make(IntegralRepository::class)->getMerIntegral((int)$user->uid,(int)$merchantCart['mer_id']);// 用户持有的该商户积分总数
|
||||
// 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);
|
||||
if (count($merchantCartList) > 1 || count($merchantCart['list']) > 1) {
|
||||
|
|
@ -232,7 +240,8 @@ class PointsOrderCreateRepository
|
|||
'mark' => $mark,
|
||||
'coupon_price' => 0,
|
||||
'platform_coupon_price' => 0,
|
||||
'pay_type' => $pay_type
|
||||
'pay_type' => $pay_type,
|
||||
'use_legumes_integral' => $merchantCart['order']['total_integral'],
|
||||
];
|
||||
$orderList[] = $_order;
|
||||
$totalCost = bcadd($totalCost, $_order['cost'], 2);
|
||||
|
|
@ -335,23 +344,23 @@ class PointsOrderCreateRepository
|
|||
$groupOrder = $storeGroupOrderRepository->create($groupOrder);
|
||||
// 减少积分
|
||||
if ($groupOrder['integral'] > 0) {
|
||||
foreach ($_orderList as $k => $order) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
// foreach ($_orderList as $k => $order) {
|
||||
// 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));
|
||||
// }
|
||||
// }
|
||||
// 减少总持有积分
|
||||
$user->integral = bcsub($user->integral, $groupOrder['integral'], 0);
|
||||
$userBillRepository->decBill($user['uid'],'integral','points_order',[
|
||||
'link_id' => $groupOrder['group_order_id'],
|
||||
'status' => 1,
|
||||
'title' => '积分商城兑换商品',
|
||||
'number' => $groupOrder['integral'],
|
||||
'mark' => '积分商城兑换商品使用商户积分'.floatval($groupOrder['integral']),
|
||||
'balance' => $user->integral
|
||||
]);
|
||||
$user->save();
|
||||
// $user->integral = bcsub($user->integral, $groupOrder['integral'], 0);
|
||||
// $userBillRepository->decBill($user['uid'],'integral','points_order',[
|
||||
// 'link_id' => $groupOrder['group_order_id'],
|
||||
// 'status' => 1,
|
||||
// 'title' => '积分商城兑换商品',
|
||||
// 'number' => $groupOrder['integral'],
|
||||
// 'mark' => '积分商城兑换商品使用商户积分'.floatval($groupOrder['integral']),
|
||||
// 'balance' => $user->integral
|
||||
// ]);
|
||||
// $user->save();
|
||||
}
|
||||
|
||||
foreach ($_orderList as $k => $order) {
|
||||
|
|
@ -408,6 +417,10 @@ class PointsOrderCreateRepository
|
|||
'nickname' => $user->nickname,
|
||||
'user_type' => $storeOrderStatusRepository::U_TYPE_USER,
|
||||
];
|
||||
// 减少豆豆积分
|
||||
Queue::push(UseLegumesIntegralJob::class,[
|
||||
'order_id' => $_order->order_id
|
||||
]);
|
||||
}
|
||||
|
||||
$storeOrderStatusRepository->batchCreateLog($orderStatus);
|
||||
|
|
|
|||
|
|
@ -1439,7 +1439,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||
|
||||
// 修改:用户持有的豆豆积分
|
||||
if((float)$order['use_legumes_integral'] > 0) {
|
||||
// 推广员佣金结算
|
||||
Queue::push(UseLegumesIntegralJob::class,[
|
||||
'order_id' => $_order->order_id
|
||||
]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue