PayProc.php 34 KB

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