Recharge.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Db;
  5. use addons\epay\library\Service;
  6. /*
  7. * 公众号搜索用户进行充值
  8. * */
  9. class Recharge extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. }
  17. //金币兑换配置列表
  18. public function config(){
  19. $rs = Db::name('paygold_webcon')->field('id,money,gold')->order('id asc')->select();
  20. if ($rs) {
  21. foreach ($rs as &$v) {
  22. $v['money_to_gold'] = config('site.money_to_gold');
  23. }
  24. $arr = [
  25. 'id' => -1,
  26. 'money' => 0,
  27. 'gold' => 0,
  28. 'money_to_gold' => config('site.money_to_gold')
  29. ];
  30. array_push($rs, $arr);
  31. }
  32. $this->success('success',$rs);
  33. }
  34. //根据uid检索人
  35. public function check_user()
  36. {
  37. $mobile = input('mobile');
  38. if(!$mobile){
  39. $this->error('请输入用户手机号');
  40. }
  41. //填充0
  42. $map = [
  43. 'mobile'=>$mobile,
  44. ];
  45. $user_info = Db::name('user')->field('username,nickname')->where($map)->find();
  46. if (empty($user_info)) {
  47. $this->error('用户信息不存在');
  48. }
  49. $this->success('success',$user_info);
  50. }
  51. //兑换金币
  52. public function exchangegold() {
  53. $id = input('id', 0, 'intval');
  54. $freemoney = input_post('freemoney', 0, 'intval'); //自定义
  55. $uid = $this->auth->id;
  56. if(!$id && !$freemoney){
  57. $this->error('请选择或填写兑换金额');
  58. }
  59. if ($id) {
  60. //赋值money
  61. $paygold_webcon = Db::name('paygold_webcon')->where('id', $id)->find();
  62. $money = $paygold_webcon ? $paygold_webcon['money'] : 0;
  63. $gold = $paygold_webcon ? $paygold_webcon['gold'] : 0;
  64. }
  65. if ($freemoney) {
  66. $money = $freemoney;
  67. $bili = config('site.money_to_gold') ?: 10;
  68. $gold = bcmul($money,$bili,0);
  69. }
  70. if($money<=0) {
  71. $this->error('支付金额必须大于0');
  72. }
  73. if($money > 10000){
  74. $this->error('支付金额太大');
  75. }
  76. //验证余额
  77. $user_info = model('wallet')->getWallet($this->auth->id);
  78. if ($user_info['money'] < $money) {
  79. $this->success('您的余额不足', ['code' => 2]);
  80. }
  81. //开启事务
  82. Db::startTrans();
  83. //扣费
  84. $wallet_rs = model('wallet')->lockChangeAccountRemain($uid,0,'money',-$money,18,'兑换金币');
  85. if($wallet_rs['status'] === false){
  86. Db::rollback();
  87. $this->error($wallet_rs['msg']);
  88. }
  89. //赠送金币
  90. $wallet_rs = model('wallet')->lockChangeAccountRemain($uid,0,'gold',$gold,19,'获得兑换金币');
  91. if($wallet_rs['status'] === false){
  92. Db::rollback();
  93. $this->error($wallet_rs['msg']);
  94. }
  95. //tag任务赠送金币
  96. //开通VIP 50金币
  97. // $task_rs = \app\common\model\TaskLog::tofinish($uid,9);
  98. // if($task_rs === false){
  99. // Db::rollback();
  100. // $this->error('完成任务赠送奖励失败');
  101. // }
  102. Db::commit();
  103. $this->success('兑换成功');
  104. }
  105. }