82 lines
3.6 KiB
PHP
82 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace app\jobs\store\platformCommission;
|
|
|
|
|
|
use app\common\model\store\platformCommission\LegumesLog;
|
|
use app\common\repositories\store\order\StoreOrderRepository;
|
|
use app\common\repositories\store\platformCommission\LegumesLogRepository;
|
|
use app\common\repositories\user\UserBillRepository;
|
|
use crmeb\interfaces\JobInterface;
|
|
use think\facade\Log;
|
|
|
|
/**
|
|
* Common: 豆豆积分使用 减少积分
|
|
* Author: wu-hui
|
|
* Time: 2023/12/29 17:52
|
|
* Class UseLegumesIntegralJob
|
|
* @package app\jobs\store\platformCommission
|
|
*/
|
|
class UseLegumesIntegralJob implements JobInterface{
|
|
|
|
public function fire($job,$data){
|
|
try{
|
|
// Log::info('豆豆积分使用 - 开始处理: '.var_export($data,1));
|
|
// 获取订单信息
|
|
$orderInfo = app()->make(StoreOrderRepository::class)
|
|
->getSearch([])
|
|
->field('order_id,uid,use_legumes_integral,use_legumes_integral_price,order_type')
|
|
->where('order_id',$data['order_id'])
|
|
->find();
|
|
if(!$orderInfo) throw new \Exception('信息不存在!');
|
|
$orderInfo = $orderInfo->toArray();
|
|
$useLegumesIntegral = (float)$orderInfo['use_legumes_integral'];
|
|
// 查询需要使用的分配记录
|
|
$useLegumesLogList = app()->make(LegumesLogRepository::class)->getUseList((int)$orderInfo['uid'],(float)$orderInfo['use_legumes_integral']);
|
|
// 循环处理
|
|
$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'] == 20) $mark = '兑换积分商品消耗'.$orderInfo['use_legumes_integral'].'积分';
|
|
else $mark = '购买商品使用'.$orderInfo['use_legumes_integral'].'积分抵扣'.floatval($orderInfo['use_legumes_integral_price']).'元';
|
|
$bills[] = [
|
|
'uid' => $orderInfo['uid'],
|
|
'link_id' => $orderInfo['order_id'],
|
|
'pm' => 0,
|
|
'title' => '购买商品',
|
|
'category' => 'integral',
|
|
'type' => 'deduction',
|
|
'number' => (float)$orderInfo['use_legumes_integral'],
|
|
'balance' => $hold_legumes_integral,
|
|
'mark' => $mark,
|
|
'mer_id' => 0,
|
|
'status' => 1
|
|
];
|
|
app()->make(UserBillRepository::class)->insertAll($bills);
|
|
}
|
|
}
|
|
catch(\Exception $e){
|
|
$data['error_msg'] = $e->getMessage();
|
|
Log::info('豆豆积分使用 - 失败: '.var_export($data,1));
|
|
}
|
|
$job->delete();
|
|
}
|
|
|
|
public function failed($data){
|
|
Log::info('豆豆积分使用 - 失败(failed): '.var_export($data,1));
|
|
}
|
|
}
|