Withdraw.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. use app\common\model\UserAlipay;
  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. $userId = $this->auth->id;
  176. //|| !$bank_name || !$open_address || !$bank_mobile || !$captcha || !$mobile
  177. if(!$realname || !$bank_no || !$open_bank ) {
  178. $this->error("请将信息填写完整");
  179. }
  180. // 获取用户信息
  181. //$userInfo = \app\common\model\User::where(["id"=>$this->auth->id])->find();
  182. /*if($userInfo->mobile !== $mobile) $this->error("请输入账号绑定的手机号码!");
  183. if (!Sms::check($mobile, $captcha, 'binkBank')) {
  184. $this->error(__('验证码不正确!'));
  185. }*/
  186. // 查询是否有过绑定
  187. $bankInfo = \app\common\model\UserBank::where(["user_id"=>$userId])->find();
  188. $data = [];
  189. $data["realname"] = $realname;
  190. $data["bank_no"] = $bank_no;
  191. $data["open_bank"] = $open_bank;
  192. /*$data["bank_name"] = $bank_name;
  193. $data["open_address"] = $open_address;
  194. $data["mobile"] = $bank_mobile;*/
  195. if($bankInfo) {
  196. $data["updatetime"] = time();
  197. $res = \app\common\model\UserBank::update($data,["user_id"=>$userId]);
  198. } else {
  199. $data["user_id"] = $userId;
  200. $data["createtime"] = time();
  201. $res = \app\common\model\UserBank::insert($data);
  202. }
  203. if($res) {
  204. //Sms::flush($mobile, 'binkBank');
  205. $this->success("银行卡绑定成功!");
  206. } else {
  207. $this->error("网络异常,请稍后重试!");
  208. }
  209. }
  210. /**
  211. * 获取绑定银行卡信息
  212. */
  213. public function getBankInfo() {
  214. // 查询是否有过绑定
  215. $bankInfo = \app\common\model\UserBank::where(["user_id"=>$this->auth->id])->find();
  216. if(!$bankInfo) $this->error("银行卡信息获取失败!");
  217. $this->success("获取成功!",$bankInfo);
  218. }
  219. /**
  220. * 绑定支付宝
  221. */
  222. public function bindAlipay() {
  223. $realname = $this->request->request('realname');//真实姓名
  224. $payNo = $this->request->request('pay_no');//支付宝账号
  225. $cardNo = $this->request->request('card_no');//身份证号
  226. //$mobile = $this->request->request('mobile'); //手机号
  227. //$captcha = $this->request->request('captcha'); //验证码
  228. $userId = $this->auth->id;
  229. if(!$realname || !$payNo || !$cardNo) {
  230. $this->error("请将信息填写完整");
  231. }
  232. // 获取用户信息
  233. //$userInfo = \app\common\model\User::where(["id"=>$this->auth->id])->find();
  234. /*if (!Sms::check($mobile, $captcha, 'binkAli')) {
  235. $this->error(__('验证码不正确!'));
  236. }*/
  237. $userAlipayModel = new UserAlipay();
  238. // 查询是否有过绑定
  239. $bankInfo = $userAlipayModel->where(["user_id"=>$userId])->find();
  240. $data = [];
  241. $data["realname"] = $realname;
  242. $data["pay_no"] = $payNo;
  243. $data["card_no"] = $cardNo;
  244. if($bankInfo) {
  245. $data["updatetime"] = time();
  246. $res = $userAlipayModel->update($data,["user_id"=>$userId]);
  247. } else {
  248. $data["user_id"] = $userId;
  249. $data["createtime"] = time();
  250. $res = $userAlipayModel->insert($data);
  251. }
  252. if($res) {
  253. //Sms::flush($mobile, 'binkBank');
  254. $this->success("支付宝绑定成功!");
  255. } else {
  256. $this->error("网络异常,请稍后重试!");
  257. }
  258. }
  259. /**
  260. * 获取绑定银行卡信息
  261. */
  262. public function getAlipayInfo() {
  263. // 查询是否有过绑定
  264. $alipayInfo = UserAlipay::where(["user_id"=>$this->auth->id])->find();
  265. if(!$alipayInfo) $this->error("支付宝信息获取失败!");
  266. $this->success("获取成功!",$alipayInfo);
  267. }
  268. /**
  269. * 获取用户账户信息
  270. */
  271. public function getUserAccountInfo() {
  272. // 获取用户信息
  273. $res = \app\common\model\User::field("id,u_id,avatar,mobile,nickname,money as use_money,frozen")->where(["id"=>$this->auth->id])->find();
  274. $res["all_money"] = bcadd($res["use_money"],$res["frozen"],2);
  275. unset($res["frozen"]);
  276. // 获取用户实名认证信息
  277. $res["realname"] = \app\common\model\UserAuth::where(["user_id"=>$res["id"]])->value("realname");
  278. // 获取用户银行卡信息
  279. $res["bankInfo"] = \app\common\model\UserBank::where(["user_id"=>$res["id"]])->find();
  280. $this->success("获取成功!",$res);
  281. }
  282. /**
  283. * 手机验证码获取用户信息
  284. *
  285. * @param string $mobile 手机号
  286. * @param string $captcha 验证码
  287. */
  288. public function mobilelogin()
  289. {
  290. $mobile = $this->request->request('mobile');
  291. $captcha = $this->request->request('captcha');
  292. if (!$mobile || !$captcha) {
  293. $this->error(__('Invalid parameters'));
  294. }
  295. if (!Validate::regex($mobile, "^1\d{10}$")) {
  296. $this->error(__('Mobile is incorrect'));
  297. }
  298. if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
  299. $this->error(__('Captcha is incorrect'));
  300. }
  301. $user = \app\common\model\User::getByMobile($mobile,"u_id,is_auth");
  302. if ($user) {
  303. Sms::flush($mobile, 'mobilelogin');
  304. $this->success("获取成功!",$user);
  305. } else {
  306. $this->error("没有查询到用户信息!请前往app注册!");
  307. }
  308. }
  309. }