feat(user): 新增设置采购款和余额功能
- 在 UserController 中添加 setPurchaseFunds 和 setnowMoney 方法 - 在 UserLogic 中实现 PurchaseFunds 和 nowMoney 方法 - 更新 CapitalFlowLogic 以支持新的资金变动类型
This commit is contained in:
parent
36c1c45415
commit
e6e2cc78c3
@ -81,7 +81,6 @@ class UserController extends BaseAdminController
|
|||||||
$res['page_no'] = $params['page_no'];
|
$res['page_no'] = $params['page_no'];
|
||||||
$res['page_size'] = $params['page_size'];
|
$res['page_size'] = $params['page_size'];
|
||||||
return $this->success('ok', $res);
|
return $this->success('ok', $res);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,7 +90,6 @@ class UserController extends BaseAdminController
|
|||||||
public function userSing()
|
public function userSing()
|
||||||
{
|
{
|
||||||
return $this->dataLists(new UserSignLogLists());
|
return $this->dataLists(new UserSignLogLists());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -113,4 +111,18 @@ class UserController extends BaseAdminController
|
|||||||
return $this->success('ok', $res);
|
return $this->success('ok', $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//设置采购款
|
||||||
|
public function setPurchaseFunds()
|
||||||
|
{
|
||||||
|
$params = $this->request->post();
|
||||||
|
$res = UserLogic::PurchaseFunds($params);
|
||||||
|
return $this->success( '设置成功',[],1,1);
|
||||||
|
}
|
||||||
|
//设置余额
|
||||||
|
public function setnowMoney()
|
||||||
|
{
|
||||||
|
$params = $this->request->post();
|
||||||
|
$res = UserLogic::nowMoney($params);
|
||||||
|
return $this->success( '设置成功',[],1,1);
|
||||||
|
}
|
||||||
}
|
}
|
@ -17,6 +17,7 @@ use app\common\enum\OrderEnum;
|
|||||||
use app\common\enum\user\UserTerminalEnum;
|
use app\common\enum\user\UserTerminalEnum;
|
||||||
use app\common\enum\YesNoEnum;
|
use app\common\enum\YesNoEnum;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\logic\CapitalFlowLogic;
|
||||||
use app\common\model\finance\CapitalFlow;
|
use app\common\model\finance\CapitalFlow;
|
||||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
@ -188,8 +189,21 @@ class UserLogic extends BaseLogic
|
|||||||
public static function detail(int $userId): array
|
public static function detail(int $userId): array
|
||||||
{
|
{
|
||||||
$field = [
|
$field = [
|
||||||
'id', 'account', 'nickname', 'avatar', 'real_name','integral','label_id','user_ship',
|
'id',
|
||||||
'sex', 'mobile', 'create_time', 'login_time', 'channel','now_money','purchase_funds'
|
'account',
|
||||||
|
'nickname',
|
||||||
|
'avatar',
|
||||||
|
'real_name',
|
||||||
|
'integral',
|
||||||
|
'label_id',
|
||||||
|
'user_ship',
|
||||||
|
'sex',
|
||||||
|
'mobile',
|
||||||
|
'create_time',
|
||||||
|
'login_time',
|
||||||
|
'channel',
|
||||||
|
'now_money',
|
||||||
|
'purchase_funds'
|
||||||
];
|
];
|
||||||
|
|
||||||
$user = User::where(['id' => $userId])->field($field)
|
$user = User::where(['id' => $userId])->field($field)
|
||||||
@ -218,6 +232,56 @@ class UserLogic extends BaseLogic
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新采购款
|
||||||
|
*/
|
||||||
|
public static function PurchaseFunds(array $params)
|
||||||
|
{
|
||||||
|
$find = User::where(['id' => $params['id']])->find();
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$capitalFlowDao = new CapitalFlowLogic($find, 'user');
|
||||||
|
if ($params['type'] == 1) {
|
||||||
|
$capitalFlowDao->userIncome('system_purchase_add', 'system', 0, $params['purchase_funds'],'',1);
|
||||||
|
$find->purchase_funds = bcadd($params['purchase_funds'], $find['purchase_funds'], 2);
|
||||||
|
$find->save();
|
||||||
|
} else {
|
||||||
|
$capitalFlowDao->userExpense('system_purchase_dec', 'system', 0, $params['purchase_funds']);
|
||||||
|
$find->purchase_funds = bcsub($params['purchase_funds'], $find['purchase_funds'], 2);
|
||||||
|
$find->save();
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new BusinessException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 更新余额
|
||||||
|
*/
|
||||||
|
public static function nowMoney(array $params)
|
||||||
|
{
|
||||||
|
$find = User::where(['id' => $params['id']])->find();
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$capitalFlowDao = new CapitalFlowLogic($find, 'user');
|
||||||
|
if ($params['type'] == 1) {
|
||||||
|
$capitalFlowDao->userIncome('system_balance_add', 'system', 0, $params['now_money'],);
|
||||||
|
$find->now_money = bcadd($params['now_money'], $find['now_money'], 2);
|
||||||
|
$find->save();
|
||||||
|
} else {
|
||||||
|
$capitalFlowDao->userExpense('system_balance_reduce', 'system', 0, $params['now_money']);
|
||||||
|
$find->now_money = bcsub($params['now_money'], $find['now_money'], 2);
|
||||||
|
$find->save();
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
throw new BusinessException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
public static function dealDetails($params)
|
public static function dealDetails($params)
|
||||||
{
|
{
|
||||||
switch ($params['type']) {
|
switch ($params['type']) {
|
||||||
@ -289,8 +353,6 @@ class UserLogic extends BaseLogic
|
|||||||
'lists' => $data,
|
'lists' => $data,
|
||||||
'count' => $count
|
'count' => $count
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function giftList($uid, $params)
|
public static function giftList($uid, $params)
|
||||||
@ -304,7 +366,6 @@ class UserLogic extends BaseLogic
|
|||||||
'lists' => $list,
|
'lists' => $list,
|
||||||
'count' => $count
|
'count' => $count
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function dealTitleCate($pay_type)
|
public static function dealTitleCate($pay_type)
|
||||||
|
@ -80,8 +80,8 @@ class CapitalFlowLogic extends BaseLogic
|
|||||||
$model->before_balance = bcadd($this->user['now_money'], $amount, 2);
|
$model->before_balance = bcadd($this->user['now_money'], $amount, 2);
|
||||||
$model->balance = $this->user['now_money'];
|
$model->balance = $this->user['now_money'];
|
||||||
} else {
|
} else {
|
||||||
$model->before_balance = $this->user['now_money'];
|
$model->before_balance = $this->user['purchase_funds'];
|
||||||
$model->balance = $this->user['now_money'];
|
$model->balance = bcsub($this->user['purchase_funds'], $amount, 2);
|
||||||
}
|
}
|
||||||
$model->create_time = date('Y-m-d H:i:s');
|
$model->create_time = date('Y-m-d H:i:s');
|
||||||
$model->type = 'out';
|
$model->type = 'out';
|
||||||
@ -176,6 +176,8 @@ class CapitalFlowLogic extends BaseLogic
|
|||||||
return "系统增加余额{$amount}元";
|
return "系统增加余额{$amount}元";
|
||||||
case 'system_purchase_add':
|
case 'system_purchase_add':
|
||||||
return "系统增加采购款{$amount}元";
|
return "系统增加采购款{$amount}元";
|
||||||
|
case 'system_purchase_dec':
|
||||||
|
return "系统减少采购款{$amount}元";
|
||||||
case 'system_balance_reduce':
|
case 'system_balance_reduce':
|
||||||
return "系统减少余额{$amount}元";
|
return "系统减少余额{$amount}元";
|
||||||
case 'user_balance_recharge_refund':
|
case 'user_balance_recharge_refund':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user