更新付费预算
This commit is contained in:
parent
44f21c4247
commit
62bf40d3fa
@ -16,6 +16,7 @@ namespace app\adminapi\logic\cost;
|
|||||||
|
|
||||||
|
|
||||||
use app\common\model\cost\CostBudget;
|
use app\common\model\cost\CostBudget;
|
||||||
|
use app\common\model\cost\CostBudgetDetail;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ class CostBudgetLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
CostBudget::create([
|
$costBudget = CostBudget::create([
|
||||||
'approve_id' => $params['approve_id'] ?? 0,
|
'approve_id' => $params['approve_id'] ?? 0,
|
||||||
'years' => $params['years'] ?? '',
|
'years' => $params['years'] ?? '',
|
||||||
'document_preparation_time' => $params['document_preparation_time'] ?? '',
|
'document_preparation_time' => $params['document_preparation_time'] ?? '',
|
||||||
@ -48,6 +49,26 @@ class CostBudgetLogic extends BaseLogic
|
|||||||
'remark' => $params['remark'] ?? '',
|
'remark' => $params['remark'] ?? '',
|
||||||
'annex' => $params['annex'] ?? '',
|
'annex' => $params['annex'] ?? '',
|
||||||
]);
|
]);
|
||||||
|
foreach ($params['detail'] ?? [] as $item)
|
||||||
|
{
|
||||||
|
CostBudgetDetail::create([
|
||||||
|
'cost_budget_id' => $costBudget->id,
|
||||||
|
'cost_subject_id' => $item['cost_subject_id'] ?? 0,
|
||||||
|
'dept_id' => $item['dept_id'] ?? 0,
|
||||||
|
'month1' => $item['month1'] ?? 0,
|
||||||
|
'month2' => $item['month2'] ?? 0,
|
||||||
|
'month3' => $item['month3'] ?? 0,
|
||||||
|
'month4' => $item['month4'] ?? 0,
|
||||||
|
'month5' => $item['month5'] ?? 0,
|
||||||
|
'month6' => $item['month6'] ?? 0,
|
||||||
|
'month7' => $item['month7'] ?? 0,
|
||||||
|
'month8' => $item['month8'] ?? 0,
|
||||||
|
'month9' => $item['month9'] ?? 0,
|
||||||
|
'month10' => $item['month10'] ?? 0,
|
||||||
|
'month11' => $item['month11'] ?? 0,
|
||||||
|
'month12' => $item['month12'] ?? 0
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
@ -78,6 +99,26 @@ class CostBudgetLogic extends BaseLogic
|
|||||||
'remark' => $params['remark'] ?? '',
|
'remark' => $params['remark'] ?? '',
|
||||||
'annex' => $params['annex'] ?? '',
|
'annex' => $params['annex'] ?? '',
|
||||||
]);
|
]);
|
||||||
|
CostBudgetDetail::where('cost_budget_id', $params['id'])->update(['delete_time' => time()]);
|
||||||
|
foreach ($params['detail'] ?? [] as $item)
|
||||||
|
{
|
||||||
|
CostBudgetDetail::where('cost_budget_id', $params['id'])->update([
|
||||||
|
'cost_subject_id' => $item['cost_subject_id'] ?? 0,
|
||||||
|
'dept_id' => $item['dept_id'] ?? 0,
|
||||||
|
'month1' => $item['month1'] ?? 0,
|
||||||
|
'month2' => $item['month2'] ?? 0,
|
||||||
|
'month3' => $item['month3'] ?? 0,
|
||||||
|
'month4' => $item['month4'] ?? 0,
|
||||||
|
'month5' => $item['month5'] ?? 0,
|
||||||
|
'month6' => $item['month6'] ?? 0,
|
||||||
|
'month7' => $item['month7'] ?? 0,
|
||||||
|
'month8' => $item['month8'] ?? 0,
|
||||||
|
'month9' => $item['month9'] ?? 0,
|
||||||
|
'month10' => $item['month10'] ?? 0,
|
||||||
|
'month11' => $item['month11'] ?? 0,
|
||||||
|
'month12' => $item['month12'] ?? 0
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
@ -111,6 +152,8 @@ class CostBudgetLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params): array
|
public static function detail($params): array
|
||||||
{
|
{
|
||||||
return CostBudget::findOrEmpty($params['id'])->toArray();
|
$costBudget = CostBudget::findOrEmpty($params['id']);
|
||||||
|
$costBudget->detail;
|
||||||
|
return $costBudget->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -34,6 +34,7 @@ class CostBudgetValidate extends BaseValidate
|
|||||||
'id' => 'require',
|
'id' => 'require',
|
||||||
'years' => 'require',
|
'years' => 'require',
|
||||||
'document_preparation_time' => 'require',
|
'document_preparation_time' => 'require',
|
||||||
|
'detail' => 'array|checkDetail',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -56,7 +57,7 @@ class CostBudgetValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneAdd()
|
public function sceneAdd()
|
||||||
{
|
{
|
||||||
return $this->only(['years','document_preparation_time']);
|
return $this->only(['years','document_preparation_time', 'detail']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ class CostBudgetValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{
|
||||||
return $this->only(['id','years','document_preparation_time']);
|
return $this->only(['id','years','document_preparation_time', 'detail']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -95,4 +96,17 @@ class CostBudgetValidate extends BaseValidate
|
|||||||
return $this->only(['id']);
|
return $this->only(['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkDetail($value, $rule, $data)
|
||||||
|
{
|
||||||
|
$firstData = $value[0] ?? [];
|
||||||
|
if (empty($firstData)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (empty($firstData['cost_subject_id'])) {
|
||||||
|
return '一级科目不能为空!';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user