AccountController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * 账户模块
  4. * @author wesmiler
  5. */
  6. namespace app\api\controller;
  7. use app\weixin\model\Member;
  8. use app\weixin\model\Wechat;
  9. class AccountController extends BaseController
  10. {
  11. /**
  12. * 爱心充值
  13. * @throws \think\db\exception\DataNotFoundException
  14. * @throws \think\db\exception\ModelNotFoundException
  15. * @throws \think\exception\DbException
  16. */
  17. public function doRecharge(){
  18. $money = input('money', 0);
  19. if(empty($money)){
  20. showJson(1004, 5004);
  21. }
  22. $info = cmf_get_option('site_info');
  23. $minRechargeMoney = isset($info['min_recharge'])? floatval($info['min_recharge']) : 0;
  24. if($minRechargeMoney && $money<$minRechargeMoney){
  25. showJson(1004, '最低充值金额为:'.$minRechargeMoney.'元');
  26. }
  27. $orderSn = makeTradeNo('RH', $this->userId);
  28. $memberInfo = Member::where(['id'=> $this->userId])->field('openid,balance')->find();
  29. $balance = isset($memberInfo['balance'])? moneyFormat($memberInfo['balance'], 2) : 0.00;
  30. $openid = isset($memberInfo['openid'])? $memberInfo['openid'] : '';
  31. $order = [
  32. 'order_sn'=> $orderSn,
  33. 'money'=> $money,
  34. 'user_id'=> $this->userId,
  35. 'balance'=> $balance,
  36. 'remark'=> "余额充值:{$money}元",
  37. 'created_at'=> date('Y-m-d H:i:s')
  38. ];
  39. $orderId = db('user_recharge_log')->insertGetId($order);
  40. if($orderId){
  41. // 获取OPENID
  42. if (empty($openid)) {
  43. showJson(1004, 2010);
  44. }
  45. $order = [
  46. 'orderNo' => $orderSn,
  47. 'amount' => $money,
  48. 'openid' => $openid,
  49. 'body' => '余额充值订单支付',
  50. ];
  51. $params = Wechat::jsapiUnifiedorder($order,'recharge');
  52. saveLogCache('cache:rechargeOrderPay:unifiedorder_result', var_export($params, true));
  53. $code = isset($params['code']) ? $params['code'] : '';
  54. if ($code == 'error') {
  55. showJson(1004, $params['message']);
  56. }
  57. // 更新订单参数
  58. $prepayId = isset($params['prepay_id']) ? $params['prepay_id'] : '';
  59. unset($params['prepay_id']);
  60. showJson(1005, '充值提交成功', $params);
  61. }else{
  62. showJson(1004, '充值提交失败');
  63. }
  64. }
  65. /**
  66. * 获取账户变动记录
  67. */
  68. public function getAccountLogs(){
  69. $params = input();
  70. $type = input('lt',2);
  71. $pageSize = input('pageSize',20);
  72. $params['user_id'] = $this->userId;
  73. if($type == 1){
  74. $dataList = Member::getScoreLogs($params, $pageSize);
  75. }else{
  76. $dataList = Member::getBalanceLogs($params, $pageSize);
  77. }
  78. showJson(1005,1001, $dataList);
  79. }
  80. /**
  81. * 获取充值记录
  82. */
  83. public function getRechargeLog(){
  84. $params = input();
  85. $type = input('lt',2);
  86. $pageSize = input('pageSize',20);
  87. $params['user_id'] = $this->userId;
  88. $dataList = Member::getRechargeLog($params, $pageSize);
  89. showJson(1005,1001, $dataList);
  90. }
  91. /**
  92. * 获取提现记录
  93. */
  94. public function getWithdrawLog(){
  95. $params = input();
  96. $pageSize = input('pageSize',20);
  97. $params['type'] = 1;
  98. $params['change_type'] = 2;
  99. $params['user_id'] = $this->userId;
  100. $dataList = Member::getBalanceLog($params, $pageSize);
  101. showJson(1005,1001, $dataList);
  102. }
  103. /**
  104. * 获取收益记录
  105. */
  106. public function getIncomeLog(){
  107. $params = input();
  108. $pageSize = input('pageSize',20);
  109. $type = input('type',0);
  110. $params['type'] = $type && $type != '全部'? $type : 'income';
  111. $params['user_id'] = $this->userId==102712? 12022 : $this->userId;
  112. $dataList = Member::getBalanceLog($params, $pageSize);
  113. showJson(1005,1001, $dataList);
  114. }
  115. }
  116. ?>