PayProc.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <?php
  2. namespace loyalsoft;
  3. require_once __DIR__ . '/PayProc/MLogType.php'; // 日志类型定义
  4. if (PLAT == 'web') {
  5. include_once __DIR__ . '/PayProc/WebPayProc.php';
  6. }
  7. /**
  8. * 付费、游戏内消费相关处理
  9. * 全部动态交易数据需要保存到db作为[存根]
  10. * @version <br/>
  11. * 4.0.0 第四版: 言灵世界 商城模块
  12. * 2.2.0 第三版: 独立的游戏币<元宝>, 面向多渠道的充值模式, 拉起充值成功后, 给玩家发放元宝. 游戏内部消费元宝,钻石和金币.可以用元宝购买金币和钻石.这一版在上面的PayProc中 * 2015年9月23日 <br/>
  13. * 2.1.0 mn_pay mn_AddUserCash ... 以 mn_ 打头的函数是第二版, 修改为伪托管模式,除了充值的时候跟腾讯通讯,其余时间自己管理游戏币:钻石. * 2015年7月23日 <br/>
  14. * 2.0.1 m_pay m_AddUserCash ... 以 m_ 打头的函数是第一版, 完全按照应用宝官方要求托管游戏币的模式开发的. * 2015年4月23日 <br/>
  15. * 1.0.0 Created at 2016-4-20. by --gwang <br/>
  16. * @author gwang (mail@wanggangzero.cn)
  17. * @copyright © 2016-4-20, SJZ LoyalSoft Corporation & gwang. All rights reserved.
  18. */
  19. class PayProc {
  20. const orderTab = 'tpl_order_tab';
  21. /**
  22. * 逻辑分发
  23. * 所有的Proc中必须有这样一个方法
  24. * @param Req $req
  25. */
  26. public static function procMain($req) {
  27. switch ($req->cmd) {
  28. // 支付相关的活动
  29. case CmdCode::cmd_pay_getfirstpaygift: # 8802 领取首充礼包
  30. return PayProc::m_GetFirstPayGift($req);
  31. // <editor-fold defaultstate="collapsed" desc=" 手机多渠道版 mpay ">
  32. case CmdCode::cmd_mpay_pay: # 8807 消费..
  33. return self::m_pay($req); # ::==> 购买普通商城物品
  34. case CmdCode::cmd_mpay_get_balance: # 8808 刷新账号余额
  35. return self::m_refreshChargeOrders($req); # ::==> 刷新订单-领取充值金额
  36. case CmdCode::cmd_mpay_buyDynamic: # 8809 购买动态商城物品
  37. return self::m_pay_buyDynamic($req);
  38. case CmdCode::cmd_mpay_getDynamic: # 8810 刷新神秘商城物品
  39. return self::m_pay_getDynamic($req);
  40. case CmdCode::cmd_mpay_selfCheckOrders: # 8811 自助检查异常订单
  41. return self::selfhelpCheckOrders($req);
  42. case CmdCode::cmd_mpay_getPayRecords: # 8812 查询订单记录
  43. return self::GetPayRecoreds($req);
  44. // </editor-fold>
  45. default:
  46. return Resp::err(ErrCode::cmd_err);
  47. }
  48. }
  49. /**
  50. * 8812 查询充值记录
  51. * @param Req $req
  52. */
  53. static function GetPayRecoreds($req) {
  54. $uid = $req->uid;
  55. $table = "tpl_order_tab";
  56. $arr = daoInst()->select(" cpOrderId as '订单' ,product_name as '道具',amount as '金额' ,from_unixtime(order_ts) as '时间' ")->from($table)
  57. ->where("uid")->eq($uid)
  58. ->andWhere("status")->eq(1)
  59. ->fetchall();
  60. return Resp::ok($arr);
  61. }
  62. //
  63. // <editor-fold defaultstate="collapsed" desc=" 移动支付 - 刷新订单 ">
  64. /**
  65. * 刷新充值订单(领取充值结果)
  66. * @param Req $req
  67. */
  68. public static function m_refreshChargeOrders($req) {
  69. # 客户端参数解析
  70. $uid = $req->uid; # userID
  71. $zoneid = $req->zoneid; # 分区Id
  72. if (count($req->paras) <= 0) { # 参数为空, 执行自检逻辑
  73. return self::selfhelpCheckOrders($req);
  74. }
  75. $cpOrderId = $req->paras[0]; # 后台订单编号
  76. if (!$uid || ($zoneid < 1) || strlen($cpOrderId) != 16) { # 订单编号长16位
  77. return Resp::err(ErrCode::paras_err);
  78. }
  79. $order = daoInst()->select()->from(self::orderTab) # 取订单数据
  80. ->where('cpOrderId')->eq($cpOrderId)
  81. ->limit(1)->fetch();
  82. if (!$order) {
  83. // var_dump($order);
  84. CLog::pay(' 订单不存在! ' . $cpOrderId);
  85. return Resp::err(ErrCode::pay_order_no);
  86. }
  87. if (false === strpos($uid, $order->uid)) { # UID不符
  88. return Resp::err(ErrCode::pay_order_uid);
  89. }
  90. if ($order->status != 1) {
  91. CLog::pay(' 订单尚未完成支付!');
  92. return Resp::err(ErrCode::pay_order_paystatus);
  93. }
  94. if ($order->drawed_ts > 0) { # 定单已经发过货了
  95. CLog::pay(' 订单重复请求发货!' . $cpOrderId);
  96. return Resp::err(ErrCode::pay_order_drawed);
  97. }
  98. // 准备发货
  99. $product_id = $order->product_id;
  100. $product_count = $order->product_count;
  101. $typid = substr("$product_id", 0, 3); # 提取商品编号前缀
  102. switch ($typid) {
  103. case '802': # 神秘商城物品
  104. $item = GameConfig::secretshop_typeId_getItem($product_id);
  105. break;
  106. case '801': # 商城物品
  107. $item = GameConfig::shop_getItem($product_id);
  108. break;
  109. default :
  110. return Resp::err(ErrCode::pay_systembusy_err);
  111. }
  112. if (!$item) {
  113. return Resp::err(ErrCode::pay_shopItem_cosnt_goods_err);
  114. }
  115. if ($item->pricetype != 0) {
  116. CLog::pay(" 道具付费类型异常:" . $product_id);
  117. return Resp::err(ErrCode::pay_m_type_err);
  118. }
  119. for ($i = 0; $i < $product_count; $i++) { # 默认为1,还没有设计为n的情况
  120. StoreProc::AddMultiItemInStore($req, $item->goods, 5); # 发货
  121. }
  122. $n = daoInst()->update(self::orderTab)
  123. ->data(array('drawed_ts' => now()))
  124. ->where('cpOrderId')->eq($cpOrderId)
  125. ->exec();
  126. my_Assert($n > 0, ErrCode::err_db); # 数据库操作失败
  127. $req->userInfo->game->baseInfo->charge_amt += $order->amount; # 历史充值记录(单位分)
  128. UserProc::updateUserInfo(); # 更新玩家数据信息
  129. Event::trigger('pay', array('amt' => $order->amount)); # 触发充值事件
  130. CLog::pay("订单发货成功: $cpOrderId");
  131. return Resp::ok(# 返回
  132. array('cash' => $req->userInfo->game->baseInfo->cash, # # 直接将游戏币的最新值返回给客户端
  133. 'charge_amt' => $req->userInfo->game->baseInfo->charge_amt, # 充值总记录
  134. 'store' => $req->userInfo->game->store, # # 背包
  135. 'goods' => $item->goods, # # 发货内容
  136. 'count' => $product_count, # # 发货数量
  137. )
  138. );
  139. }
  140. /**
  141. * 检查内侧订单
  142. * @param Req $req
  143. */
  144. static function checkDeltest($req) {
  145. $uid = $req->uid;
  146. if (!isset($req->userInfo->game->privateState->deltest)) {
  147. $orders = daoInst()->select()->from('tpl_order_tab_deltest')
  148. ->where('uid')->eq(substr($uid, strpos($uid, "-") + 1))
  149. ->andwhere('status')->eq(1)
  150. ->fetchall();
  151. if (count($orders) > 0) { # 有充值记录
  152. foreach ($orders as $order) {
  153. // 准备补发
  154. $product_id = $order->product_id;
  155. $product_count = $order->product_count;
  156. $typid = substr("$product_id", 0, 3); # 提取商品编号前缀
  157. switch ($typid) {
  158. case '802': # 神秘商城物品
  159. $item = GameConfig::secretshop_typeId_getItem($product_id);
  160. break;
  161. case '801': # 商城物品
  162. $item = GameConfig::shop_getItem($product_id);
  163. break;
  164. default :
  165. return Resp::err(ErrCode::pay_systembusy_err);
  166. }
  167. if (!$item) {
  168. return Resp::err(ErrCode::pay_shopItem_cosnt_goods_err);
  169. }
  170. if ($item->pricetype != 0) { # 并非人民币定价
  171. CLog::pay(" 道具付费类型异常:" . $product_id);
  172. return Resp::err(ErrCode::pay_m_type_err);
  173. }
  174. for ($i = 0; $i < $product_count; $i++) { # 默认为1,还没有设计为n的情况
  175. EmailProc::SendDelTestMail($req->zoneid, $uid, $item->name, $item->goods);
  176. }
  177. CLog::pay($req->uid . '发送删档内侧补偿邮件' . $order->cpOrderId);
  178. }
  179. }
  180. $req->userInfo->game->privateState->deltest = 0;
  181. }
  182. }
  183. /**
  184. * 检查异常订单
  185. * @param Req $req
  186. */
  187. public static function selfhelpCheckOrders($req) {
  188. if ('ios' == PLAT) { # ios版的创建订单时带着前缀了。。。
  189. $uid = $req->uid;
  190. } else {
  191. $uid = substr($req->uid, strpos($req->uid, '-') + 1);
  192. }
  193. $orders = daoInst()->select()
  194. ->from('tpl_order_tab')
  195. ->where('uid')->eq($uid)
  196. ->andWhere('status')->eq(1)
  197. ->andWhere('drawed_ts')->le(0)
  198. ->fetchAll();
  199. if (count($orders) > 0) {
  200. foreach ($orders as $order) {
  201. // 准备补发
  202. $product_id = $order->product_id;
  203. $product_count = $order->product_count;
  204. $typid = substr("$product_id", 0, 3); # 提取商品编号前缀
  205. $goods = '';
  206. switch ($typid) {
  207. case '802': # 神秘商城物品
  208. $item = GameConfig::secretshop_typeId_getItem($product_id);
  209. break;
  210. case '801': # 商城物品
  211. $item = GameConfig::shop_getItem($product_id);
  212. break;
  213. default :
  214. return Resp::err(ErrCode::pay_systembusy_err);
  215. }
  216. if (!$item) {
  217. return Resp::err(ErrCode::pay_shopItem_cosnt_goods_err);
  218. }
  219. if ($item->pricetype != 0) { # 并非人民币定价
  220. CLog::pay(" 道具付费类型异常:" . $product_id);
  221. return Resp::err(ErrCode::pay_m_type_err);
  222. }
  223. for ($i = 0; $i < $product_count; $i++) { # 默认为1,还没有设计为n的情况
  224. StoreProc::AddMultiItemInStore($req, $item->goods, 5); # 发货
  225. }
  226. $goods .= $item->goods;
  227. $n = daoInst()->update(self::orderTab) # 更新订单状态
  228. ->data(array('drawed_ts' => now()))
  229. ->where('cpOrderId')->eq($order->cpOrderId)
  230. ->exec();
  231. if (!$n) { # 影响条数应为1
  232. CLog::pay($req->uid . ' 登录补发订单失败 ' . $order->cpOrderId);
  233. return Resp::err(ErrCode::err_db); # 数据库操作失败
  234. }
  235. $req->userInfo->game->baseInfo->charge_amt += $order->amount; # 历史充值记录(单位分)
  236. UserProc::updateUserInfo(); # 回写玩家数据
  237. CLog::pay($req->uid . ' 登录补发订单 ' . $order->cpOrderId);
  238. }
  239. return Resp::ok(# 返回
  240. array('cash' => $req->userInfo->game->baseInfo->cash, # # 直接将游戏币的最新值返回给客户端
  241. 'store' => $req->userInfo->game->store, # # 背包
  242. 'goods' => $goods, # # 发货内容
  243. 'count' => count($orders), # # 发货数量
  244. 'msg' => "找到并处理" . count($orders) . "条未发货订单."
  245. ));
  246. }
  247. return Resp::ok('ok'); # everything is ok!
  248. }
  249. // </editor-fold>
  250. //
  251. // <editor-fold defaultstate="collapsed" desc=" 移动支付 - 商城购买 ">
  252. /**
  253. * 【移动支付】获取神秘商城物品
  254. * 刷新规则: 根据玩家拥有的英雄、装备、道具等数据进行刷新。(因英雄、道具、装备数量不足以支撑该刷新规则,目前先按照随机刷新做,几率平等)
  255. * @param Req $req
  256. */
  257. public static function m_pay_getDynamic($req) {
  258. $user = $req->userInfo->game;
  259. $userSecretshop = new userSecretshopModel($user->userSecretshop);
  260. // 参数提取
  261. $refreshType = $req->paras[0]; # 刷新类型(参数)0,不刷,1,免费刷,2,钻石刷
  262. switch ($refreshType) {
  263. case 1: # 免费刷
  264. if (now() < $userSecretshop->lastRefreshTs + glc()->secretshop_refresh_interval) { // 检查是否达到免费刷新时间了, 执行自动更新
  265. return Resp::err(ErrCode::pay_secretshopt_freeRefresh_Time);
  266. }
  267. break;
  268. case 2: # 钻石刷
  269. if (glc()->secretshop_refresh_maxtimes <= $userSecretshop->refreshedTimes) { // 检查刷新次数, 已达上限, 返回错误信息
  270. return Resp::err(ErrCode::pay_refresh_times);
  271. } # 可以继续刷新,
  272. $cishu = $userSecretshop->refreshedTimes + 1; # 下次
  273. $amt = GameConfig::secretshop_refresh_getItem($cishu)->price;
  274. if (!UserGameModel::Consume_Cash($user, $amt)) { # 扣除本次所需费用, 余额不足, 返回错误信息
  275. return Resp::err(ErrCode::notenough_cash_msg);
  276. }
  277. $userSecretshop->refreshedTimes++; # 增加当天付费刷新计数
  278. break;
  279. case 0: # 不刷
  280. default : # 默认不刷
  281. // do nothing.
  282. break;
  283. }
  284. if ($refreshType != 0) { # 是否刷新
  285. $err = self::refreshDynamicShopItems($req, $userSecretshop); # 更新物品表
  286. if ($err) {
  287. return Resp::err($err);
  288. }
  289. $user->userSecretshop = $userSecretshop;
  290. $req->userInfo->game = $user;
  291. UserProc::updateUserInfo();
  292. }
  293. // 返回最新物品表
  294. return Resp::ok(array(# # 成功后将最新的玩家数据返回给客户端
  295. 'gold' => $user->baseInfo->gold,
  296. 'tili' => $user->baseInfo->tili,
  297. 'cash' => $user->baseInfo->cash,
  298. 'uss' => $userSecretshop, # # 当前神秘商城数据
  299. ));
  300. }
  301. /**
  302. * 更新神秘商城物品
  303. * @param Req $req
  304. * @param UserSecretshopModel $userSecretshop Description
  305. */
  306. private static function refreshDynamicShopItems($req, &$userSecretshop) {
  307. $userSecretshop->lastRefreshTs = now();
  308. // todo: 这里补完更新物品的函数, // 第一版: 随机
  309. $userSecretshop->currentItems = ObjectInit();
  310. for ($i = 1; $i <= 3; $i++) { # 3种类型的商品
  311. $arr = GameConfig::secretshop_goodsType_getItem($i);
  312. if (count($arr) > 0) {
  313. $err = self::Dice(GameConfig::secretshop_goodsType_getItem($i), 1, $userSecretshop); # 一个种类一次1个物品
  314. if ($err) {
  315. return $err;
  316. }
  317. }
  318. }
  319. return ErrCode::ok;
  320. }
  321. /**
  322. * 投骰子
  323. * @param assoc_array $arr 奖池物品
  324. * @param int $number 提取数量
  325. * @return string itemid,num;itemid,num;...
  326. */
  327. static function Dice($arr, $number, &$userSecretshop) {
  328. $max = 0; # 计算物品权重总和
  329. array_walk($arr, function ($value) use(&$max) {
  330. $max += $value->probability;
  331. });
  332. if (!$max) { # 配置数据有问题
  333. return ErrCode::err_const_no;
  334. }
  335. for ($i = 0; $i < $number; $i++) {
  336. $rnd = CommUtil::random(1, $max); # 投骰子
  337. $start = 0;
  338. $rew = null;
  339. foreach ($arr as $item) { # 循环判断落入那个物品上
  340. if (CommUtil::isPropertyExists($item, 'probability') // #
  341. && $start < $rnd && $rnd <= $start + $item->probability) { # 落入区间
  342. $rew = $item; # 记录物品
  343. break;
  344. }
  345. $start += $item->probability; # 继续判断是否落入下一物品的区间
  346. } # foreach end
  347. if (!$rew) {
  348. return ErrCode::lottery_noselecteditem;
  349. }
  350. $id = $rew->typeId;
  351. $userSecretshop->currentItems->$id = 0;
  352. } # for end
  353. return ErrCode::ok;
  354. }
  355. /**
  356. * 清理每日各种上限
  357. * @param Req $req
  358. */
  359. private static function clearDailyLimits($req) {
  360. $userSecretshop = new userSecretshopModel($req->userInfo->game->userSecretshop);
  361. $userSecretshop->refreshedTimes = 0;
  362. $req->userInfo->game->userSecretshop = $userSecretshop;
  363. }
  364. /**
  365. * 【移动支付】购买神秘商城物品
  366. * 规则: 商城物品会刷新
  367. * @param Req $req
  368. */
  369. public static function m_pay_buyDynamic($req) {
  370. $user = new UserGameModel($req->userInfo->game);
  371. $userSecretshop = new userSecretshopModel($user->userSecretshop);
  372. // 参数提取
  373. $itemId = $req->paras[0]; # 商品id (点一次购买一个)
  374. $num = 1; # 暂时固定为一次购买一个
  375. #
  376. if (!CommUtil::isPropertyExists($userSecretshop->currentItems, $itemId)) {
  377. return Resp::err(ErrCode::pay_secretshop_noitem_err);
  378. }
  379. $cishu = $userSecretshop->currentItems->$itemId; # 购买次数
  380. if ($cishu >= glc()->secretshop_itembuy_maxtimes) { # 判断购买次数
  381. return Resp::err(ErrCode::pay_secretshop_buytimes);
  382. }
  383. $shopItem = GameConfig::secretshop_typeId_getItem($itemId); # 常量数据
  384. $amt = $shopItem->price * pow(2, $cishu); # 计算价格
  385. switch ($shopItem->pricetype) {
  386. case 1:
  387. if (!UserGameModel::Consume_Cash($user->baseInfo, $amt)) { # 扣除钻石
  388. return Resp::err(ErrCode::notenough_cash_msg);
  389. }
  390. break;
  391. case 2:
  392. if (!UserGameModel::Consume_Gold($user->baseInfo, $amt)) { # 扣除金币
  393. return Resp::err(ErrCode::notenough_gold_msg);
  394. }
  395. break;
  396. default :
  397. return Resp::err(ErrCode::pay_m_type_err);
  398. }
  399. // 道具解包/发货
  400. $err = self::expendSecretShopItem($shopItem, $num, $req); # 发放商品()
  401. if ($err != ErrCode::ok) { # 发货失败
  402. return Resp::err($err);
  403. }
  404. $userSecretshop->currentItems->$itemId += 1; # 购买次数+1
  405. $user->userSecretshop = $userSecretshop;
  406. $req->userInfo->game = $user;
  407. UserProc::updateUserInfo(); # 回写数据
  408. StatProc::secretShopbuy($req->zoneid, $req->uid, $itemId, $num); # 统计/监控数据
  409. return Resp::ok(array(# # 成功后将最新的玩家数据返回给客户端
  410. 'gold' => $user->baseInfo->gold,
  411. 'tili' => $user->baseInfo->tili,
  412. 'cash' => $user->baseInfo->cash,
  413. 'store' => $user->baseInfo->store, # # 背包,(装备、碎片、。。)
  414. 'heros' => $user->baseInfo->heros # # 角色
  415. ));
  416. //
  417. }
  418. /**
  419. *
  420. * @param sm_secretshop $shopItem
  421. * @param type $num
  422. * @param type $req
  423. */
  424. private static function expendSecretShopItem($shopItem, $num, $req) {
  425. for ($i = 0; $i < $num; $i++) {
  426. $err = StoreProc::AddMultiItemInStore($req, $shopItem->goods, '神秘商城');
  427. if ($err) {
  428. return $err;
  429. }
  430. }
  431. return ErrCode::ok;
  432. }
  433. /**
  434. * 【移动支付】 购买普通商城物品
  435. * @param Req $req
  436. * @return type
  437. */
  438. public static function m_pay($req) {
  439. $zoneid = $req->zoneid;
  440. $uid = $req->uid;
  441. $user = $req->userInfo->game; # user引用
  442. if (count($req->paras) < 3) { # 参数不足
  443. return Resp::err(ErrCode::parasnotenough_msg);
  444. }
  445. $paytype = $req->paras[0]; # 付费类型, 1.钻石, 2.金币
  446. $itemId = $req->paras[1]; # 道具ID
  447. $num = $req->paras[2]; # 数量, 默认为1
  448. if ($num < 1) { # 参数非法,
  449. return Resp::err(ErrCode::paras_err);
  450. }
  451. $shopItem = GameConfig::shop_getItem($itemId); # 取商品的常量数据
  452. if ($shopItem == null) { # 检测是否存在道具的常量数据
  453. return Resp::err(ErrCode::err_const_no);
  454. }
  455. if ($shopItem->pricetype != $paytype) { # 商品定价类型检查
  456. return Resp::err(ErrCode::pay_price_err);
  457. }
  458. $amt = $shopItem->price; # 道具价格(钻石)
  459. if ($amt <= 0) { # 商品定价数值检查
  460. return Resp::err(ErrCode::pay_price_err);
  461. }
  462. $bDeal = false; # 成交标志位
  463. switch ($paytype) { # 1. 钻石, 2. 金币, other:非法
  464. case 1: # 钻石
  465. $err = self::_SaveUserCash($req, $amt * $num); # 更新(扣除)玩家游戏币(钻石)余额
  466. if (ErrCode::ok != $err) {
  467. return Resp::err($err);
  468. }
  469. $bDeal = true;
  470. break;
  471. case 2: # 金币
  472. if (!UserGameModel::Consume_Gold($user->baseInfo, $amt * $num)) { # 更新玩家金币余额
  473. return Resp::err(ErrCode::notenough_gold_msg);
  474. } # 更新(扣除)玩家游戏币(金币)余额
  475. $bDeal = true;
  476. break;
  477. default : # 未知的支付类型
  478. return Resp::err(ErrCode::pay_m_type_err);
  479. }
  480. if ($bDeal) {
  481. // var_dump($shopItem);
  482. $err = self::expendShopItem($shopItem, $num, $req); # 发放商品(普通商城只有金币和体力)
  483. if ($err != ErrCode::ok) { # 发货失败
  484. return Resp::err($err);
  485. }
  486. UserProc::updateUserInfo(); # 回写数据
  487. StatProc::shopbuy($zoneid, $uid, $itemId, $num); # 统计/监控数据
  488. return Resp::ok(array(# # 成功后将最新的玩家数据返回给客户端
  489. 'gold' => $user->baseInfo->gold,
  490. 'tili' => $user->baseInfo->tili,
  491. 'cash' => $user->baseInfo->cash,
  492. 'store' => $user->store
  493. ));
  494. }
  495. return Resp::err(ErrCode::err_innerfault);
  496. }
  497. /**
  498. * 解包商城物品
  499. * @param sm_Shop $shopItem
  500. * @param int $num 数量
  501. * @param Req $req
  502. */
  503. static function expendShopItem($shopItem, $num, $req) {
  504. for ($i = 0; $i < $num; $i++) {
  505. $err = StoreProc::AddMultiItemInStore($req, $shopItem->goods, '商城');
  506. if ($err) {
  507. return $err;
  508. }
  509. }
  510. return ErrCode::ok;
  511. }
  512. /**
  513. * 扣除玩家钻石
  514. * @param Req $req
  515. * @param int $amt
  516. * @return int
  517. */
  518. static function _SaveUserCash($req, $amt) {
  519. $err = ErrCode::ok;
  520. if ($amt > 0) { # 防御,数量不可能小于0
  521. $user = $req->userInfo->game;
  522. if ($user->cash < $amt) { # 余额不足
  523. $err = ErrCode::notenough_cash_msg;
  524. } else { # 更新玩家游戏币余额
  525. UserGameModel::set_Cash($user, $user->cash - $amt);
  526. }
  527. }
  528. return $err;
  529. }
  530. /**
  531. * 扣除玩家金币
  532. * @param req $req
  533. * @param type $amt
  534. * @param type $source
  535. * @param type $itemId
  536. * @return type
  537. */
  538. static function _SaveUserGold($req, $amt) {
  539. $err = ErrCode::ok;
  540. $user = $req->userInfo->game;
  541. if (!UserGameModel::Consume_Gold($user->baseInfo, $amt)) { # 更新玩家金币余额
  542. $err = ErrCode::notenough_gold_msg;
  543. }
  544. return $err;
  545. }
  546. // </editor-fold>
  547. //
  548. //
  549. // <editor-fold defaultstate="collapsed" desc=" 支付活动 - 首付礼包">
  550. /**
  551. * 领取首付礼包
  552. * @param Req $req
  553. * @return Resp
  554. */
  555. public static function m_GetFirstPayGift($req) {
  556. $itemId = glc()->FirstPay_ItemId;
  557. $privateState = $req->userInfo->game->privateState;
  558. if (CommUtil::isPropertyExists($privateState, "firstPayGift") #
  559. && $privateState->firstPayGift) { # 如果已经领取首付礼包
  560. return Resp::err(ErrCode::pay_firstpaygetted);
  561. }
  562. if ($req->userInfo->game->baseInfo->charge_amt <= 0) { # 如果尚未完成首付
  563. return Resp::err(ErrCode::pay_firstpayno_err);
  564. }
  565. $itemModel = GameConfig::shop_getItem($itemId); # 取商品常量
  566. if ($itemModel == null) { # 检测首付礼包是否存在
  567. return Resp::err(ErrCode::err_const_no);
  568. }
  569. $req->userInfo->game->privateState->firstPayGift = true; # 设置首付标志
  570. StoreProc::AddMultiItemInStore($req, $itemModel->goods); # 发放首付礼包到玩家仓库
  571. UserProc::updateUserInfo(); # 更新玩家数据
  572. return Resp::ok(array('itemid' => $itemId,
  573. 'rewardstr' => $itemModel->goods,
  574. 'store' => $req->userInfo->game->store)); # 回送成功信息
  575. }
  576. // </editor-fold>
  577. //
  578. //
  579. //
  580. }