修改计å¤备货单金额计算&&采购单编写â
This commit is contained in:
@@ -5,6 +5,7 @@ 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
|
||||
{
|
||||
@@ -28,4 +29,49 @@ class VehMoneyValueService
|
||||
{
|
||||
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