...
|
...
|
@@ -2,10 +2,12 @@ |
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\admin\model\UserWithdraw;
|
|
|
use app\common\controller\Api;
|
|
|
use app\common\library\Ems;
|
|
|
use app\common\library\Sms;
|
|
|
use fast\Random;
|
|
|
use think\Db;
|
|
|
use think\Validate;
|
|
|
use think\Cache;
|
|
|
use app\api\model\HouseJoin;
|
...
|
...
|
@@ -363,6 +365,84 @@ class User extends Api |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 提现
|
|
|
* @ApiWeigh (15)
|
|
|
*
|
|
|
* @ApiTitle (提现)
|
|
|
* @ApiSummary (提现)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/store/withdraw)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="money", type="integer", required=true, description="提现金额")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功',
|
|
|
"data": {
|
|
|
})
|
|
|
*/
|
|
|
public function withdraw()
|
|
|
{
|
|
|
if($this->request->isPost()) {
|
|
|
$param = $this->request->param();
|
|
|
$validate = new \think\Validate([
|
|
|
'money' => 'require|number',
|
|
|
]);
|
|
|
$validate->message([
|
|
|
'money.require' => '请输入提现金额!',
|
|
|
'money.number' => '提现金额必须为数字!',
|
|
|
]);
|
|
|
if (!$validate->check($param)) {
|
|
|
$this->error($validate->getError());
|
|
|
}
|
|
|
if ($param['money'] < 1) {
|
|
|
$this->error('提现金额不可小于1元');
|
|
|
}
|
|
|
if ($param['money'] > 1000) {
|
|
|
$this->error('提现金额不可大于1000元');
|
|
|
}
|
|
|
// 判断余额是否充足
|
|
|
if ($param['money'] > $this->auth->money) {
|
|
|
$this->error('余额不足,无法提现');
|
|
|
}
|
|
|
// 提现记录
|
|
|
Db::startTrans();
|
|
|
$user_model = $this->auth->getUser();
|
|
|
$withdraw_model = new UserWithdraw();
|
|
|
$user = $user_model->where('id', $this->auth->id)->find();
|
|
|
$order_sn = date('YmdHis').rand(0000,9999);
|
|
|
$withdraw = [
|
|
|
'type' => 2,
|
|
|
'user_id' => $this->auth->id,
|
|
|
'before_money' => $this->auth->money,
|
|
|
'after_money' => $this->auth->money - $param['money'],
|
|
|
'order_sn' => $order_sn,
|
|
|
'money' => $param['money'],
|
|
|
];
|
|
|
$result = $withdraw_model->isUpdate(false)->save($withdraw);
|
|
|
// 记录用户余额
|
|
|
$result_user = $user_model->isUpdate(true)->save(['money' => $user['money'] - $param['money']]);
|
|
|
// 记录余额变更
|
|
|
$insert_data = array(
|
|
|
'user_id' => $this->auth->id,
|
|
|
'score' => $param['money'],
|
|
|
'before' => $this->auth->money,
|
|
|
'after' => $this->auth->money - $param['money'],
|
|
|
'createtime' => time(),
|
|
|
'memo' => '用户提现',
|
|
|
);
|
|
|
$res_log = Db::name('user_money_log')->insert($insert_data);
|
|
|
if (!$result || !$result_user || !$res_log) {
|
|
|
Db::rollback();
|
|
|
$this->error('提现申请失败', [$result, $result_user]);
|
|
|
}
|
|
|
Db::commit();
|
|
|
$this->success('提现申请成功');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 会员登录
|
|
|
*
|
|
|
* @param string $account 账号
|
...
|
...
|
|