作者 Cool

绑定新社区调试,新增用户提现接口

@@ -813,7 +813,7 @@ class Store extends Api @@ -813,7 +813,7 @@ class Store extends Api
813 */ 813 */
814 public function store_new() 814 public function store_new()
815 { 815 {
816 - $param = (new StoreValidate())->goCheck('store_new'); 816 + $param = (new StoreValidate())->goCheck('house_new');
817 $store = $this->get_store(); 817 $store = $this->get_store();
818 $order_sn = $param['order_sn'] = get_order_sn(); 818 $order_sn = $param['order_sn'] = get_order_sn();
819 // 获取配置 819 // 获取配置
@@ -1199,7 +1199,7 @@ class Store extends Api @@ -1199,7 +1199,7 @@ class Store extends Api
1199 $this->error('提现金额不可大于1000元'); 1199 $this->error('提现金额不可大于1000元');
1200 } 1200 }
1201 // 判断余额是否充足 1201 // 判断余额是否充足
1202 - if ($param['money'] * $withdraw_percent > $this->auth->money) { 1202 + if ($param['money'] * $withdraw_percent > $this->auth->score) {
1203 $this->error('余额不足,无法提现'); 1203 $this->error('余额不足,无法提现');
1204 } 1204 }
1205 // 提现记录 1205 // 提现记录
@@ -2,10 +2,12 @@ @@ -2,10 +2,12 @@
2 2
3 namespace app\api\controller; 3 namespace app\api\controller;
4 4
  5 +use app\admin\model\UserWithdraw;
5 use app\common\controller\Api; 6 use app\common\controller\Api;
6 use app\common\library\Ems; 7 use app\common\library\Ems;
7 use app\common\library\Sms; 8 use app\common\library\Sms;
8 use fast\Random; 9 use fast\Random;
  10 +use think\Db;
9 use think\Validate; 11 use think\Validate;
10 use think\Cache; 12 use think\Cache;
11 use app\api\model\HouseJoin; 13 use app\api\model\HouseJoin;
@@ -363,6 +365,84 @@ class User extends Api @@ -363,6 +365,84 @@ class User extends Api
363 } 365 }
364 366
365 /** 367 /**
  368 + * 提现
  369 + * @ApiWeigh (15)
  370 + *
  371 + * @ApiTitle (提现)
  372 + * @ApiSummary (提现)
  373 + * @ApiMethod (POST)
  374 + * @ApiRoute (/api/store/withdraw)
  375 + * @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
  376 + * @ApiParams (name="money", type="integer", required=true, description="提现金额")
  377 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  378 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  379 + * @ApiReturn ({
  380 + 'code':'1',
  381 + 'msg':'返回成功',
  382 + "data": {
  383 + })
  384 + */
  385 + public function withdraw()
  386 + {
  387 + if($this->request->isPost()) {
  388 + $param = $this->request->param();
  389 + $validate = new \think\Validate([
  390 + 'money' => 'require|number',
  391 + ]);
  392 + $validate->message([
  393 + 'money.require' => '请输入提现金额!',
  394 + 'money.number' => '提现金额必须为数字!',
  395 + ]);
  396 + if (!$validate->check($param)) {
  397 + $this->error($validate->getError());
  398 + }
  399 + if ($param['money'] < 1) {
  400 + $this->error('提现金额不可小于1元');
  401 + }
  402 + if ($param['money'] > 1000) {
  403 + $this->error('提现金额不可大于1000元');
  404 + }
  405 + // 判断余额是否充足
  406 + if ($param['money'] > $this->auth->money) {
  407 + $this->error('余额不足,无法提现');
  408 + }
  409 + // 提现记录
  410 + Db::startTrans();
  411 + $user_model = $this->auth->getUser();
  412 + $withdraw_model = new UserWithdraw();
  413 + $user = $user_model->where('id', $this->auth->id)->find();
  414 + $order_sn = date('YmdHis').rand(0000,9999);
  415 + $withdraw = [
  416 + 'type' => 2,
  417 + 'user_id' => $this->auth->id,
  418 + 'before_money' => $this->auth->money,
  419 + 'after_money' => $this->auth->money - $param['money'],
  420 + 'order_sn' => $order_sn,
  421 + 'money' => $param['money'],
  422 + ];
  423 + $result = $withdraw_model->isUpdate(false)->save($withdraw);
  424 + // 记录用户余额
  425 + $result_user = $user_model->isUpdate(true)->save(['money' => $user['money'] - $param['money']]);
  426 + // 记录余额变更
  427 + $insert_data = array(
  428 + 'user_id' => $this->auth->id,
  429 + 'score' => $param['money'],
  430 + 'before' => $this->auth->money,
  431 + 'after' => $this->auth->money - $param['money'],
  432 + 'createtime' => time(),
  433 + 'memo' => '用户提现',
  434 + );
  435 + $res_log = Db::name('user_money_log')->insert($insert_data);
  436 + if (!$result || !$result_user || !$res_log) {
  437 + Db::rollback();
  438 + $this->error('提现申请失败', [$result, $result_user]);
  439 + }
  440 + Db::commit();
  441 + $this->success('提现申请成功');
  442 + }
  443 + }
  444 +
  445 + /**
366 * 会员登录 446 * 会员登录
367 * 447 *
368 * @param string $account 账号 448 * @param string $account 账号