MpayController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * MpayController.php UTF-8
  4. * 米大师支付
  5. *
  6. * @date : 2018/8/10 14:53
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HuoMp 1.0
  11. */
  12. namespace mini\sdk\controller;
  13. use huo\controller\pay\Notify;
  14. use huo\controller\pay\Sdk;
  15. use huolib\constant\OrderConst;
  16. use huolib\status\OrderStatus;
  17. use huoMpay\Payments;
  18. use mini\common\controller\V2ApiBaseController;
  19. use think\Log;
  20. class MpayController extends V2ApiBaseController {
  21. public function _initialize() {
  22. parent::_initialize();
  23. // Log::write(
  24. // $this->request->scheme().'://'.$this->request->server('HTTP_HOST').$this->request->server('REQUEST_URI').'?'
  25. // .$this->request->getContent(),
  26. // Log::LOG
  27. // );
  28. }
  29. /**
  30. * 【米大师】查询余额接口
  31. * http://doc.1tsdk.com/159?page_id=4386
  32. * 【域名】/mp/mpay/query
  33. */
  34. public function get_balance_m() {
  35. $this->checkLogin();
  36. $_order_rq = $this->setOrderData();
  37. $_order_id = $_order_rq->getOrderId();
  38. if (empty($_order_id)) {
  39. $_code = OrderStatus::ORDER_ID_EMPTY;
  40. $this->error(OrderStatus::getMsg($_code), [], $_code);
  41. }
  42. /* 1 检查订单是否支付 */
  43. $_order = new Sdk();
  44. $_rdata = $_order->getStatus($_order_rq->getOrderId());
  45. if (false == $_rdata) {
  46. $_code = OrderStatus::INVALID_PARAMS;
  47. $this->error(OrderStatus::getMsg($_code), [], $_code);
  48. }
  49. /* 未支付 查询米大师余额 并扣除米大师余额 */
  50. if (OrderConst::PAY_STATUS_SUC != $_rdata['status']) {
  51. $_rs = (new Payments())->getBalanceAndPay($this->mem_id, $_order_rq->getOrderId());
  52. if (OrderStatus::NO_ERROR != $_rs['code']) {
  53. $this->returnData($_rs);
  54. }
  55. $_rdata = $_rs['data'];
  56. }
  57. if (OrderConst::CP_STATUS_SUC != $_rdata['cp_status'] && OrderConst::PAY_STATUS_SUC == $_rdata['status']) {
  58. $_rs = (new Notify())->notify($_order_rq->getOrderId());
  59. if (OrderStatus::NO_ERROR == $_rs['code']) {
  60. $_rdata['status'] = OrderConst::PAY_STATUS_SUC;
  61. $_rdata['cp_status'] = OrderConst::CP_STATUS_SUC;
  62. }
  63. }
  64. $_rdata['order_id'] = $_order_rq->getOrderId();
  65. $this->success(lang('SUCCESS'), $_rdata);
  66. }
  67. }