123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- <?php
- /**
- * AccountOrder.php UTF-8
- *
- *
- * @date : 2018/6/13 16:01
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huoAccountDeal\controller;
- use huo\controller\common\Base;
- use huo\controller\member\MemCache;
- use huo\model\member\MemGameModel;
- use huoAccountDeal\logic\AccountLogic;
- use huoAccountDeal\logic\AccountOrderLogic;
- use huoAccountDeal\model\AccountGoodsModel;
- use huoAccountDeal\model\AccountOrderModel;
- use huolib\constant\AccountConst;
- use huolib\constant\CommonConst;
- use huolib\constant\OrderConst;
- use huolib\constant\WalletConst;
- use huolib\status\AccountStatus;
- use huolib\status\CommonStatus;
- use huolib\status\MemberStatus;
- use huolib\status\OrderStatus;
- use huolib\tool\StrUtils;
- use think\Log;
- class AccountOrder extends Base {
- protected function retSucMsg($code, $data = []) {
- $_msg = OrderStatus::getMsg($code);
- return $this->huoSuccess($code, $_msg, $data);
- }
- protected function retErrMsg($code) {
- $_err_msg = OrderStatus::getMsg($code);
- return $this->huoError($code, $_err_msg);
- }
- /**
- * 预下单
- *
- * @param $mem_id
- * @param $ags_id
- * @param $payway
- *
- * @return array|bool|string
- */
- public function preorder($mem_id, $ags_id) {
- if (empty($mem_id)) {
- $_code = MemberStatus::LOGIN_IS_OUT;
- return $this->huoError($_code, MemberStatus::getMsg($_code));
- }
- $_mc_class = MemCache::ins();
- $_mem_data = $_mc_class->getInfoById($mem_id);
- $_me_data = $_mc_class->getMeInfoById($mem_id);
- if (empty($_mem_data) || empty($_me_data)) {
- $_code = MemberStatus::UID_INVALID;
- return $this->huoError($_code, MemberStatus::getMsg($_code));
- }
- //小号商品验证
- $_account_goods = (new AccountLogic())->getDetail($ags_id);
- if (empty($_account_goods)) {
- $_code = AccountStatus::INVALID_ACCOUNT_GOODS;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- if ($mem_id == $_account_goods['mem_id']) {
- $_code = AccountStatus::CANNOT_BUY_YOUR_ACCOUNT_GOODS;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- if (AccountConst::STATUS_PULL_ON_SHELVES != $_account_goods['status']) {
- $_code = AccountStatus::CANNOT_BUY_NOT_PULL_ON_SHELVES;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- if (CommonConst::CONST_NOT_DELETE != $_account_goods['is_delete']) {
- $_code = AccountStatus::ACCOUNT_HAS_BEEN_DELETED;
- return $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- // TODO: luowei 2018/6/13 支付方式验证
- $_order_id = StrUtils::genOrderId(
- $_mem_data['agent_id'], $_mem_data['agent_id'], $mem_id,
- WalletConst::WALLET_ORDER_PREFIX_AG
- );
- $_data = [
- 'order_id' => $_order_id,
- 'sell_mem_id' => $_account_goods['mem_id'],
- 'buy_mem_id' => $mem_id,
- 'ags_id' => $_account_goods['id'],
- 'app_id' => $_account_goods['app_id'],
- 'mg_mem_id' => $_account_goods['mg_mem_id'],
- 'price' => $_account_goods['price'],
- 'real_price' => $_account_goods['price'],
- 'status' => OrderConst::PAY_STATUS_NOT,
- 'payway' => '',
- ];
- $_rs = (new AccountLogic())->addPreorderData($_data);
- if ($_rs) {
- $_rdata = [
- 'order_id' => $_order_id,
- 'real_amount' => $_account_goods['price'],
- 'status' => OrderConst::PAY_STATUS_NOT,
- ];
- $_code = CommonStatus::NO_ERROR;
- return $this->huoError($_code, CommonStatus::getMsg($_code), $_rdata);
- } else {
- $_code = CommonStatus::INNER_ERROR;
- return $this->huoError($_code, CommonStatus::getMsg($_code));
- }
- }
- /**
- * @param $order_id
- *
- * @return bool
- */
- public function getStatus($order_id = '') {
- if (empty($order_id)) {
- return false;
- }
- $_ao_model = new AccountOrderModel();
- $_rs = $_ao_model->getStatus($order_id);
- if (false == $_rs) {
- return false;
- }
- return $_rs;
- }
- /**
- *
- * @return array
- */
- public function getPayWays() {
- // TODO: wuyonghong 2018/4/28 从数据库读取
- /* 获取支付方式 */
- $_rdata[0]['payway'] = 'alipay';
- $_rdata[0]['name'] = '支付宝';
- $_rdata[0]['icon'] = '';
- $_rdata[0]['url'] = STATICSITE.'/h5sdk/images/arwec.png';
- $_rdata[1]['payway'] = 'wxpay';
- $_rdata[1]['name'] = '微信';
- $_rdata[1]['icon'] = STATICSITE.'/h5sdk/images/wergcder.png';
- $_rdata[1]['url'] = '支付宝';
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_rdata);
- }
- /**
- * 查询微信订单
- *
- * @param $order_id
- */
- public function queryWxOrder($order_id) {
- // TODO: wuyonghong 2018/5/7 查询订单完成情况
- }
- public function getOrderList($_map = [], $page = '1,10') {
- $_order_data = (new AccountOrderLogic())->getOrderList($_map, $page);
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code), $_order_data);
- }
- /**
- * 取消订单
- *
- * @param $mem_id
- * @param $order_id
- *
- * @param int $is_sell
- *
- * @return array
- */
- public function cancel($mem_id, $order_id, $is_sell = 0) {
- //验证订单
- $_account_order = (new AccountOrderModel())->getInfoByOrderId($order_id);
- if (empty($_account_order)) {
- $_code = AccountStatus::ORDER_NOT_EXISTS;
- $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- if ($_account_order['status'] != OrderConst::PAY_STATUS_NOT) {
- $_code = AccountStatus::CANNOT_CANCEL_ORDER;
- $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- if ($_account_order['buy_mem_id'] != $mem_id) {
- $_code = AccountStatus::ONLY_OPERATE_YOUR_OWN_ORDER;
- $this->huoError($_code, AccountStatus::getMsg($_code));
- }
- $_rs = (new AccountOrderLogic())->cancel($order_id, $_account_order['ags_id']);
- if ($_rs) {
- $_code = CommonStatus::NO_ERROR;
- return $this->huoSuccess($_code, CommonStatus::getMsg($_code));
- } else {
- $_code = CommonStatus::INNER_ERROR;
- return $this->huoError($_code, CommonStatus::getMsg($_code));
- }
- }
- /**
- * 支付成功操作
- *
- * @param $order_id
- * @param $trade_no
- * @param $amount
- * @param $payway
- *
- * @return bool
- */
- public function payNotifyByAccount($order_id, $trade_no, $amount, $payway) {
- $_notify_data['order_id'] = $order_id;
- $_notify_data['trade_no'] = $trade_no;
- $_notify_data['amount'] = $amount;
- $_notify_data['payway'] = $payway;
- if (empty($order_id)) {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&step1&code=".OrderStatus::ORDER_ID_EMPTY.'¬ify_data.'
- .http_build_query($_notify_data),
- LOG::ERROR
- );
- return false;
- }
- if (empty($amount)) {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&step2&code=".OrderStatus::ORDER_AMOUNT_IS_ZERO
- .'¬ify_data.'
- .http_build_query($_notify_data),
- LOG::ERROR
- );
- return false;
- }
- $_ao_model = new AccountOrderModel();
- $_order_data = $_ao_model->getDetail($order_id);
- if (false == $_order_data) {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&step3&code=".OrderStatus::ORDER_NOT_EXISTS.'¬ify_data.'
- .http_build_query($_notify_data),
- LOG::ERROR
- );
- return false;
- }
- $_amount = number_format($amount, 2, '.', '');
- $_order_amount = number_format($_order_data['real_price'], 2, '.', '');
- if (($_amount < $_order_amount)) {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&step4&code=".OrderStatus::NOTIFY_AMOUNT_ERROR.'¬ify_data.'
- .http_build_query($_notify_data).'&order_data='.http_build_query($_order_data),
- LOG::ERROR
- );
- return false;
- }
- if (OrderConst::PAY_STATUS_SUC == $_order_data['status']) {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&step5&code=".OrderStatus::ORDER_HAS_PAY.'¬ify_data.'
- .http_build_query($_notify_data).'&order_data='.http_build_query($_order_data),
- LOG::LOG
- );
- // return true;
- }
- /* 更新订单支付状态 */
- $_order_data['status'] = OrderConst::PAY_STATUS_SUC;
- $_order_data['trade_no'] = $trade_no;
- $_order_data['pay_time'] = time();
- $_rs = $_ao_model->updateOrder($_order_data, $_order_data['id']);
- if (false == $_rs) {
- return false;
- }
- //修改商品状态
- $_ag_data = ['status' => AccountConst::STATUS_SOLD_OUT];
- $_ag_model = new AccountGoodsModel();
- $_ag_model->updateData($_ag_data, $_order_data['ags_id']);
- //转移小号并启用
- $_account_goods = $_ag_model->getInfoById($_order_data['ags_id']);
- if ($_account_goods) {
- $_mg_data['mem_id'] = $_order_data['buy_mem_id'];
- $_mg_data['status'] = MemGameModel::STATUS_NORMAL;
- $_mg_model = new MemGameModel();
- $_rs = $_mg_model->updateData($_mg_data, $_account_goods['mg_mem_id']);
- if (false === $_rs) {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&step6&code=".OrderStatus::ORDER_HAS_PAY.'¬ify_data.'
- .http_build_query($_notify_data).'&order_data='.http_build_query($_order_data),
- LOG::ERROR
- );
- return true;
- }
- }
- return true;
- }
- }
|