goods.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  1. <?php
  2. defined('IN_WEB') or die('Include Error!');
  3. /**
  4. * 商品相关
  5. */
  6. class ModelGoods{
  7. /**
  8. * 疯狂的上帝商品
  9. * Created by: Owen
  10. * Created on: 2019/7/3 18:36
  11. * Description:
  12. */
  13. public function getCrazyGodGood($uid,$sid=''){
  14. $tb = otable::goodsCrazy();
  15. $goodsInfo = oo::commonOprDb('payment')->getAll("SELECT * FROM {$tb} WHERE gstatus=1 ORDER BY gid",MYSQLI_ASSOC);
  16. $property = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  17. $level = intval($property['levelId']);
  18. $out = [];
  19. $coinsArr = self::getCoinsDataByLevel($level);
  20. $version = oo::commonOprModel('user')->getUserVersion($uid);
  21. $giftArr = self::getGiftConfig();
  22. $configArr = self::getGoodTransformConfig();
  23. $exclusionGid= [];
  24. $cardChest = self::getCardChestConfig($level);
  25. $iosSubArr = ['subscription01'=>'sub01','subscription02'=>'sub03','subscription03'=>'sub02'];
  26. $point = oo::commonOprModel('newvip')->getUserCurPoint($uid); //积分
  27. $sid = empty($sid)?oo::getDefinedSid($uid):$sid;
  28. foreach ($goodsInfo as $row) {
  29. if(in_array($row['gid'],$exclusionGid)){
  30. continue;
  31. }
  32. if($row['gid']>720&&$row['gid']<=750){//超级连环礼包(动态数据)剔除
  33. continue;
  34. }
  35. if($row['gid']>750&&$row['gid']<=760){//四选一活动礼包(动态数据)剔除
  36. continue;
  37. }
  38. if($row['gtype']==27){//召回礼包(动态数据)剔除
  39. continue;
  40. }
  41. if($row['gid']>760&&$row['gid']<=790){//超级连环礼包2(动态数据)剔除
  42. continue;
  43. }
  44. $row['gsku'] = ($sid == 1) ? self::googleSkuToAndroid($row['gsku']) : self::googleSkuToIosSku($row['gsku']);
  45. $goodTypeId = $row['gtype'];
  46. $config = $configArr[$goodTypeId];
  47. if(empty($config)){
  48. continue;
  49. }
  50. $temp = [];
  51. foreach ($config['character'] as $key=>$value){
  52. $temp[$key] = $row[$value];
  53. $key=='price' && $temp[$key] = '$'.$row[$value];
  54. $key=='priceNum' && $temp[$key] = (string)$row[$value];
  55. }
  56. if($goodTypeId == 2){
  57. $coinsType = explode('.',$row['gsku']);
  58. $temp['num'] = $coinsArr[end($coinsType)];
  59. }else if($goodTypeId == 3){
  60. //1.14版本魔幻宝箱重新上架,使用金币购买
  61. if(oo::compareVersion($version,'1.8.3') && $row['gid'] == 304){
  62. continue; //下架魔幻宝箱
  63. }
  64. if(!oo::compareVersion($version,'1.8.4') && $row['gid'] == 306){
  65. continue; //旧每日宝箱不上架
  66. }
  67. $cardInfo = explode(',',$row['gbaseReward']);
  68. $temp['cardNum'] = $cardInfo[0];
  69. if(in_array($row['gid'], [306])){
  70. $temp['price'] = '$'.$row['gprice'];
  71. }else{
  72. $temp['price'] = $cardChest[$row['gsku']];
  73. }
  74. if($row['gid'] == 306){
  75. $chestInfo = oo::commonOprModel('activitynew')->getDailyChest($uid);
  76. if(empty($chestInfo)){
  77. continue;
  78. }
  79. }else{
  80. $cardStarArr = array_filter(oo::commonOprModel('card')->getCardTypeProConfig($row['gimg']));
  81. $cardStar = $key = array_search(max($cardStarArr),$cardStarArr);
  82. unset($cardStarArr[$key]);
  83. $cardStar2= array_search(max($cardStarArr),$cardStarArr);
  84. if($cardStar < $cardStar2){
  85. $t = $cardStar2;
  86. $cardStar2 = $cardStar;
  87. $cardStar = $t;
  88. }
  89. $temp['cardStar']= [$cardStar2,$cardStar];
  90. }
  91. $temp['priceNum']= (string)$temp['price'];
  92. if(in_array($row['gid'], [304, 306])){
  93. $temp['sku'] = $row['gsku'];
  94. }
  95. }else if($goodTypeId == 6){
  96. if($row['gid'] == 601){
  97. $temp['coin'] = intval($coinsArr['coins03']*0.5);
  98. $temp['coins']= intval($coinsArr['coins03']*0.5);
  99. if(oo::compareVersion($version,'1.7.3')){
  100. if(!empty($row['goriginReward'])) {
  101. $props = json_decode($row['goriginReward'], true);
  102. foreach ($props as $p) {
  103. $p['propsId'] == 22 && $temp['diamond'] = $p['num'];
  104. if($p['propsId'] == 14){
  105. $temp['coin'] = $temp['coins'] = $p['num'];
  106. }
  107. }
  108. }
  109. }
  110. $temp['spin'] = $row['gbaseReward'];
  111. $temp['spins']= $row['gbaseReward'];
  112. }else if($row['gid'] == 602){
  113. $props = json_decode($row['gbaseReward'],true);
  114. foreach ($props as $p){
  115. $p['propsId'] == 14 && $temp['coin'] = $p['num'] && $temp['coins'] = $p['num'];
  116. $p['propsId'] == 15 && $temp['spin'] = $p['num'] && $temp['spins'] = $p['num'];
  117. $p['propsId'] == 22 && $temp['diamond'] = $p['num'];
  118. }
  119. $temp['props'] = $props;
  120. }
  121. $temp['coupon'] = 1;
  122. $couponVer = oo::commonOprRedis('common')->get(okeys::firstPayCouponVersion());
  123. $couponVer = empty($couponVer) ? '1.9.1' : $couponVer; //1.9.1版本临时隐藏首冲优惠券商品
  124. if(in_array($row['gid'], [601, 602]) && oo::compareVersion($version, $couponVer)){
  125. $temp['coupon'] = 0;
  126. }
  127. }else if($goodTypeId == 7){
  128. if(in_array($row['gid'],[710,711,712])){
  129. $chainGiftFlag = true;
  130. $aid = oo::commonOprModel('activitynew')->activityLock($uid,'chain_gift');
  131. if($aid){
  132. $chainGiftFlag = false;
  133. oo::commonOprRedis('activity')->setex(okeys::bindChainGift($uid),$aid,86400*3);//连环礼包绑定活动id
  134. $ret = oo::commonOprModel('activitynew')->getChainGiftConf($uid,$aid,$row['gid']);
  135. foreach ($ret['props'] as $k=>$p){
  136. $pConf = oo::commonOprModel('props')->getChestData($uid,$p['propsId']);
  137. $pConf && $ret['props'][$k]['reward'] = $pConf;
  138. }
  139. $temp['coin'] =$ret['coin'];
  140. $temp['coins'] =$ret['coin'];
  141. $temp['spin'] =$ret['spin'];
  142. $temp['spins'] =$ret['spin'];
  143. $temp['props'] =$ret['props'];
  144. $temp['price'] =$ret['price'];
  145. $temp['priceNum'] =$ret['priceNum'];
  146. $temp['sku'] =($sid == 1) ? self::googleSkuToAndroid($ret['sku']) : self::googleSkuToIosSku($ret['sku']);
  147. $temp['giftType'] =$ret['giftType'];
  148. $temp['gMax'] =$ret['gMax'];
  149. }
  150. if($chainGiftFlag){
  151. if(strpos($row['gsku'],'com.sa') !== false || strpos($row['gsku'],'newsky.cc') !== false||strpos($row['gsku'],'com.gworld') !== false||strpos($row['gsku'],'gworld.cc') !== false){
  152. $gsku = $row['gsku'];
  153. $price = '$'.$row['gprice'];
  154. $priceNum= (string)$row['gprice'];
  155. }else{
  156. $gsku = "";
  157. $price = json_decode($row['gsku'],true);
  158. $priceNum= empty($price['bet']) ? 0 : (string)$coinsArr[$price['coins']] * $price['bet'];
  159. }
  160. $reward = json_decode($row['gbaseReward'],true);
  161. $coin = $coinsArr[$reward['coins']['coins']] * $reward['coins']['bet'];
  162. $temp['coin'] =intval($coin);
  163. $temp['coins'] =intval($coin);
  164. $temp['spin'] =intval($reward['spins']);
  165. $temp['spins'] =intval($reward['spins']);
  166. $temp['props'] =$reward['props'];
  167. $temp['price'] =$price;
  168. $temp['priceNum'] =$priceNum;
  169. $temp['sku'] =$gsku;
  170. $temp['giftType'] =1;
  171. $temp['gMax'] =$row['gMax'];
  172. }
  173. }else{
  174. $reward = $giftArr[$row['gid']];
  175. $temp['coin'] = intval($coinsArr[$reward['coins']] * $reward['coinsBet']);
  176. $temp['coins'] = intval($coinsArr[$reward['coins']] * $reward['coinsBet']);
  177. $temp['giftType'] = $reward['giftType'];
  178. if(oo::compareVersion($version,'1.7.3')){
  179. if(!empty($row['goriginReward'])){
  180. $props = json_decode($row['goriginReward'],true);
  181. foreach ($props as $p){
  182. $p['propsId'] == 22 && $temp['diamond'] = $p['num'];
  183. }
  184. }
  185. foreach ([14=>'coins',15=>'spins',22=>'diamond'] as $k => $v){
  186. $propsTemp = [];
  187. $propsTemp['propsId'] = $k;
  188. if(is_array($temp[$v]) && $k == 14){
  189. $propsTemp['value'] = $temp[$v];
  190. $propsTemp['num'] = 0;
  191. $temp['props'][] = $propsTemp;
  192. }else{
  193. if(!empty($temp[$v])){
  194. $propsTemp['num'] = $temp[$v];
  195. $temp['props'][] = $propsTemp;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. }else if($goodTypeId == 8){
  202. if($sid == 2){
  203. foreach ($iosSubArr as $subscription=>$sub){
  204. if(strpos($row['gsku'],$subscription) !== false){
  205. $temp['sku'] = str_replace($subscription,$sub,$row['gsku']);
  206. break;
  207. }
  208. }
  209. }
  210. }else if($goodTypeId == 9){
  211. $temp['goods'] = json_decode($row['gbaseReward'],true);
  212. $temp['buyNum'] = intval(oo::commonOprRedis('User')->hGet(okeys::GoodBuyNum(),$uid.'_'.$row['gid']));
  213. }else if($goodTypeId == 10){
  214. $temp['goods'] = json_decode($row['gbaseReward'],true);
  215. }else if($goodTypeId == 14){
  216. continue;
  217. }else if($goodTypeId == 15){
  218. //if(oo::compareVersion($version,'1.7.8')){
  219. // $noEnoughArr = [1502];
  220. //}else{
  221. // $noEnoughArr = [1501,1502,1511];
  222. //}
  223. $noEnoughArr = [1501,1502,1511];
  224. if(in_array($row['gid'],$noEnoughArr)){
  225. //根据玩家积分、等级 返回对应商品
  226. $keyType = $row['gid']==1501?'money':($row['gid'] == 1502 ? 'spins' : 'diamond');
  227. if($row['gid'] == 1502 || ($point < 1000 && in_array($row['gid'], [1501, 1511]))){
  228. $configNotEnough = oo::commonOprModel('config')->getShopNotEnoughConfig($keyType);
  229. }else{
  230. $configNotEnough = [];
  231. }
  232. $gid = 0;
  233. foreach($configNotEnough as $rowTemp){
  234. if($rowTemp['point'] <= $point && $rowTemp['level'] <= $level){
  235. $gid = $rowTemp['gid'];
  236. }
  237. }
  238. if($gid){
  239. $goodInfoTemp = self::getGoodsInfoByGid($gid);
  240. if(!empty($goodInfoTemp)){
  241. $temp['sku'] = ($sid == 1) ? self::googleSkuToAndroid($goodInfoTemp['gsku']) : self::googleSkuToIosSku($goodInfoTemp['gsku']);
  242. $temp['price'] = '$'.$goodInfoTemp['gprice'];
  243. $temp['priceNum'] = (string)$goodInfoTemp['gprice'];
  244. $temp['addRatio'] = $goodInfoTemp['gaddRatio'];
  245. $row['gbaseReward'] = $goodInfoTemp['gbaseReward'];
  246. oo::commonOprRedis('common')->setex(okeys::shopNotEnoughLog($uid,$row['gid']),json_encode($goodInfoTemp),1 * 24 * 3600);
  247. }
  248. }
  249. }
  250. if(in_array($row['gid'],[1501,1503,1504,1505,1506,1507])){
  251. $rewardTemp = json_decode($row['gbaseReward'],true);
  252. $coins = self::getGoodCoinsByLevelId($level + 1,$rewardTemp['coins']['coins']);
  253. $temp['num'] = $coins * $rewardTemp['coins']['bet'];
  254. }else if(in_array($row['gid'],[1502,1508,1509,1510,1511,1512,1513,1514,1515])){
  255. $temp['num'] = $row['gbaseReward'];
  256. }
  257. }else if($goodTypeId == 17){
  258. $temp['isoSku'] = self::googleSkuToIosSku($row['gsku']);
  259. $temp['giftType']= $row['gtype']==17?5:$row['gtype'];
  260. }else if(in_array($goodTypeId,[16,18,19])){
  261. $reward = json_decode($row['gbaseReward'],true);
  262. $temp['isoSku'] = self::googleSkuToIosSku($row['gsku']);
  263. $temp['giftType']= 5;
  264. $temp['coins'] = oo::commonOprModel('goods')->getGoodCoins($uid,$reward['coins']['coins']) * $reward['coins']['bet'];
  265. $temp['spins'] = $reward['spins'];
  266. $temp['props'] = $reward['props'];
  267. if($goodTypeId == 16){
  268. $propsTemp = $reward['props'];
  269. foreach ($propsTemp as $key=>$p){
  270. $pConfig = oo::commonOprModel('props')->getChestData($uid,$p['propsId']);
  271. if($pConfig){
  272. $propsTemp[$key]['value'] = $pConfig;
  273. }
  274. }
  275. $temp['props'] = $propsTemp;
  276. }
  277. if(oo::compareVersion($version,'1.7.3')){
  278. foreach ([14=>'coins',15=>'spins',22=>'diamond'] as $k => $v){
  279. $props = [];
  280. $props['propsId'] = $k;
  281. if(!empty($temp[$v])){
  282. $props['num'] = $temp[$v];
  283. $temp['props'][] = $props;
  284. }
  285. }
  286. }
  287. $temp['coins'] = [
  288. 'gid' => oo::commonOprModel('config')->coinsToGid($reward['coins']['coins']),
  289. 'bet' => $reward['coins']['bet']
  290. ];
  291. if(oo::compareVersion($version,'1.8.1') && !in_array($row['gid'],[1760,1761,1762])){
  292. $temp['coins']['bet'] = 0;
  293. }
  294. if(in_array($goodTypeId,[16,18])){
  295. unset($temp['coins'],$temp['spins'],$temp['diamond']);
  296. }else if($goodTypeId == 19){
  297. $temp['spins'] = 0;
  298. $temp['diamond'] = 0;
  299. }
  300. }else if($goodTypeId == 21){
  301. if(!oo::compareVersion($version,'1.7.1')){
  302. continue;
  303. }
  304. $temp['diamond'] = $row['gbaseReward'];
  305. }else if($goodTypeId == 26){ //基金活动动态修改gsku和pirce
  306. $actInfo = oo::commonOprModel('activitynew')->getBindActivity($uid,'fund',true);
  307. if(!empty($actInfo)&&!empty($actInfo['reward_conf'])){
  308. $rewardConf = (array)json_decode($actInfo['reward_conf'], true);
  309. $rfmGroup = oo::commonOprModel('config')->getUserGroupIdByCid($uid, 2);
  310. foreach($rewardConf as $ext){
  311. if(!isset($ext['data'][$row['gid']])){
  312. continue;
  313. }
  314. $groupConf = !empty($ext['gid']) ? $ext['gid'] : [];
  315. if(in_array(0, $groupConf) || (in_array($rfmGroup, $ext['gid']))){
  316. $temp['sku'] = ($sid == 1)?self::googleSkuToAndroid($ext['data'][$row['gid']]['gsku']):self::googleSkuToIosSku($ext['data'][$row['gid']]['gsku']);
  317. $temp['price'] = $ext['data'][$row['gid']]['gprice'];
  318. $temp['gdiscount'] = $ext['data'][$row['gid']]['gdiscount'];
  319. }
  320. }
  321. }
  322. } elseif ($goodTypeId == 23) { //体力存钱罐
  323. $safeGoodsInfo = oo::commonOprModel('activitynew')->getSpinSafeGoodsByGid($uid, $row['gid']);
  324. if($safeGoodsInfo){ //体力存钱罐商品过期保存,防止活动过期
  325. oo::commonOprModel('activitynew')->setActivityShopCache(
  326. okeys::activityShopCache($uid, 'spin_safe-'.$row['gid']), $safeGoodsInfo
  327. );
  328. }
  329. if(!empty($safeGoodsInfo)){
  330. $safeSku = $safeGoodsInfo['sku'];
  331. $temp['sku'] = ($sid == 1)?self::googleSkuToAndroid($safeSku):self::googleSkuToIosSku($safeSku);
  332. $temp['priceNum'] = $safeGoodsInfo['price'];
  333. $temp['price'] = '$'.$safeGoodsInfo['price'];
  334. }
  335. }
  336. $temp['sku'] == "" && $temp['sku'] = NULL;
  337. $temp['priceDollar'] = '$';
  338. $temp['priceCurrencyCode'] = 'USD';
  339. if($config['name'] == 'gift' && !empty($row['gShowGroup'])){
  340. $temp['rfmGroup'] = array_filter(array_map('intval', explode(',', $row['gShowGroup'])));
  341. }
  342. $out[$config['name']][] = $temp;
  343. }
  344. //钻石兑换物品列表
  345. if(oo::compareVersion($version,'1.7.1')){
  346. $out['diamondExchanges'] = oo::commonOprModel('diamond')->getShopDiamondWithClient($uid);
  347. }
  348. if(oo::compareVersion($version,'1.8.0')){
  349. $diamonNotEnoughEx = oo::commonOprModel('diamond')->notEnoughWithClient($uid);
  350. $out['diamondCoin'] = $diamonNotEnoughEx['diamondCoin'];
  351. $out['diamondSpin'] = $diamonNotEnoughEx['diamondSpin'];
  352. }
  353. //新连环礼包
  354. if(oo::compareVersion($version,'1.7.4')){
  355. $out['super_serial_pack'] = array_values(oo::commonOprModel('activitynew')->getCGGoodList($uid,'super_serial_pack'));
  356. }
  357. //新连环礼包2
  358. if(oo::compareVersion($version,'1.10.1')){
  359. $out['super_serial_pack2'] = array_values(oo::commonOprModel('activitynew')->getCGGoodList($uid,'super_serial_pack2'));
  360. }
  361. //二选一活动
  362. if(oo::compareVersion($version,'1.8.1')){
  363. $out['chooseOne'] = oo::commonOprModel('activitynew')->getChooseOneGoods($uid);
  364. }
  365. //1+1礼包
  366. if(oo::compareVersion($version,'1.14.1')){
  367. $out['onePlusGift'] = oo::commonOprModel('activitynew')->getActivityGoods($uid,"one_plus_gift");
  368. }
  369. //安全惊喜礼包
  370. if(oo::compareVersion($version,'1.14.1')){
  371. $out['safeSurprise'] = oo::commonOprModel('activitynew')->getActivityGoods($uid,"safe_surprise");
  372. }
  373. //四选一活动礼包
  374. // if(oo::compareVersion($version,'1.8.4')){
  375. // $out['easter_egg'] = oo::commonOprModel('activitynew')->getEasterGiftBag($uid);
  376. // }
  377. /**
  378. * 大转盘根据等级展现给用户
  379. */
  380. $out['wheel'] = $this->turnDataByLevelId($level,$out['wheel']);
  381. if(!empty($out['fund'])){
  382. //基金活动设置活动动态缓存,发货时更新动态价格
  383. oo::commonOprModel('activitynew')->setActivityShopCache(okeys::activityShopCache($uid, 'fund'), $out['fund']);
  384. }
  385. return ['code'=>1,'list'=>$out,'recomment'=>self::getRecommend($uid)];
  386. }
  387. /**
  388. * 大转盘根据等级展现给用户
  389. * @param $level
  390. * @param $data
  391. * @return mixed
  392. * Created by: Owen
  393. * Created on: 2021/1/12 19:35
  394. */
  395. public function turnDataByLevelId($level,$data){
  396. $between = [
  397. ["levelId"=>20, "gid"=>501],
  398. ["levelId"=>40, "gid"=>502],
  399. ["levelId"=>70, "gid"=>503],
  400. ["levelId"=>100,"gid"=>504],
  401. ["levelId"=>200,"gid"=>505],
  402. ["levelId"=>300,"gid"=>506],
  403. ];
  404. $action = ["levelId"=>300,"gid"=>506];
  405. foreach ($between as $row){
  406. if($level <= $row["levelId"]){
  407. $action = $row;
  408. break;
  409. }
  410. }
  411. $tmp = array_column($data,null,'gid');
  412. $out = [];
  413. $out[] = $tmp[500];
  414. $out[] = $tmp[$action['gid']];
  415. return $out;
  416. }
  417. /**
  418. * 资源不足道具列表(1501,1502,1511)
  419. * @param int $uid
  420. */
  421. public function getextraCrazyGodGood($uid, $sid = ''){
  422. $gids = [1501,1502,1511];
  423. $tb = otable::goodsCrazy();
  424. $sql = "SELECT * FROM {$tb} WHERE gstatus=1 AND gid IN (".implode(",", $gids).") ORDER BY gtype";
  425. $goodsInfo = oo::commonOprDb('payment')->getAll($sql,MYSQLI_ASSOC);
  426. $property = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  427. $level = intval($property['levelId']);
  428. $out = [];
  429. $coinsArr = self::getCoinsDataByLevel($level);
  430. $configArr = self::getGoodTransformConfig();
  431. $point = oo::commonOprModel('newvip')->getUserCurPoint($uid); //积分
  432. $sid = empty($sid)?oo::getDefinedSid($uid):$sid;
  433. foreach ($goodsInfo as $row) {
  434. $row['gsku'] = ($sid == 1) ? self::googleSkuToAndroid($row['gsku']) : self::googleSkuToIosSku($row['gsku']);
  435. $goodTypeId = $row['gtype'];
  436. $config = $configArr[$goodTypeId];
  437. if(empty($config)){
  438. continue;
  439. }
  440. $temp = [];
  441. foreach ($config['character'] as $key=>$value){
  442. $temp[$key] = $row[$value];
  443. $key=='price' && $temp[$key] = '$'.$row[$value];
  444. $key=='priceNum' && $temp[$key] = (string)$row[$value];
  445. }
  446. //根据玩家积分、等级 返回对应商品
  447. $keyType = $row['gid']==1501?'money':($row['gid'] == 1502 ? 'spins' : 'diamond');
  448. if($row['gid'] == 1502 || ($point < 1000 && in_array($row['gid'], [1501, 1511]))){
  449. $configNotEnough = oo::commonOprModel('config')->getShopNotEnoughConfig($keyType);
  450. } else {
  451. $configNotEnough = [];
  452. }
  453. $gid = 0;
  454. foreach($configNotEnough as $rowTemp){
  455. if($rowTemp['point'] <= $point && $rowTemp['level'] <= $level){
  456. $gid = $rowTemp['gid'];
  457. }
  458. }
  459. if($gid){
  460. $goodInfoTemp = self::getGoodsInfoByGid($gid);
  461. if(!empty($goodInfoTemp)){
  462. $temp['sku'] = ($sid == 1) ? self::googleSkuToAndroid($goodInfoTemp['gsku']) : self::googleSkuToIosSku($goodInfoTemp['gsku']);
  463. $temp['price'] = '$'.$goodInfoTemp['gprice'];
  464. $temp['priceNum'] = (string)$goodInfoTemp['gprice'];
  465. $temp['addRatio'] = $goodInfoTemp['gaddRatio'];
  466. $row['gbaseReward'] = $goodInfoTemp['gbaseReward'];
  467. oo::commonOprRedis('common')->setex(okeys::shopNotEnoughLog($uid,$row['gid']),json_encode($goodInfoTemp),1 * 24 * 3600);
  468. }
  469. }
  470. if(in_array($row['gid'],[1501])){
  471. $rewardTemp = json_decode($row['gbaseReward'],true);
  472. $coins = self::getGoodCoinsByLevelId($level + 1,$rewardTemp['coins']['coins']);
  473. $temp['num'] = $coins * $rewardTemp['coins']['bet'];
  474. }else if(in_array($row['gid'],[1502,1511])){
  475. $temp['num'] = $row['gbaseReward'];
  476. }
  477. $temp['sku'] == "" && $temp['sku'] = NULL;
  478. $temp['priceDollar'] = '$';
  479. $temp['priceCurrencyCode'] = 'USD';
  480. $out[$config['name']][] = $temp;
  481. }
  482. return ['code'=>1,'list'=>$out];
  483. }
  484. /**
  485. * Notes:通过类型获取商品(局部刷新商品配置)
  486. * User: wsc
  487. * Time: 2020/11/27 16:13
  488. * @param $uid
  489. * @param $type
  490. * @return array
  491. */
  492. public function getGoodListByType($uid,$type){
  493. $out =[];
  494. $sid = oo::getDefinedSid($uid);
  495. if($type=='super_serial_pack'){
  496. $out['super_serial_pack'] = array_values(oo::commonOprModel('activitynew')->getCGGoodList($uid,$type));
  497. }else if($type=='super_serial_pack2'){
  498. $out['super_serial_pack2'] = array_values(oo::commonOprModel('activitynew')->getCGGoodList($uid,$type));
  499. }else if($type=='chain_gift'){
  500. $aid = oo::commonOprModel('activitynew')->activityLock($uid,'chain_gift');
  501. if($aid){
  502. foreach ([710,711,712] as $gid){
  503. oo::commonOprRedis('activity')->setex(okeys::bindChainGift($uid),$aid,86400*3);//连环礼包绑定活动id
  504. $ret = oo::commonOprModel('activitynew')->getChainGiftConf($uid,$aid,$gid);
  505. foreach ($ret['props'] as $k=>$p){
  506. $pConf = oo::commonOprModel('props')->getChestData($uid,$p['propsId']);
  507. $pConf && $ret['props'][$k]['reward'] = $pConf;
  508. }
  509. $temp['coin'] =$ret['coin'];
  510. $temp['coins'] =$ret['coin'];
  511. $temp['spin'] =$ret['spin'];
  512. $temp['spins'] =$ret['spin'];
  513. $temp['props'] =$ret['props'];
  514. $temp['price'] =$ret['price'];
  515. $temp['priceNum'] =$ret['priceNum'];
  516. $temp['sku'] =($sid == 1) ? self::googleSkuToAndroid($ret['sku']) : self::googleSkuToIosSku($ret['sku']);
  517. $temp['giftType'] =$ret['giftType'];
  518. $temp['gMax'] =$ret['gMax'];
  519. $temp['priceDollar'] = '$';
  520. $temp['priceCurrencyCode'] = 'USD';
  521. $out['gift'][] = $temp;
  522. }
  523. }
  524. }else if($type=='easter_egg'){
  525. $out['easter_egg'] = oo::commonOprModel('activitynew')->getEasterGiftBag($uid);
  526. }else if($type=='chooseOne'){
  527. $out['chooseOne'] = oo::commonOprModel('activitynew')->getChooseOneGoods($uid);
  528. }else if($type=='onePlusGift'){
  529. $out['onePlusGift'] = oo::commonOprModel('activitynew')->getActivityGoods($uid,"one_plus_gift");
  530. }else if($type=='safeSurprise'){
  531. $out['safeSurprise'] = oo::commonOprModel('activitynew')->getActivityGoods($uid,"safe_surprise");
  532. }
  533. return ['code'=>1,'list'=>$out,'recomment'=>[]];
  534. }
  535. ///**
  536. // * 苹果过审商品sku临时替换
  537. // * @return string
  538. // */
  539. //public function appleSkuReplace($sku) {
  540. // $sku = str_replace('sa.crazygod','astak.crazyspin',$sku);
  541. // $sku = str_replace('gworld.cc','astak.crazyspin',$sku);
  542. // switch($sku){
  543. // case 'com.astak.crazyspin.gift01': //9.99
  544. // $sku = 'com.astak.crazyspin.coins03';
  545. // break;
  546. // case 'com.astak.crazyspin.gift02': //19.99
  547. // $sku = 'com.astak.crazyspin.coins04';
  548. // break;
  549. // case 'com.astak.crazyspin.gift04': //4.99
  550. // $sku = 'com.astak.crazyspin.coins02';
  551. // break;
  552. // case 'com.astak.crazyspin.gift07': //1.99
  553. // $sku = 'com.astak.crazyspin.coins01';
  554. // break;
  555. // case 'com.astak.crazyspin.gift09': //49.99
  556. // $sku = 'com.astak.crazyspin.coins05';
  557. // break;
  558. // }
  559. // return $sku;
  560. //}
  561. /**
  562. * 谷歌Sku转换成Ios Sku
  563. * @param $sku
  564. * @return mixed
  565. * Created by: Owen
  566. * Created on: 2020/8/17 14:38
  567. */
  568. public function googleSkuToIosSku($sku){
  569. $sku = str_replace('sa.crazygod', 'gworld.cc', $sku);
  570. return str_replace('gworld.cc','astak.crazyspin',$sku);
  571. }
  572. /**
  573. * 安卓旧版sku转新版
  574. * @param $sku
  575. * @return mixed
  576. * Created by: Owen
  577. * Created on: 2021/5/7 15:09
  578. */
  579. public function googleSkuToAndroid($sku){
  580. return str_replace('sa.crazygod','gworld.cc',$sku);
  581. }
  582. /**
  583. * 获取礼包配置
  584. * @return array
  585. * Created by: Owen
  586. * Created on: 2020/8/17 14:46
  587. */
  588. public function getGiftConfig(){
  589. return [
  590. 701 => ['coins'=>'coins02','coinsBet'=>0.5 ,'giftType'=>1],
  591. 702 => ['coins'=>'coins02','coinsBet'=>1 ,'giftType'=>1],
  592. 703 => ['coins'=>'coins02','coinsBet'=>2 ,'giftType'=>1],
  593. 704 => ['coins'=>'coins01','coinsBet'=>0.25,'giftType'=>2],
  594. 705 => ['coins'=>'coins02','coinsBet'=>0.25,'giftType'=>2],
  595. 706 => ['coins'=>'coins03','coinsBet'=>0.25,'giftType'=>2],
  596. 707 => ['coins'=>'coins01','coinsBet'=>1.8 ,'giftType'=>3],
  597. 708 => ['coins'=>'coins02','coinsBet'=>1.4 ,'giftType'=>3],
  598. 709 => ['coins'=>'coins03','coinsBet'=>1.2 ,'giftType'=>3],
  599. ];
  600. }
  601. /**
  602. * 获取等级coins值
  603. * @param $level
  604. * @return array
  605. * Created by: Owen
  606. * Created on: 2020/8/17 14:56
  607. */
  608. public function getCoinsDataByLevel($level){
  609. $coins = ["coins01","coins02","coins03","coins04","coins05","coins06"];
  610. $coinsArr = [];
  611. foreach ($coins as $coin) {
  612. $coinsArr[$coin] = self::getGoodCoinsByLevelId($level,$coin);
  613. }
  614. return $coinsArr;
  615. }
  616. /**
  617. * 获取商城卡片宝箱价格
  618. * @param $level
  619. * @return array|mixed
  620. * Created by: Owen
  621. * Created on: 2020/8/17 15:09
  622. */
  623. public function getCardChestConfig($level){
  624. $cacheKey = okeys::CardChestConfig();
  625. $cache = oo::commonOprRedis('Config')->hGet($cacheKey,$level);
  626. if(empty($cache)){
  627. $tb = otable::CardChest();
  628. $cache = oo::commonOprDb('payment')->getOne("SELECT * FROM {$tb} WHERE levelId={$level} LIMIT 1",MYSQLI_ASSOC);
  629. oo::commonOprRedis('Config')->hSet($cacheKey,$level,json_encode($cache));
  630. }else{
  631. $cache = json_decode($cache,true);
  632. }
  633. return $cache;
  634. }
  635. public function getGoodTransformConfig(){
  636. return [
  637. 1=>[
  638. 'name' =>'spin',
  639. 'character'=>[
  640. 'tagType' =>'gattribute',
  641. 'gid' =>'gid',
  642. 'id' =>'gimg',
  643. 'addRatio' =>'gaddRatio',
  644. 'num' =>'gbaseReward',
  645. 'originalNum'=>'goriginReward',
  646. 'price' =>'gprice',
  647. 'priceNum' =>'gprice',
  648. 'sku' =>'gsku',
  649. 'ggameid' =>'ggameid',
  650. 'gdiscount' =>'gdiscount',
  651. ]
  652. ],
  653. 2=>[
  654. 'name' =>'coin',
  655. 'character'=>[
  656. 'tagType' =>'gattribute',
  657. 'id' =>'gimg',
  658. 'gid' =>'gid',
  659. 'addRatio' =>'gaddRatio',
  660. 'price' =>'gprice',
  661. 'priceNum' =>'gprice',
  662. 'sku' =>'gsku',
  663. 'ggameid' =>'ggameid',
  664. 'gdiscount'=>'gdiscount',
  665. ]
  666. ],
  667. 3=>[
  668. 'name' =>'chest',
  669. 'character'=>[
  670. 'id' =>'gimg',
  671. 'gid' =>'gid',
  672. 'title' =>'gname_en',
  673. 'ggameid' =>'ggameid',
  674. 'gdiscount' =>'gdiscount',
  675. ]
  676. ],
  677. 5=>[
  678. 'name' =>'wheel',
  679. 'character'=>[
  680. 'id' =>'gimg',
  681. 'gid' =>'gid',
  682. 'addRatio' =>'gaddRatio',
  683. 'num' =>'gbaseReward',
  684. 'price' =>'gprice',
  685. 'priceNum' =>'gprice',
  686. 'sku' =>'gsku',
  687. 'ggameid' =>'ggameid',
  688. 'gdiscount' =>'gdiscount',
  689. ]
  690. ],
  691. 6=>[
  692. 'name' =>'firstPay',
  693. 'character'=>[
  694. 'id' =>'gimg',
  695. 'gid' =>'gid',
  696. 'price' =>'gprice',
  697. 'priceNum' =>'gprice',
  698. 'sku' =>'gsku',
  699. 'ggameid' =>'ggameid',
  700. 'gdiscount' =>'gdiscount',
  701. ]
  702. ],
  703. 7=>[
  704. 'name' =>'gift',
  705. 'character'=>[
  706. 'id' =>'gimg',
  707. 'gid' =>'gid',
  708. 'ggameid' =>'ggameid',
  709. 'gdiscount' =>'gdiscount',
  710. 'addRatio' =>'gaddRatio',
  711. 'spin' => 'gbaseReward',
  712. 'spins' => 'gbaseReward',
  713. 'price' => 'gprice',
  714. 'priceNum' => 'gprice',
  715. 'sku' => 'gsku',
  716. ]
  717. ],
  718. 8=>[
  719. 'name' =>'subscription',
  720. 'character'=>[
  721. 'id' =>'gimg',
  722. 'gid' =>'gid',
  723. 'price' =>'gprice',
  724. 'priceNum' =>'gprice',
  725. 'sku' =>'gsku',
  726. 'ggameid' =>'ggameid',
  727. 'gdiscount' =>'gdiscount',
  728. 'addRatio' =>'gaddRatio',
  729. ]
  730. ],
  731. // 9=>[
  732. // 'name' =>'festival',
  733. // 'character'=>[
  734. // 'id' =>'gimg',
  735. // 'gid' =>'gid',
  736. // 'price' =>'gprice',
  737. // 'priceNum' =>'gprice',
  738. // 'sku' =>'gsku',
  739. // 'ggameid' =>'ggameid',
  740. // 'gdiscount'=>'gdiscount',
  741. // 'addRatio' =>'gaddRatio',
  742. // 'maxNum' =>'gMax',
  743. // ]
  744. // ],
  745. 10=>[
  746. 'name' =>'monthly',
  747. 'character'=>[
  748. 'id' =>'gimg',
  749. 'gid' =>'gid',
  750. 'price' =>'gprice',
  751. 'priceNum' =>'gprice',
  752. 'sku' =>'gsku',
  753. 'ggameid' =>'ggameid',
  754. 'gdiscount'=>'gdiscount',
  755. 'addRatio' =>'gaddRatio',
  756. ]
  757. ],
  758. // 11=>[
  759. // 'name' =>'bless',
  760. // 'character'=>[
  761. // 'id' =>'gimg',
  762. // 'gid' =>'gid',
  763. // 'price' =>'gprice',
  764. // 'priceNum' =>'gprice',
  765. // 'sku' =>'gsku',
  766. // 'ggameid' =>'ggameid',
  767. // 'gdiscount'=>'gdiscount',
  768. // 'addRatio' =>'gaddRatio',
  769. // ]
  770. // ],
  771. 12=>[
  772. 'name' =>'luckyDraw',
  773. 'character'=>[
  774. 'id' =>'gimg',
  775. 'gid' =>'gid',
  776. 'price' =>'gprice',
  777. 'priceNum' =>'gprice',
  778. 'sku' =>'gsku',
  779. 'ggameid' =>'ggameid',
  780. 'gdiscount'=>'gdiscount',
  781. 'addRatio' =>'gaddRatio',
  782. ]
  783. ],
  784. 13=>[
  785. 'name' =>'petFeed',
  786. 'character'=>[
  787. 'id' =>'gimg',
  788. 'gid' =>'gid',
  789. 'price' =>'gprice',
  790. 'priceNum'=>'gprice',
  791. 'sku' =>'gsku',
  792. 'num' =>'gbaseReward',
  793. 'expNum' =>'goriginReward',
  794. 'ggameid' =>'ggameid',
  795. ]
  796. ],
  797. 14=>[
  798. 'name' =>'petExp',
  799. 'character'=>[
  800. 'id' =>'gimg',
  801. 'gid' =>'gid',
  802. 'price' =>'gprice',
  803. 'priceNum'=>'gprice',
  804. 'sku' =>'gsku',
  805. 'num' =>'gbaseReward',
  806. 'ggameid' =>'ggameid',
  807. ]
  808. ],
  809. 15=>[
  810. 'name' =>'special',
  811. 'character'=>[
  812. 'tagType' =>'gattribute',
  813. 'id' =>'gimg',
  814. 'gid' =>'gid',
  815. 'addRatio' =>'gaddRatio',
  816. 'num' =>'gbaseReward',
  817. 'price' =>'gprice',
  818. 'priceNum' =>'gprice',
  819. 'sku' =>'gsku',
  820. 'ggameid' =>'ggameid',
  821. 'gdiscount'=>'gdiscount',
  822. ]
  823. ],
  824. 16=>[
  825. 'name' =>'gift',
  826. 'character'=>[
  827. 'gid' =>'gid',
  828. 'pid' =>'gpid',
  829. 'price' =>'gprice',
  830. 'priceNum' =>'gprice',
  831. 'sku' =>'gsku',
  832. 'ggameid' =>'ggameid',
  833. 'gdiscount'=>'gdiscount',
  834. 'addRatio' =>'gaddRatio',
  835. 'expire' =>'gExpire',
  836. 'max' =>'gMax',
  837. ]
  838. ],
  839. 17=>[
  840. 'name' =>'gift',
  841. 'character'=>[
  842. 'gid' =>'gid',
  843. 'pid' =>'gpid',
  844. 'price' =>'gprice',
  845. 'priceNum' =>'gprice',
  846. 'sku' =>'gsku',
  847. 'ggameid' =>'ggameid',
  848. 'gdiscount'=>'gdiscount',
  849. 'addRatio' =>'gaddRatio',
  850. 'expire' =>'gExpire',
  851. 'max' =>'gMax',
  852. ]
  853. ],
  854. 18=>[
  855. 'name' =>'gift',
  856. 'character'=>[
  857. 'gid' =>'gid',
  858. 'pid' =>'gpid',
  859. 'price' =>'gprice',
  860. 'priceNum' =>'gprice',
  861. 'sku' =>'gsku',
  862. 'ggameid' =>'ggameid',
  863. 'gdiscount'=>'gdiscount',
  864. 'addRatio' =>'gaddRatio',
  865. 'expire' =>'gExpire',
  866. 'max' =>'gMax',
  867. ]
  868. ],
  869. 19=>[
  870. 'name' =>'gift',
  871. 'character'=>[
  872. 'gid' =>'gid',
  873. 'pid' =>'gpid',
  874. 'price' =>'gprice',
  875. 'priceNum' =>'gprice',
  876. 'sku' =>'gsku',
  877. 'ggameid' =>'ggameid',
  878. 'gdiscount'=>'gdiscount',
  879. 'addRatio' =>'gaddRatio',
  880. 'expire' =>'gExpire',
  881. 'max' =>'gMax',
  882. ]
  883. ],
  884. 20=>[
  885. 'name' =>'pass',
  886. 'character'=>[
  887. 'gid' =>'gid',
  888. 'pid' =>'gpid',
  889. 'price' =>'gprice',
  890. 'priceNum' =>'gprice',
  891. 'sku' =>'gsku',
  892. 'ggameid' =>'ggameid',
  893. 'gdiscount'=>'gdiscount',
  894. 'addRatio' =>'gaddRatio',
  895. 'expire' =>'gExpire',
  896. 'max' =>'gMax',
  897. ]
  898. ],
  899. // 21=>[
  900. // 'name' =>'diamond',
  901. // 'character'=>[
  902. // 'tagType' =>'gattribute',
  903. // 'gid' =>'gid',
  904. // 'id' =>'gimg',
  905. // 'pid' =>'gpid',
  906. // 'addRatio' =>'gaddRatio',
  907. // 'num' =>'gbaseReward',
  908. // 'originalNum'=>'goriginReward',
  909. // 'price' =>'gprice',
  910. // 'priceNum' =>'gprice',
  911. // 'sku' =>'gsku',
  912. // 'ggameid' =>'ggameid',
  913. // 'gdiscount' =>'gdiscount',
  914. // ]
  915. // ],
  916. // 22=>[
  917. // 'name' =>'super_serial_pack',
  918. // 'character'=>[
  919. // 'id' =>'gimg',
  920. // 'gid' =>'gid',
  921. // 'ggameid' =>'ggameid',
  922. // 'gdiscount' =>'gdiscount',
  923. // 'addRatio' =>'gaddRatio',
  924. // 'price' => 'gprice',
  925. // 'priceNum' => 'gprice',
  926. // 'sku' => 'gsku',
  927. // ]
  928. // ]
  929. 23=>[
  930. 'name' =>'safeBox',
  931. 'character'=>[
  932. 'tagType' =>'gattribute',
  933. 'gid' =>'gid',
  934. 'id' =>'gimg',
  935. 'pid' =>'gpid',
  936. 'price' =>'gprice',
  937. 'priceNum' =>'gprice',
  938. 'sku' =>'gsku',
  939. 'ggameid' =>'ggameid',
  940. 'gdiscount' =>'gdiscount',
  941. ]
  942. ],
  943. 24=>[
  944. 'name' =>'passLevel',
  945. 'character'=>[
  946. 'gid' =>'gid',
  947. 'pid' =>'gpid',
  948. 'price' =>'gprice',
  949. 'priceNum' =>'gprice',
  950. 'sku' =>'gsku',
  951. 'ggameid' =>'ggameid',
  952. 'gdiscount'=>'gdiscount',
  953. 'addRatio' =>'gaddRatio',
  954. 'expire' =>'gExpire',
  955. 'max' =>'gMax',
  956. ]
  957. ],
  958. 26=>[
  959. 'name' =>'fund',
  960. 'character'=>[
  961. 'gid' =>'gid',
  962. 'pid' =>'gpid',
  963. 'price' =>'gprice',
  964. 'priceNum' =>'gprice',
  965. 'sku' =>'gsku',
  966. 'ggameid' =>'ggameid',
  967. 'gdiscount'=>'gdiscount',
  968. 'addRatio' =>'gaddRatio',
  969. 'expire' =>'gExpire',
  970. 'max' =>'gMax',
  971. ]
  972. ],
  973. ];
  974. }
  975. /**
  976. * 推荐商品
  977. * @param $uid
  978. * @return array
  979. * Created by: Owen
  980. * Created on: 2020/4/23 11:43
  981. */
  982. public function getRecommend($uid){
  983. $recommend = oo::commonOprModel('readconfig')->getSysCon('Shop',"recommend");
  984. $recommend = json_decode($recommend,true);
  985. $i = 1;
  986. $out = [];
  987. array_multisort(array_column($recommend,'sort'),SORT_ASC,$recommend);
  988. foreach ($recommend as $row){
  989. if($row['open'] == 0 || $i>3){
  990. continue;
  991. }
  992. if($row['id'] == 1){
  993. if(oo::commonOprModel('member')->getUserFirstPayStatus($uid)){
  994. if(oo::commonOprModel('activity')->activityLock($uid,1,true)){
  995. continue;
  996. }
  997. }
  998. }
  999. //if($row['id'] == 4){
  1000. // $isVip = oo::commonOprModel('newvip')->checkVip($uid);
  1001. // if($isVip && $isVip['isFreeing'] == 0){
  1002. // continue;
  1003. // }
  1004. //}
  1005. if($row['id'] == 2){
  1006. if(oo::commonOprRedis('common')->get(okeys::promotion($uid,703))){
  1007. if(oo::commonOprModel('activity')->activityLock($uid,5,true)){
  1008. continue;
  1009. }
  1010. }
  1011. }
  1012. $out[] = $row;
  1013. $i++;
  1014. }
  1015. return $out;
  1016. }
  1017. /**
  1018. * 获得coins的值
  1019. * @param $uid
  1020. * @param $coins
  1021. * @return int
  1022. * Created by: Owen
  1023. * Created on: 2019/11/6 14:59
  1024. */
  1025. public function getGoodCoins($uid,$coins){
  1026. $property = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  1027. $level = intval($property['levelId']);
  1028. return self::getGoodCoinsByLevelId($level,$coins);
  1029. }
  1030. /**
  1031. * 根据等级获得coins的值
  1032. * @param $level
  1033. * @param $coins
  1034. * @return int
  1035. * Created by: Owen
  1036. * Created on: 2019/12/17 14:41
  1037. */
  1038. public function getGoodCoinsByLevelId($level,$coins){
  1039. $cacheKey = okeys::GoodsCoin($level,$coins);
  1040. $cache = oo::commonOprRedis('config')->get($cacheKey);
  1041. if($cache){
  1042. return $cache;
  1043. }
  1044. $tb = otable::goodsCoin();
  1045. $sql = "SELECT * FROM {$tb} WHERE gsku='com.gworld.cc.{$coins}' AND levelId={$level}";
  1046. $coinInfo = oo::commonOprDb('payment')->getOne($sql,MYSQLI_ASSOC);
  1047. $num = $coinInfo['num']??0;
  1048. oo::commonOprRedis('config')->setex($cacheKey,$num,7*24*60*60);
  1049. return $num;
  1050. }
  1051. /**
  1052. * 获取限时特惠
  1053. * @param $uid
  1054. * @return array
  1055. * Created by: Owen
  1056. * Created on: 2020/8/17 11:06
  1057. */
  1058. public function specialOffer($uid){
  1059. $giftArr = [
  1060. 704 => ['coins'=>'coins01','coinsBet'=>0.25,'giftType'=>2],
  1061. 705 => ['coins'=>'coins02','coinsBet'=>0.25,'giftType'=>2],
  1062. 706 => ['coins'=>'coins03','coinsBet'=>0.25,'giftType'=>2],
  1063. ];
  1064. $userPayNum = oo::commonOprModel('payment')->getUserTotalPayNum($uid);
  1065. if($userPayNum > 10){
  1066. $gid = 706;
  1067. }else if($userPayNum > 0){
  1068. $gid = 705;
  1069. }else{
  1070. $gid = 704;
  1071. }
  1072. $sid = oo::getDefinedSid($uid);
  1073. $reward = $giftArr[$gid];
  1074. $money = intval(self::getGoodCoins($uid,$reward['coins']) * $reward['coinsBet']);
  1075. $tb = otable::goodsCrazy();
  1076. $sql = "SELECT * FROM {$tb} WHERE gid={$gid} limit 1";
  1077. $goodsInfo = oo::commonOprDb('payment')->getOne($sql,1);
  1078. $temp = [];
  1079. $goodsInfo['gsku'] = ($sid==1)?$goodsInfo['gsku']:str_replace('sa.crazygod','newsky.cc',$goodsInfo['gsku']);
  1080. $temp[] = [
  1081. 'id' =>$goodsInfo['gimg'],
  1082. 'gid' =>$goodsInfo['gid'],
  1083. 'coin' =>$money,
  1084. 'coins' =>$money,
  1085. 'spin' =>intval($goodsInfo['gbaseReward']),
  1086. 'spins' =>intval($goodsInfo['gbaseReward']),
  1087. 'price' =>'$'.$goodsInfo['gprice'],
  1088. 'sku' =>$goodsInfo['gsku'],
  1089. 'ggameid' =>$goodsInfo['ggameid'],
  1090. 'gdiscount' =>$goodsInfo['gdiscount'],
  1091. 'priceDollar'=>'$',
  1092. 'priceCurrencyCode'=>'USD',
  1093. 'addRatio' =>$goodsInfo['gaddRatio'],
  1094. ];
  1095. return $temp;
  1096. }
  1097. /**
  1098. * 限时特惠分段
  1099. * @param $uid
  1100. * @return int
  1101. * Created by: Owen
  1102. * Created on: 2020/8/17 11:05
  1103. */
  1104. public function specialOfferLv($uid){
  1105. $lv = 1;
  1106. $tb = otable::payment($uid);
  1107. $sql = "SELECT SUM(pusd) AS sum FROM {$tb} WHERE uid={$uid} AND status=2";
  1108. $ret = oo::commonOprDb('payment')->getOne($sql,MYSQLI_ASSOC);
  1109. if(!empty($ret)){
  1110. if($ret['sum'] > 0){
  1111. $lv = 2;
  1112. }
  1113. if($ret['sum'] > 10){
  1114. $lv = 3;
  1115. }
  1116. }
  1117. return $lv;
  1118. }
  1119. /**
  1120. * 通过订单号返回对应的商品名称
  1121. * @param int $order
  1122. * @return bool
  1123. * Created by: Owen
  1124. * Created on: 2020/8/17 11:05
  1125. */
  1126. public function getGpidByOrderIdCrazyGod($order = 0){
  1127. $stable = otable::summarylist();
  1128. $sql = " SELECT sl_gid FROM {$stable} WHERE sl_orderid = '{$order}' LIMIT 1";
  1129. $dbData = oo::commonOprDb('payment')->getOne($sql, MYSQLI_ASSOC);
  1130. if (empty($dbData)) {
  1131. return false;
  1132. }
  1133. $sl_gid = $dbData['sl_gid'];
  1134. $gtable = otable::goodsCrazy();
  1135. $gsql = " SELECT gsku FROM {$gtable} WHERE gid = {$sl_gid} LIMIT 1 ";
  1136. $goodsDbData = oo::commonOprDb('payment')->getOne($gsql, MYSQLI_ASSOC);
  1137. if (empty($goodsDbData)) {
  1138. return false;
  1139. }
  1140. return $goodsDbData['gsku'];
  1141. }
  1142. /**
  1143. * 根据uid和gpid(商品名称)获取订单ID
  1144. * @param int $uid
  1145. * @param int $gpid
  1146. * @return bool
  1147. * Created by: Owen
  1148. * Created on: 2020/8/17 11:06
  1149. */
  1150. public function getOrderByUidAndgpidCrazyGod($uid = 0, $gpid = 0){
  1151. if(empty($uid) || empty($gpid)) {
  1152. return false;
  1153. }
  1154. $goodsTable = otable::goodsCrazy();
  1155. $sql_goods = " SELECT gid FROM {$goodsTable} WHERE gpid = '{$gpid}' AND gchannel = 3";
  1156. $retGoodsData = oo::commonOprDb('payment')->getOne($sql_goods, 1);
  1157. oo::logs()->debug3(array('retGoodsData' => $retGoodsData, 'sql_goods' => $sql_goods), 'getOrderByUidAndgpid.log');
  1158. if (empty($retGoodsData)) {
  1159. return false;
  1160. }
  1161. $gid = $retGoodsData['gid'];//商品ID
  1162. $table = otable::payment($uid);
  1163. $sql = " SELECT order_id FROM {$table} WHERE uid = {$uid} AND gid = {$gid} AND status = 1 ORDER BY order_time DESC ";
  1164. $retpayData = oo::commonOprDb('payment')->getOne($sql, 1);
  1165. oo::logs()->debug3(array('retpayData' => $retpayData, 'sql' => $sql), 'getOrderByUidAndgpid.log');
  1166. if (empty($retpayData)) {
  1167. return false;
  1168. }
  1169. $orderId = $retpayData['order_id'];
  1170. return $orderId;
  1171. }
  1172. /**
  1173. * 通过商品id获取商品的信息
  1174. * @param $gid
  1175. * @return mixed
  1176. */
  1177. public function getGoodsInfoByGid($gid){
  1178. $table = otable::goodsCrazy();
  1179. $sql = "SELECT * FROM {$table} WHERE gid = {$gid} LIMIT 1 ";
  1180. $ret = oo::commonOprDb('payment')->getOne($sql, 1);
  1181. return $ret;
  1182. }
  1183. /**
  1184. * 用户商店横条数据
  1185. * @param $uid
  1186. * @return string
  1187. * Created by: Owen
  1188. * Created on: 2021/1/22 12:15
  1189. */
  1190. public function getFreeBarData($uid){
  1191. $conf = json_decode(oo::commonOprModel('readconfig')->getSysCon('Shop',"freeBar"),true);
  1192. $reward = $conf['reward'];
  1193. foreach ($reward as &$row){
  1194. $pConf = oo::commonOprModel('props')->getChestData($uid,$row['propsId']);
  1195. if($pConf){
  1196. $row['value'] = $pConf;
  1197. }
  1198. }
  1199. $data = [
  1200. 'isOpen' => $conf['isOpen'],
  1201. 'time' => time() + intval(oo::commonOprRedis('User')->ttl(okeys::UserFreeBarTtl($uid))),
  1202. 'reward' => $reward,
  1203. ];
  1204. return oo::response(1,$data);
  1205. }
  1206. /**
  1207. * 领取商店横条奖励
  1208. * @param $uid
  1209. * @return string
  1210. * Created by: Owen
  1211. * Created on: 2021/1/22 12:28
  1212. */
  1213. public function rewardFreeBar($uid){
  1214. if(oo::commonOprRedis('User')->ttl(okeys::UserFreeBarTtl($uid)) > 0){
  1215. return oo::response(errorCode::FREE_BAR_TTL_ERROR);
  1216. }
  1217. $conf = json_decode(oo::commonOprModel('readconfig')->getSysCon('Shop',"freeBar"),true);
  1218. $reward = $conf['reward'];
  1219. foreach ($reward as &$row){
  1220. oo::commonOprModel('member')->sendReward($uid,$row['propsId'],$row['num'],117,'商店横条',[],$row);
  1221. }
  1222. $interval = intval($conf['interval'] ?? 24 *60*60);
  1223. oo::commonOprRedis('User')->setex(okeys::UserFreeBarTtl($uid),1,$interval);
  1224. $time = time() + $interval;
  1225. $data = [
  1226. 'isOpen' => $conf['isOpen'],
  1227. 'time' => $time,
  1228. 'reward' => $reward,
  1229. ];
  1230. oo::commonOprRedis('Usercache')->zAdd(okeys::PushCrontab("FreeBar"),$time,$uid);
  1231. return oo::response(1,$data);
  1232. }
  1233. }