diff --git a/app/adminapi/lists/financial/FinancialExpenseReimbursementDetailLists.php b/app/adminapi/lists/financial/FinancialExpenseReimbursementDetailLists.php index 4f3d7133d..50545bbbd 100644 --- a/app/adminapi/lists/financial/FinancialExpenseReimbursementDetailLists.php +++ b/app/adminapi/lists/financial/FinancialExpenseReimbursementDetailLists.php @@ -1,77 +1,83 @@ - ['expense_reimbursement_id'], - ]; - } - - - /** - * @notes 获取财务管理--费用报销单--报销明细列表 - * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException - * @author likeadmin - * @date 2024/03/28 09:26 - */ - public function lists(): array - { - return FinancialExpenseReimbursementDetail::where($this->searchWhere) - ->field(['id', 'expense_reimbursement_id', 'dept_id', 'date', 'subject_name', 'amount', 'abstract']) - ->limit($this->limitOffset, $this->limitLength) - ->order(['id' => 'desc']) - ->select() - ->toArray(); - } - - - /** - * @notes 获取财务管理--费用报销单--报销明细数量 - * @return int - * @author likeadmin - * @date 2024/03/28 09:26 - */ - public function count(): int - { - return FinancialExpenseReimbursementDetail::where($this->searchWhere)->count(); - } - -} \ No newline at end of file + ['expense_reimbursement_id'], + + ]; + } + + + /** + * @notes 获取财务管理--费用报销单--报销明细列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/03/28 09:26 + */ + public function lists(): array + { + return FinancialExpenseReimbursementDetail::where($this->searchWhere) + ->field(['id', 'expense_reimbursement_id', 'dept_id', 'date', 'subject_name', 'amount', 'abstract']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($data) { + $dept = Dept::field('name')->where('id', $data['dept_id'])->findOrEmpty(); + $data['dept_name'] = $dept['name']; + $data['subject_name_text'] = $data->subject_name_text; + }) + ->toArray(); + } + + + /** + * @notes 获取财务管理--费用报销单--报销明细数量 + * @return int + * @author likeadmin + * @date 2024/03/28 09:26 + */ + public function count(): int + { + return FinancialExpenseReimbursementDetail::where($this->searchWhere)->count(); + } + + } \ No newline at end of file diff --git a/app/adminapi/logic/financial/FinancialExpenseReimbursementDetailLogic.php b/app/adminapi/logic/financial/FinancialExpenseReimbursementDetailLogic.php index 7037451f3..46a37f288 100644 --- a/app/adminapi/logic/financial/FinancialExpenseReimbursementDetailLogic.php +++ b/app/adminapi/logic/financial/FinancialExpenseReimbursementDetailLogic.php @@ -16,6 +16,7 @@ use app\common\logic\BaseLogic; + use app\common\model\dept\Dept; use app\common\model\financial\FinancialExpenseReimbursementDetail; use think\facade\Db; @@ -46,9 +47,8 @@ 'date' => !empty($params['date']) ? strtotime($params['date']) : 0, 'subject_name' => $params['subject_name'], 'amount' => $params['amount'], - 'abstract' => $params['abstract'], + 'abstract' => $params['abstract'] ?? '', ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -73,12 +73,12 @@ FinancialExpenseReimbursementDetail::where('id', $params['id'])->update([ 'expense_reimbursement_id' => $params['expense_reimbursement_id'], 'dept_id' => $params['dept_id'], - 'date' => $params['date'], + 'date' => !empty($params['date']) ? strtotime($params['date']) : 0, 'subject_name' => $params['subject_name'], 'amount' => $params['amount'], - 'abstract' => $params['abstract'], + 'abstract' => $params['abstract'] ?? '', + 'update_time' => time(), ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -111,6 +111,10 @@ */ public static function detail($params): array { - return FinancialExpenseReimbursementDetail::findOrEmpty($params['id'])->toArray(); + $data = FinancialExpenseReimbursementDetail::withoutField('create_time,update_time,delete_time')->findOrEmpty($params['id']); + $dept = Dept::field('name')->where('id', $data['dept_id'])->findOrEmpty(); + $data['dept_name'] = $dept['name']; + $data['subject_name_text'] = $data->subject_name_text; + return $data->toArray(); } } \ No newline at end of file diff --git a/app/common/model/financial/FinancialExpenseReimbursementDetail.php b/app/common/model/financial/FinancialExpenseReimbursementDetail.php index 28dc13d4e..17a785581 100644 --- a/app/common/model/financial/FinancialExpenseReimbursementDetail.php +++ b/app/common/model/financial/FinancialExpenseReimbursementDetail.php @@ -11,24 +11,35 @@ // +---------------------------------------------------------------------- // | author: likeadminTeam // +---------------------------------------------------------------------- - -namespace app\common\model\financial; - - -use app\common\model\BaseModel; -use think\model\concern\SoftDelete; - - -/** - * 财务管理--费用报销单--报销明细模型 - * Class FinancialExpenseReimbursementDetail - * @package app\common\model\financial - */ -class FinancialExpenseReimbursementDetail extends BaseModel -{ - use SoftDelete; - protected $name = 'financial_expense_reimbursement_detail'; - protected $deleteTime = 'delete_time'; - - -} \ No newline at end of file + + namespace app\common\model\financial; + + + use app\common\model\BaseModel; + use app\common\model\dict\DictData; + use think\model\concern\SoftDelete; + + + /** + * 财务管理--费用报销单--报销明细模型 + * Class FinancialExpenseReimbursementDetail + * @package app\common\model\financial + */ + class FinancialExpenseReimbursementDetail extends BaseModel + { + use SoftDelete; + + protected $name = 'financial_expense_reimbursement_detail'; + protected $deleteTime = 'delete_time'; + + public function getDateAttr($value): string + { + return !empty($value) ? date('Y-m-d', $value) : ''; + } + + public function getSubjectNameTextAttr($value, $data) + { + $dict = DictData::where('type_value', 'subject_category')->column('name', 'value'); + return !empty($data['subject_name']) ? $dict[$data['subject_name']] : ''; + } + } \ No newline at end of file