75 lines
3.3 KiB
PHP
75 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.gobuysaas.com
|
|
* =========================================================
|
|
*/
|
|
namespace addon\commission\job;
|
|
|
|
use addon\commission\model\Legumes;
|
|
use app\model\NewBaseModel;
|
|
use think\facade\Db;
|
|
use think\queue\Job;
|
|
|
|
class UseLegumesIntegralJob{
|
|
|
|
public function fire(Job $job,$data){
|
|
// Db::startTrans();
|
|
try{
|
|
// trace($data, '平台抽成 - 豆豆积分抵扣处理 - 开始处理');
|
|
// 获取订单信息
|
|
$orderInfo = model('order')->getInfo([
|
|
['order_id','=', $data['order_id']],
|
|
['legumes_integral_use','>', 0]
|
|
],'order_id,site_id,member_id,legumes_integral_use,legumes_integral_money');
|
|
if(!$orderInfo) throw new \Exception('信息不存在!');
|
|
$useLegumesIntegral = (float)$orderInfo['legumes_integral_use'];
|
|
// 查询需要使用的分配记录
|
|
$useLegumesLogList = (new Legumes())->getUseList((int)$orderInfo['member_id'],(float)$orderInfo['legumes_integral_use']);
|
|
// 循环处理
|
|
$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){
|
|
// 修改豆豆积分使用信息
|
|
$goodsSkuModel = (new NewBaseModel(['table_name' => 'commission_legumes_log', 'pk' => 'id']));
|
|
$goodsSkuModel->saveAll($updateData);
|
|
// 添加用户账单信息变更记录
|
|
$mark = '购买商品使用'.$orderInfo['legumes_integral_use'].'积分抵扣'.floatval($orderInfo['legumes_integral_money']).'元';
|
|
model('commission_account')->add([
|
|
'site_id' => $orderInfo['site_id'],
|
|
'member_id' => $orderInfo['member_id'],
|
|
'join_id' => $orderInfo['order_id'],
|
|
'account_type' => 'use_legumes_integral',
|
|
'account_type_name' => '积分使用',
|
|
'account_data' => '-'.$orderInfo['legumes_integral_use'],
|
|
'status' => 1,
|
|
'remark' => $mark,
|
|
]);
|
|
}
|
|
// Db::commit();
|
|
}
|
|
catch(\Exception $e){
|
|
// Db::rollback();
|
|
$data['error_msg'] = $e->getMessage();
|
|
trace($data, '平台抽成 - 豆豆积分抵扣处理 - 失败');
|
|
}
|
|
$job->delete();
|
|
}
|
|
|
|
public function failed($data){
|
|
trace($data, '平台抽成 - 豆豆积分抵扣处理 - 失败(failed)');
|
|
}
|
|
}
|