PtbController.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /**
  3. * PtbController.php UTF-8
  4. * 平台币
  5. *
  6. * @date : 2018/6/2 15:46
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace api\cfloat\controller;
  13. use api\common\controller\CFloatBaseController;
  14. use huo\controller\common\CommonFunc;
  15. use huo\controller\common\HuoSession;
  16. use huo\controller\member\Member;
  17. use huo\controller\member\MemCache;
  18. use huo\controller\wallet\Ptb;
  19. use huolib\constant\DeviceTypeConst;
  20. use huolib\constant\FormatConst;
  21. use huolib\constant\OrderConst;
  22. use huolib\constant\WalletConst;
  23. use huolib\pay\Pay;
  24. use huolib\status\CommonStatus;
  25. use huolib\status\OrderStatus;
  26. use huolib\tool\StrUtils;
  27. use huolib\utils\OrderUtils;
  28. use think\Exception;
  29. class PtbController extends CFloatBaseController {
  30. private $mem_data;
  31. public function _initialize() {
  32. parent::_initialize();
  33. $this->checkLogin();
  34. $this->mem_data = (new Member())->getMemInfo($this->mem_id);
  35. if (FormatConst::FORMAT_HTML == $this->response_type) {
  36. $this->assign('userinfo', $this->mem_data);
  37. }
  38. }
  39. /**
  40. * 平台消费记录列表
  41. * http://doc.1tsdk.com/138?page_id=3403
  42. * 【域名】/cfloat/ptb/consume_record
  43. */
  44. public function consumeRecord() {
  45. $_mem_id = $this->mem_id;
  46. $_page = get_val($this->rq_data, 'page', 0); /* 页码 默认为1 代表第一页 1 */
  47. $_offset = get_val($this->rq_data, 'offset', 10); /* 每页显示数量 默认为10 */
  48. $_map = [];
  49. $_page = $_page.','.$_offset;
  50. $_rdata = (new Ptb())->getMemConsumeList($_mem_id, $_map, $_page);
  51. return $this->returnData($_rdata);
  52. }
  53. /**
  54. * 平台充值记录列表
  55. * http://doc.1tsdk.com/138?page_id=3405
  56. * 【域名】/cfloat/ptb/recharge_record
  57. */
  58. public function rechargeRecord() {
  59. $_mem_id = $this->mem_id;
  60. $_page = get_val($this->rq_data, 'page', 0); /* 页码 默认为1 代表第一页 1 */
  61. $_offset = get_val($this->rq_data, 'offset', 10); /* 每页显示数量 默认为10 */
  62. $_status = get_val($this->rq_data, 'status', 0);
  63. $_map = [];
  64. $_order_status = array_keys(OrderConst::getPayStatusMsg(0,true));
  65. if (in_array($_status, $_order_status)) {
  66. $_map['status'] = $_status;
  67. }
  68. $_page = $_page.','.$_offset;
  69. $_where['type'] = WalletConst::WALLET_TYPE_CHARGE;
  70. $_rdata = (new Ptb())->getMemChargeList($_mem_id, $_map, $_page);
  71. return $this->returnData($_rdata);
  72. }
  73. /**
  74. * 平台币充值
  75. * http://doc.1tsdk.com/138?page_id=3406
  76. * 【域名】/cfloat/ptb/recharge
  77. */
  78. public function recharge() {
  79. $_mc_class = MemCache::ins();
  80. $_me_data = $_mc_class->getMeInfoById($this->mem_id);
  81. $_ptb_rmb_rate = CommonFunc::getPtbRmbRate();
  82. $_pay_type = (new Ptb())->getPayWays(0);
  83. $_rdata = [
  84. 'code' => CommonStatus::NO_ERROR,
  85. 'msg' => CommonStatus::getMsg(CommonStatus::NO_ERROR),
  86. 'data' => [
  87. 'ptb_cnt' => isset($_me_data['ptb_cnt']) ? StrUtils::formatNumber($_me_data['ptb_cnt']) : 0,
  88. 'ptb_rate' => $_ptb_rmb_rate,
  89. 'pay_type' => $_pay_type
  90. ],
  91. ];
  92. return $this->returnData($_rdata);
  93. }
  94. /**
  95. * 选择支付进行支付
  96. * http://doc.1tsdk.com/138?page_id=3407
  97. * 【域名】/cfloat/ptb/pay/post
  98. */
  99. public function payPost() {
  100. $_payway = $this->request->param('payway/s', '');
  101. $_amount = $this->request->param('amount/f', 0);
  102. $_pw_check_rs = OrderUtils::checkPayway($_payway);
  103. if (OrderStatus::NO_ERROR != $_pw_check_rs) {
  104. $this->error(OrderStatus::getMsg($_pw_check_rs), [], $_pw_check_rs);
  105. }
  106. $_amount_chk_rs = OrderUtils::checkAmount($_amount);
  107. if (OrderStatus::NO_ERROR != $_amount_chk_rs) {
  108. $this->error(OrderStatus::getMsg($_amount_chk_rs), [], $_amount_chk_rs);
  109. }
  110. $_type = WalletConst::WALLET_FROM_CHARGE;
  111. $_rdata = (new Ptb())->preorder($this->mem_id, $_amount, $_type, $_payway);
  112. if (CommonStatus::NO_ERROR != $_rdata['code']) {
  113. $this->returnData($_rdata);
  114. }
  115. $_order_id = $_rdata['data']['order_id'];
  116. try {
  117. $_pay_class = Pay::ins()->get($_payway);
  118. $_func = $this->getFunc($this->device_type);
  119. $_show_url = url('cfloat/' . $_payway.'/show', ['order_id' => $_order_id], false, APISITE);
  120. $_return_url = url(
  121. 'cfloat/' . $_payway.'/return', ['order_id' => $_order_id], false, APISITE
  122. );
  123. $_pay_class->setReturnUrl($_return_url);
  124. $_pay_class->setShowUrl($_show_url);
  125. $_pay_class->setOrderId($_order_id);
  126. $_product_name = config('CURRENCY_NAME').'充值'.$_amount;
  127. $_pay_class->setProductName($_product_name);
  128. $_pay_class->setProductDesc($_product_name);
  129. $_pay_class->setRealAmount($_amount);
  130. $_pay_class->setProductId(WalletConst::WALLET_PRODUCT_MEM_PTB);
  131. $_pay_class->setIp($this->request->ip());
  132. $_pay_class->setOpenId((new HuoSession($this->mem_id))->getOpenId());
  133. $_pay_rs = $_pay_class->$_func();
  134. if (empty($_pay_rs)) {
  135. $_code = OrderStatus::PAYWAY_PREORDER_ERROR;
  136. $this->error(OrderStatus::getMsg($_code), [], $_code);
  137. }
  138. $_code = OrderStatus::NO_ERROR;
  139. $this->success(OrderStatus::getMsg($_code), $_pay_rs, $_code);
  140. } catch (Exception $e) {
  141. $_code = OrderStatus::PAYWAY_NOT_EXISTS;
  142. $this->error(OrderStatus::getMsg($_code), [], $_code);
  143. }
  144. }
  145. /**
  146. * 查询支付结果
  147. * http://doc.1tsdk.com/138?page_id=3408
  148. * 【域名】/cfloat/ptb/order/query
  149. */
  150. public function orderQuery() {
  151. $_order_id = $this->request->param('order-order_id/s', '');
  152. $_order = new Ptb();
  153. $_rdata = $_order->getStatus($_order_id);
  154. if (false == $_rdata) {
  155. $this->error(lang('ERROR'));
  156. }
  157. $_rdata['order_id'] = $_order_id;
  158. $this->success(lang('SUCCESS'), $_rdata);
  159. }
  160. /**
  161. * @param $device_type
  162. *
  163. * @return string clientPay mobilePay pcPay
  164. */
  165. private function getFunc($device_type) {
  166. switch ($device_type) {
  167. case DeviceTypeConst::DEVICE_TYPE_IOSAPPLESDK:
  168. $_type = 'clientPay';
  169. break;
  170. case DeviceTypeConst::DEVICE_TYPE_IOSSDK:
  171. $_type = 'clientPay';
  172. break;
  173. case DeviceTypeConst::DEVICE_TYPE_IOSAPP:
  174. $_type = 'clientPay';
  175. break;
  176. case DeviceTypeConst::DEVICE_TYPE_IOSH5APP:
  177. $_type = 'clientPay';
  178. break;
  179. case DeviceTypeConst::DEVICE_TYPE_SAFARI:
  180. $_type = 'mobilePay';
  181. break;
  182. case DeviceTypeConst::DEVICE_TYPE_ANDSDK:
  183. $_type = 'clientPay';
  184. break;
  185. case DeviceTypeConst::DEVICE_TYPE_ANDAPP:
  186. $_type = 'clientPay';
  187. break;
  188. case DeviceTypeConst::DEVICE_TYPE_ANDH5APP:
  189. $_type = 'clientPay';
  190. break;
  191. case DeviceTypeConst::DEVICE_TYPE_ANDBROWSER:
  192. $_type = 'mobilePay';
  193. break;
  194. case DeviceTypeConst::DEVICE_TYPE_WEIXIN:
  195. $_type = 'jsPay';
  196. break;
  197. case DeviceTypeConst::DEVICE_TYPE_PC:
  198. $_type = 'pcPay';
  199. break;
  200. case DeviceTypeConst::DEVICE_TYPE_WAP:
  201. $_type = 'mobilePay';
  202. break;
  203. default:
  204. $_type = 'mobilePay';
  205. }
  206. return $_type;
  207. }
  208. }