1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * MpayController.php UTF-8
- * 米大师支付
- *
- * @date : 2018/8/10 14:53
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace mini\sdk\controller;
- use huo\controller\pay\Notify;
- use huo\controller\pay\Sdk;
- use huolib\constant\OrderConst;
- use huolib\status\OrderStatus;
- use huoMpay\Payments;
- use mini\common\controller\V2ApiBaseController;
- use think\Log;
- class MpayController extends V2ApiBaseController {
- public function _initialize() {
- parent::_initialize();
- // Log::write(
- // $this->request->scheme().'://'.$this->request->server('HTTP_HOST').$this->request->server('REQUEST_URI').'?'
- // .$this->request->getContent(),
- // Log::LOG
- // );
- }
- /**
- * 【米大师】查询余额接口
- * http://doc.1tsdk.com/159?page_id=4386
- * 【域名】/mp/mpay/query
- */
- public function get_balance_m() {
- $this->checkLogin();
- $_order_rq = $this->setOrderData();
- $_order_id = $_order_rq->getOrderId();
- if (empty($_order_id)) {
- $_code = OrderStatus::ORDER_ID_EMPTY;
- $this->error(OrderStatus::getMsg($_code), [], $_code);
- }
- /* 1 检查订单是否支付 */
- $_order = new Sdk();
- $_rdata = $_order->getStatus($_order_rq->getOrderId());
- if (false == $_rdata) {
- $_code = OrderStatus::INVALID_PARAMS;
- $this->error(OrderStatus::getMsg($_code), [], $_code);
- }
- /* 未支付 查询米大师余额 并扣除米大师余额 */
- if (OrderConst::PAY_STATUS_SUC != $_rdata['status']) {
- $_rs = (new Payments())->getBalanceAndPay($this->mem_id, $_order_rq->getOrderId());
- if (OrderStatus::NO_ERROR != $_rs['code']) {
- $this->returnData($_rs);
- }
- $_rdata = $_rs['data'];
- }
- if (OrderConst::CP_STATUS_SUC != $_rdata['cp_status'] && OrderConst::PAY_STATUS_SUC == $_rdata['status']) {
- $_rs = (new Notify())->notify($_order_rq->getOrderId());
- if (OrderStatus::NO_ERROR == $_rs['code']) {
- $_rdata['status'] = OrderConst::PAY_STATUS_SUC;
- $_rdata['cp_status'] = OrderConst::CP_STATUS_SUC;
- }
- }
- $_rdata['order_id'] = $_order_rq->getOrderId();
- $this->success(lang('SUCCESS'), $_rdata);
- }
- }
|