93 lines
2.9 KiB
PHP
93 lines
2.9 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace app\api\controller;
|
||
|
|
|
||
|
|
use app\common\controller\Api;
|
||
|
|
use app\common\model\Accounts;
|
||
|
|
use app\common\service\AccountLogService;
|
||
|
|
use app\common\service\AccountService;
|
||
|
|
use app\common\service\AccountWithdrawService;
|
||
|
|
use app\common\service\CategoryService;
|
||
|
|
use app\common\service\DemandBiddingService;
|
||
|
|
use app\common\service\DemandService;
|
||
|
|
use app\common\service\GoodsService;
|
||
|
|
use app\common\model\Category;
|
||
|
|
use app\common\service\OrderService;
|
||
|
|
use app\common\service\UserService;
|
||
|
|
use fast\Tree;
|
||
|
|
use think\Exception;
|
||
|
|
use think\exception\HttpResponseException;
|
||
|
|
use think\Validate;
|
||
|
|
|
||
|
|
class Account extends Api
|
||
|
|
{
|
||
|
|
protected $noNeedLogin = [];
|
||
|
|
protected $noNeedRight = ['*'];
|
||
|
|
|
||
|
|
public function logs()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$user_id = $this->auth->id ?? -1;
|
||
|
|
$page = $this->request->get('page', 1);
|
||
|
|
$page_size = $this->request->get('page_size', 10);
|
||
|
|
$tab = $this->request->get('tab', 'all');
|
||
|
|
$accountType = $this->request->get('accountType', '');
|
||
|
|
$where = [
|
||
|
|
'user_id' => $user_id,
|
||
|
|
];
|
||
|
|
if ($tab != 'all') {
|
||
|
|
$where['inc_or_exp'] = $tab == 'income' ? 1 : 2;
|
||
|
|
}
|
||
|
|
if ($accountType) {
|
||
|
|
$where['account_type'] = $accountType == 'amount' ? ['in', ['amount', 'freeze']] : $accountType;
|
||
|
|
}
|
||
|
|
$list = AccountLogService::getList($where, $page_size, 'id desc')->toArray();
|
||
|
|
|
||
|
|
$this->success('', $list);
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
if ($e instanceof HttpResponseException) {
|
||
|
|
throw $e;
|
||
|
|
}
|
||
|
|
$this->error($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public function info()
|
||
|
|
{
|
||
|
|
$user_id = $this->auth->id ?? -1;
|
||
|
|
$data = AccountService::getOne(['user_id' => $user_id]);
|
||
|
|
|
||
|
|
$this->success('success', $data);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function applyWithdraw()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$user_id = $this->auth->id ?? -1;
|
||
|
|
$amount = $this->request->post('amount', 0);
|
||
|
|
$name = $this->request->post('name', '');
|
||
|
|
// 验证参数
|
||
|
|
$error = $this->validate($this->request->post(), [
|
||
|
|
'name' => 'require',
|
||
|
|
'amount' => 'require|number|between:1,500',
|
||
|
|
], [
|
||
|
|
'name.require' => '微信真实姓名必填',
|
||
|
|
'amount.require' => '提现金额不正确',
|
||
|
|
'amount.number' => '提现金额必须为数字',
|
||
|
|
'amount.between' => '提现金额必须在1到500之间',
|
||
|
|
]);
|
||
|
|
if (true !== $error) {
|
||
|
|
throw new \Exception($error);
|
||
|
|
}
|
||
|
|
AccountWithdrawService::applyWithdraw($user_id, $amount, $name);
|
||
|
|
|
||
|
|
$this->success('提现申请成功,1-3个工作日到账');
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
if ($e instanceof HttpResponseException) {
|
||
|
|
throw $e;
|
||
|
|
}
|
||
|
|
$this->error($e->getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|