PayProc.php 27 KB

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