Withdraw.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\library\Sms;
  4. use app\api\controller\Common;
  5. use think\Db;
  6. use think\Exception;
  7. use think\Validate;
  8. /**
  9. *
  10. */
  11. class Withdraw extends Common
  12. {
  13. protected $layout = 'default';
  14. protected $noNeedLogin = ['getUserInfoByMobile','bindBank','mobilelogin'];
  15. protected $noNeedRight = ['*'];
  16. // /**
  17. // * 余额提现
  18. // * @return string
  19. // */
  20. // public function withdraw()
  21. // {
  22. // $config = get_addon_config('withdraw');
  23. // $this->view->assign('addonConfig', $config);
  24. // $this->view->assign('title', __('Withdraw'));
  25. // return $this->view->fetch();
  26. // }
  27. //
  28. // /**
  29. // * 余额日志
  30. // * @return string
  31. // */
  32. // public function withdrawlog()
  33. // {
  34. // $withdrawloglist = \addons\withdraw\model\Withdraw::where(['user_id' => $this->auth->id])
  35. // ->order('id desc')
  36. // ->paginate(10);
  37. //
  38. // $this->view->assign('title', __('Withdraw log'));
  39. // $this->view->assign('withdrawloglist', $withdrawloglist);
  40. // return $this->view->fetch();
  41. // }
  42. // /**
  43. // * 创建订单并发起支付请求
  44. // * @throws \think\exception\DbException
  45. // */
  46. // public function submit()
  47. // {
  48. // $money = $this->request->request('money');
  49. // $account = $this->request->request('account');
  50. // $name = $this->request->request('name');
  51. // $type = $this->request->request('type','alipay');
  52. //// $type = 'alipay';
  53. //
  54. //
  55. // if ($money <= 0) {
  56. // $this->error('提现金额不正确');
  57. // }
  58. // if ($money > $this->auth->money) {
  59. // $this->error('提现金额超出可提现额度');
  60. // }
  61. // if (!$account) {
  62. // $this->error("提现账户不能为空");
  63. // }
  64. // if (!$name) {
  65. // $this->error("真实姓名不能为空");
  66. // }
  67. // if (!Validate::is($account, "email") && !Validate::is($account, "/^1\d{10}$/")) {
  68. // $this->error("提现账户只能是手机号或Email");
  69. // }
  70. //
  71. // $config = get_addon_config('withdraw');
  72. // if (isset($config['minmoney']) && $money < $config['minmoney']) {
  73. // $this->error('提现金额不能低于' . $config['minmoney'] . '元');
  74. // }
  75. // if ($config['monthlimit']) {
  76. // $count = \addons\withdraw\model\Withdraw::where('user_id', $this->auth->id)->whereTime('createtime', 'month')->count();
  77. // if ($count >= $config['monthlimit']) {
  78. // $this->error("已达到本月最大可提现次数");
  79. // }
  80. // }
  81. // Db::startTrans();
  82. // try {
  83. // $data = [
  84. // 'orderid' => date("YmdHis") . sprintf("%08d", $this->auth->id) . mt_rand(1000, 9999),
  85. // 'user_id' => $this->auth->id,
  86. // 'money' => $money,
  87. // 'type' => $type,
  88. // 'account' => $account,
  89. // 'name' => $name,
  90. // ];
  91. // \addons\withdraw\model\Withdraw::create($data);
  92. // \app\common\model\User::money(-$money, $this->auth->id, "提现");
  93. // Db::commit();
  94. // } catch (Exception $e) {
  95. // Db::rollback();
  96. // $this->error($e->getMessage());
  97. // }
  98. // $this->success("提现申请成功!请等待后台审核!", url("withdraw/withdrawlog"));
  99. // return;
  100. // }
  101. //
  102. // /**
  103. // * 企业支付通知和回调
  104. // * @throws \think\exception\DbException
  105. // */
  106. // public function epay()
  107. // {
  108. // $type = $this->request->param('type');
  109. // $paytype = $this->request->param('paytype');
  110. // if ($type == 'notify') {
  111. // $pay = \addons\epay\library\Service::checkNotify($paytype);
  112. // if (!$pay) {
  113. // echo '签名错误';
  114. // return;
  115. // }
  116. // $data = $pay->verify();
  117. // try {
  118. // $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
  119. // \addons\recharge\model\Order::settle($data['out_trade_no'], $payamount);
  120. // } catch (Exception $e) {
  121. // }
  122. // echo $pay->success();
  123. // } else {
  124. // $pay = \addons\epay\library\Service::checkReturn($paytype);
  125. // if (!$pay) {
  126. // $this->error('签名错误');
  127. // }
  128. // //微信支付没有返回链接
  129. // if ($pay === true) {
  130. // $this->success("请返回网站查看支付状态!", "");
  131. // }
  132. //
  133. // //你可以在这里定义你的提示信息,但切记不可在此编写逻辑
  134. // $this->success("恭喜你!充值成功!", url("user/index"));
  135. // }
  136. // return;
  137. // }
  138. /**
  139. * 根据手机号获取用户信息
  140. */
  141. public function getUserInfoByMobile() {
  142. $mobile = $this->request->request('mobile');// 手机号
  143. if(!$mobile) $this->error("请输入手机号!");
  144. $field = "u_id,avatar,money,nickname,mobile";
  145. $userInfo = \app\common\model\User::getByMobile($mobile,$field);
  146. $this->success("获取成功!",$userInfo);
  147. }
  148. /**
  149. * 验证身份证号
  150. */
  151. public function validateCard() {
  152. $idcard = $this->request->request('idcard');// 身份证号
  153. if(!$idcard) $this->error("参数缺失!");
  154. // 获取用户信息
  155. $idcardInfo = \app\common\model\UserAuth::where(["user_id"=>$this->auth->id])->value("idcard");
  156. if($idcardInfo === $idcard) {
  157. $this->success("验证成功!");
  158. } else {
  159. $this->error("验证失败!");
  160. }
  161. }
  162. /**
  163. * 绑定银行卡
  164. */
  165. public function bindBank() {
  166. $realname = $this->request->request('realname');// 真实姓名
  167. $bank_no = $this->request->request('bank_no');// 银行账号
  168. $bank_name = $this->request->request('bank_name');// 银行名称
  169. $open_address = $this->request->request('open_address');// 开户地
  170. $open_bank = $this->request->request('open_bank');// 开户行
  171. $bank_mobile = $this->request->request('bank_mobile');// 银行预留手机号
  172. $captcha = $this->request->request('captcha'); // 验证码
  173. $mobile = $this->request->request('mobile'); // 手机号
  174. if(!$realname || !$bank_no || !$bank_name || !$open_address || !$open_bank || !$bank_mobile || !$captcha || !$mobile) {
  175. $this->error("请将信息填写完整");
  176. }
  177. // 获取用户信息
  178. $userInfo = \app\common\model\User::where(["id"=>$this->auth->id])->find();
  179. if($userInfo->mobile !== $mobile) $this->error("请输入账号绑定的手机号码!");
  180. if (!Sms::check($mobile, $captcha, 'binkBank')) {
  181. $this->error(__('验证码不正确!'));
  182. }
  183. // 查询是否有过绑定
  184. $bankInfo = \app\common\model\UserBank::where(["user_id"=>$userInfo["id"]])->find();
  185. $data = [];
  186. $data["realname"] = $realname;
  187. $data["bank_no"] = $bank_no;
  188. $data["bank_name"] = $bank_name;
  189. $data["open_address"] = $open_address;
  190. $data["open_bank"] = $open_bank;
  191. $data["mobile"] = $bank_mobile;
  192. if($bankInfo) {
  193. $data["updatetime"] = time();
  194. $res = \app\common\model\UserBank::update($data,["user_id"=>$userInfo["id"]]);
  195. } else {
  196. $data["user_id"] = $userInfo["id"];
  197. $data["createtime"] = time();
  198. $res = \app\common\model\UserBank::insert($data);
  199. }
  200. if($res) {
  201. Sms::flush($mobile, 'binkBank');
  202. $this->success("银行卡信息更新/绑定成功!");
  203. } else {
  204. $this->error("网络异常,请稍后重试!");
  205. }
  206. }
  207. /**
  208. * 获取绑定银行卡信息
  209. */
  210. public function getBankInfo() {
  211. // 查询是否有过绑定
  212. $bankInfo = \app\common\model\UserBank::where(["user_id"=>$this->auth->id])->find();
  213. if(!$bankInfo) $this->error("银行卡信息获取失败!");
  214. $this->success("获取成功!",$bankInfo);
  215. }
  216. /**
  217. * 获取用户账户信息
  218. */
  219. public function getUserAccountInfo() {
  220. // 获取用户信息
  221. $res = \app\common\model\User::field("id,u_id,avatar,mobile,nickname,money as use_money,frozen")->where(["id"=>$this->auth->id])->find();
  222. $res["all_money"] = bcadd($res["use_money"],$res["frozen"],2);
  223. unset($res["frozen"]);
  224. // 获取用户实名认证信息
  225. $res["realname"] = \app\common\model\UserAuth::where(["user_id"=>$res["id"]])->value("realname");
  226. // 获取用户银行卡信息
  227. $res["bankInfo"] = \app\common\model\UserBank::where(["user_id"=>$res["id"]])->find();
  228. $this->success("获取成功!",$res);
  229. }
  230. /**
  231. * 手机验证码获取用户信息
  232. *
  233. * @param string $mobile 手机号
  234. * @param string $captcha 验证码
  235. */
  236. public function mobilelogin()
  237. {
  238. $mobile = $this->request->request('mobile');
  239. $captcha = $this->request->request('captcha');
  240. if (!$mobile || !$captcha) {
  241. $this->error(__('Invalid parameters'));
  242. }
  243. if (!Validate::regex($mobile, "^1\d{10}$")) {
  244. $this->error(__('Mobile is incorrect'));
  245. }
  246. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  247. $this->error(__('Captcha is incorrect'));
  248. }
  249. $user = \app\common\model\User::getByMobile($mobile,"u_id,is_auth");
  250. if ($user) {
  251. Sms::flush($mobile, 'mobilelogin');
  252. $this->success("获取成功!",$user);
  253. } else {
  254. $this->error("没有查询到用户信息!请前往app注册!");
  255. }
  256. }
  257. }