PtbController.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /**
  3. * PtbController.php UTF-8
  4. * h5 wap 平台币
  5. *
  6. * @date : 2018/4/27 18:09
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : liuhongliang <lhl@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace h5wap\wap\controller;
  13. use h5wap\common\controller\V2BaseController;
  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\WalletConst;
  22. use huolib\pay\Pay;
  23. use huolib\status\CommonStatus;
  24. use huolib\status\OrderStatus;
  25. use huolib\utils\OrderUtils;
  26. use think\Exception;
  27. class PtbController extends V2BaseController {
  28. private $mem_data;
  29. public function _initialize() {
  30. parent::_initialize();
  31. $this->checkLogin();
  32. $this->mem_data = (new Member())->getMemInfo($this->mem_id);
  33. if (FormatConst::FORMAT_HTML == $this->response_type) {
  34. $this->assign('userinfo', $this->mem_data);
  35. }
  36. }
  37. /**
  38. * 平台币首页
  39. * http://doc.1tsdk.com/138?page_id=3125 *
  40. * 【域名】/wap/ptb/index
  41. *
  42. * @throws \think\Exception
  43. */
  44. public function index() {
  45. $_data = (new Member())->getMemInfo($this->mem_id);
  46. $_rdata['userinfo'] = $_data;
  47. $this->assign('userinfo', $_rdata['userinfo']);
  48. return $this->fetch('ptb/index');
  49. }
  50. /**
  51. * 平台币充值
  52. * http://doc.1tsdk.com/138?page_id=3136
  53. * 【域名】/wap/ptb/recharge
  54. *
  55. * @throws \think\Exception
  56. */
  57. public function recharge() {
  58. $_ptb_rmb_rate = CommonFunc::getPtbRmbRate();
  59. $this->assign('ptb_rmb_rate', $_ptb_rmb_rate);
  60. $_pay_type = (new Ptb())->getPayWays(0);
  61. $this->assign('pay_type', $_pay_type);
  62. return $this->fetch('ptb/recharge');
  63. }
  64. /**
  65. * 平台币充值记录
  66. * http://doc.1tsdk.com/138?page_id=3132
  67. *
  68. * 【域名】/wap/ptb/recharge/record
  69. *
  70. * @return mixed
  71. * @throws \think\Exception
  72. */
  73. public function rechargeRecord() {
  74. $_mem_id = $this->mem_id;
  75. $_page = $this->request->param('page/d', 1);
  76. $_offset = $this->request->param('offset/d', 10);
  77. $_page = $_page.','.$_offset;
  78. $_where['type'] = WalletConst::WALLET_TYPE_CHARGE;
  79. $_rdata = (new Ptb())->getMemChargeList($_mem_id, [], $_page);
  80. if (FormatConst::FORMAT_HTML == $this->response_type) {
  81. $this->assign('ptb_recharge_record', $_rdata['data']);
  82. return $this->fetch('ptb/rechargeRecord');
  83. }
  84. return $this->returnData($_rdata);
  85. }
  86. /**
  87. * 平台币消费记录
  88. * http://doc.1tsdk.com/138?page_id=3133 *
  89. * 【域名】/wap/ptb/consume/record
  90. *
  91. * @return mixed
  92. * @throws \think\Exception
  93. */
  94. public function consumeRecord() {
  95. $_mem_id = $this->mem_id;
  96. $_page = $this->request->param('page/d', 1);
  97. $_offset = $this->request->param('offset/d', 10);
  98. $_page = $_page.','.$_offset;
  99. $_rdata = (new Ptb())->getMemConsumeList($_mem_id, [], $_page);
  100. if (FormatConst::FORMAT_HTML == $this->response_type) {
  101. $this->assign('ptb_consume_record', $_rdata['data']);
  102. return $this->fetch('ptb/consumeRecord');
  103. }
  104. return $this->returnData($_rdata);
  105. }
  106. /**
  107. * 查询支付结果
  108. * http://doc.1tsdk.com/138?page_id=3325
  109. * 【域名】/ptb/order/query
  110. */
  111. public function read() {
  112. $_order_id = $this->request->param('order-order_id/s', '');
  113. $_order = new Ptb();
  114. $_rdata = $_order->getStatus($_order_id);
  115. if (false == $_rdata) {
  116. $this->error(lang('ERROR'));
  117. }
  118. $_rdata['order_id'] = $_order_id;
  119. $this->success(lang('SUCCESS'), $_rdata);
  120. }
  121. /**
  122. * 选择支付进行支付
  123. * http://doc.1tsdk.com/138?page_id=3326
  124. *【域名】/ptb/pay/post
  125. *
  126. */
  127. public function pay() {
  128. $_payway = $this->request->param('payway/s', '');
  129. $_amount = $this->request->param('amount/f', 0);
  130. $_mc_class = MemCache::ins();
  131. $_mem_data = $_mc_class->getInfoById($this->mem_id);
  132. $_pw_check_rs = OrderUtils::checkPayway($_payway);
  133. if (OrderStatus::NO_ERROR != $_pw_check_rs) {
  134. $this->error(OrderStatus::getMsg($_pw_check_rs), [], $_pw_check_rs);
  135. }
  136. $_amount_chk_rs = OrderUtils::checkAmount($_amount);
  137. if (OrderStatus::NO_ERROR != $_amount_chk_rs) {
  138. $this->error(OrderStatus::getMsg($_amount_chk_rs), [], $_amount_chk_rs);
  139. }
  140. $_type = WalletConst::WALLET_FROM_CHARGE;
  141. $_rdata = (new Ptb())->preorder($this->mem_id, $_amount, $_type, $_payway);
  142. if (CommonStatus::NO_ERROR != $_rdata['code']) {
  143. $this->returnData($_rdata);
  144. }
  145. $_order_id = $_rdata['data']['order_id'];
  146. try {
  147. $_pay_class = Pay::ins()->get($_payway);
  148. $_func = $this->getFunc($this->device_type);
  149. $_show_url = url('wap/'.$_payway.'/showUrl', ['order_id' => $_order_id], false, H5MSITE);
  150. $_return_url = url(
  151. 'wap/'.$_payway.'/returnUrl', ['order_id' => $_order_id], false, H5MSITE
  152. );
  153. $_pay_class->setReturnUrl($_return_url);
  154. $_pay_class->setShowUrl($_show_url);
  155. $_pay_class->setOrderId($_order_id);
  156. $_product_name = config('CURRENCY_NAME').'充值'.$_amount;
  157. $_pay_class->setProductName($_product_name);
  158. $_pay_class->setProductDesc($_product_name);
  159. $_pay_class->setRealAmount($_amount);
  160. $_pay_class->setProductId(WalletConst::WALLET_PRODUCT_MEM_PTB);
  161. $_pay_class->setIp($this->request->ip());
  162. $_pay_class->setOpenId(HuoSession::getOpenId());
  163. $_pay_class->setMemId($this->mem_id);
  164. $_pay_class->setMemRealName($_mem_data['real_name']);
  165. $_pay_class->setMemRegTime($_mem_data['create_time']);
  166. $_pay_class->setMemMobile($_mem_data['mobile']);
  167. $_pay_rs = $_pay_class->$_func();
  168. if (empty($_pay_rs)) {
  169. $_code = OrderStatus::PAYWAY_PREORDER_ERROR;
  170. $this->error(OrderStatus::getMsg($_code), [], $_code);
  171. }
  172. $_code = OrderStatus::NO_ERROR;
  173. $this->success(OrderStatus::getMsg($_code), $_pay_rs, $_code);
  174. } catch (Exception $e) {
  175. $_code = OrderStatus::PAYWAY_NOT_EXISTS;
  176. $this->error(OrderStatus::getMsg($_code), [], $_code);
  177. }
  178. }
  179. /**
  180. * @param $device_type
  181. *
  182. * @return string clientPay mobilePay pcPay
  183. */
  184. public function getFunc($device_type) {
  185. switch ($device_type) {
  186. case DeviceTypeConst::DEVICE_TYPE_IOSAPPLESDK:
  187. $_type = 'clientPay';
  188. break;
  189. case DeviceTypeConst::DEVICE_TYPE_IOSSDK:
  190. $_type = 'clientPay';
  191. break;
  192. case DeviceTypeConst::DEVICE_TYPE_IOSAPP:
  193. $_type = 'clientPay';
  194. break;
  195. case DeviceTypeConst::DEVICE_TYPE_IOSH5APP:
  196. $_type = 'clientPay';
  197. break;
  198. case DeviceTypeConst::DEVICE_TYPE_SAFARI:
  199. $_type = 'mobilePay';
  200. break;
  201. case DeviceTypeConst::DEVICE_TYPE_ANDSDK:
  202. $_type = 'clientPay';
  203. break;
  204. case DeviceTypeConst::DEVICE_TYPE_ANDAPP:
  205. $_type = 'clientPay';
  206. break;
  207. case DeviceTypeConst::DEVICE_TYPE_ANDH5APP:
  208. $_type = 'clientPay';
  209. break;
  210. case DeviceTypeConst::DEVICE_TYPE_ANDBROWSER:
  211. $_type = 'mobilePay';
  212. break;
  213. case DeviceTypeConst::DEVICE_TYPE_WEIXIN:
  214. $_type = 'jsPay';
  215. break;
  216. case DeviceTypeConst::DEVICE_TYPE_PC:
  217. $_type = 'pcPay';
  218. break;
  219. case DeviceTypeConst::DEVICE_TYPE_WAP:
  220. $_type = 'mobilePay';
  221. break;
  222. default:
  223. $_type = 'mobilePay';
  224. }
  225. return $_type;
  226. }
  227. }