163 lines
4.2 KiB
PHP
163 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic;
|
|
|
|
|
|
use app\admin\logic\delivery_service\DeliveryServiceLogic;
|
|
use app\common\model\PurchaseFunds;
|
|
use app\common\logic\BaseLogic;
|
|
use support\exception\BusinessException;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* PurchaseFunds逻辑
|
|
* Class PurchaseFundsLogic
|
|
* @package app\admin\logic
|
|
*/
|
|
class PurchaseFundsLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2025/03/19 14:59
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
PurchaseFunds::create([
|
|
'from_uid' => $params['from_uid'],
|
|
'amount' => $params['amount'],
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 编辑
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2025/03/19 14:59
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
PurchaseFunds::where('id', $params['id'])->update([
|
|
'from_uid' => $params['from_uid'],
|
|
'approve_uid' => $params['approve_uid'],
|
|
'amount' => $params['amount'],
|
|
'status' => $params['status'],
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 删除
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2025/03/19 14:59
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return PurchaseFunds::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取详情
|
|
* @param $params
|
|
* @return array
|
|
* @author admin
|
|
* @date 2025/03/19 14:59
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
return PurchaseFunds::findOrEmpty($params['id'])->toArray();
|
|
}
|
|
|
|
/**
|
|
* @notes 审核
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2025/03/19 14:59
|
|
*/
|
|
public static function audit(array $params): bool
|
|
{
|
|
$purchaseFunds = PurchaseFunds::findOrEmpty($params['id']);
|
|
if ($purchaseFunds->isEmpty()) {
|
|
throw new BusinessException('数据不存在');
|
|
}
|
|
Db::startTrans();
|
|
try {
|
|
$attrs = [
|
|
'approve_uid' => $params['approve_uid'],
|
|
'status' => $params['status'],
|
|
'audit_time' => time(),
|
|
];
|
|
if ($params['status'] == 1) {
|
|
$attrs['current_amount'] = $purchaseFunds['amount'];
|
|
}
|
|
PurchaseFunds::where('id', $params['id'])->update($attrs);
|
|
if ($params['status'] == 1) {
|
|
DeliveryServiceLogic::addPurchaseFunds($purchaseFunds['from_uid'], $purchaseFunds['amount']);
|
|
}
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @notes 补充
|
|
* @param array $params
|
|
* @return bool
|
|
* @author admin
|
|
* @date 2025/03/19 14:59
|
|
*/
|
|
public static function replenish(array $params): bool
|
|
{
|
|
$purchaseFunds = PurchaseFunds::findOrEmpty($params['id']);
|
|
if ($purchaseFunds->isEmpty()) {
|
|
throw new BusinessException('数据不存在');
|
|
}
|
|
Db::startTrans();
|
|
try {
|
|
PurchaseFunds::where('id', $params['id'])->update([
|
|
'amount' => Db::raw('amount+' . $params['replenish_amount']),
|
|
'current_amount' => Db::raw('current_amount+' . $params['replenish_amount']),
|
|
]);
|
|
DeliveryServiceLogic::addPurchaseFunds($purchaseFunds['from_uid'], $params['replenish_amount']);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Throwable $e) {
|
|
Db::rollback();
|
|
throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
} |