作者 郭文星

123

@@ -669,12 +669,42 @@ class Car extends Base @@ -669,12 +669,42 @@ class Car extends Base
669 /** 669 /**
670 * 钱包金额 670 * 钱包金额
671 * @return void 671 * @return void
672 - * @throws \think\db\exception\DataNotFoundException  
673 - * @throws \think\db\exception\ModelNotFoundException  
674 - * @throws \think\exception\DbException  
675 */ 672 */
676 public function mywallet(){ 673 public function mywallet(){
677 $res=Db::name("user")->where("id",$this->auth->id)->field("money")->find(); 674 $res=Db::name("user")->where("id",$this->auth->id)->field("money")->find();
678 return $this->success("请求成功",$res); 675 return $this->success("请求成功",$res);
679 } 676 }
  677 +
  678 + /**
  679 + * 提现接口
  680 + * @return void
  681 + */
  682 + public function withdrawal(){
  683 + $money=$this->request->param("money");
  684 + $name=$this->request->param("name");
  685 + $bank_card=$this->request->param("bank_card");
  686 + $user_id=$this->auth->id;
  687 + $user=Db::name("user")->where("id",$user_id)->find();
  688 + if($user['money']<$money){
  689 + $this->error("金额不足");
  690 + }
  691 + //减少金额
  692 + $newmoney=bcsub($user['money'],$money,2);
  693 + $updatemoney=Db::name("user")->where("id",$user_id)->update(['money'=>$newmoney]);
  694 + if($updatemoney){
  695 + //添加提现记录
  696 + $data=[
  697 + "user_id"=>$user_id,
  698 + "bank_card"=>$bank_card,
  699 + "name"=>$name,
  700 + "create_time"=>time(),
  701 + "money"=>$money,
  702 + "newmoney"=>$newmoney,
  703 + ];
  704 + $res=Db::name("withdrawal")->insert($data);
  705 + return $this->success("提现成功",$res);
  706 + }else{
  707 + return $this->error("提现失败");
  708 + }
  709 + }
680 } 710 }