调试账单还款

This commit is contained in:
lewis 2025-02-07 17:54:51 +08:00
parent 850c06df40
commit 31320e3961
3 changed files with 116 additions and 4 deletions

View File

@ -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());
}
}

View File

@ -0,0 +1,68 @@
<?php
namespace app\admin\lists;
use app\common\lists\ListsSearchInterface;
use app\common\model\beforehand_order\BeforehandOrder;
use app\common\model\finance\AccountsReceivable;
use app\common\model\finance\AccountsReceivableInfo;
use app\common\model\system_store\SystemStore;
/**
* AccountsReceivableInfoLists
* Class AccountsReceivableInfoLists
* @package app\admin\lists
*/
class AccountsReceivableInfoLists extends BaseAdminDataLists implements ListsSearchInterface
{
public function setSearch(): array
{
return [
'=' => ['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();
}
}

View File

@ -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)
{
}
}