From 31320e396156b440306140971ee0675223329b97 Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Fri, 7 Feb 2025 17:54:51 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95=E8=B4=A6=E5=8D=95=E8=BF=98?= =?UTF-8?q?=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AccountsReceivableController.php | 10 ++- .../lists/AccountsReceivableInfoLists.php | 68 +++++++++++++++++++ app/admin/logic/AccountsReceivableLogic.php | 42 +++++++++++- 3 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 app/admin/lists/AccountsReceivableInfoLists.php diff --git a/app/admin/controller/accounts_receivable/AccountsReceivableController.php b/app/admin/controller/accounts_receivable/AccountsReceivableController.php index 8359978a0..dba9a7996 100644 --- a/app/admin/controller/accounts_receivable/AccountsReceivableController.php +++ b/app/admin/controller/accounts_receivable/AccountsReceivableController.php @@ -3,6 +3,7 @@ namespace app\admin\controller\accounts_receivable; use app\admin\controller\BaseAdminController; +use app\admin\lists\AccountsReceivableInfoLists; use app\admin\lists\AccountsReceivableLists; use app\admin\logic\AccountsReceivableLogic; use app\admin\validate\app_update\AppUpdateValidate; @@ -21,10 +22,10 @@ class AccountsReceivableController extends BaseAdminController public function edit() { - $params = (new AppUpdateValidate())->post()->goCheck('edit'); + $params = $this->request->post(); $result = AccountsReceivableLogic::edit($params); if (true === $result) { - return $this->success('编辑成功', [], 1, 1); + return $this->success('操作成功', [], 1, 1); } return $this->fail(AccountsReceivableLogic::getError()); } @@ -43,4 +44,9 @@ class AccountsReceivableController extends BaseAdminController return $this->data($result); } + public function record() + { + return $this->dataLists(new AccountsReceivableInfoLists()); + } + } \ No newline at end of file diff --git a/app/admin/lists/AccountsReceivableInfoLists.php b/app/admin/lists/AccountsReceivableInfoLists.php new file mode 100644 index 000000000..e5e78c2cf --- /dev/null +++ b/app/admin/lists/AccountsReceivableInfoLists.php @@ -0,0 +1,68 @@ + ['accounts_receivable_id'], + ]; + } + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function lists(): array + { + $query = AccountsReceivableInfo::where($this->searchWhere); + $list = $query + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + $accountReceivable = AccountsReceivable::field('id,store_id,nickname')->where('id', $this->params['accounts_receivable_id'])->findOrEmpty()->toArray(); + $store = SystemStore::where('id', $accountReceivable['store_id'])->value('name'); + $payTypeMap = [ + 1 => '现金', + 2 => '微信支付', + 3 => '支付宝支付', + 4 => '对公账号', + 5 => '其他' + ]; + foreach ($list as &$item) { + $item['store_name'] = $store; + $item['pay_type_name'] = $payTypeMap[$item['pay_type']]; + $item['nickname'] = $accountReceivable['nickname']; + } + return $list; + } + + /** + * @notes 获取数量 + * @return int + */ + public function count(): int + { + $query = AccountsReceivableInfo::where($this->searchWhere); + return $query->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/AccountsReceivableLogic.php b/app/admin/logic/AccountsReceivableLogic.php index b02c63dd7..9098dda9f 100644 --- a/app/admin/logic/AccountsReceivableLogic.php +++ b/app/admin/logic/AccountsReceivableLogic.php @@ -2,10 +2,9 @@ namespace app\admin\logic; -use app\common\model\ActivityZone; use app\common\logic\BaseLogic; -use app\common\model\ActivityZoneForm; use app\common\model\finance\AccountsReceivable; +use app\common\model\finance\AccountsReceivableInfo; use support\exception\BusinessException; use think\facade\Db; @@ -34,4 +33,43 @@ class AccountsReceivableLogic extends BaseLogic $model->save(); } + public static function edit($params) + { + Db::startTrans(); + try { + $accountsReceivable = AccountsReceivable::where(['id' => $params['accounts_receivable_id']])->find(); + if ($accountsReceivable->surplus_debt <= 0) { + throw new BusinessException('该账单已支付'); + } + $surplusDebt = bcsub($accountsReceivable->surplus_debt, $params['pay_debt'], 2); + $model = new AccountsReceivableInfo(); + $model->accounts_receivable_id = $params['accounts_receivable_id']; + $model->pay_type = $params['pay_type']; + $model->total_debt = $params['surplus_debt']; + $model->pay_debt = $params['pay_debt']; + $model->recipient = $params['recipient']; + $model->surplus_debt = $surplusDebt; + $model->file = $params['file']; + $model->mark = $params['mark']; + if (!$model->save()) { + throw new BusinessException('添加失败'); + } + $accountsReceivable->pay_debt = bcadd($accountsReceivable->pay_debt, $params['pay_debt'], 2); + $accountsReceivable->surplus_debt = $surplusDebt; + if (!$accountsReceivable->save()) { + throw new BusinessException('更新账单出错'); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + public static function record($params) + { + + } + } \ No newline at end of file