diff --git a/app/adminapi/controller/financial/FinancialBorrowMoneyController.php b/app/adminapi/controller/financial/FinancialBorrowMoneyController.php index 3f6e86cc1..f1823e49b 100644 --- a/app/adminapi/controller/financial/FinancialBorrowMoneyController.php +++ b/app/adminapi/controller/financial/FinancialBorrowMoneyController.php @@ -11,98 +11,103 @@ // +---------------------------------------------------------------------- // | author: likeadminTeam // +---------------------------------------------------------------------- - - -namespace app\adminapi\controller\financial; - - -use app\adminapi\controller\BaseAdminController; -use app\adminapi\lists\financial\FinancialBorrowMoneyLists; -use app\adminapi\logic\financial\FinancialBorrowMoneyLogic; -use app\adminapi\validate\financial\FinancialBorrowMoneyValidate; - - -/** - * 财务管理--借款单控制器 - * Class FinancialBorrowMoneyController - * @package app\adminapi\controller\financial - */ -class FinancialBorrowMoneyController extends BaseAdminController -{ - - - /** - * @notes 获取财务管理--借款单列表 - * @return \think\response\Json - * @author likeadmin - * @date 2024/03/29 10:35 - */ - public function lists() - { - return $this->dataLists(new FinancialBorrowMoneyLists()); - } - - - /** - * @notes 添加财务管理--借款单 - * @return \think\response\Json - * @author likeadmin - * @date 2024/03/29 10:35 - */ - public function add() - { - $params = (new FinancialBorrowMoneyValidate())->post()->goCheck('add'); - $result = FinancialBorrowMoneyLogic::add($params); - if (true === $result) { - return $this->success('添加成功', [], 1, 1); - } - return $this->fail(FinancialBorrowMoneyLogic::getError()); - } - - - /** - * @notes 编辑财务管理--借款单 - * @return \think\response\Json - * @author likeadmin - * @date 2024/03/29 10:35 - */ - public function edit() - { - $params = (new FinancialBorrowMoneyValidate())->post()->goCheck('edit'); - $result = FinancialBorrowMoneyLogic::edit($params); - if (true === $result) { - return $this->success('编辑成功', [], 1, 1); - } - return $this->fail(FinancialBorrowMoneyLogic::getError()); - } - - - /** - * @notes 删除财务管理--借款单 - * @return \think\response\Json - * @author likeadmin - * @date 2024/03/29 10:35 - */ - public function delete() - { - $params = (new FinancialBorrowMoneyValidate())->post()->goCheck('delete'); - FinancialBorrowMoneyLogic::delete($params); - return $this->success('删除成功', [], 1, 1); - } - - - /** - * @notes 获取财务管理--借款单详情 - * @return \think\response\Json - * @author likeadmin - * @date 2024/03/29 10:35 - */ - public function detail() - { - $params = (new FinancialBorrowMoneyValidate())->goCheck('detail'); - $result = FinancialBorrowMoneyLogic::detail($params); - return $this->data($result); - } - - -} \ No newline at end of file + + + namespace app\adminapi\controller\financial; + + + use app\adminapi\controller\BaseAdminController; + use app\adminapi\lists\financial\FinancialBorrowMoneyLists; + use app\adminapi\logic\financial\FinancialBorrowMoneyLogic; + use app\adminapi\validate\financial\FinancialBorrowMoneyValidate; + + + /** + * 财务管理--借款单控制器 + * Class FinancialBorrowMoneyController + * @package app\adminapi\controller\financial + */ + class FinancialBorrowMoneyController extends BaseAdminController + { + + + /** + * @notes 获取财务管理--借款单列表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/29 10:35 + */ + public function lists() + { + return $this->dataLists(new FinancialBorrowMoneyLists()); + } + + + /** + * @notes 添加财务管理--借款单 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/29 10:35 + */ + public function add() + { + $params = (new FinancialBorrowMoneyValidate())->post()->goCheck('add'); + $result = FinancialBorrowMoneyLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(FinancialBorrowMoneyLogic::getError()); + } + + + /** + * @notes 编辑财务管理--借款单 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/29 10:35 + */ + public function edit() + { + $params = (new FinancialBorrowMoneyValidate())->post()->goCheck('edit'); + $result = FinancialBorrowMoneyLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(FinancialBorrowMoneyLogic::getError()); + } + + + /** + * @notes 删除财务管理--借款单 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/29 10:35 + */ + public function delete() + { + $params = (new FinancialBorrowMoneyValidate())->post()->goCheck('delete'); + FinancialBorrowMoneyLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取财务管理--借款单详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/29 10:35 + */ + public function detail() + { + $params = (new FinancialBorrowMoneyValidate())->goCheck('detail'); + $result = FinancialBorrowMoneyLogic::detail($params); + return $this->data($result); + } + + public function datas() + { + return $this->data(FinancialBorrowMoneyLogic::datas()); + } + + + } \ No newline at end of file diff --git a/app/adminapi/controller/financial/FinancialRepaymentController.php b/app/adminapi/controller/financial/FinancialRepaymentController.php new file mode 100644 index 000000000..b453c360b --- /dev/null +++ b/app/adminapi/controller/financial/FinancialRepaymentController.php @@ -0,0 +1,108 @@ +dataLists(new FinancialRepaymentLists()); + } + + + /** + * @notes 添加财务管理--还款单 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function add() + { + $params = (new FinancialRepaymentValidate())->post()->goCheck('add'); + $result = FinancialRepaymentLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(FinancialRepaymentLogic::getError()); + } + + + /** + * @notes 编辑财务管理--还款单 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function edit() + { + $params = (new FinancialRepaymentValidate())->post()->goCheck('edit'); + $result = FinancialRepaymentLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(FinancialRepaymentLogic::getError()); + } + + + /** + * @notes 删除财务管理--还款单 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function delete() + { + $params = (new FinancialRepaymentValidate())->post()->goCheck('delete'); + FinancialRepaymentLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取财务管理--还款单详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function detail() + { + $params = (new FinancialRepaymentValidate())->goCheck('detail'); + $result = FinancialRepaymentLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/financial/FinancialRepaymentLists.php b/app/adminapi/lists/financial/FinancialRepaymentLists.php new file mode 100644 index 000000000..f4ca2d481 --- /dev/null +++ b/app/adminapi/lists/financial/FinancialRepaymentLists.php @@ -0,0 +1,106 @@ + ['borrow_money_id'], + '%like%' => ['code', 'create_user'], + ]; + } + + + /** + * @notes 获取财务管理--还款单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function lists(): array + { + $params = $this->request->get(); + $where = []; + if (!empty($params['payer_name'])) { + $admin_ids = Admin::where('name', 'like', '%' . $params['payer_name'] . '%')->column('id'); + $where[] = ['payer', 'in', $admin_ids]; + } + if (!empty($params['create_time'])) { + $date = explode(',', $params['create_time']); + $where[] = ['create_time', 'between', [strtotime($date[0] . ' 00:00:00'), strtotime($date[1] . ' 23:59:59')]]; + } + return FinancialRepayment::where($this->searchWhere)->where($where) + ->field(['id', 'borrow_money_id', 'code', 'payer', 'amount', 'desc', 'create_user', 'create_time']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($data) { + $borrow_money = FinancialBorrowMoney::field('code,amount')->where('id', $data['borrow_money_id'])->findOrEmpty(); + $admin = Admin::field('name')->where('id', $data['payer'])->findOrEmpty(); + $data['borrow_code'] = $borrow_money['code']; + $data['borrow_amount'] = $borrow_money['amount']; + $data['payer_name'] = $admin['name']; + }) + ->toArray(); + } + + + /** + * @notes 获取财务管理--还款单数量 + * @return int + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function count(): int + { + $params = $this->request->get(); + $where = []; + if (!empty($params['payer_name'])) { + $admin_ids = Admin::where('name', 'like', '%' . $params['payer_name'] . '%')->column('id'); + $where[] = ['payer', 'in', $admin_ids]; + } + if (!empty($params['create_time'])) { + $date = explode(',', $params['create_time']); + $where[] = ['create_time', 'between', [strtotime($date[0] . ' 00:00:00'), strtotime($date[1] . ' 23:59:59')]]; + } + return FinancialRepayment::where($this->searchWhere)->where($where)->count(); + } + + } \ No newline at end of file diff --git a/app/adminapi/logic/financial/FinancialBorrowMoneyLogic.php b/app/adminapi/logic/financial/FinancialBorrowMoneyLogic.php index 3501ba35a..60151126d 100644 --- a/app/adminapi/logic/financial/FinancialBorrowMoneyLogic.php +++ b/app/adminapi/logic/financial/FinancialBorrowMoneyLogic.php @@ -123,4 +123,11 @@ $data['cost_type_text'] = $data->cost_type_text; return $data->toArray(); } + + public static function datas() + { + return FinancialBorrowMoney::field(['id', 'code'])->order(['id' => 'desc'])->select()->each(function ($data) { + $data['projectinfo'] = 'ID:' . $data['id'] . ' / 单据编号:' . $data['code']; + })->toArray(); + } } \ No newline at end of file diff --git a/app/adminapi/logic/financial/FinancialRepaymentLogic.php b/app/adminapi/logic/financial/FinancialRepaymentLogic.php new file mode 100644 index 000000000..995f207bd --- /dev/null +++ b/app/adminapi/logic/financial/FinancialRepaymentLogic.php @@ -0,0 +1,124 @@ + $params['borrow_money_id'], + 'code' => data_unique_code('HKD'), + 'payer' => $params['payer'], + 'amount' => $params['amount'], + 'desc' => $params['desc'] ?? '', + 'create_user' => $params['create_user'], + 'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : time(), + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑财务管理--还款单 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + FinancialRepayment::where('id', $params['id'])->update([ + 'borrow_money_id' => $params['borrow_money_id'], + 'payer' => $params['payer'], + 'amount' => $params['amount'], + 'desc' => $params['desc'] ?? '', + 'create_user' => $params['create_user'], + 'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : time(), + 'update_time' => time() + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除财务管理--还款单 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public static function delete(array $params): bool + { + return FinancialRepayment::destroy($params['id']); + } + + + /** + * @notes 获取财务管理--还款单详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public static function detail($params): array + { + $data = FinancialRepayment::withoutField('update_time,delete_time')->findOrEmpty($params['id']); + $borrow_money = FinancialBorrowMoney::field('code,amount')->where('id', $data['borrow_money_id'])->findOrEmpty(); + $admin = Admin::field('name')->where('id', $data['payer'])->findOrEmpty(); + $data['borrow_code'] = $borrow_money['code']; + $data['borrow_amount'] = $borrow_money['amount']; + $data['payer_name'] = $admin['name']; + return $data->toArray(); + } + } \ No newline at end of file diff --git a/app/adminapi/validate/financial/FinancialRepaymentValidate.php b/app/adminapi/validate/financial/FinancialRepaymentValidate.php new file mode 100644 index 000000000..85189b7ff --- /dev/null +++ b/app/adminapi/validate/financial/FinancialRepaymentValidate.php @@ -0,0 +1,122 @@ + 'require|checkData', + 'borrow_money_id' => 'require|checkBorrowMoney', + 'payer' => 'require|checkPayer', + 'amount' => 'require|float|gt:0', + 'create_user' => 'require', + 'create_time' => 'require|dateFormat:Y-m-d H:i:s', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'borrow_money_id' => '借款单id', + 'code' => '单据编号', + 'payer' => '还款人', + 'amount' => '还款金额', + 'desc' => '说明', + 'create_user' => '经办人', + 'create_time' => '还款日期', + ]; + + + /** + * @notes 添加场景 + * @return FinancialRepaymentValidate + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function sceneAdd() + { + return $this->only(['borrow_money_id', 'payer', 'amount', 'desc', 'create_user', 'create_time']); + } + + + /** + * @notes 编辑场景 + * @return FinancialRepaymentValidate + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function sceneEdit() + { + return $this->only(['id', 'borrow_money_id', 'payer', 'amount', 'desc', 'create_user', 'create_time']); + } + + + /** + * @notes 删除场景 + * @return FinancialRepaymentValidate + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function sceneDelete() + { + return $this->only(['id'])->remove('id', 'checkData'); + } + + + /** + * @notes 详情场景 + * @return FinancialRepaymentValidate + * @author likeadmin + * @date 2024/03/29 11:15 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkData($value): bool|string + { + $data = FinancialRepayment::where('id', $value)->findOrEmpty(); + if ($data->isEmpty()) return '数据不存在'; + return true; + } + + public function checkBorrowMoney($value): bool|string + { + $data = FinancialBorrowMoney::where('id', $value)->findOrEmpty(); + if ($data->isEmpty()) return '借款单不存在'; + return true; + } + + } \ No newline at end of file diff --git a/app/common/model/financial/FinancialRepayment.php b/app/common/model/financial/FinancialRepayment.php new file mode 100644 index 000000000..d04e3bba3 --- /dev/null +++ b/app/common/model/financial/FinancialRepayment.php @@ -0,0 +1,34 @@ +