Recharge.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace app\clientappapi\controller;
  3. use app\common\controller\ClientApi;
  4. use app\main\constants\ErrorCodeConstants;
  5. use app\main\constants\OrderContents;
  6. use app\main\constants\PayConstants;
  7. use app\main\helper\ArrayHelper;
  8. use app\main\service\AdminService;
  9. use app\main\service\FinancialService;
  10. use app\main\service\GoodsService;
  11. use app\main\service\OrderService;
  12. use app\main\service\WebUserService;
  13. class Recharge extends ClientApi {
  14. /**
  15. * 商品、支付列表
  16. */
  17. public function goodslist()
  18. {
  19. $this->userInfo = WebUserService::instance()->getUserInfo();
  20. $user = WebUserService::instance()->getUserInfo();
  21. // $free_diankan = FinancialService::instance()->getRechargeModel()->getTotalFreeKandian($user->id);
  22. // $kandian = intval($user->kandian) + $free_diankan;
  23. $is_test = AdminService::instance()->checkIsTestChannel($user->agent_id, $user->channel_id);
  24. $goods_list = model('Goods')->getGoodsListForApp(PayConstants::BUSINESS_APP, $is_test, $user->is_pay);
  25. foreach ($goods_list as $index => $item) {
  26. $goods_list[$index]['second_description'] = mb_substr($item['second_description'], 0, 10);
  27. $goods_list[$index]['icon'] = mb_substr($item['icon'], 0, 3);
  28. }
  29. // $pay_list = model('Wxpay')->getListByBusiness(PayConstants::BUSINESS_APP);
  30. // $pay_list = ArrayHelper::extractColumn($pay_list, ['id','p_desc','icon']);
  31. $data = [
  32. // 'pay_list' => $pay_list,
  33. 'goods_list' => $goods_list,
  34. ];
  35. $this->success('商品信息', $data);
  36. }
  37. public function paytypelist()
  38. {
  39. $pay_list = model('Wxpay')->getListByBusiness(PayConstants::BUSINESS_APP);
  40. $pay_list = ArrayHelper::extractColumn($pay_list, ['id', 'payment_method', 'p_desc', 'icon']);
  41. $data = [
  42. 'pay_list' => $pay_list,
  43. ];
  44. $this->success('支付方式信息', $data);
  45. }
  46. /**
  47. * 下单
  48. */
  49. public function pay()
  50. {
  51. $user_info = WebUserService::instance()->getUserInfo();
  52. //登录检测
  53. if (!$user_info->id) {
  54. $this->error('登录信息获取失败');
  55. }
  56. $payment_method = intval($this->getParams('paymentMethod'));
  57. $payService = OrderService::instance()->getOrderService($payment_method);
  58. if (!$payService) {
  59. $this->error('支付方式错误' . $payment_method);
  60. }
  61. try{
  62. $result = $payService->init($payment_method)->setParams($this->params)->setUser($user_info)->saveOrder();
  63. }catch (\Exception $e) {
  64. $this->error($e->getMessage());
  65. }
  66. if ($result->code == ErrorCodeConstants::SUCCESS) {
  67. $this->success($result->msg, $result->data);
  68. } else {
  69. $this->error($result->msg);
  70. }
  71. }
  72. /**
  73. * 获取充值记录
  74. */
  75. public function record()
  76. {
  77. $pageSize = $this->getParams('pageSize');
  78. $page = $this->getParams('page');
  79. $userId = WebUserService::instance()->getUserInfo()->id;
  80. $result = OrderService::instance()->getRechargeRecord($userId, $page, $pageSize);
  81. if ($result->code == ErrorCodeConstants::SUCCESS) {
  82. //整理下数据
  83. $data = [];
  84. if ($result->data['record_list']) {
  85. foreach ($result->data['record_list'] as $key => $val) {
  86. $data[$key] = $val;
  87. if ($val['business_line'] == PayConstants::BUSINESS_APP) {
  88. $data[$key]['type_text'] = $val['type_text'] . '-'. $val['notes'];
  89. }
  90. if ($val['type'] == '1' || $val['type'] == '3' || $val['type'] == '5' || $val['type'] == '6') { //书币
  91. if (intval($val['kandian']) == 0) { //免费书币
  92. if (intval($val['free_kandian']) > 0) {
  93. $data[$key]['show_item'] = '+' . $val['free_kandian'] . '书币'; //int转string
  94. $data[$key]['end_date'] = '有效期至:'.Date('Y-m-d', $val['free_endtime']); //书币失效日期
  95. } else {
  96. $data[$key]['show_item'] = $val['free_kandian'] . '书币'; //int转string
  97. $data[$key]['end_date'] = '永久'; //书币失效日期
  98. }
  99. if ($val['type'] == 1) {
  100. $data[$key]['type_text'] = '充值赠送书币';
  101. } elseif (intval($val['type']) == 6) {
  102. $data[$key]['type_text'] = '活动赠送书币';
  103. }
  104. } else { //永久书币
  105. if (intval($val['kandian']) > 0) {
  106. $data[$key]['show_item'] = '+' . $val['kandian'] . '书币'; //int转string
  107. } else {
  108. $data[$key]['show_item'] = $val['kandian'] . '书币'; //int转string
  109. }
  110. $data[$key]['end_date'] = '永久'; //书币失效日期
  111. }
  112. } else { //vip
  113. if (intval($val['day']) > 0 || intval($val['hour']) > 0) { //加vip时长
  114. if (intval($val['day']) > 0) {
  115. $data[$key]['show_item'] = '+' . $val['day'] . '天';
  116. if (intval($val['hour']) > 0) {
  117. $data[$key]['show_item'] = $data[$key]['showItem'] . $val['hour'] . '小时';
  118. }
  119. } else {
  120. $data[$key]['show_item'] = '+' . $val['hour'] . '小时';
  121. }
  122. } else { //减少vip时长
  123. if (intval($val['day']) < 0) {
  124. $data[$key]['show_item'] = $val['day'] . '天';
  125. if (intval($val['hour']) < 0) {
  126. $data[$key]['show_item'] = $data[$key]['showItem'] . abs($val['hour']) . '小时';
  127. }
  128. } else {
  129. if (intval($val['hour']) < 0) {
  130. $data[$key]['show_item'] = $val['hour'] . '小时';
  131. }
  132. }
  133. }
  134. $days = $val['day'] ?? 0;
  135. $hour = $val['hour'] ?? 0;
  136. if ($val['vip_starttime']) {
  137. $data[$key]['end_date'] = date('Y-m-d H:i:s', strtotime("+{$days} days {$hour} hours ", $val['vip_starttime']));
  138. } else {
  139. $data[$key]['end_date'] = '-';
  140. }
  141. }
  142. }
  143. }
  144. $this->success($result->msg, ['total' => $result->data['total'], 'record_list' => $data]);
  145. } else {
  146. $this->error($result->msg);
  147. }
  148. }
  149. public function checkpaid()
  150. {
  151. $id = $this->getParams('orderId');
  152. $uid = WebUserService::instance()->getUserInfo()->id;
  153. $mOrder = OrderService::instance()->getOrderModel()
  154. ->where('out_trade_no', $id)
  155. ->where('user_id', $uid)
  156. ->find();
  157. if ($mOrder) {
  158. $data = [
  159. 'state'=>$mOrder['state']
  160. ];
  161. if ($data['state'] == OrderContents::ORDER_STATE_PAID) {
  162. $data['free_kandian'] = FinancialService::instance()->getTotalFreeKandian($uid)->data;
  163. $data['kandian'] = FinancialService::instance()->getTotalKandian($uid)->data;
  164. $data['goods'] = GoodsService::instance()->getGoodsModel()->where('id', $mOrder['goods_id'])->find()->toArray();
  165. }
  166. $this->success('订单状态', $data);
  167. } else {
  168. $this->error('订单查询失败');
  169. }
  170. }
  171. }