添加:在线买单 - 支持使用豆豆积分进行支付
This commit is contained in:
parent
e71d9f9f3e
commit
d18e655e96
|
|
@ -1597,9 +1597,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||
// 整理订单数据
|
||||
$orderList[] = [
|
||||
'cartInfo' => [],
|
||||
'activity_type' => $activityType,// 30=在线买单;32=代理入驻;33=参加活动支付
|
||||
'activity_type' => $activityType,// 30=在线买单;
|
||||
'commission_rate' => 0,
|
||||
'order_type' => 0,
|
||||
'order_type' => $activityType,
|
||||
'is_virtual' => 1,
|
||||
'extension_one' => 0,
|
||||
'extension_two' => 0,
|
||||
|
|
@ -1652,6 +1652,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||
'give_integral' => 0,
|
||||
'activity_type' => $activityType,// 30=在线买单;32=代理入驻;33=参加活动支付
|
||||
];
|
||||
|
||||
|
||||
$group = Db::transaction(function() use ($user,$groupOrder,$orderList){
|
||||
$storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
|
||||
$storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class);
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@ namespace app\common\repositories\store\order;
|
|||
use app\common\dao\store\order\StoreOrderDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\platformCommission\LegumesLog;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\delivery\DeliveryOrderRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||
use app\common\repositories\store\platformCommission\LegumesLogRepository;
|
||||
use app\common\repositories\store\product\ProductAssistSetRepository;
|
||||
use app\common\repositories\store\product\ProductAttrValueRepository;
|
||||
use app\common\repositories\store\product\ProductCopyRepository;
|
||||
|
|
@ -67,9 +69,9 @@ use think\model\Relation;
|
|||
class StoreOrderRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* 支付类型 0余额 1 微信 2 小程序 3 微信 4 支付宝 5 支付宝 6 微信
|
||||
* 支付类型 0=余额;1=微信;2=小程序;3=微信;4=支付宝;5=支付宝;6=微信;7=豆豆积分
|
||||
*/
|
||||
const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr'];
|
||||
const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr', 'legumes_integral'];
|
||||
const PAY_TYPE_FILTEER = [
|
||||
0 => 0,
|
||||
1 => '1,2,3,6',
|
||||
|
|
@ -101,14 +103,15 @@ class StoreOrderRepository extends BaseRepository
|
|||
*/
|
||||
public function pay(string $type, User $user, StoreGroupOrder $groupOrder, $return_url = '', $isApp = false)
|
||||
{
|
||||
// 判断:余额支付 || 豆豆积分支付 特殊处理
|
||||
|
||||
if ($type === 'balance') {
|
||||
return $this->payBalance($user, $groupOrder);
|
||||
}
|
||||
// debug($type);
|
||||
if ($type === 'balance') return $this->payBalance($user, $groupOrder);
|
||||
else if ($type === 'legumes_integral') return $this->payLegumesIntegral($user, $groupOrder);
|
||||
|
||||
// 其他支付处理
|
||||
if (in_array($type, ['weixin', 'alipay'], true) && $isApp) $type .= 'App';
|
||||
|
||||
if (in_array($type, ['weixin', 'alipay'], true) && $isApp) {
|
||||
$type .= 'App';
|
||||
}
|
||||
event('order.pay.before', compact('groupOrder', 'type', 'isApp'));
|
||||
if (in_array($type, ['weixin', 'weixinApp', 'routine', 'h5', 'weixinQr'], true) && systemConfig('open_wx_combine')) {
|
||||
$service = new CombinePayService($type, $groupOrder->getCombinePayParams());
|
||||
|
|
@ -156,6 +159,69 @@ class StoreOrderRepository extends BaseRepository
|
|||
});
|
||||
return app('json')->status('success', '余额支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
||||
}
|
||||
// 豆豆积分支付
|
||||
public function payLegumesIntegral(User $user, StoreGroupOrder $groupOrder){
|
||||
// 判断:用户豆豆积分是否可用
|
||||
$hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$user['uid']);
|
||||
if($hold_legumes_integral < $groupOrder['pay_price']) throw new ValidateException("积分不足,剩余{$hold_legumes_integral}可用积分");
|
||||
// 订单处理
|
||||
Db::transaction(function () use ($user, $groupOrder) {
|
||||
$groupOrder->append(['orderList.orderProduct']);
|
||||
foreach ($groupOrder->orderList as $orderKey => $orderInfo) {
|
||||
// 获取订单信息
|
||||
if(!$orderInfo) continue;
|
||||
$orderInfo = $orderInfo->toArray();
|
||||
$useLegumesIntegral = (float)$orderInfo['pay_price'];
|
||||
// 查询需要使用的分配记录
|
||||
$useLegumesLogList = app()->make(LegumesLogRepository::class)->getUseList((int)$orderInfo['uid'],(float)$orderInfo['pay_price']);
|
||||
// 循环处理
|
||||
$updateData = [];
|
||||
foreach($useLegumesLogList as $logInfo){
|
||||
$useIntegral = $useLegumesIntegral >= $logInfo['surplus_integral'] ? (float)$logInfo['surplus_integral'] : (float)$useLegumesIntegral;
|
||||
$useLegumesIntegral = (float)sprintf("%.2f",$useLegumesIntegral - $useIntegral);
|
||||
$updateData[] = [
|
||||
'id' => $logInfo['id'],
|
||||
'use_integral' => (float)sprintf("%.2f",$logInfo['use_integral'] + $useIntegral)
|
||||
];
|
||||
if($useLegumesIntegral <= 0) break;
|
||||
}
|
||||
// 修改成功信息
|
||||
if($updateData){
|
||||
LegumesLog::batchUpdate(array_values($updateData));
|
||||
// 获取用户可用豆豆积分
|
||||
$hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$orderInfo['uid']);
|
||||
// 添加用户账单信息变更记录
|
||||
if($orderInfo['order_type'] == 30) {
|
||||
$title = '在线买单';
|
||||
$mark = '在线买单消耗'.$orderInfo['pay_price'].'积分';
|
||||
}
|
||||
else {
|
||||
$title = '购买商品';
|
||||
$mark = '购买商品使用'.$orderInfo['pay_price'].'积分抵扣'.floatval($orderInfo['pay_price']).'元';
|
||||
}
|
||||
$bills[] = [
|
||||
'uid' => $orderInfo['uid'],
|
||||
'link_id' => $orderInfo['order_id'],
|
||||
'pm' => 0,
|
||||
'title' => $title,
|
||||
'category' => 'integral',
|
||||
'type' => 'deduction',
|
||||
'number' => (float)$orderInfo['pay_price'],
|
||||
'balance' => $hold_legumes_integral,
|
||||
'mark' => $mark,
|
||||
'mer_id' => 0,
|
||||
'status' => 1
|
||||
];
|
||||
app()->make(UserBillRepository::class)->insertAll($bills);
|
||||
}
|
||||
}
|
||||
|
||||
$this->paySuccess($groupOrder);
|
||||
});
|
||||
return app('json')->status('success', '积分支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function changePayType(StoreGroupOrder $groupOrder, int $pay_type)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue