123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- namespace loyalsoft;
- /*
- * 支付日志模块
- * 2016.10.13 gwang 提取
- */
- /**
- * 支付日志类
- */
- class YuanBaoPayProc {
- /**
- * 【多平台】扣除玩家游戏币(Ps.发货逻辑最后执行此步骤)
- * @param UserModel $user
- * @param Req $req Description
- * @param int $amt 扣除数量
- * @param string $source (string)备注,扣除来源(模块)
- * @return int ErrCode
- */
- public static function mn_SaveUserYuanbao($req, $amt, $source = "") {
- $err = ErrCode::ok;
- if ($amt > 0) { // 防御,数量不可能小于0
- $user = $req->userInfo->game->baseInfo;
- $zoneid = $req->zoneid; // 分区Id
- if ($user->yuanbao < $amt) { // 余额不足
- CLog::err("[Cheating] mn_SaveUserYuanbao:" . $req->uid, __CLASS__);
- $err = ErrCode::notenought_yuanbao;
- } else {// 更新玩家游戏币余额
- $user->yuanbao -= $amt;
- self::$m_billno = date("Y-m-d H:i:is");
- }
- self::_mPayLog($zoneid, $req->uid, MLogType::Save, $err, #
- $amt, $user->yuanbao, $user->cash, $user->gift_cash, $user->charge_amt, $source);
- }
- return $err;
- }
- /**
- * 新版支付(引入元宝这种货币)
- * @param Req $req
- * @return type
- */
- public static function m_payByYuanbao($req) {
- $resp = Resp::err(ErrCode::err_method_notimplement);
- $user = $req->userInfo->game->baseInfo; # user引用
- $privateState = $req->userInfo->game->privateState;
- // 客户端参数解析
- $paytype = $req->paras[0]; // 付费类型 3.元宝, 2. 钻石, 1. 金币,
- $itemId = $req->paras[1]; // 道具ID
- $itemModel = CGameConfig::item_getItem($itemId); # 取道具的常量数据
- if ($itemModel == null) { //1.检测是否存在道具的常量数据
- $resp = Resp::err(ErrCode::err_const_no);
- } else {
- $properties = JsonUtil::decode($itemModel->properties);
- if (CommUtil::isPropertyExists($properties, "isActive") # 活动物品
- && StlUtil::arrayIn($privateState->activeList, $properties->isActive)) {
- $resp = Resp::err(Errcode::active_hasgetted); # 已领过
- } else {
- if ($paytype == 3) {# 元宝
- if ($user->yuanbao < $itemModel->cost) { # 元宝不足
- CLog::err("[Cheating] m_payByYuanbao:" . $req->uid, __CLASS__);
- $resp = Resp::err(ErrCode::notenought_yuanbao);
- } else { # 发货
- StoreProc::addSeprateItem($itemModel, $req);
- $amt = $itemModel->cost;
- $source = "商城购买-" . $itemModel->name;
- self::mn_SaveUserYuanbao($req, $amt, $source); // 更新玩家游戏币余额
- UserProc::updateUserInfo(); // 直接将$user的最新值返回给客户端
- $resp = Resp::ok("success");
- }
- } else { # 钻石、金币
- $prize = JsonUtil::decode($itemModel->prize); # 价格
- if (property_exists($prize, "c") && $prize->c > 0) {// 钻石购买
- $amt = self::_getItemCashPrize($itemModel); // 道具价格(钻石)
- if ($amt <= 0) {
- $resp = Resp::err(ErrCode::pay_price_err);
- } else {
- if ($user->cash < $amt) { // 余额不足
- $resp = Resp::err(ErrCode::notenough_cash_msg);
- } else { // 发货
- StoreProc::addSeprateItem($itemModel, $req); // 更新玩家游戏币余额
- // $user->cash -= $amt;
- self::mn_SaveUserCash($req, $amt, "商城购买-花钻", $itemId);
- UserProc::updateUserInfo(); // 直接将$user的最新值返回给客户端
- $resp = Resp::ok($user);
- }
- }
- }// 金币购买
- else if (CommUtil::isPropertyExists($prize, "g") && $prize->g > 0) {
- if ($req->userInfo->game->baseInfo->gold < $prize->g) {
- $resp = Resp::err(ErrCode::notenough_gold_msg);
- } else {// 发货
- StoreProc::addSeprateItem($itemModel, $req); // 更新玩家金币余额
- UserModel::Comsume_Gold($user, $prize->g); // 更新玩家数据信息
- UserProc::updateUserInfo(); // 直接将$user的最新值返回给客户端
- $resp = Resp::ok($user);
- }
- } else { # 未知的支付类型
- $resp = Resp::err(ErrCode::pay_m_type_err);
- }
- }
- }
- }
- return $resp;
- }
- /**
- * 缓存一个账单号,如果代码执行过程中出现错误,直接取消扣除游戏币
- * 注意,若是逻辑不是在一次Request内完成的,那么次订单号需要进行存储
- * @var string
- */
- static $m_billno;
- /**
- * 【多平台版】刷新充值订单(领取充值结果)
- * @param Req $req
- */
- public static function m_refreshChargeOrders($req) {
- my_Assert($req, ErrCode::err_method_notimplement);
- $userinfo = $req->userInfo;
- my_Assert($userinfo, ErrCode::user_no_err);
- $user = $userinfo->game->baseInfo;
- my_Assert($user, ErrCode::user_no_err);
- // 客户端参数解析
- $uid = $req->uid; // userID
- $zoneid = $req->zoneid; // 分区Id
- my_Assert(!empty($uid) && ($zoneid > 0), ErrCode::paras_err);
- $mem = gMem();
- my_Assert($mem, ErrCode::err_mem);
- $orders = $mem->get(MemKey_User::PayOrders($zoneid, $uid)); # 取挂起的订单数据
- $amt = 0;
- $num = 0;
- if ($orders == null) { # 订单为空
- $orders = ArrayInit();
- }
- foreach ($orders as $order) { # 多张订单合并
- $amt += $order->price;
- $num += $order->amt;
- }
- $user->yuanbao += $num; #
- $user->charge_amt += $amt; # 历史充值记录(单位分)
- if ($amt > 0 # 充值金额大于0,且首付标志为false才可以
- && isset($req->userInfo->game->privateState->firstPayGift) # 无此字段代表已经领取礼包
- && !$req->userInfo->game->privateState->firstPayGift) {
- $req->userInfo->game->privateState->firstPayGift = true;
- }
- $orders = ArrayInit(); # 清空
- $mem->set(MemKey_User::PayOrders($zoneid, $uid), $orders); # 清理已经处理过的订单
- UserProc::updateUserInfo(); # 更新玩家数据信息
- $resp = Resp::ok($user->yuanbao); // 直接将$user的最新值返回给客户端
- # todo: 这里可以再加一条订单记录
- self::_mPayLog($zoneid, $uid, MLogType::Inquire, 0, #
- $num, $user->yuanbao, $user->cash, $user->gift_cash, $user->charge_amt, "刷新订单");
- return $resp;
- }
- /**
- * 取物品的价格(钻石)
- * @param GoodsItemModel $itemModel
- */
- private static function _getItemCashPrize($itemModel) {
- $c = 0;
- $prize = JsonUtil::decode($itemModel->prize);
- if (CommUtil::isPropertyExists($prize, "c")) {
- $c = $prize->c;
- }
- return $c;
- }
- /**
- * 【移动端】增加玩家游戏币
- * @param UserModel $user
- * @param Req $req Description
- * @param int $amt 增加数量
- * @param string $source (string)备注,增加来源(模块)
- * @return int ErrCode
- */
- public static function m_AddUserYuanbao($req, $amt, $source = "") {
- $err = ErrCode::ok;
- if ($amt > 0) { // 防御,数量不可能小于0
- $user = $req->userInfo->game->baseInfo;
- $zoneid = $req->zoneid; // 分区Id
- // 更新玩家游戏币余额
- $user->yuanbao += $amt;
- self::$m_billno = date("Y-m-d H:i:is");
- self::_mPayLog($zoneid, $req->uid, MLogType::Present, $err, #
- $amt, $user->yuanbao, $user->cash, $user->gift_cash, $user->charge_amt, $source);
- }
- return $err;
- }
- // <editor-fold defaultstate="collapsed" desc="==== 移动支付 插入日志 ====">
- /**
- * Sql语句移动支付插入一条log日志。
- * @var string
- */
- const SQL_M_LOG = "INSERT INTO `tab_mpaylog_%s` (zoneid,type,result,amt,balance,cash,giftedcash,chargedcash,source,oid,itemid) VALUES (%d,%d,%d,%d,%d,%d,%d,%d,'%s','%s','%s')";
- /**
- * 移动支付插入一条记录
- * @param int $zoneid
- * @param string $oid
- * @param int $type
- * @param int $amt
- * @param int $balance
- * @param int $cash 钻石
- * @param int $giftedcash
- * @param int $chargedcash
- * @param int $source
- */
- public static function _mPayLog($zoneid, $oid, $type, $result, $amt, $balance, $cash, $giftedcash, $chargedcash, $source = "srcUnKnown", $itemid = "") {
- // $month = date("Ym");
- // $sql = sprintf(self::SQL_M_LOG, $month, $zoneid, $type, $result, $amt, $balance, $cash, $giftedcash, $chargedcash, $source, $oid, $itemid);
- // $paydb = CPayInit();
- // $paydb->query($sql);
- // $paydb->close();
- }
- // </editor-fold>
- // <editor-fold defaultstate="collapsed" desc="WEB支付日志">
- // 在自己的模块里面呆着吧
- // </editor-fold>
- // <editor-fold defaultstate="collapsed" desc="yyb支付日志">
- // </editor-fold>
- }
|