PayProc.php 29 KB

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