| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 | <?php/** * PtbController.php UTF-8 * h5 wap 平台币 * * @date    : 2018/4/27 18:09 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : liuhongliang <lhl@huosdk.com> * @version : HUOSDK 8.0 */namespace h5wap\wap\controller;use h5wap\common\controller\V2BaseController;use huo\controller\common\CommonFunc;use huo\controller\common\HuoSession;use huo\controller\member\Member;use huo\controller\member\MemCache;use huo\controller\wallet\Ptb;use huolib\constant\DeviceTypeConst;use huolib\constant\FormatConst;use huolib\constant\WalletConst;use huolib\pay\Pay;use huolib\status\CommonStatus;use huolib\status\OrderStatus;use huolib\utils\OrderUtils;use think\Exception;class PtbController extends V2BaseController {    private $mem_data;    public function _initialize() {        parent::_initialize();        $this->checkLogin();        $this->mem_data = (new Member())->getMemInfo($this->mem_id);        if (FormatConst::FORMAT_HTML == $this->response_type) {            $this->assign('userinfo', $this->mem_data);        }    }    /**     * 平台币首页     * http://doc.1tsdk.com/138?page_id=3125     *     * 【域名】/wap/ptb/index     *     * @throws \think\Exception     */    public function index() {        $_data = (new Member())->getMemInfo($this->mem_id);        $_rdata['userinfo'] = $_data;        $this->assign('userinfo', $_rdata['userinfo']);        return $this->fetch('ptb/index');    }    /**     * 平台币充值     * http://doc.1tsdk.com/138?page_id=3136     * 【域名】/wap/ptb/recharge     *     * @throws \think\Exception     */    public function recharge() {        $_ptb_rmb_rate = CommonFunc::getPtbRmbRate();        $this->assign('ptb_rmb_rate', $_ptb_rmb_rate);        $_pay_type = (new Ptb())->getPayWays(0);        $this->assign('pay_type', $_pay_type);        return $this->fetch('ptb/recharge');    }    /**     * 平台币充值记录     * http://doc.1tsdk.com/138?page_id=3132     *     * 【域名】/wap/ptb/recharge/record     *     * @return mixed     * @throws \think\Exception     */    public function rechargeRecord() {        $_mem_id = $this->mem_id;        $_page = $this->request->param('page/d', 1);        $_offset = $this->request->param('offset/d', 10);        $_page = $_page.','.$_offset;        $_where['type'] = WalletConst::WALLET_TYPE_CHARGE;        $_rdata = (new Ptb())->getMemChargeList($_mem_id, [], $_page);        if (FormatConst::FORMAT_HTML == $this->response_type) {            $this->assign('ptb_recharge_record', $_rdata['data']);            return $this->fetch('ptb/rechargeRecord');        }        return $this->returnData($_rdata);    }    /**     * 平台币消费记录     * http://doc.1tsdk.com/138?page_id=3133     *     * 【域名】/wap/ptb/consume/record     *     * @return mixed     * @throws \think\Exception     */    public function consumeRecord() {        $_mem_id = $this->mem_id;        $_page = $this->request->param('page/d', 1);        $_offset = $this->request->param('offset/d', 10);        $_page = $_page.','.$_offset;        $_rdata = (new Ptb())->getMemConsumeList($_mem_id, [], $_page);        if (FormatConst::FORMAT_HTML == $this->response_type) {            $this->assign('ptb_consume_record', $_rdata['data']);            return $this->fetch('ptb/consumeRecord');        }        return $this->returnData($_rdata);    }    /**     * 查询支付结果     * http://doc.1tsdk.com/138?page_id=3325     * 【域名】/ptb/order/query     */    public function read() {        $_order_id = $this->request->param('order-order_id/s', '');        $_order = new Ptb();        $_rdata = $_order->getStatus($_order_id);        if (false == $_rdata) {            $this->error(lang('ERROR'));        }        $_rdata['order_id'] = $_order_id;        $this->success(lang('SUCCESS'), $_rdata);    }    /**     * 选择支付进行支付     * http://doc.1tsdk.com/138?page_id=3326     *【域名】/ptb/pay/post     *     */    public function pay() {        $_payway = $this->request->param('payway/s', '');        $_amount = $this->request->param('amount/f', 0);        $_mc_class = MemCache::ins();        $_mem_data = $_mc_class->getInfoById($this->mem_id);        $_pw_check_rs = OrderUtils::checkPayway($_payway);        if (OrderStatus::NO_ERROR != $_pw_check_rs) {            $this->error(OrderStatus::getMsg($_pw_check_rs), [], $_pw_check_rs);        }        $_amount_chk_rs = OrderUtils::checkAmount($_amount);        if (OrderStatus::NO_ERROR != $_amount_chk_rs) {            $this->error(OrderStatus::getMsg($_amount_chk_rs), [], $_amount_chk_rs);        }        $_type = WalletConst::WALLET_FROM_CHARGE;        $_rdata = (new Ptb())->preorder($this->mem_id, $_amount, $_type, $_payway);        if (CommonStatus::NO_ERROR != $_rdata['code']) {            $this->returnData($_rdata);        }        $_order_id = $_rdata['data']['order_id'];        try {            $_pay_class = Pay::ins()->get($_payway);            $_func = $this->getFunc($this->device_type);            $_show_url = url('wap/'.$_payway.'/showUrl', ['order_id' => $_order_id], false, H5MSITE);            $_return_url = url(                'wap/'.$_payway.'/returnUrl', ['order_id' => $_order_id], false, H5MSITE            );            $_pay_class->setReturnUrl($_return_url);            $_pay_class->setShowUrl($_show_url);            $_pay_class->setOrderId($_order_id);            $_product_name = config('CURRENCY_NAME').'充值'.$_amount;            $_pay_class->setProductName($_product_name);            $_pay_class->setProductDesc($_product_name);            $_pay_class->setRealAmount($_amount);            $_pay_class->setProductId(WalletConst::WALLET_PRODUCT_MEM_PTB);            $_pay_class->setIp($this->request->ip());            $_pay_class->setOpenId(HuoSession::getOpenId());            $_pay_class->setMemId($this->mem_id);            $_pay_class->setMemRealName($_mem_data['real_name']);            $_pay_class->setMemRegTime($_mem_data['create_time']);            $_pay_class->setMemMobile($_mem_data['mobile']);            $_pay_rs = $_pay_class->$_func();            if (empty($_pay_rs)) {                $_code = OrderStatus::PAYWAY_PREORDER_ERROR;                $this->error(OrderStatus::getMsg($_code), [], $_code);            }            $_code = OrderStatus::NO_ERROR;            $this->success(OrderStatus::getMsg($_code), $_pay_rs, $_code);        } catch (Exception $e) {            $_code = OrderStatus::PAYWAY_NOT_EXISTS;            $this->error(OrderStatus::getMsg($_code), [], $_code);        }    }    /**     * @param $device_type     *     * @return string clientPay mobilePay pcPay     */    public function getFunc($device_type) {        switch ($device_type) {            case DeviceTypeConst::DEVICE_TYPE_IOSAPPLESDK:                $_type = 'clientPay';                break;            case DeviceTypeConst::DEVICE_TYPE_IOSSDK:                $_type = 'clientPay';                break;            case DeviceTypeConst::DEVICE_TYPE_IOSAPP:                $_type = 'clientPay';                break;            case DeviceTypeConst::DEVICE_TYPE_IOSH5APP:                $_type = 'clientPay';                break;            case DeviceTypeConst::DEVICE_TYPE_SAFARI:                $_type = 'mobilePay';                break;            case DeviceTypeConst::DEVICE_TYPE_ANDSDK:                $_type = 'clientPay';                break;            case DeviceTypeConst::DEVICE_TYPE_ANDAPP:                $_type = 'clientPay';                break;            case DeviceTypeConst::DEVICE_TYPE_ANDH5APP:                $_type = 'clientPay';                break;            case DeviceTypeConst::DEVICE_TYPE_ANDBROWSER:                $_type = 'mobilePay';                break;            case DeviceTypeConst::DEVICE_TYPE_WEIXIN:                $_type = 'jsPay';                break;            case DeviceTypeConst::DEVICE_TYPE_PC:                $_type = 'pcPay';                break;            case DeviceTypeConst::DEVICE_TYPE_WAP:                $_type = 'mobilePay';                break;            default:                $_type = 'mobilePay';        }        return $_type;    }}
 |