登录
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\validate\VehMoneyValueValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\VehMoneyValue;
|
||||
use support\Db;
|
||||
|
||||
class VehMoneyValueService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = VehMoneyValue::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = VehMoneyValueValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 复制金额记录
|
||||
*
|
||||
* @param string $fromScene 源场景
|
||||
* @param int $fromId 源对象ID
|
||||
* @param string $toScene 目标场景
|
||||
* @param int $toId 目标对象ID
|
||||
* @return int 插入条数
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public function copyMoneyValues(string $fromScene, int $fromId, string $toScene, int $toId): int
|
||||
{
|
||||
// 1. 查询源数据
|
||||
$rows = Db::table('veh_money_value')
|
||||
->where('object_scene', $fromScene)
|
||||
->where('object_id', $fromId)
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
if (empty($rows)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$insertData = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$insertData[] = [
|
||||
'object_scene' => $toScene,
|
||||
'object_id' => $toId,
|
||||
'field' => $row->field,
|
||||
'currency' => $row->currency,
|
||||
'amount' => $row->amount,
|
||||
'exchange_rate' => $row->exchange_rate,
|
||||
'remark' => $row->remark,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
];
|
||||
}
|
||||
|
||||
// 2. 插入新数据
|
||||
return Db::table('veh_money_value')->insert($insertData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user