添加发起提现、列表
This commit is contained in:
parent
e51684c991
commit
7abdcd8952
38
app/adminapi/controller/finance/WithdrawController.php
Normal file
38
app/adminapi/controller/finance/WithdrawController.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\adminapi\controller\finance;
|
||||||
|
|
||||||
|
use app\adminapi\controller\BaseAdminController;
|
||||||
|
use app\adminapi\lists\finance\AccountLogLists;
|
||||||
|
use app\common\enum\user\AccountLogEnum;
|
||||||
|
use app\common\model\user\Withdraw;
|
||||||
|
|
||||||
|
class WithdrawController extends BaseAdminController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
[$page, $limit] = $this->getPage();
|
||||||
|
$query = Withdraw::where('status', '<>', -1);
|
||||||
|
$count = $query->count();
|
||||||
|
$list = $query->order('id', 'desc')->page($page)->limit($limit)->select()->toArray();
|
||||||
|
return $this->success('success', ['count' => $count, 'data' => $list]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update($id)
|
||||||
|
{
|
||||||
|
$status = $this->request->param('status');
|
||||||
|
if (!in_array($status, [1, 2, 3])) {
|
||||||
|
return $this->fail('参数错误');
|
||||||
|
}
|
||||||
|
$data = Withdraw::find($id);
|
||||||
|
if (empty($data)) {
|
||||||
|
return $this->fail('数据不存在');
|
||||||
|
}
|
||||||
|
$data->status = $status;
|
||||||
|
$data->udpate_time = time();
|
||||||
|
$data->save();
|
||||||
|
return $this->success('操作成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -144,4 +144,22 @@ class UserController extends BaseApiController
|
|||||||
return $this->fail(UserLogic::getError());
|
return $this->fail(UserLogic::getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withdraw()
|
||||||
|
{
|
||||||
|
$params = $this->request->param();
|
||||||
|
$params['user_id'] = $this->userId;
|
||||||
|
$result = UserLogic::withdraw($params);
|
||||||
|
if($result) {
|
||||||
|
return $this->success('提现申请已提交', [], 1, 1);
|
||||||
|
}
|
||||||
|
return $this->fail(UserLogic::getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withdrawList()
|
||||||
|
{
|
||||||
|
[$page, $limit] = $this->getPage();
|
||||||
|
[$count, $list] = UserLogic::withdrawList($this->userId, $page, $limit);
|
||||||
|
return $this->success('success', ['count' => $count, 'data' => $list]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,17 +14,20 @@
|
|||||||
|
|
||||||
namespace app\api\logic;
|
namespace app\api\logic;
|
||||||
|
|
||||||
|
|
||||||
use app\common\{enum\notice\NoticeEnum,
|
use app\common\{enum\notice\NoticeEnum,
|
||||||
enum\user\UserTerminalEnum,
|
enum\user\UserTerminalEnum,
|
||||||
enum\YesNoEnum,
|
enum\YesNoEnum,
|
||||||
logic\BaseLogic,
|
logic\BaseLogic,
|
||||||
model\user\User,
|
model\user\User,
|
||||||
model\user\UserAuth,
|
model\user\UserAuth,
|
||||||
|
model\user\Withdraw,
|
||||||
service\sms\SmsDriver,
|
service\sms\SmsDriver,
|
||||||
service\wechat\WeChatMnpService};
|
service\wechat\WeChatMnpService
|
||||||
use app\Request;
|
};
|
||||||
|
use think\db\exception\DataNotFoundException;
|
||||||
|
use think\exception\ValidateException;
|
||||||
use think\facade\Config;
|
use think\facade\Config;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会员逻辑层
|
* 会员逻辑层
|
||||||
@ -118,7 +121,7 @@ class UserLogic extends BaseLogic
|
|||||||
public static function hasWechatAuth(int $userId)
|
public static function hasWechatAuth(int $userId)
|
||||||
{
|
{
|
||||||
//是否有微信授权登录
|
//是否有微信授权登录
|
||||||
$terminal = [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA,UserTerminalEnum::PC];
|
$terminal = [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA, UserTerminalEnum::PC];
|
||||||
$auth = UserAuth::where(['user_id' => $userId])
|
$auth = UserAuth::where(['user_id' => $userId])
|
||||||
->whereIn('terminal', $terminal)
|
->whereIn('terminal', $terminal)
|
||||||
->findOrEmpty();
|
->findOrEmpty();
|
||||||
@ -289,4 +292,54 @@ class UserLogic extends BaseLogic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function withdraw($params)
|
||||||
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
$user = User::findOrEmpty($params['user_id']);
|
||||||
|
if ($user->isEmpty()) {
|
||||||
|
throw new DataNotFoundException('用户不存在');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验提现金额
|
||||||
|
if ($params['amount'] <= 0) {
|
||||||
|
throw new ValidateException('提现金额错误');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 校验提现金额
|
||||||
|
if ($params['amount'] > $user['user_money']) {
|
||||||
|
throw new ValidateException('余额不足');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存提现记录
|
||||||
|
$withdraw = new Withdraw();
|
||||||
|
$withdraw->user_id = $user['id'];
|
||||||
|
$withdraw->admin_id = $user['admin_id'];
|
||||||
|
$withdraw->order_sn = $withdraw->buildOrderSn();
|
||||||
|
$withdraw->amount = $params['amount'];
|
||||||
|
$withdraw->create_time = time();
|
||||||
|
$withdraw->update_time = time();
|
||||||
|
$withdraw->save();
|
||||||
|
|
||||||
|
// 扣除余额
|
||||||
|
$user->user_money = $user['user_money'] - $params['amount'];
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
self::setError($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function withdrawList($userId, $page, $limit)
|
||||||
|
{
|
||||||
|
$query = Withdraw::where('user_id', $userId);
|
||||||
|
$count = $query->count();
|
||||||
|
$list = $query->order('id', 'desc')->page($page)->limit($limit)->select()->toArray();
|
||||||
|
return [$count, $list];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
16
app/common/model/user/Withdraw.php
Normal file
16
app/common/model/user/Withdraw.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\user;
|
||||||
|
|
||||||
|
use think\model;
|
||||||
|
|
||||||
|
class Withdraw extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
public function buildOrderSn()
|
||||||
|
{
|
||||||
|
return 'TX' . date('YmdHis') . rand(10000, 99999);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user