Withdraw.php 9.7 KB

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