123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- /**
- * OrderController.php UTF-8
- * 小号订单
- *
- * @date : 2018/7/31 10:45
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : Huosdk 8.0
- */
- namespace api\accountdeal\controller;
- use api\common\controller\V2ApiBaseController;
- use Exception;
- use huo\controller\common\HuoSession;
- use huoAccountDeal\controller\AccountOrder;
- use huoAccountDeal\model\AccountOrderModel;
- use huolib\constant\DeviceTypeConst;
- use huolib\constant\WalletConst;
- use huolib\pay\Pay;
- use huolib\status\AccountStatus;
- use huolib\status\OrderStatus;
- use huolib\tool\StrUtils;
- use think\Lang;
- class OrderController extends V2ApiBaseController {
- public function _initialize() {
- parent::_initialize();
- $langSet = $this->request->langset();
- Lang::load([APP_PATH.'accountdeal'.DS.'lang'.DS.$langSet.DS.'account'.EXT,]);
- }
- /**
- * 买号-购买小号下单
- * http://doc.huosdk.com/138?page_id=3435
- * 【域名】/account/goods/buy
- */
- public function preorder() {
- $_param = $this->request->param();
- $_result = $this->validate($_param, 'Account.buy');
- if ($_result !== true) {
- $this->error($_result);
- }
- $this->checkLogin();
- $_mem_id = $this->getMemId();
- $_ags_id = $this->request->param('goods_id/d');
- $_rdata = (new AccountOrder())->preorder($_mem_id, $_ags_id);
- if (AccountStatus::NO_ERROR == $_rdata['code']) {
- $_pay_token = md5(md5($_rdata['data']['order_id']).time());
- (new HuoSession($this->mem_id))->setAgToken($_pay_token);
- $_rdata['data']['token'] = $_pay_token;
- }
- $this->returnData($_rdata);
- }
- /**
- * 买号-购买小号支付
- * http://doc.huosdk.com/138?page_id=3844
- * 【域名】/account/goods/pay
- */
- public function pay() {
- $this->checkLogin();
- $_check_token = (new HuoSession($this->mem_id))->getAgToken();
- $_pay_token = $this->request->param('pay_token/s', '');
- if ($_pay_token != $_check_token) {
- $_code = AccountStatus::ACCOUNT_TOKEN_ERROR;
- $this->error(AccountStatus::getMsg($_code), [], $_code);
- }
- (new HuoSession($this->mem_id))->clearAgToken();
- $_payway = $this->request->param('payway/s', '');
- $_order_id = $this->request->param('order_id/s', '');
- $_ao_model = (new AccountOrderModel());
- $_order_data = $_ao_model->getDetail($_order_id);
- if (empty($_order_data)) {
- $_code = AccountStatus::ORDER_NOT_EXISTS;
- $this->error(AccountStatus::getMsg($_code), [], $_code);
- }
- $_order_data['payway'] = $_payway;
- $_ao_model->updateData($_order_data, $_order_data['id']);
- $_product_name = '购买小号';
- $_product_desc = $_product_name;
- $_pay_rs = null;
- try {
- $_pay_class = Pay::ins()->get($_payway);
- $_func = $this->getFunc($this->device_type);
- $_show_url = url('wapapp/'.$_payway.'/show', ['order_id' => $_order_id], false, APISITE);
- $_return_url = url(
- 'wapapp/'.$_payway.'/return', ['order_id' => $_order_id], false, APISITE
- );
- $_pay_class->setReturnUrl($_return_url);
- $_pay_class->setShowUrl($_show_url);
- $_pay_class->setOrderId($_order_id);
- $_pay_class->setProductName($_product_name);
- $_pay_class->setProductDesc($_product_desc);
- $_order_data['real_price'] = StrUtils::formatNumber($_order_data['real_price']);
- $_pay_class->setRealAmount($_order_data['real_price']);
- $_pay_class->setProductId(WalletConst::WALLET_PRODUCT_ACCOUNT);
- $_pay_class->setIp($this->request->ip());
- $_pay_class->setOpenId((new HuoSession($this->mem_id))->getOpenId($_order_data['app_id']));
- $_pay_rs = $_pay_class->$_func();
- } catch (Exception $e) {
- $_code = OrderStatus::PAYWAY_NOT_EXISTS;
- $this->error(OrderStatus::getMsg($_code), [], $_code);
- }
- 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);
- }
- /**
- * 买号-获取支付方式
- * http://doc.huosdk.com/138?page_id=3549
- * 【域名】/account/pay/payway
- */
- public function getPayways() {
- $_rs = (new AccountOrder())->getPayWays();
- $this->returnData($_rs);
- }
- /**
- * 买号-取消购买/取消卖出
- * http://doc.huosdk.com/138?page_id=3550
- * 【域名】/account/order/cancel
- */
- public function cancel() {
- $_param = $this->request->param();
- $_result = $this->validate($_param, 'Account.cancelOrder');
- if ($_result !== true) {
- $this->error($_result);
- }
- $this->checkLogin();
- $_mem_id = $this->getMemId();
- $_order_id = $this->request->param('order_id/s', '');
- $_is_sell = $this->request->param('is_sell/d', 0);
- $_rs = (new AccountOrder())->cancel($_mem_id, $_order_id, $_is_sell);
- $this->returnData($_rs);
- }
- /**
- * 玩家-交易订单列表
- * http://doc.huosdk.com/138?page_id=3433
- * 【域名】/account/order/list
- */
- public function getList() {
- $this->checkLogin();
- $_param['buy_mem_id'] = $this->getMemId();
- $_status = $this->request->param('status/s', 0);
- $_page = $this->request->param('page/d', 1);
- $_offset = $this->request->param('offset/d', 10);
- $_page = $_page.','.$_offset;
- if (!empty($_status)) {
- $_param['status'] = $_status;
- }
- $_rs = (new AccountOrder())->getOrderList($_param, $_page);
- $this->returnData($_rs);
- }
- /**
- * @param $device_type
- *
- * @return string clientPay mobilePay pcPay
- */
- private 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 = 'clientPay';
- break;
- case DeviceTypeConst::DEVICE_TYPE_WAP:
- $_type = 'mobilePay';
- break;
- default:
- $_type = 'mobilePay';
- }
- return $_type;
- }
- /**
- * 买号-查询支付结果
- * http://doc.huosdk.com/138?page_id=3848
- * 【域名】/account/order/query
- */
- public function orderQuery() {
- $this->checkLogin();
- $_order_id = $this->request->param('order_id/s', '');
- $_rs = (new AccountOrder())->getStatus($_order_id);
- if (false == $_rs) {
- $this->error(lang('ERROR'));
- }
- $_rs['order_id'] = $_order_id;
- $this->success(lang('SUCCESS'), $_rs);
- }
- }
|