Game.php 195 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846
  1. <?php
  2. /**
  3. * 游戏管理控制器
  4. */
  5. namespace app\admin\controller;
  6. use app\common\library\FileUpload;
  7. use app\common\library\MakeReport;
  8. use app\common\library\MakeReportGo;
  9. use app\common\model\AndroidSdk;
  10. use app\common\model\GameBand;
  11. use app\common\model\Game as GameModel;
  12. use app\common\logic\SubPackage as SubChannel;
  13. use app\common\model\GameBelong;
  14. use app\common\model\GameBindDouyinOpen;
  15. use app\common\model\SdkGameList;
  16. use app\common\model\GameInfo;
  17. use app\common\model\GameNotify;
  18. use app\common\model\GameBanned;
  19. use app\common\model\GameExtraPointRatio;
  20. use app\common\model\Setting;
  21. use app\common\library\ChannelUtil;
  22. use Overtrue\Pinyin\Pinyin;
  23. use app\common\model\PromotionShortLink;
  24. use app\common\model\CompanyGameBind;
  25. use think\Db;
  26. use think\Env;
  27. use think\Exception;
  28. class Game extends Admin
  29. {
  30. protected $gameModel;
  31. // 游戏等级
  32. protected $gameLevel = ['S', 'A1', 'A2', 'B1', 'B2', 'B3', 'B4', 'C', 'D'];
  33. /**
  34. * 游戏列表
  35. */
  36. public function index()
  37. {
  38. $where = $this->_indexParam();
  39. $gameBandModel = new GameBand();
  40. //查询参数
  41. $param = input('get.');
  42. $list = $this->gameModel->alias('game')
  43. ->join('cy_gameinfo info', 'game.id = info.game_id', 'left')
  44. ->join('nw_android_sdk_config sdk', 'game.android_sdk_id = sdk.id', 'left')
  45. ->field('game.id,game.type,game.name,game.origin_name,game.pinyin,game.cooperation_status,game.channel_version,game.order_recheck,game.create_time,game.remarks,game.is_show,game.logout_btn,game.game_kind,info.platform,sdk.version as sdk_version,game.is_default,game.is_login,game.is_register')
  46. ->where($where)
  47. ->order('game.id desc')
  48. ->paginate(10, false, array('query' => $param))
  49. ->each(function($item, $key) use($gameBandModel) {
  50. // 绑定信息
  51. $bandWhere = [];
  52. if($item['type'] == 1){
  53. $bandWhere['ios_game_id'] = $item['id'];
  54. } else if ($item['type'] == 2) {
  55. $bandWhere['android_game_id'] = $item['id'];
  56. } else if ($item['type'] == 3) {
  57. $bandWhere['h5_game_id'] = $item['id'];
  58. }
  59. $gameBandInfo = $gameBandModel->where($bandWhere)->field('id,android_game_id,ios_game_id,h5_game_id')->find();
  60. $item['band_info'] = $gameBandInfo;
  61. });
  62. $this->assign('version', (new AndroidSdk())->getAllVersion());
  63. $this->assign('list', $list);
  64. $this->assign('page', $list->render());
  65. $tmpGameList = $this->cyModel('game')->field('id,name')->select();
  66. $gameList = array();
  67. foreach ($tmpGameList as $game) {
  68. $gameList[$game['id']] = $game;
  69. }
  70. $this->assign('gameList', $gameList);
  71. return $this->fetch();
  72. }
  73. // 游戏列表 查询条件 列表页面和报表下载共用
  74. public function _indexParam()
  75. {
  76. $where = [];
  77. //游戏ID
  78. if (input('request.id') != '') {
  79. $where['game.id'] = input('request.id');
  80. }
  81. //游戏类型
  82. if (input('request.game_kind') != '') {
  83. $where['game.game_kind'] = input('request.game_kind');
  84. }
  85. //游戏名称
  86. if (input('request.game_name') != '') {
  87. $where['game.name'] = ['like', '%' . input('request.game_name') . '%'];
  88. }
  89. //对接状态
  90. if (input('request.cooperation_status_str') != '') {
  91. $cooperation_status = explode(',', input('request.cooperation_status_str'));
  92. $where['game.cooperation_status'] = ['in', $cooperation_status];
  93. }
  94. //是否显示
  95. if (input('request.is_show') != '') {
  96. $where['game.is_show'] = input('request.is_show');
  97. }
  98. //SDK版本号
  99. if (input('request.android_sdk_id') != '') {
  100. $where['game.android_sdk_id'] = input('request.android_sdk_id');
  101. }
  102. // 游戏名(模糊搜)
  103. if (input('request.game_name_link') != '') {
  104. $where['game.name'] = ['like', '%' . input('request.game_name_link') . '%'];
  105. }
  106. //游戏类型
  107. if (input('request.game_type') != '') {
  108. $where['game.type'] = ['in', input('request.game_type')];
  109. }
  110. return $where;
  111. }
  112. /**
  113. * 新增游戏
  114. */
  115. public function create()
  116. {
  117. if (request()->isPost()) {
  118. $this->assign('is_default', 1);
  119. $data = [
  120. 'name' => input('post.name'),
  121. 'package_name' => input('post.package_name'),
  122. 'origin_name' => input('post.name'),
  123. 'order_recheck' => input('post.order_recheck'),
  124. 'cooperation_status' => input('post.cooperation_status'),
  125. 'is_show' => input('post.is_show'),
  126. 'channel_version' => input('post.channel_version'),
  127. // 'channel_split_ratio' => input('post.channel_split_ratio'),
  128. 'type' => input('post.type'),
  129. 'remarks' => input('post.remarks'),
  130. 'logout_btn' => input('post.logout_btn'),
  131. 'is_default' => input('post.is_default'),
  132. 'game_kind' => input('post.game_kind'),
  133. 'download_url' => input('post.download_url'),
  134. 'free_pay' => input('post.free_pay'),
  135. 'is_pay' => input('post.is_pay'),
  136. 'is_welfare' => input('post.is_welfare'),
  137. 'is_login' => input('post.is_login'),
  138. 'is_register' => input('post.is_register'),
  139. 'ban_login_msg' => input('post.ban_login_msg'),
  140. 'ban_register_msg' => input('post.ban_register_msg'),
  141. 'landing_page_status' => input('post.landing_page_status'),
  142. 'belonging_status' => input('post.belonging_status'),
  143. ];
  144. $ver_id = input('post.version_id');
  145. if (empty($ver_id)) {
  146. $this->error('请选择SDK版本号');
  147. }
  148. $company_id = input('post.company_id', "", 'intval');
  149. // if (empty($company_id)) {
  150. // $this->error('请选择关联公司');
  151. // }
  152. $data['android_sdk_id'] = $ver_id;
  153. $result = $this->validate($data, [
  154. ['name', 'require|max:30|unique:cy_game', '请输入游戏名称|游戏名称不能超过30个字符|游戏名称已存在'],
  155. ['order_recheck', 'integer', '游客登录必须为整型'],
  156. ['cooperation_status', 'integer|in:0,1,2,3', '对接状态必须为整型|对接状态参数错误'],
  157. ['is_show', 'integer|in:0,1', '是否显示必须为整型|是否显示参数错误'],
  158. ['channel_version', 'integer', '强更版本必须为整型'],
  159. // ['channel_split_ratio', 'integer|egt:0|elt:99', '渠道分成比例必须为整型|渠道分成比例不能低于1|渠道分成比例不能超过99'],
  160. ['type', 'integer|in:1,2,3', '平台必须为整型|平台参数错误'],
  161. ['game_kind', 'integer|in:1,2', '类型必须为整型|类型参数错误'],
  162. ['remarks', 'max:800', '备注不能超过800字'],
  163. ['android_sdk_id', 'require|integer', '请选择SDK版本号|SDK版本号必须为整型'],
  164. ['logout_btn', 'require|integer|in:0,1', '请选择注销状态|注销状态必须为整型|注销状态参数错误'],
  165. ['is_default', 'integer|in:0,1', '是否内部游戏必须为整型|是否内部游戏参数错误'],
  166. ['download_url', 'url', '下载地址结构错误'],
  167. ['free_pay', 'require|integer|in:1,2', '请选择自由支付状态|自由支付状态必须为整型|自由支付状态参数错误'],
  168. ['is_pay', 'require|integer|in:1,2', '请选择停止充值状态|停止充值状态必须为整型|停止充值状态参数错误'],
  169. ['is_welfare', 'require|integer|in:1,2', '请选择福状态|福状态必须为整型|福状态参数错误'],
  170. ['is_login', 'require|integer|in:0,1', '请选封禁状态|封禁状态必须为整型|封禁状态参数错误'],
  171. ['is_register', 'require|integer|in:0,1', '请选封禁状态|封禁状态必须为整型|封禁状态参数错误'],
  172. ]);
  173. //绑定的游戏判断
  174. // , 'cooperation_status' => ['<>', 3]
  175. // if (!empty(input('post.band_game_id')) && !$this->gameModel->field('id')->where(['id' => input('post.band_game_id')])->find()) {
  176. // $this->error('绑定游戏不存在或者已经下架');
  177. // }
  178. if (true !== $result) {
  179. $this->error($result);
  180. } else {
  181. $pinyin = new Pinyin();
  182. $pinyinStr = $pinyin->permalink($data['name'], '');
  183. //游戏的拼音是否存在
  184. $isExitPinyin = $this->gameModel->field('id')->where(['pinyin' => $pinyinStr])->find();
  185. if ($isExitPinyin) {
  186. $this->error('游戏拼音已经存在,请在游戏名称上加入标识字符');
  187. } else {
  188. $data['pinyin'] = $pinyinStr;
  189. $data['initial'] = $pinyin->abbr($data['name']);
  190. $gameInfoModel = new GameInfo;
  191. $data['create_time'] = NOW_TIMESTAMP;
  192. Db::startTrans();
  193. try {
  194. //insert触发不了事件
  195. if(!$this->gameModel->allowField(true)->save($data)){
  196. $this->error('添加失败,请重试!');
  197. }
  198. // 游戏扩展表
  199. $gameInfoData = ['game_id' => $this->gameModel->id, 'platform' => input('post.type')];
  200. if($data['ban_login_msg']){
  201. $gameInfoData['ban_login_msg'] = $data['ban_login_msg'];
  202. }
  203. if($data['ban_register_msg']){
  204. $gameInfoData['ban_register_msg'] = $data['ban_register_msg'];
  205. }
  206. if($data['landing_page_status']){
  207. $gameInfoData['landing_page_status'] = $data['landing_page_status'];
  208. }
  209. if($data['belonging_status']){
  210. $gameInfoData['belonging_status'] = $data['belonging_status'];
  211. }
  212. $gameInfoModel->insert($gameInfoData);
  213. $CooperationStatusString = "";
  214. if ($data['cooperation_status'] == 0) {
  215. $CooperationStatusString = "对接中";
  216. } else if ($data['cooperation_status'] == 1) {
  217. $CooperationStatusString = "上线";
  218. } else if ($data['cooperation_status'] == 2) {
  219. $CooperationStatusString = "白名单限制";
  220. } else if ($data['cooperation_status'] == 3) {
  221. $CooperationStatusString = "下架";
  222. }
  223. // $message = "添加游戏:" . $this->gameModel->name ." ,分成比例为:" .$data['channel_split_ratio']." ,对接状态为:" .$CooperationStatusString;
  224. $message = "添加游戏:" . $this->gameModel->name . " ,对接状态为:" . $CooperationStatusString . ',登陆封禁:' . $data['is_login'] == 0 ? '关' : '开' . ',注册封禁:' . $data['is_register'] == 0 ? '关' : '开';
  225. $this->insertLog($this->current_node, $message, 11);
  226. // 根据标准化游戏名自动加入或创建游戏组
  227. $this->syncGameBand($this->gameModel->id, $data['type'], $data['name']);
  228. if($company_id){
  229. $this->syncCompanyGameBind($this->gameModel->id, $company_id);
  230. }
  231. Db::commit();
  232. } catch (Exception $e) {
  233. // 回滚事务
  234. Db::rollback();
  235. $this->error('游戏添加失败: ' . $e->getMessage());
  236. }
  237. $this->success('游戏新增成功', 'game/index');
  238. }
  239. }
  240. }
  241. $this->assign('version', (new AndroidSdk())->getAllVersion());
  242. $companyList = (new CompanyGameBind())->field('id, company_alias')->order('company_name asc')->select();
  243. $this->assign('companyList', $companyList);
  244. return $this->fetch('new');
  245. }
  246. /**
  247. * 根据游戏类型和标准化游戏名维护游戏组。
  248. *
  249. * 已按当前平台绑定的游戏不做处理;未绑定时加入同名组,
  250. * 同名组不存在则创建新组。已有游戏组名称不会被修改。
  251. *
  252. * @param int $gameId
  253. * @param int $gameType 1=iOS、2=安卓、3=H5
  254. * @param string $gameName
  255. * @throws \Exception
  256. */
  257. private function syncGameBand($gameId, $gameType, $gameName)
  258. {
  259. $platformFields = [
  260. 1 => 'ios_game_id',
  261. 2 => 'android_game_id',
  262. 3 => 'h5_game_id',
  263. ];
  264. if (!isset($platformFields[$gameType])) {
  265. throw new \Exception('游戏平台类型错误');
  266. }
  267. $gameId = (int)$gameId;
  268. if ($gameId <= 0) {
  269. throw new \Exception('游戏ID错误');
  270. }
  271. $platformField = $platformFields[$gameType];
  272. $gameBandModel = new GameBand();
  273. // 编辑时当前平台已存在绑定关系,则保持原游戏组及组名不变
  274. if ($gameBandModel->where([$platformField => $gameId])->find()) {
  275. return;
  276. }
  277. $cleanName = cleanGameName((string)$gameName);
  278. if ($cleanName === '') {
  279. throw new \Exception('清洗后的游戏组名称不能为空');
  280. }
  281. $gameBandInfo = $gameBandModel->where(['game_name' => $cleanName])->find();
  282. if ($gameBandInfo) {
  283. $boundGameId = (int)$gameBandInfo[$platformField];
  284. if ($boundGameId > 0 && $boundGameId !== $gameId) {
  285. throw new \Exception("游戏组“{$cleanName}”已绑定同平台游戏(ID:{$boundGameId})");
  286. }
  287. $result = $gameBandModel->save(
  288. [$platformField => $gameId],
  289. ['id' => $gameBandInfo['id']]
  290. );
  291. if ($result === false) {
  292. throw new \Exception("游戏组“{$cleanName}”绑定失败");
  293. }
  294. return;
  295. }
  296. $bandData = [
  297. 'android_game_id' => 0,
  298. 'ios_game_id' => 0,
  299. 'h5_game_id' => 0,
  300. 'game_name' => $cleanName,
  301. 'status' => GameBand::STATUS_ENABLE,
  302. 'create_time' => NOW_TIMESTAMP,
  303. ];
  304. $bandData[$platformField] = $gameId;
  305. if ($gameBandModel->save($bandData) === false) {
  306. throw new \Exception("游戏组“{$cleanName}”创建失败");
  307. }
  308. }
  309. /**
  310. * 查询出游戏接入需要的参数
  311. */
  312. public function queryGameParam()
  313. {
  314. $game_id = $this->request->post('id');
  315. if (empty($game_id)) {
  316. $this->error('参数错误');
  317. }
  318. $game_data = model('Game')->where(['id' => $game_id])->field('id, type')->find();
  319. if (empty($game_data)) {
  320. $this->error('参数错误,不存在数据');
  321. }
  322. $appkey = model('App')->where(['gameid' => $game_id])->field('id,appkey,client_appkey')->find();
  323. $data['id'] = isset($game_data['id']) ? $game_data['id'] : '';
  324. $data['type'] = $game_data['type'];
  325. $data['appkey'] = isset($appkey['appkey']) ? $appkey['appkey'] : '';
  326. $data['appid'] = isset($appkey['id']) ? $appkey['id'] : '';
  327. $data['gameid'] = isset($game_data['id']) ? $game_data['id'] : '';
  328. $data['client_appkey'] = isset($appkey['client_appkey']) ? $appkey['client_appkey'] : '';
  329. $data['h5_game_url'] = (new Setting())->getSetting('HTTP_HOST_URL_H5').'/?g='.$game_id;
  330. $this->success('成功', '', $data);
  331. }
  332. /**
  333. * 编辑
  334. */
  335. public function update($id)
  336. {
  337. $id = (int)$id;
  338. if (empty($id)) {
  339. $this->error('游戏ID不能为空');
  340. }
  341. $gameInfo = Db::table('cy_game')->alias('g')->join('cy_gameinfo info', 'g.id=info.game_id', 'left')
  342. ->field('g.*,info.id as info_id,info.platform, info.ban_login_msg, info.ban_register_msg, info.landing_page_status, info.belonging_status, info.ai_status, info.ban_channel_ids')->where(['g.id' => $id])->find();
  343. if (empty($gameInfo)) $this->error('游戏不存在');
  344. if (request()->isPost()) {
  345. $data = [
  346. 'name' => input('post.name'),
  347. 'type' => input('post.type'),
  348. 'package_name' => input('post.package_name'),
  349. 'order_recheck' => input('post.order_recheck'),
  350. 'cooperation_status' => input('post.cooperation_status'),
  351. 'is_show' => input('post.is_show'),
  352. 'channel_version' => input('post.channel_version'),
  353. // 'channel_split_ratio' => input('post.channel_split_ratio'),
  354. 'remarks' => input('post.remarks'),
  355. 'logout_btn' => input('post.logout_btn'),
  356. 'android_sdk_id' => input('post.version_id'),
  357. // 'is_default' => input('post.is_default'),
  358. // 'download_url' => input('post.download_url'),
  359. 'game_auth_type' => input('post.game_auth_type'),
  360. 'game_bizid' => input('post.game_bizid'),
  361. 'free_pay' => input('post.free_pay'),
  362. 'is_pay' => input('post.is_pay'),
  363. 'is_welfare' => input('post.is_welfare'),
  364. 'is_login' => input('post.is_login'),
  365. 'is_register' => input('post.is_register'),
  366. 'ban_login_msg' => input('post.ban_login_msg'),
  367. 'ban_register_msg' => input('post.ban_register_msg'),
  368. 'landing_page_status' => input('post.landing_page_status'),
  369. 'belonging_status' => input('post.belonging_status'),
  370. 'ban_channel_ids' => input('post.ban_channel_ids'),
  371. ];
  372. $result = $this->validate($data, [
  373. ['name', 'require|max:30', '请输入游戏名称|游戏名称不能超过30个字符'],
  374. ['order_recheck', 'integer', '游客登录必须为整型'],
  375. ['cooperation_status', 'integer|in:0,1,2,3', '对接状态必须为整型|对接状态参数错误'],
  376. ['is_show', 'integer|in:0,1', '是否显示必须为整型|是否显示参数错误'],
  377. ['channel_version', 'integer', '强更版本必须为整型'],
  378. ['type', 'integer|in:1,2,3', '平台必须为整型|平台参数错误'],
  379. // ['channel_split_ratio', 'integer|egt:0|elt:99', '渠道分成比例必须为整型|渠道分成比例不能低于0|渠道分成比例不能超过99'],
  380. ['remarks', 'max:800', '备注不能超过800字'],
  381. ['android_sdk_id', 'require|integer', '请选择SDK版本号|SDK版本号必须为整型'],
  382. ['logout_btn', 'require|integer|in:0,1', '请选择注销状态|注销状态必须为整型|注销状态参数错误'],
  383. ['game_auth_type', 'integer|in:0,1,2', '实名认证方式必须为整型|实名认证方式参数错误'],
  384. // ['download_url', 'url', '下载地址结构错误'],
  385. ['free_pay', 'require|integer|in:1,2', '请选择自由支付状态|自由支付状态必须为整型|自由支付状态参数错误'],
  386. ['is_pay', 'require|integer|in:1,2', '请选择停止充值状态|停止充值状态必须为整型|停止充值状态参数错误'],
  387. ['is_welfare', 'require|integer|in:1,2', '请选择福状态|福状态必须为整型|福状态参数错误'],
  388. ['is_login', 'require|integer|in:0,1', '请选封禁状态|封禁状态必须为整型|封禁状态参数错误'],
  389. ['is_register', 'require|integer|in:0,1', '请选封禁状态|封禁状态必须为整型|封禁状态参数错误'],
  390. ['ban_login_msg', 'max:25', '封禁登录提示,限制25字以内'],
  391. ['ban_register_msg', 'max:25', '封禁注册提示,限制25字以内'],
  392. ]);
  393. // 修改游戏名称 验证是否唯一
  394. if ($gameInfo['name'] != $data['name']) {
  395. if ($this->gameModel->where(['name' => $data['name']])->find()) {
  396. $this->error('游戏名称已经存在');
  397. }
  398. // 去除编辑时候修改游戏名,不然之前的分包就不能用了。
  399. // $pinyin = new Pinyin();
  400. // $data['pinyin'] = $pinyin->permalink($data['name'], '');
  401. // $data['initial'] = $pinyin->abbr($data['name']);
  402. }
  403. if ($data['game_auth_type'] == 1 && !trim($data['game_bizid'])) {
  404. $this->error('实名认证方式为“中宣部认证”时,游戏备案识别码(bizId)必须填写');
  405. }
  406. if($data['is_register'] == 1 && !$data['ban_channel_ids']){
  407. $this->error('封禁注册,封禁渠道选择必须选择!');
  408. }
  409. $company_id = input('post.company_id', "", 'intval');
  410. // if (empty($company_id)) {
  411. // $this->error('请选择关联公司');
  412. // }
  413. if (true !== $result) {
  414. $this->error($result);
  415. } else {
  416. // 启动事务
  417. Db::startTrans();
  418. try {
  419. // 游戏表
  420. $this->gameModel->allowField(true)->save($data, ['id' => $id]);
  421. $gameInfoModel = new GameInfo;
  422. // 游戏扩展表
  423. $gameInfoData = ['platform' => input('post.type')];
  424. if($data['ban_login_msg']){
  425. $gameInfoData['ban_login_msg'] = $data['ban_login_msg'];
  426. }
  427. $gameInfoData['ban_register_msg'] = '当前游戏禁止注册!';
  428. if($data['ban_register_msg']){
  429. $gameInfoData['ban_register_msg'] = $data['ban_register_msg'];
  430. }
  431. if($data['landing_page_status']){
  432. $gameInfoData['landing_page_status'] = $data['landing_page_status'];
  433. }
  434. if($data['belonging_status']){
  435. $gameInfoData['belonging_status'] = $data['belonging_status'];
  436. }
  437. // 封禁渠道
  438. $gameInfoData['ban_channel_ids'] = $data['ban_channel_ids'] ?? null;
  439. if (!empty($gameInfo['info_id'])) {
  440. $gameInfoModel->update($gameInfoData, [
  441. 'id' => $gameInfo['info_id'],
  442. 'game_id' => $id,
  443. ]);
  444. } else {
  445. $gameInfoData['game_id'] = $id;
  446. $gameInfoModel->insert($gameInfoData);
  447. }
  448. // 登录白名单
  449. $white_username = input('post.white_username', '');
  450. if(input('post.is_login', '') == 1){
  451. Db::name('cy_game_user_white')->where('game_id', $id)->delete();
  452. }
  453. if($white_username && input('post.is_login', '') == 1){
  454. // 适配多系统
  455. $normalized = str_replace(["\r\n", "\r"], "\n", $white_username);
  456. $lines = explode("\n", $normalized);
  457. $lines = array_map('trim', $lines);
  458. $white_list = array_filter($lines);
  459. $addWhiteData = [];
  460. for($i=0; $i<count($white_list); $i++){
  461. if(!empty($white_list[$i])){
  462. $addWhiteData[] = ['game_id' => $id, 'username' => $white_list[$i]];
  463. }
  464. }
  465. if($addWhiteData){
  466. if(!Db::name('cy_game_user_white')->insertAll($addWhiteData)){
  467. throw new \Exception('白名单保存失败,确认是否有重复数据');
  468. }
  469. }
  470. }
  471. // 已归组则保持不变,未归组时按标准化游戏名自动绑定
  472. $this->syncGameBand($id, $data['type'], $data['name']);
  473. if($company_id){
  474. $this->syncCompanyGameBind($id, $company_id);
  475. }
  476. // 写入日志
  477. $gameDJStatus = '';
  478. if ($data['cooperation_status'] == 0) {
  479. $gameDJStatus = '对接中';
  480. } elseif ($data['cooperation_status'] == 1) {
  481. $gameDJStatus = '上线';
  482. } elseif ($data['cooperation_status'] == 2) {
  483. $gameDJStatus = '白名单限制';
  484. } elseif ($data['cooperation_status'] == 3) {
  485. $gameDJStatus = '下架';
  486. }
  487. if ($gameInfo['name'] != $data['name']) {
  488. // $this->insertLog($this->current_node,'游戏名:'.$gameInfo['name'].' -> '.$data['name'].',修改后的强更版号:'.input('post.channel_version').',对接状态:'.$gameDJStatus.',分成比例:'.$data['channel_split_ratio'], 11);
  489. $this->insertLog($this->current_node, '游戏名:' . $gameInfo['name'] . ' -> ' . $data['name'] . ',修改后的强更版号:' . input('post.channel_version') . ',对接状态:' . $gameDJStatus . ',登陆封禁:' . $data['is_login'] == 0 ? '关' : '开' . ',注册封禁:' . $data['is_register'] == 0 ? '关' : '开', 11);
  490. } else {
  491. // $this->insertLog($this->current_node,'游戏名:'.$gameInfo['name'].',修改后的强更版号:'.input('post.channel_version').',对接状态:'.$gameDJStatus.',分成比例:'.$data['channel_split_ratio'], 11);
  492. $this->insertLog($this->current_node, '游戏名:' . $gameInfo['name'] . ',修改后的强更版号:' . input('post.channel_version') . ',对接状态:' . $gameDJStatus . ',登陆封禁:' . $data['is_login'] == 0 ? '关' : '开' . ',注册封禁:' . $data['is_register'] == 0 ? '关' : '开', 11);
  493. }
  494. // 提交事务
  495. Db::commit();
  496. } catch (\Exception $e) {
  497. // 回滚事务
  498. Db::rollback();
  499. // dump('游戏信息编辑失败: ' . $e->getMessage().' - '. $e->getFile().":".$e->getLine());
  500. $this->error('游戏信息编辑失败: ' . $e->getMessage().' - '. $e->getFile().":".$e->getLine());
  501. }
  502. $this->success('游戏信息编辑成功', 'game/index');
  503. }
  504. }
  505. // 登录白名单
  506. $whiteListNew = "";
  507. $whiteList = Db::name('cy_game_user_white')->whereIn('game_id', $id)->column('username');
  508. if($whiteList){
  509. $whiteListNew = implode("\n", $whiteList);
  510. }
  511. $this->assign('whiteList', $whiteListNew);
  512. // 抖音游戏平台绑定
  513. $dyConfig = Db::name('cy_game_bind_douyin_open')->where('game_id', $id)->find();
  514. $this->assign('dyConfig', $dyConfig);
  515. // AI 配置
  516. $aiChannelIds = Db::table('cy_game_ai_channel')->where(['game_id' => $id])->column('channel_id');
  517. if($aiChannelIds){
  518. $aiChannelIds = implode(',', $aiChannelIds);
  519. }
  520. $this->assign('ai_channel_ids', !empty($aiChannelIds)?$aiChannelIds:'');
  521. $this->assign('gameInfo', $gameInfo);
  522. $this->assign('version', (new AndroidSdk())->getAllVersion());
  523. // 封禁渠道选择
  524. $this->assign('channelTree', json_encode(ChannelUtil::getFullChannelTree(), JSON_UNESCAPED_UNICODE));
  525. $banChannelIds = $gameInfo['ban_channel_ids'] ?? '';
  526. $this->assign('banChannelIds', $banChannelIds);
  527. $this->assign('selectedBanChannels', json_encode(ChannelUtil::getSelectedChannels($banChannelIds), JSON_UNESCAPED_UNICODE));
  528. // 关联公司
  529. $companyList = (new CompanyGameBind())->field('id, company_alias')->order('id desc')->select();
  530. $this->assign('companyList', $companyList);
  531. $currentCompanyId = (new CompanyGameBind())
  532. ->whereRaw("FIND_IN_SET(?, game_ids)", [(string)$id])
  533. ->value('id') ?: 0;
  534. $this->assign('currentCompanyId', $currentCompanyId);
  535. return $this->fetch('edit');
  536. }
  537. /**
  538. * 同步游戏与公司的绑定关系。
  539. */
  540. private function syncCompanyGameBind($gameId, $newCompanyId)
  541. {
  542. $companyGameBind = new CompanyGameBind();
  543. $gameIdStr = (string)$gameId;
  544. $oldCompany = $companyGameBind
  545. ->whereRaw("FIND_IN_SET(?, game_ids)", [$gameIdStr])
  546. ->field('id, game_ids')
  547. ->find();
  548. if (!empty($oldCompany) && $oldCompany['id'] != $newCompanyId) {
  549. $gameIds = explode(',', $oldCompany['game_ids']);
  550. $gameIds = array_map('trim', $gameIds);
  551. $gameIds = array_filter($gameIds);
  552. $gameIds = array_values(array_diff($gameIds, [$gameIdStr]));
  553. $companyGameBind->where('id', $oldCompany['id'])->update([
  554. 'game_ids' => implode(',', $gameIds),
  555. 'updated_at' => date('Y-m-d H:i:s')
  556. ]);
  557. }
  558. if ($newCompanyId > 0) {
  559. $newCompany = $companyGameBind->where('id', $newCompanyId)->find();
  560. if (empty($newCompany)) {
  561. throw new \Exception('选择的公司不存在');
  562. }
  563. $gameIds = [];
  564. if (!empty($newCompany['game_ids'])) {
  565. $gameIds = explode(',', $newCompany['game_ids']);
  566. $gameIds = array_map('trim', $gameIds);
  567. $gameIds = array_filter($gameIds);
  568. }
  569. if (!in_array($gameIdStr, $gameIds)) {
  570. $gameIds[] = $gameIdStr;
  571. $companyGameBind->where('id', $newCompanyId)->update([
  572. 'game_ids' => implode(',', $gameIds),
  573. 'updated_at' => date('Y-m-d H:i:s')
  574. ]);
  575. }
  576. }
  577. }
  578. /**
  579. * 保存游戏关联公司(保留给旧入口使用)
  580. */
  581. public function companyBindSave()
  582. {
  583. $gameId = input('game_id', 0, 'intval');
  584. $newCompanyId = input('company_id', 0, 'intval');
  585. if (empty($gameId)) {
  586. return json(['code' => -100, 'msg' => '游戏ID不能为空']);
  587. }
  588. $gameInfo = Db::name('cy_game')->where('id', $gameId)->find();
  589. if (empty($gameInfo)) {
  590. return json(['code' => -100, 'msg' => '游戏不存在']);
  591. }
  592. Db::startTrans();
  593. try {
  594. $this->syncCompanyGameBind($gameId, $newCompanyId);
  595. $companyName = $newCompanyId > 0 ? (new CompanyGameBind())->where('id', $newCompanyId)->value('company_name') : '无';
  596. $this->insertLog($this->current_node, "游戏:{$gameInfo['name']} 关联公司:{$companyName}", 41);
  597. Db::commit();
  598. return json(['code' => 100, 'msg' => '操作成功!']);
  599. } catch (\Exception $e) {
  600. Db::rollback();
  601. return json(['code' => -100, 'msg' => '操作失败:' . $e->getMessage()]);
  602. }
  603. }
  604. public function dyConfigSave(){
  605. $input = input();
  606. $dy_id = input('dy_id', '');
  607. $data = [
  608. 'game_id' => $input['game_id'],
  609. 'app_id' => $input['app_id'],
  610. 'app_secret' => $input['app_secret'],
  611. ];
  612. if($dy_id){
  613. $data['id'] = $dy_id;
  614. $res = GameBindDouyinOpen::update($data);
  615. }else{
  616. $res = GameBindDouyinOpen::insert($data);
  617. }
  618. if($res){
  619. $gameName = Db::name('cy_game')->where('id', $input['game_id'])->value('name');
  620. $this->insertLog($this->current_node, "游戏:".$gameName." 绑定 抖音游戏 app_id:".$input['app_id'],41);
  621. $this->result([], 100, "操作成功!");
  622. }
  623. $this->result([], -100, '操作失败!');
  624. }
  625. public function aiConfigSave(){
  626. $input = input();
  627. if(empty($input['ai_status']) || empty($input['game_id'])){
  628. $this->result([], -110, '提交参数有误!');
  629. }
  630. $aiChannelData = [];
  631. if(!empty($input['channel_ids'])){
  632. $channel_ids = explode(',', $input['channel_ids']);
  633. foreach($channel_ids as $v){
  634. $aiChannelData[] = [
  635. 'game_id' => $input['game_id'],
  636. 'channel_id' => $v,
  637. ];
  638. }
  639. }
  640. $gameName = Db::name('cy_game')->where('id', $input['game_id'])->value('name');
  641. $msg = "游戏:{$gameName}, AI 配置状态:";
  642. if($input['ai_status'] == 1){
  643. $msg .= "开启";
  644. }else{
  645. $msg .= "关闭";
  646. }
  647. Db::startTrans();
  648. try {
  649. // 更新游戏详情状态
  650. $updateStatus = Db::table('cy_gameinfo')->where(['game_id' => $input['game_id']])->update(['ai_status' => $input['ai_status']]);
  651. if($updateStatus === false){
  652. throw new \Exception("更新游戏详情失败");
  653. }
  654. // 处理渠道绑定
  655. // 无论是否有渠道数据,都先删除旧的绑定
  656. Db::table('cy_game_ai_channel')->where(['game_id' => $input['game_id']])->delete();
  657. if(!empty($aiChannelData)){
  658. if(!Db::table('cy_game_ai_channel')->insertAll($aiChannelData)){
  659. throw new \Exception("渠道绑定失败");
  660. }
  661. }
  662. $this->insertLog($this->current_node, $msg, 41);
  663. Db::commit();
  664. } catch (\Exception $e) {
  665. Db::rollback();
  666. $this->result([], -100, '操作失败: ' . $e->getMessage());
  667. }
  668. $this->result([], 200, "操作成功!");
  669. }
  670. /**
  671. * 获取下级渠道数据(用于异步懒加载)
  672. */
  673. public function getChannels()
  674. {
  675. $parentId = $this->request->param('parent_id', 0, 'intval');
  676. $data = ChannelUtil::getChildChannels($parentId);
  677. return json(['code' => 1, 'data' => $data]);
  678. }
  679. /**
  680. * 搜索渠道(支持远程搜索,用于懒加载树的搜索功能)
  681. */
  682. public function searchChannels()
  683. {
  684. $keyword = $this->request->param('keyword', '', 'trim');
  685. if (empty($keyword)) {
  686. return json(['code' => 1, 'data' => []]);
  687. }
  688. $channelList = Db::name('nw_channel')
  689. ->where('name', 'like', "%{$keyword}%")
  690. ->where('status', 1)
  691. ->field('id as value, name, parent_id')
  692. ->order('id', 'asc')
  693. ->limit(50)
  694. ->select();
  695. $data = [];
  696. foreach ($channelList as $v) {
  697. $hasChildren = Db::name('nw_channel')
  698. ->where(['parent_id' => $v['value'], 'status' => 1])
  699. ->count() > 0;
  700. $data[] = [
  701. 'name' => $v['name'],
  702. 'value' => (int)$v['value'],
  703. 'children' => $hasChildren ? [] : null,
  704. ];
  705. }
  706. return json(['code' => 1, 'data' => $data]);
  707. }
  708. /**
  709. * 通过ajax获得绑定游戏信息
  710. *
  711. */
  712. public function packageApply()
  713. {
  714. $page_size = input('page_size', 10);
  715. $where = [];
  716. //白名单
  717. //$where['g.cooperation_status'] = 2;
  718. //游戏名称;
  719. if (input('request.game_name') != '') {
  720. $where['g.name'] = [['eq', input('request.game_name', '', 'trim')], ['exp', Db::raw('is null')], 'or'];
  721. }
  722. //审核状态
  723. if (input('request.apply_status') != '') {
  724. $where['apply.apply_status'] = ['eq', input('request.apply_status')];
  725. }
  726. $channelList = model('common/Channel')->where(['level' => 1])->column('name', 'id');
  727. $param = input('get.');
  728. $list = Db::name('nw_game_package_apply')->alias('apply')
  729. ->field('apply.id,apply.channel_id,apply.game_id,FROM_UNIXTIME( apply.create_time ) AS create_time,apply.apply_status,g.name game_name,g.game_kind,channel.name as channel_name,frozen.subpackage,bchild.name as bchild_name,bchild.parent_id as bcparent_id,channel.parent_id as cparent_id') //,bchild.name as bchild_name,b.name as b_name
  730. ->join('cy_game g', 'g.id=apply.game_id', 'left')
  731. ->join('nw_channel channel', 'channel.id=apply.channel_id', 'left')
  732. ->join('nw_channel bchild', 'bchild.id=channel.parent_id AND bchild.level = 2', 'left')
  733. // ->join('nw_channel b', '(b.id=bchild.parent_id or b.id = channel.parent_id) AND b.level = 1', 'left')
  734. ->join('nw_channel_frozen frozen', 'apply.channel_id = frozen.channel_id and apply.game_id = frozen.game_id', 'LEFT')
  735. ->where($where)->order('apply.apply_status asc,apply.create_time desc')
  736. ->paginate($page_size, false, array('query' => $param))->each(function ($item, $key) use ($channelList) {
  737. if ($item['bcparent_id']) {
  738. $item['b_name'] = $channelList[$item['bcparent_id']];
  739. } else {
  740. $item['b_name'] = $channelList[$item['cparent_id']];
  741. }
  742. return $item;
  743. });
  744. $tmpGameList = $this->cyModel('game')->field('id,name')->select();
  745. $gameList = array();
  746. foreach ($tmpGameList as $game) {
  747. $gameList[$game['id']] = $game;
  748. }
  749. $this->assign('gameList', $gameList);
  750. $this->assign('notify_list', $list);
  751. $this->assign('page', $list->render());
  752. return $this->fetch();
  753. }
  754. /**
  755. * 游戏公告列表
  756. */
  757. public function notifyLists()
  758. {
  759. $notify = new GameNotify;
  760. $where = [];
  761. //游戏名称
  762. if (input('request.game_name') != '') {
  763. $where['g.name'] = [['eq', input('request.game_name', '', 'trim')], ['exp', Db::raw('is null')], 'or'];
  764. }
  765. //标题
  766. if (input('request.title') != '') {
  767. $where['n.title'] = ['like', '%' . input('request.title', '', 'trim') . '%'];
  768. }
  769. //推送类型
  770. if (input('request.status') != '') {
  771. $where['n.status'] = input('request.status', 0, 'intval');
  772. }
  773. //限制类型
  774. if (input('request.deny_type') != '') {
  775. $where['n.deny_type'] = input('request.deny_type', 0, 'intval');
  776. }
  777. //查询参数
  778. $param = input('get.');
  779. $notify_list = $notify->alias('n')->field('n.*,g.name game_name')->join('cy_game g', 'g.id=n.game_id', 'left')
  780. ->where($where)->order('n.create_time desc')
  781. ->paginate(10, false, array('query' => $param));
  782. $this->assign('notify_list', $notify_list);
  783. $this->assign('page', $notify_list->render());
  784. $this->assign('gameList', $this->selfGameList);
  785. return $this->fetch('notify_list');
  786. }
  787. public function notifyList()
  788. {
  789. $input = input('get.');
  790. $where = [];
  791. $ids = [];
  792. // 游戏
  793. if (!empty($input['game_id'])) {
  794. $ids = Db::table('cy_game_notify_relation')->whereIn('game_id', $input['game_id'])->column('notify_id');
  795. }
  796. // 渠道
  797. if (!empty($input['channel_id'])) {
  798. $cIds = Db::table('cy_game_notify_deny')->whereIn('target_id', $input['channel_id'])->where(['target_type' => 1])->column('notify_id');
  799. if($cIds){
  800. // $ids = array_intersect($ids, $cIds);
  801. $ids = array_merge($ids, $cIds);
  802. }
  803. }
  804. if($ids){
  805. $where['id'] = ['in', $ids];
  806. }
  807. // 标题
  808. if (!empty($input['title'])) {
  809. $where['title'] = ['like', '%' . $input['title'] . '%'];
  810. }
  811. // 推送类型
  812. if (!empty($input['status'])) {
  813. $where['status'] = $input['status'];
  814. }
  815. // 公告类型
  816. if (!empty($input['notify_type'])) {
  817. $where['notify_type'] = $input['notify_type'];
  818. }
  819. // 限制类型
  820. if (!empty($input['deny_type'])) {
  821. $where['deny_type'] = $input['deny_type'];
  822. }
  823. // 状态
  824. if (!empty($input['status'])) {
  825. $where['status'] = $input['status'];
  826. }
  827. //查询参数
  828. $notify_list = Db::table('cy_game_notify')
  829. ->where($where)->order('create_time desc')
  830. ->paginate(10, false, array('query' => $input))
  831. ->each(function($item, $key){
  832. // 游戏名称处理
  833. $gameList = Db::table('cy_game_notify_relation')->alias('cgnr')
  834. ->join('cy_game cg', 'cgnr.game_id=cg.id', 'left')
  835. ->where(['notify_id' => $item['id']])->column('cg.name');
  836. if (count($gameList) > 3) {
  837. $count = count($gameList);
  838. $item['game_name'] = implode(', ', array_slice($gameList, 0, 3)) . ", ... 共{$count}个";
  839. } else {
  840. $item['game_name'] = implode(', ', $gameList);
  841. }
  842. return $item;
  843. });
  844. $this->assign('notify_list', $notify_list);
  845. $this->assign('page', $notify_list->render());
  846. return $this->fetch('notify_list');
  847. }
  848. /**
  849. * 获得限制渠道信息
  850. */
  851. public function notifychannel()
  852. {
  853. $id = input('id', 0, 'intval');
  854. if (empty($id)) $this->error('删除记录的ID不能为空');
  855. $notify = new GameNotify;
  856. if (!$info = $notify->where(['id' => $id])->find()) {
  857. $this->error('参数错误');
  858. }
  859. $ids = Db::table('cy_game_notify_deny')->where(['notify_id' => $id, 'target_type' => $info['data_type'], 'deny_type' => $info['deny_type']])->column('target_id');
  860. if($info['data_type'] == 2){
  861. $userListResult = model('Members')->field('id as value,username as name,"true" as selected ')->whereIn('id', $ids)->select();
  862. foreach ($userListResult as $k=>$v){
  863. echo "ID: ".$v['value']." - Username: ".$v['name']."<br />";
  864. }
  865. }else{
  866. $denied_channel_arr = model('channel')->field('id,name')->whereIn('id', $ids)->select();
  867. if ($denied_channel_arr) {
  868. foreach ($denied_channel_arr as $item) {
  869. echo "渠道号: ".$item['name']."(".$item['id'].")<br />";
  870. }
  871. }
  872. }
  873. exit;
  874. }
  875. /**
  876. * 新增游戏公告
  877. */
  878. public function notifyCreate()
  879. {
  880. return $this->fetch('notify_new');
  881. }
  882. // 新增和编辑公告
  883. public function notifySave(){
  884. if (request()->isPost()) {
  885. $input = input();
  886. $fileUpload = new FileUpload();
  887. $notify = new GameNotify;
  888. $result = $this->validate($input, [
  889. // ['game_id', 'require|integer', '请选择游戏|游戏ID必须为整型'],
  890. ['title', 'require|max:50', '通知标题不能为空|通知标题不能超过50个字符'],
  891. ['content', 'require', '通知内容不能为空'],
  892. ['notify_type', 'integer', '上架类型必须为整型'],
  893. ['deny_type', 'integer', '限制方式必须为整型'],
  894. ['data_type', 'integer', '限制类型必须为整型'],
  895. ['status', 'require|integer', '是否推送不能为空|是否推送必须为整型'],
  896. ]);
  897. if (true !== $result) {
  898. $this->error($result);
  899. }
  900. $imgFile = request()->file('img'); //图片
  901. $img_url = $fileUpload->upload($imgFile); //图片URL
  902. if (!empty($imgFile) && empty($img_url)) {
  903. $this->error($fileUpload->getError());
  904. }
  905. $data = [
  906. 'title' => $input['title'],
  907. 'content' => $input['content'],
  908. 'notify_type' => $input['notify_type'], // 内容类型:1=公告,2=广告、3=游戏强更、4=时效性公告
  909. 'img_url' => $img_url != false?$img_url:'',
  910. 'create_time' => time(),
  911. // 'game_id' => input('post.select_game', '', 'intval'),
  912. // 'channel_id' => input('post.select_channel', '', 'intval'),
  913. 'status' => $input['status']??'',
  914. 'deny_type' => $input['deny_type'], // 限制类型:0=黑名单,1=白名单
  915. 'data_type' => $input['data_type'], // 数据类型区分: 1=渠道、2=用户
  916. 'begin_time' => 0,
  917. 'end_time' => 0,
  918. // 'user_id' => input('post.select_select_user', '', 'intval'),
  919. // 'target_id' => input('post.target_id', '', 'intval'),
  920. ];
  921. // 根据通知类型处理时间字段
  922. if ($input['notify_type'] == 4) {
  923. // 时效性公告:设置时间范围
  924. $begin_time = input('post.begin_time', '');
  925. $end_time = input('post.end_time', '');
  926. if (!empty($begin_time)) {
  927. $data['begin_time'] = strtotime($begin_time);
  928. } else {
  929. $data['begin_time'] = 0;
  930. }
  931. if (!empty($end_time)) {
  932. $data['end_time'] = strtotime($end_time);
  933. } else {
  934. $data['end_time'] = 0;
  935. }
  936. }
  937. $id = input('id', '');
  938. Db::startTrans();
  939. try {
  940. if(!$id){
  941. $id = $notify->allowField(true)->insertGetId($data);
  942. } else {
  943. unset($data['create_time']);
  944. $notify->allowField(true)->save($data, ['id' => $id]);
  945. }
  946. // dump($id);
  947. if(!$id){
  948. throw new \Exception('操作失败!');
  949. }
  950. // if($data['data_type'] == 2){
  951. // $select_user = input('post.select_user', '');
  952. // if($select_user != ''){
  953. // $select_user_ids = explode(',', $select_user);
  954. // $newData = [];
  955. // foreach ($select_user_ids as $uid) {
  956. // $newData[] = [
  957. // 'pid' => $id, // 假设 $id 是外部定义的变量
  958. // 'uid' => $uid,
  959. // 'update_time' => time(),
  960. // ];
  961. // }
  962. // Db::table('cy_game_notify_user')->insertAll($newData);
  963. // }
  964. // }
  965. Db::table('cy_game_notify_relation')->where(['notify_id' => $id])->delete();
  966. if($input['select_game']){
  967. $gameIds = explode(',', $input['select_game']);
  968. $relationData = [];
  969. foreach ($gameIds as $value) {
  970. $relationData[] = [
  971. 'notify_id' => $id,
  972. 'game_id' => $value,
  973. ];
  974. }
  975. if($relationData){
  976. if(!Db::table('cy_game_notify_relation')->insertAll($relationData)){
  977. throw new \Exception('操作失败,关联游戏存储失败!');
  978. }
  979. }
  980. }
  981. // 类型与黑白名单处理
  982. $handleIds = [];
  983. if($input['select_channel']){
  984. $handleIds = explode(',', $input['select_channel']);
  985. }
  986. if($input['select_user']){
  987. $handleIds = explode(',', $input['select_user']);
  988. }
  989. Db::table('cy_game_notify_deny')->where(['notify_id' => $id])->delete();
  990. if($handleIds){
  991. $denyData = [];
  992. foreach ($handleIds as $value) {
  993. $denyData[] = [
  994. 'notify_id' => $id,
  995. 'target_id' => $value,
  996. 'target_type' => $input['data_type'],
  997. 'deny_type' => $input['deny_type'],
  998. ];
  999. }
  1000. if($denyData){
  1001. if(!Db::table('cy_game_notify_deny')->insertAll($denyData)){
  1002. throw new \Exception('操作失败,关联黑白名单存储失败!');
  1003. }
  1004. }
  1005. }
  1006. Db::commit();
  1007. } catch (\Exception $e) {
  1008. Db::rollback();
  1009. // dump($e->getMessage(), $e->getFile(), $e->getLine());
  1010. $this->error('操作失败: ' . $e->getMessage());
  1011. }
  1012. $this->success('操作成功', 'game/notifyList');
  1013. }
  1014. $this->error('非法操作!');
  1015. }
  1016. /**
  1017. * 编辑游戏公告
  1018. */
  1019. public function notifyEdit()
  1020. {
  1021. $id = input('id', 0, 'intval');
  1022. if (empty($id)) $this->error('游戏公告的ID不能为空');
  1023. $notifyInfo = Db::table('cy_game_notify')->where(['id' => $id])->find();
  1024. if (empty($notifyInfo)) $this->error('记录不存在');
  1025. $relationData = Db::table('cy_game_notify_relation')->where(['notify_id' => $id])->column('game_id');
  1026. $notifyInfo['relation_data'] = json_encode($relationData);
  1027. $denyData = Db::table('cy_game_notify_deny')
  1028. ->where(['notify_id' => $id, 'deny_type' => $notifyInfo['deny_type'], 'target_type' => $notifyInfo['data_type']])
  1029. ->column('target_id');
  1030. $channel_list = [];
  1031. $user_list = [];
  1032. $userListResult = [];
  1033. if($notifyInfo['data_type'] == 1){
  1034. $channel_list = $denyData;
  1035. }else{
  1036. $user_list = $denyData;
  1037. $userListResult = model('Members')->field('id as value,username as name,"true" as selected ')->whereIn('id', $denyData)->select();
  1038. }
  1039. $notifyInfo['channel_list'] = json_encode($channel_list);
  1040. $notifyInfo['user_list'] = json_encode($user_list);
  1041. // dump($userListResult);
  1042. $this->assign('data', $notifyInfo);
  1043. $this->assign('userList', json_encode($userListResult));
  1044. return $this->fetch('notify_edit');
  1045. }
  1046. /**
  1047. * 删除游戏公告
  1048. *
  1049. */
  1050. public function notifyDelete()
  1051. {
  1052. $id = input('id', 0, 'intval');
  1053. if (empty($id)) $this->error('删除记录的ID不能为空');
  1054. $notify = new GameNotify;
  1055. if ($notify->where(['id' => $id])->delete()) {
  1056. $this->success('删除成功');
  1057. } else {
  1058. $this->error('删除失败');
  1059. }
  1060. }
  1061. // 获取匹配的用户名相关账户列表
  1062. public function getUserList(){
  1063. $username = input('username', '');
  1064. if(!$username){
  1065. $this->jsonResult('',0,'查询参数有误!');
  1066. }
  1067. $list = model('Members')->field('id as value,username as name')->whereLike('username', "%".$username."%")->limit(1000)->select();
  1068. return $this->jsonResult($list, 1);
  1069. }
  1070. /**
  1071. *是否显示
  1072. */
  1073. public function show()
  1074. {
  1075. $id = $this->request->param('id', '', 'intval');
  1076. $status = $this->request->param('is_show', '', 'intval');
  1077. $data['is_show'] = $status;
  1078. if (empty($id)) {
  1079. $this->error('参数错误!');
  1080. }
  1081. $result = $this->validate($data, [
  1082. ['is_show', 'in:0,1', '状态参数错误'],
  1083. ]);
  1084. if (true !== $result) {
  1085. $this->error($result);
  1086. }
  1087. $gameModel = model("Game");
  1088. if (!$gameModel->find($id)) {
  1089. $this->error('参数错误,不存在该数据');
  1090. }
  1091. if ($gameModel->update($data, ['id' => $id])) {
  1092. $msg = $status ? '显示' : '隐藏';
  1093. $this->insertLog($this->current_node, $msg . '游戏:' . get_game_name($id), 11);
  1094. $this->success('修改成功');
  1095. }
  1096. $error = $gameModel->getError();
  1097. $this->error($error ?: '修改失败');
  1098. }
  1099. /**
  1100. * 游戏点位
  1101. *
  1102. * @return mixed|string
  1103. */
  1104. public function gamePointList()
  1105. {
  1106. $where['g.cooperation_status'] = ['not in', '3']; //下架的游戏不显示
  1107. //游戏名称
  1108. if (input('request.game_id') != '') {
  1109. $where['g.id'] = ['=', input('request.game_id')];
  1110. $game = get_game_name(input('request.game_id'));
  1111. $message = "查询游戏:{$game}";
  1112. $this->insertLog($this->current_node, $message, 12);
  1113. }
  1114. $list = Db::table('cy_game')->alias('g')->join('cy_game_point p', 'g.id = p.game_id', 'left')
  1115. ->join("nw_game_channel_pointset b", "b.game_id=g.id", "left")
  1116. ->field("p.*,g.id as game_id,g.name,b.isset_first,b.restricted_list_1,b.isset_second,b.restricted_list_2")->order('g.id desc')->where($where)->where("g.is_default = 0")
  1117. ->paginate(10, false, ['query' => input('get.')])
  1118. ->each(function ($item, $key) {
  1119. $item['restricted_list_1'] = ltrim($item['restricted_list_1'], ',');
  1120. $item['restricted_list_2'] = ltrim($item['restricted_list_2'], ',');
  1121. // 判断首充渠道限制名单是否为空
  1122. $item['channel_name_1'] = '';
  1123. $item['channel_name_2'] = '';
  1124. if (!empty($item['restricted_list_1'])) {
  1125. $channelArr = Db::table('cy_department')
  1126. ->field("name")
  1127. ->where('id', 'IN', $item['restricted_list_1'])
  1128. ->select();
  1129. $nameStr = '';
  1130. foreach ($channelArr as $v) {
  1131. $nameStr .= $v['name'] . ',';
  1132. }
  1133. $nameStr = substr($nameStr, 0, strlen($nameStr) - 3);
  1134. $item['channel_name_1'] = $nameStr; //给数据集追加字段num并赋值
  1135. }
  1136. // 判断续充渠道限制名单是否为空
  1137. if (!empty($item['restricted_list_2'])) {
  1138. $channelArr = Db::table('cy_department')
  1139. ->field("name")
  1140. ->where('id', 'IN', $item['restricted_list_2'])
  1141. ->select();
  1142. $nameStr = '';
  1143. foreach ($channelArr as $v) {
  1144. $nameStr .= $v['name'] . ',';
  1145. }
  1146. $nameStr = substr($nameStr, 0, strlen($nameStr) - 3);
  1147. $item['channel_name_2'] = $nameStr; //给数据集追加字段num并赋值
  1148. }
  1149. return $item;
  1150. });
  1151. // 获取配置表 首充默认最大天数 FIRST_MAX_DAY
  1152. $FIRST_MAX_DAY = model('Setting')->where(['name' => 'FIRST_MAX_DAY'])->field('value')->find()['value'];
  1153. $this->assign('game_list', $this->selfGameList);
  1154. $this->assign('game_point_list', $list);
  1155. $this->assign('FIRST_MAX_DAY', $FIRST_MAX_DAY);
  1156. $this->assign('page', $list->render());
  1157. return $this->fetch('game_point_list');
  1158. }
  1159. public function gamePointDownload()
  1160. {
  1161. if (request()->isAjax()) {
  1162. $where['g.cooperation_status'] = ['not in', '0,3']; //对接中,下架的游戏不显示
  1163. //游戏名称
  1164. if (input('request.game_id') != '') {
  1165. $where['g.id'] = ['=', input('request.game_id', '0', 'intval')];
  1166. }
  1167. $num = Db::table('cy_game')->alias('g')
  1168. ->join('cy_game_point p', 'g.id = p.game_id', 'left')
  1169. ->field("g.id as game_id,g.name,p.game_level,p.inner_point,p.min_percent,p.third_party_pay_point,
  1170. p.remark,p.gp_create_time,p.gp_update_time,p.first_max_days")
  1171. ->where($where)
  1172. ->order('g.id desc')
  1173. ->count('*');
  1174. //2023-2-7
  1175. $this->success('查无数据,不支持下载');
  1176. if (!$num) {
  1177. $this->success('查无数据,不支持下载');
  1178. }
  1179. $sql = Db::table('cy_game')->alias('g')
  1180. ->join('cy_game_point p', 'g.id = p.game_id', 'left')
  1181. ->field("g.id as game_id,g.name,p.game_level,p.inner_first_point,p.inner_point,p.min_percent,p.third_party_pay_point,
  1182. p.remark,p.gp_create_time,p.gp_update_time,p.first_max_days")
  1183. ->where($where)
  1184. ->order('g.id desc')
  1185. ->fetchSql(true)
  1186. ->select();
  1187. if ((new MakeReportGo())->addTask('gamePointList', $sql, session_id())) {
  1188. $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  1189. } else {
  1190. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  1191. }
  1192. } else {
  1193. $this->error('非法请求');
  1194. }
  1195. }
  1196. // 游戏点位报表
  1197. public function editPoint()
  1198. {
  1199. $data = $this->request->param();
  1200. if (isset($data['type'])) {
  1201. if ($data['type'] == 'editMultiLevel') {
  1202. $this->editMultiLevel();
  1203. }
  1204. if ($data['type'] == 'editLevel') {
  1205. $this->editLevel();
  1206. }
  1207. if ($data['type'] == 'editPercent') {
  1208. $this->editPercent();
  1209. }
  1210. }
  1211. $type = ['third_party_pay_point', 'inner_point', 'remark', 'inner_first_point', 'first_max_days'];
  1212. if (!in_array($data['name'], $type)) {
  1213. $this->error('选择参数错误');
  1214. }
  1215. //返点
  1216. $gamePointModel = model("GamePoint");
  1217. $oldPoint = $gamePointModel->where("game_id = '{$data['pk']}'")->field('gp_id,inner_point,inner_first_point,third_party_pay_point')->find();
  1218. $nameZK = '';
  1219. if ($data['name'] == 'third_party_pay_point') {
  1220. $result = $this->validate($data, [
  1221. ['pk|ID', 'require', '参数错误'],
  1222. ['value|点数', 'number|between:0,100'],
  1223. ['name', 'require', '点位参数错误'],
  1224. ]);
  1225. } else if ($data['name'] == 'inner_first_point') {
  1226. // 首充
  1227. $result = $this->validate($data, [
  1228. ['pk|ID', 'require', '参数错误'],
  1229. ['value|首充折扣', 'number|between:0,10'],
  1230. ['name', 'require', '点位参数错误'],
  1231. ]);
  1232. $nameZK = '首充折扣';
  1233. $point_fla = true;
  1234. if ($data['value'] <= 0 || $data['value'] > 10 || !is_numeric($data['value'])) {
  1235. $result = '折扣点位只能0<折扣≤10';
  1236. $point_fla = false;
  1237. } elseif ((float)$oldPoint['inner_point'] > 0 && $data['value'] > $oldPoint['inner_point'] && $point_fla) {
  1238. $result = '首充折扣要小等于续充折扣';
  1239. }
  1240. } else if ($data['name'] == 'inner_point') {
  1241. // 续充
  1242. $result = $this->validate($data, [
  1243. ['pk|ID', 'require', '参数错误'],
  1244. ['value|续充折扣', 'number|between:0,10'],
  1245. ['name', 'require', '点位参数错误'],
  1246. ]);
  1247. $nameZK = '续充折扣';
  1248. $point_fla = true;
  1249. if ($data['value'] <= 0 || $data['value'] > 10 || !is_numeric($data['value'])) {
  1250. $result = '折扣点位只能0<折扣≤10';
  1251. $point_fla = false;
  1252. } elseif ((float)$oldPoint['inner_first_point'] > 0 && $data['value'] < $oldPoint['inner_first_point'] && $point_fla) {
  1253. $result = '续充折扣要大等于首充折扣';
  1254. }
  1255. } else if ($data['name'] == 'first_max_days') {
  1256. $result = true;
  1257. if ($data['value'] != '') {
  1258. if ($data['value'] <= 0 || !is_numeric($data['value']) || floor($data['value']) != $data['value']) {
  1259. $result = '首充最大天数只能是大于0的整数';
  1260. }
  1261. } else {
  1262. $data['value'] = null;
  1263. }
  1264. } else {
  1265. // 备注
  1266. $result = $this->validate($data, [
  1267. ['pk|ID', 'require', '参数错误'],
  1268. ['value|备注', 'require|max:500'],
  1269. ['name', 'require', '点位参数错误'],
  1270. ]);
  1271. }
  1272. if (true !== $result) {
  1273. $this->error($result);
  1274. }
  1275. // 开启事务
  1276. Db::startTrans();
  1277. $insert[$data['name']] = $data['value'];
  1278. $result = $gamePointModel->updateData($insert, ['game_id' => $data['pk']]);
  1279. if (!isset($oldPoint['gp_id'])) {
  1280. $oldPoint['gp_id'] = $gamePointModel->where("game_id = '{$data['pk']}'")->field('gp_id')->find()['gp_id'];
  1281. }
  1282. $logArr = [
  1283. "gp_id" => $oldPoint['gp_id'],
  1284. $data['name'] => $data['value'],
  1285. 'operate_id' => $admin_id = session('ADMIN_ID') ?: 1
  1286. ];
  1287. $res = true;
  1288. if (($data['name'] == 'inner_point' || $data['name'] == 'inner_first_point' || $data['name'] == 'third_party_pay_point')) {
  1289. $res = model('GamePointLog')->add($logArr);
  1290. }
  1291. if ($result && $res) {
  1292. // 提交事务
  1293. Db::commit();
  1294. $game = get_game_name($data['pk']);
  1295. if ($data['name'] == 'inner_point') {
  1296. $field = '续充点位';
  1297. } else if ($data['name'] == 'third_party_pay_point') {
  1298. $field = '其它支付返点';
  1299. } else if ($data['name'] == 'inner_first_point') {
  1300. $field = '首充点位';
  1301. }
  1302. if (isset($field)) {
  1303. $message = "更新游戏:{$game} 的{$field}:{$data['value']}";
  1304. $this->insertLog($this->current_node, $message, 12);
  1305. }
  1306. $this->success('修改成功');
  1307. } else {
  1308. // 回滚事务
  1309. Db::rollback();
  1310. $this->error('修改失败');
  1311. }
  1312. }
  1313. public function editMultiLevel()
  1314. {
  1315. $pks = $this->request->param('pks');
  1316. $level = $this->request->param('value');
  1317. $result = $this->validate(['value' => $level], [
  1318. ['value', 'require|in:' . implode(',', $this->gameLevel), '游戏等级不能为空|游戏等级不存在']
  1319. ]);
  1320. if (true !== $result) {
  1321. $this->error($result);
  1322. }
  1323. $pksArr = explode(',', $pks);
  1324. if (empty($pksArr)) {
  1325. $this->error('请选择游戏');
  1326. }
  1327. $result = model("GamePoint")->updateData(['game_level' => $level], ['game_id' => ['IN', $pksArr]]);
  1328. if ($result) {
  1329. if (isset($field)) {
  1330. $message = "更新游戏:批量更新游戏ID为[{$pks}]游戏等级:{$level}";
  1331. $this->insertLog($this->current_node, $message, 12);
  1332. }
  1333. $this->success('修改成功');
  1334. } else {
  1335. $this->error('修改失败');
  1336. }
  1337. }
  1338. public function editLevel()
  1339. {
  1340. $data = [
  1341. 'pk' => $this->request->param('pk'),
  1342. 'value' => $this->request->param('value')
  1343. ];
  1344. $result = $this->validate($data, [
  1345. ['pk', 'require', '参数错误'],
  1346. ['value', 'require|in:' . implode(',', $this->gameLevel), '游戏等级不能为空|游戏等级不存在']
  1347. ]);
  1348. if (true !== $result) {
  1349. $this->error($result);
  1350. }
  1351. $result = model("GamePoint")->updateData(['game_level' => $data['value']], ['game_id' => $data['pk']]);
  1352. if ($result) {
  1353. $game = get_game_name($data['pk']);
  1354. if (isset($field)) {
  1355. $message = "更新游戏:{$game} 的游戏等级:{$data['value']}";
  1356. $this->insertLog($this->current_node, $message, 12);
  1357. }
  1358. $this->success('修改成功');
  1359. } else {
  1360. $this->error('修改失败');
  1361. }
  1362. }
  1363. public function editPercent()
  1364. {
  1365. $data = [
  1366. 'pk' => $this->request->param('pk'),
  1367. 'value' => $this->request->param('value')
  1368. ];
  1369. $result = $this->validate($data, [
  1370. ['pk|ID', 'require', '参数错误'],
  1371. ['value|折扣', 'number|between:0,10', '必须是数字|折扣在0到10之间']
  1372. ]);
  1373. if (true !== $result) {
  1374. $this->error($result);
  1375. }
  1376. $result = model("GamePoint")->updateData(['min_percent' => $data['value']], ['game_id' => $data['pk']]);
  1377. if ($result) {
  1378. $game = get_game_name($data['pk']);
  1379. if (isset($field)) {
  1380. $message = "更新游戏:{$game} 的最低折扣:{$data['value']}";
  1381. $this->insertLog($this->current_node, $message, 12);
  1382. }
  1383. $this->success('修改成功');
  1384. } else {
  1385. $this->error('修改失败');
  1386. }
  1387. }
  1388. // 最低折扣
  1389. public function editPointStatus()
  1390. {
  1391. $id = $this->request->param('gp_id', '', 'intval');
  1392. $status = $this->request->param('gp_status', '', 'intval');
  1393. $data['gp_status'] = $status;
  1394. if (empty($id)) {
  1395. $this->error('参数错误,如果未设置游戏点位数据,请先设置!');
  1396. }
  1397. $result = $this->validate($data, [
  1398. ['gp_status', 'in:0,1', '状态参数错误'],
  1399. ]);
  1400. if (true !== $result) {
  1401. $this->error($result);
  1402. }
  1403. $gamePointModel = model("GamePoint");
  1404. if (!$info = $gamePointModel->where(['gp_id' => $id])->field('gp_id')->find()) {
  1405. $this->error('参数错误,如果未设置游戏点位数据,请先设置');
  1406. }
  1407. if ($gamePointModel->update(['gp_status' => $status], ['gp_id' => $info['gp_id']])) {
  1408. $this->success('修改成功');
  1409. } else {
  1410. $this->error('修改失败');
  1411. }
  1412. }
  1413. // 游戏等级
  1414. public function editPointDisplay()
  1415. {
  1416. $id = $this->request->param('gp_id', '', 'intval');
  1417. $status = $this->request->param('gp_isdisplay', '', 'intval');
  1418. $data['gp_isdisplay'] = $status;
  1419. if (empty($id)) {
  1420. $this->error('参数错误,如果未设置游戏点位数据,请先设置!');
  1421. }
  1422. $result = $this->validate($data, [
  1423. ['gp_isdisplay', 'in:0,1', '状态参数错误'],
  1424. ]);
  1425. if (true !== $result) {
  1426. $this->error($result);
  1427. }
  1428. $gamePointModel = model("GamePoint");
  1429. if (!$info = $gamePointModel->where(['gp_id' => $id])->field('gp_id')->find()) {
  1430. $this->error('参数错误,如果未设置游戏点位数据,请先设置');
  1431. }
  1432. if ($gamePointModel->update(['gp_isdisplay' => $status], ['gp_id' => $info['gp_id']])) {
  1433. $this->success('修改成功');
  1434. } else {
  1435. $this->error('修改失败');
  1436. }
  1437. }
  1438. // 批量修改等级
  1439. /**
  1440. * 游戏内容编辑列表
  1441. *
  1442. */
  1443. public function contentList()
  1444. {
  1445. $where = [];
  1446. $order = input('order', 'id desc', 'trim');
  1447. if ($order == 'xulie_desc') {
  1448. $order = 'g.xulie desc';
  1449. } elseif ($order == 'xulie_asc') {
  1450. $order = 'g.xulie asc';
  1451. } else {
  1452. $order = 'id desc';
  1453. }
  1454. //显示样式
  1455. if (input('request.show_style') != '') {
  1456. $where['info.show_style'] = ['like', '%' . input('request.show_style') . ',%'];
  1457. }
  1458. //游戏名称
  1459. if (input('request.game_name') != '') {
  1460. $where['g.name'] = ['like', '%' . input('request.game_name') . '%'];
  1461. }
  1462. //对接状态
  1463. if (input('request.cooperation_status') != '') {
  1464. $where['g.cooperation_status'] = input('request.cooperation_status');
  1465. }
  1466. // 游戏状态
  1467. if (input('request.lanmu') != '') {
  1468. $where['g.lanmu'] = input('request.lanmu');
  1469. }
  1470. //查询参数
  1471. $param = input('get.');
  1472. $list = $this->gameModel
  1473. ->alias('g')
  1474. ->join('cy_gameinfo info', 'g.id=info.game_id', 'left')
  1475. ->join('cy_gamesubject s', 'g.subject=s.id', 'left')
  1476. ->join('cy_gametype t', 'g.type=t.id', 'left')
  1477. ->field('g.*, t.name as type, s.name as subject,info.mobileicon,info.show_style')
  1478. ->where($where)->order($order)->paginate(10, false, array('query' => $param));
  1479. $this->assign('list', $list);
  1480. $this->assign('page', $list->render());
  1481. $tmpGameList = $this->gameList;
  1482. $gameList = array();
  1483. foreach ($tmpGameList as $game) {
  1484. $gameList[$game['id']] = $game;
  1485. }
  1486. $this->assign('game_list', $gameList);
  1487. return $this->fetch('content_list');
  1488. }
  1489. /**
  1490. * 游戏内容编辑页
  1491. */
  1492. public function contentUpdate($id)
  1493. {
  1494. set_time_limit(300);
  1495. $id = (int)$id; //游戏ID
  1496. if (empty($id)) {
  1497. $this->error('游戏ID不能为空');
  1498. }
  1499. $gameInfo = $this->gameModel->alias('g')->join('cy_gameinfo info', 'g.id=info.game_id', 'left')
  1500. ->field('g.*,info.id as info_id,info.platform,info.description,info.drawingImg,info.video,info.mobileicon,info.bigimage,info.developer,info.video_image,info.updateinfo,info.show_style,info.landing_img,info.title_img')
  1501. ->where(['g.id' => $id])->find();
  1502. if (empty($gameInfo)) $this->error('游戏不存在');
  1503. if (request()->isPost()) {
  1504. $this->contentUpdateProcess($id);
  1505. }
  1506. if ($gameInfo['bigimage']) {
  1507. $bigimage_list = explode(';', $gameInfo['bigimage']);
  1508. } else {
  1509. $bigimage_list = [];
  1510. }
  1511. $gameType = Db::name('cy_gametype')->select();
  1512. $gameSubject = Db::name('cy_gamesubject')->select();
  1513. $gameInfo['show_style'] = explode(",", $gameInfo['show_style']);
  1514. $this->assign('game_type', $gameType);
  1515. $this->assign('gameid', $id);
  1516. $this->assign('game_subject', $gameSubject);
  1517. $this->assign('gameInfo', $gameInfo);
  1518. $this->assign('bigimage_list', $bigimage_list);
  1519. $this->assign('drawingimage_list', json_decode($gameInfo['drawingImg'], 1));
  1520. return $this->fetch('content_edit');
  1521. }
  1522. /**
  1523. * 游戏内容编辑页保存处理
  1524. *
  1525. */
  1526. private function contentUpdateProcess($id)
  1527. {
  1528. $fileUpload = new FileUpload();
  1529. $gameInfoModel = new GameInfo; //游戏扩展表
  1530. //游戏图标
  1531. $mobileicon_url = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000)->set('dir', 'image/game/icons')->upload(request()->file('mobileicon'));
  1532. $mobileicon_error = $fileUpload->getError();
  1533. //视频封面
  1534. $videoImg_url = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1572864)->set('dir', 'image/game/videoImg')->upload(request()->file('video_image'));
  1535. $videoImg_error = $fileUpload->getError();
  1536. //视频
  1537. $video_url = $fileUpload->set('allowExt', 'mp4')->set('maxsize', 52428800)->set('dir', 'video/game/icons')->upload(request()->file('video'));
  1538. $video_error = $fileUpload->getError();
  1539. //落地页背景
  1540. $landing_img_img_url = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 10485760)->set('dir', 'image/game/landing')->upload(request()->file('landing_img'));
  1541. $landing_img_url_error = $fileUpload->getError();
  1542. //游戏宣传语
  1543. $publicity = input('post.publicity', '', 'trim');
  1544. //头部图片
  1545. $title_img_url = $fileUpload->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000)->set('dir', 'image/game/icons')->upload(request()->file('title_img'));
  1546. $title_img_error = $fileUpload->getError();
  1547. $gameName = Db::table('cy_game')->where(['id' => $id])->value('name');
  1548. $data = [
  1549. 'nickname' => $gameName, // CPS后台展示用使用的,目前已弃用,暂时使用 name 参数替换
  1550. 'xulie' => input('post.xulie'),
  1551. 'type' => input('post.type'),
  1552. 'subject' => input('post.subject'),
  1553. 'package_name' => input('post.package_name'),
  1554. 'developer' => input('post.developer'),
  1555. 'publicity' => $publicity,
  1556. ];
  1557. $result = $this->validate($data, [
  1558. // ['nickname', 'require|max:32', '游戏昵称不能为空|游戏昵称不能超过32个字符'],
  1559. ['xulie', 'integer', '游戏序列号必须为整型'],
  1560. ['type', 'require', '游戏类型不能为空'],
  1561. ['subject', 'require', '游戏题材不能为空'],
  1562. ['package_name', 'max:100', '游戏包名不能超过100个字符'],
  1563. ['developer', 'max:30', '开发商不能超过30个字符'],
  1564. ['publicity', 'max:50', '游戏宣传语不能超过50个字符'],
  1565. ]);
  1566. if (true !== $result) {
  1567. $this->error($result);
  1568. } elseif (!empty(request()->file('mobileicon')) && empty($mobileicon_url)) { // 游戏图标上传出错时
  1569. $this->error('游戏图标:' . $mobileicon_error);
  1570. } elseif (!empty(request()->file('video_image')) && empty($videoImg_url)) {
  1571. $this->error('视频封面:' . $videoImg_error);
  1572. } elseif (!empty(request()->file('video')) && empty($video_url)) { //视频上传失败
  1573. $this->error('视频上传:' . $video_error);
  1574. } elseif (!empty(request()->file('landing_img')) && empty($landing_img_img_url)) {
  1575. $this->error('落地页背景:' . $landing_img_url_error);
  1576. } elseif (!empty(request()->file('title_img_url')) && empty($title_img_url)) {
  1577. $this->error('落地页背景:' . $title_img_error);
  1578. } else {
  1579. // 启动事务
  1580. Db::startTrans();
  1581. try {
  1582. $gameData['nickname'] = $data['nickname'];
  1583. $gameData['lanmu'] = input('post.lanmu'); //游戏状态
  1584. $gameData['xulie'] = $data['xulie']; //游戏序列号
  1585. // $gameData['type'] = $data['type'];
  1586. $gameData['subject'] = $data['subject'];
  1587. $gameData['package_name'] = $data['package_name'];
  1588. $gameData['publicity'] = $publicity;
  1589. //cy_game表更新
  1590. $this->gameModel->save($gameData, ['id' => $id]);
  1591. $arrImage = [];
  1592. //游戏截图
  1593. for ($i = 1; $i <= 5; $i++) {
  1594. $file = new FileUpload();
  1595. $bigimage_url = $file->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000)->set('dir', 'image/game/screenshots')->upload(request()->file('bigimage' . $i));
  1596. if (!empty(request()->file('bigimage' . $i)) && $bigimage_url == false) {
  1597. throw new Exception('游戏截图:' . $file->getError());
  1598. }
  1599. if (!empty($bigimage_url))
  1600. $arrImage[$i] = $bigimage_url;
  1601. }
  1602. //立绘截图
  1603. for ($i = 1; $i <= 5; $i++) {
  1604. $file = new FileUpload();
  1605. $drawing_url = $file->set('allowExt', 'jpg,jpeg,png')->set('maxsize', 1024000)->set('dir', 'image/game/screenshots')->upload(request()->file('drawingimage' . $i));
  1606. if (!empty(request()->file('drawingimage' . $i)) && $drawing_url == false) {
  1607. throw new Exception('立绘截图:' . $file->getError());
  1608. }
  1609. if (!empty($drawing_url))
  1610. $aryImage[$i - 1] = $drawing_url;
  1611. }
  1612. //有上传游戏截图时
  1613. if (!empty($arrImage)) {
  1614. $imgRet = $gameInfoModel->where(['game_id' => $id])->value('bigimage');
  1615. if ($imgRet) {
  1616. $imgRet = explode(';', $imgRet);
  1617. foreach ($arrImage as $key => $value) {
  1618. $imgRet[$key - 1] = $value;
  1619. }
  1620. $gameInfoData['bigimage'] = implode(";", $imgRet);
  1621. } else {
  1622. $gameInfoData['bigimage'] = implode(";", $arrImage);
  1623. }
  1624. }
  1625. if (!empty($aryImage)) {
  1626. $imgRet = $gameInfoModel->where(['game_id' => $id])->value('drawingImg');
  1627. if ($imgRet) {
  1628. $imgRet = json_decode($imgRet, 1);
  1629. foreach ($aryImage as $key => $value) {
  1630. $imgRet[$key] = $value;
  1631. }
  1632. $gameInfoData['drawingImg'] = json_encode($imgRet);
  1633. } else {
  1634. $gameInfoData['drawingImg'] = json_encode($aryImage);
  1635. }
  1636. }
  1637. //有上传游戏截图时
  1638. if (!empty($mobileicon_url))
  1639. $gameInfoData['mobileicon'] = $mobileicon_url;
  1640. //落地页背景图
  1641. if (!empty($landing_img_img_url)) {
  1642. $gameInfoData['landing_img'] = $landing_img_img_url;
  1643. $gameInfoData['new_back_img'] = STATIC_DOMAIN . $landing_img_img_url;
  1644. }
  1645. if (!empty($videoImg_url))
  1646. $gameInfoData['video_image'] = $videoImg_url;
  1647. if (!empty($title_img_url))
  1648. $gameInfoData['title_img'] = STATIC_DOMAIN .'/'. $title_img_url;
  1649. //有视频的时候
  1650. if (!empty($video_url))
  1651. $gameInfoData['video'] = $video_url;
  1652. $gameInfoData['description'] = input('post.description');
  1653. $gameInfoData['developer'] = input('post.developer');
  1654. $gameInfoData['updateinfo'] = input('post.updateinfo'); //更新说明
  1655. //单机游戏或者为未选择时
  1656. if ($gameData['lanmu'] == 5 || empty($gameData['lanmu'])) {
  1657. $gameInfoData['show_style'] = ''; //更新说明
  1658. } else {
  1659. $gameInfoData['show_style'] = !empty($_POST['show_style']) ? implode(",", input('post.show_style/a')) . ',' : ''; //更新说明
  1660. }
  1661. //更新游戏扩展信息
  1662. $gameInfoModel->where(['game_id' => $id])->update($gameInfoData);
  1663. Db::commit();
  1664. } catch (\Exception $e) {
  1665. // 回滚事务
  1666. Db::rollback();
  1667. $this->error('游戏信息编辑失败:' . $e->getMessage());
  1668. }
  1669. $this->success('游戏信息编辑成功', url('game/contentList'));
  1670. }
  1671. }
  1672. /**
  1673. * delimg图片删除
  1674. *
  1675. * @param string $value [description]
  1676. */
  1677. public function delimg()
  1678. {
  1679. $type = input('type');
  1680. $index = input('index');
  1681. $id = input('gameid');
  1682. $gameInfoModel = new GameInfo;
  1683. if (empty($type) || empty($index) || empty($id))
  1684. $this->error('参数错误,请刷新后重试');
  1685. if ($type == 'bigimage') {
  1686. $imgRet = $gameInfoModel->where(['game_id' => $id])->value('bigimage');
  1687. if ($imgRet) {
  1688. $imgRet = explode(';', $imgRet);
  1689. if (isset($imgRet[$index - 1])) {
  1690. unset($imgRet[$index - 1]);
  1691. $updateData['bigimage'] = implode(";", $imgRet);
  1692. } else {
  1693. $this->error('没有图片哦,请刷新后重试');
  1694. }
  1695. } else {
  1696. $this->error('没有图片哦,请刷新后重试');
  1697. }
  1698. }
  1699. if ($type == 'drawingimage') {
  1700. $imgRet = $gameInfoModel->where(['game_id' => $id])->value('drawingImg');
  1701. if ($imgRet) {
  1702. $imgRet = json_decode($imgRet, 1);
  1703. if (isset($imgRet[$index - 1])) {
  1704. unset($imgRet[$index - 1]);
  1705. $updateData['drawingImg'] = json_encode($imgRet);
  1706. } else {
  1707. $this->error('没有图片哦,请刷新后重试');
  1708. }
  1709. } else {
  1710. $this->error('没有图片哦,请刷新后重试');
  1711. }
  1712. }
  1713. $res = $gameInfoModel->where(['game_id' => $id])->update($updateData);
  1714. if ($res) {
  1715. $this->success('删除图片成功');
  1716. } else {
  1717. $this->error('删除失败,请刷新后重试');
  1718. }
  1719. }
  1720. /**
  1721. * 玩家是否在线查询
  1722. *
  1723. * @return mixed|string
  1724. */
  1725. public function online()
  1726. {
  1727. $info = [];
  1728. if ($this->request->isPost()) {
  1729. $gameid = input('gameid');
  1730. $username = input('username', '', 'trim');
  1731. $where = [];
  1732. if (empty($gameid)) {
  1733. $this->error('游戏不能为空!');
  1734. }
  1735. if (empty($username)) {
  1736. $this->error('玩家名称不能为空!');
  1737. }
  1738. $where['m.username'] = $username;
  1739. $where['s.game_id'] = $gameid;
  1740. $membersModel = Db::name('cy_members');
  1741. $info = $membersModel->table('cy_members m,nw_subaccount s')
  1742. ->field('m.id,m.username,s.sub_username')
  1743. ->where('m.id=s.member_id')
  1744. ->where($where)
  1745. ->select();
  1746. foreach ($info as &$val) {
  1747. $val['token'] = '';
  1748. $redisTokenRandom = \think\Cache::store('default')->get('token|sdk|' . $val['id'] . '|' . $gameid);
  1749. if ($redisTokenRandom) {
  1750. $token = auth_code($val['id'] . '|' . $val['username'] . '|' . $gameid . '|' . $val['sub_username'] . '|' . $redisTokenRandom . '|sdk', "ENCODE", Env::get('auth_key'));
  1751. $isLogin = \think\Cache::store('default')->get($token);
  1752. if ($isLogin) {
  1753. $val['token'] = $token;
  1754. }
  1755. }
  1756. }
  1757. unset($val);
  1758. }
  1759. $this->assign('list', $info);
  1760. $this->assign('game_list', $this->selfGameList);
  1761. $this->assign('list_count', count($info));
  1762. return $this->fetch();
  1763. }
  1764. /**
  1765. * 玩家踢下线
  1766. *
  1767. */
  1768. public function downline()
  1769. {
  1770. $token = input('token');
  1771. if (empty($token)) {
  1772. $this->error('token不能为空! ');
  1773. }
  1774. $isLogin = \think\Cache::store('default')->get($token);
  1775. if (empty($isLogin)) {
  1776. $this->error('token已失效! ');
  1777. }
  1778. list($userid, $username, $gameid, $sub_username, $token_random, $type) = explode('|', auth_code($token, "DECODE", Env::get('auth_key')));
  1779. \think\Cache::store('default')->rm($token);
  1780. \think\Cache::store('default')->rm('token|sdk|' . $userid . '|' . $gameid);
  1781. $this->success('已强制下线!', url('online'));
  1782. }
  1783. /**
  1784. * 获取改游戏历史点位修改记录
  1785. */
  1786. public function showPointHistory()
  1787. {
  1788. $gp_id = $this->request->param('gp_id', '', 'intval');
  1789. $list = model("GamePointLog")->selectAll($gp_id);
  1790. $code = 1;
  1791. if (!count($list)) {
  1792. $code = 0;
  1793. } else {
  1794. foreach ($list as &$v) {
  1795. if (empty($v['username'])) {
  1796. $v['username'] = '';
  1797. }
  1798. }
  1799. }
  1800. echo json_encode(['code' => $code, 'data' => $list]);
  1801. }
  1802. public function setGameChannelPoint()
  1803. {
  1804. $data['game_id'] = input('post.id');
  1805. $data['isset_first'] = input('post.isset_first');
  1806. $data['isset_second'] = input('post.isset_second');
  1807. $data['restricted_list_1'] = implode(',', input('denied_channel_1/a', [])) . ',';
  1808. $data['restricted_list_2'] = implode(',', input('denied_channel_2/a', [])) . ',';
  1809. $game_id = $data['game_id'];
  1810. $isset_first = $data['isset_first'];
  1811. $isset_second = $data['isset_second'];
  1812. $restricted_list_1 = $data['restricted_list_1'];
  1813. $restricted_list_2 = $data['restricted_list_2'];
  1814. if (empty($data['game_id']) || $data['isset_first'] == null || $data['isset_second'] == null) {
  1815. echo json_encode(['code' => 0, 'msg' => '参数错误!']);
  1816. exit;
  1817. }
  1818. // 过滤没有选择限制渠道名单
  1819. $firstStr = true; // 有首充限制名单
  1820. $secondtStr = true; // 有续充限制名单
  1821. if (strlen($data['restricted_list_1']) == 1) {
  1822. // unset($data['restricted_list_1']);
  1823. $data['restricted_list_1'] = null;
  1824. $firstStr = false;
  1825. }
  1826. if (strlen($data['restricted_list_2']) == 1) {
  1827. // unset($data['restricted_list_2']);
  1828. $data['restricted_list_2'] = null;
  1829. $secondtStr = false;
  1830. }
  1831. /*
  1832. * 去 渠道游戏点位表(cy_channel_game_point) 进行数据操作
  1833. * 1、获取 游戏id
  1834. * 2、判断【首充】是否允许设置
  1835. * 1)、首充允许配置:
  1836. * a、无黑名单,不进行操作;
  1837. * b、有黑名单, 对 黑名单里的 在 cy_channel_game_point 的首充配置 清 0
  1838. * 2)、首充 【 不 】 允许配置:
  1839. * a、无白名单, 对 cy_channel_game_point 里关于 该游戏的 所有渠道首充清0 ;
  1840. * b、有白名单, 对 白名单外的 在 cy_channel_game_point 的首充配置 清 0
  1841. * 3、判断【续充】是否允许:判断规则如上
  1842. *
  1843. * */
  1844. // 判断【首充】是否允许设置
  1845. $map1 = ['game_id' => $game_id]; // 查询条件
  1846. $where1 = []; // 要修改的数据
  1847. if ($isset_first) { // 允许
  1848. // 判断有没有黑名单
  1849. if ($firstStr) {
  1850. $where1 = ['first_point' => 0];
  1851. $map1['channel_id'] = ['IN', $restricted_list_1];
  1852. }
  1853. } else {
  1854. $where1 = ['first_point' => 0];
  1855. // 不允许设置首充,那么判断有没有 白名单
  1856. if ($firstStr) {
  1857. $map1['channel_id'] = ['NOT IN', $restricted_list_1];
  1858. }
  1859. }
  1860. // 判断 【续充】是否允许设置
  1861. $map2 = ['game_id' => $game_id]; // 查询条件
  1862. $where2 = []; // 要修改的数据
  1863. if ($isset_second) { // 允许
  1864. // 判断有没有黑名单
  1865. if ($secondtStr) {
  1866. $where2 = ['point' => 0];
  1867. $map2['channel_id'] = ['IN', $restricted_list_2];
  1868. }
  1869. } else {
  1870. $where2 = ['point' => 0];
  1871. // 不允许设置续充,那么判断有没有 白名单
  1872. if ($secondtStr) {
  1873. $map2['channel_id'] = ['NOT IN', $restricted_list_2];
  1874. }
  1875. }
  1876. // DB::startTrans();
  1877. // 判断是否必要对 cy_channel_game_point 的首充 进行操作
  1878. $res1 = true;
  1879. if (count($where1)) {
  1880. $res1 = model('ChannelGamePoint')->allowField(true)->save($where1, $map1);
  1881. }
  1882. $res = model("GameChannelPointset")->add($data);
  1883. // 判断是否必要对 cy_channel_game_point 的 续充 进行操作
  1884. $res2 = true;
  1885. if (count($where2)) {
  1886. // $res2 = model('ChannelGamePoint')->allowField(true)->save($where2,$map2);
  1887. $res2 = Db::table('cy_channel_game_point')->where($map2)->update($where2);
  1888. }
  1889. $resArr = ['code' => 1, 'msg' => '设置成功!'];
  1890. // if( $res1 && $res2){
  1891. // //DB::commit();
  1892. // $resArr = ['code'=>1,'msg'=>'设置成功!'];
  1893. // }else{
  1894. // //DB::rollback();
  1895. // $resArr = ['code'=>0,'msg'=>'设置失败,请检查数据!'];
  1896. // }
  1897. echo json_encode($resArr);
  1898. }
  1899. /**
  1900. * ajax获取一级渠道列表
  1901. */
  1902. public function getChannelByOne()
  1903. {
  1904. $parent_id = config('TOP_CHANNEL_ID');
  1905. $channel_list = model('Common/Channel')->where('parent_id', "{$parent_id}")->select();
  1906. $result = [];
  1907. foreach ($channel_list as $v) {
  1908. $result[$v['id']] = $v['name'];
  1909. }
  1910. echo json_encode($result);
  1911. }
  1912. /**
  1913. * 加载游戏补点页面
  1914. */
  1915. public function fillPoint()
  1916. {
  1917. $model = model('GameExtraPoint');
  1918. $list = $model->field('id,year_month,add_user,add_time,update_time')->order("year_month DESC")->where([])->paginate(10, false, ['query' => input('get.')]);
  1919. $this->assign('list', $list);
  1920. $this->assign('page', $list->render());
  1921. return $this->fetch('fillPoint');
  1922. }
  1923. /**
  1924. * 新增游戏补点月份
  1925. */
  1926. public function addFillPointMonth()
  1927. {
  1928. $date_c = input('post.date_c', '', 'filterAndTrimInput');
  1929. if (empty($date_c)) {
  1930. $this->error('请选择月份');
  1931. }
  1932. // 查找一下看是否已经添加了 这个月份的
  1933. $res_1 = model("GameExtraPoint")->where(['year_month' => $date_c])->count('id');
  1934. if ($res_1) {
  1935. $this->error('每月只可添加一条记录,不可重复');
  1936. }
  1937. $res = model("GameExtraPoint")->add(['year_month' => $date_c, 'add_user' => session('USERNAME'), 'add_time' => time()]);
  1938. if ($res) {
  1939. $where['id'] = $res;
  1940. $this->insertLog($this->current_node, '添加游戏补点月份:' . $date_c, 14);
  1941. $this->success('设置完成');
  1942. } else {
  1943. $this->error('每月只可添加一条记录,不可重复');
  1944. }
  1945. }
  1946. /**
  1947. * 加载补点详情页
  1948. */
  1949. public function fillPointDetails()
  1950. {
  1951. $monthid = $this->request->param('monthid');
  1952. $game_id = $this->request->param('game_id');
  1953. $status = $this->request->param('status');
  1954. $type = $this->request->param('type');
  1955. $department_id = $this->request->param('channel_id');
  1956. /*$ID = $this->request->param('ID');*/
  1957. $is_download = $this->request->param('down');
  1958. //查询条件设置
  1959. if (!empty($game_id)) {
  1960. $condition['a.game_id'] = array('eq', $game_id);
  1961. }
  1962. if (!empty($type)) {
  1963. $condition['a.type'] = array('eq', $type);
  1964. }
  1965. if ($status != '') {
  1966. if ($status == 3) {
  1967. $condition['a.status'] = array('in', '3,5');
  1968. } else {
  1969. $condition['a.status'] = array('eq', $status);
  1970. }
  1971. }
  1972. if (!empty($department_id)) {
  1973. $condition['a.channel_id'] = array('eq', $department_id);
  1974. }
  1975. /*if(!empty($ID)) {
  1976. $condition['a.id'] = array('eq', $ID);
  1977. }*/
  1978. if (!empty($monthid)) {
  1979. $condition['a.year_month'] = array('eq', $monthid);
  1980. session('year_month', $monthid);
  1981. } else {
  1982. $monthid = session('year_month');
  1983. $condition['a.year_month'] = array('eq', $monthid);
  1984. }
  1985. // 查询条件存session 留着下载报表的时候用
  1986. session('fillPointDownCondition', $condition);
  1987. //列表数据整理
  1988. $list = model('GameExtraPointRatio')
  1989. ->alias('a')
  1990. ->join("nw_channel b", "b.id=a.channel_id", "left")
  1991. ->join("cy_game c", "c.id=a.game_id", 'left')
  1992. ->field('a.*, b.name channel_name, c.name game_name')
  1993. ->order("a.create_time desc , a.id desc")
  1994. ->where($condition)
  1995. ->paginate(10, false, ['query' => input('get.')]);
  1996. $this->assign('list', $list);
  1997. $this->assign('status', $status);
  1998. $this->assign('game_id', $game_id);
  1999. $this->assign('channel_id', $department_id);
  2000. /*$this->assign('ID', $ID);*/
  2001. $this->assign('YearMonth', session('year_month'));
  2002. $this->assign('page', $list->render());
  2003. $gameList = $this->cyModel('game')->field('id,name')->select();
  2004. $this->assign('game_list', $gameList);
  2005. return $this->fetch('fillPointDetails');
  2006. }
  2007. /**
  2008. * 下载补点详情页的报表
  2009. */
  2010. public function fillPointDetailsDown()
  2011. {
  2012. //1.从数据库中取出数据
  2013. $condition = session('fillPointDownCondition');
  2014. $list = model('GameExtraPointRatio')
  2015. ->alias('a')
  2016. ->join("nw_channel b", "b.id=a.channel_id", "left")
  2017. ->join("cy_game c", "c.id=a.game_id", 'left')
  2018. ->field('a.*, b.name channel_name, c.name game_name')
  2019. ->order("a.add_time", " desc")
  2020. ->where($condition)
  2021. ->select();
  2022. // 判断是否有数据
  2023. if (count($list)) {
  2024. Vendor('PHPExcel.PHPExcel');//调用类库,路径是基于vendor文件夹的
  2025. Vendor('PHPExcel.PHPExcel.Worksheet.Drawing');
  2026. Vendor('PHPExcel.PHPExcel.Writer.Excel2007');
  2027. $objExcel = new \PHPExcel();
  2028. //set document Property
  2029. $objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
  2030. $objActSheet = $objExcel->getActiveSheet();
  2031. $key = ord("A");
  2032. $letter = explode(',', "A,B,C,D,E,F,G,H,I,J,K,L");
  2033. $arrHeader = array('ID', '开始时间', '结束时间', '游戏', '渠道', '首充补点', '续充补点', '自然补点', '自然返利', '备注', '添加时间', '状态');;
  2034. //填充表头信息
  2035. $lenth = count($arrHeader);
  2036. for ($i = 0; $i < $lenth; $i++) {
  2037. $objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]");
  2038. };
  2039. //填充表格信息
  2040. foreach ($list as $k => $v) {
  2041. $k += 2;
  2042. $objActSheet->setCellValue('A' . $k, $v['id']);
  2043. $objActSheet->setCellValue('B' . $k, date('Y-m-d', $v['begin_date']));
  2044. // // 图片生成
  2045. // $objDrawing[$k] = new \PHPExcel_Worksheet_Drawing();
  2046. // $objDrawing[$k]->setPath('public/static/admin/images/profile_small.jpg');
  2047. // // 设置宽度高度
  2048. // $objDrawing[$k]->setHeight(40);//照片高度
  2049. // $objDrawing[$k]->setWidth(40); //照片宽度
  2050. // /*设置图片要插入的单元格*/
  2051. // $objDrawing[$k]->setCoordinates('C'.$k);
  2052. // // 图片偏移距离
  2053. // $objDrawing[$k]->setOffsetX(30);
  2054. // $objDrawing[$k]->setOffsetY(12);
  2055. // $objDrawing[$k]->setWorksheet($objPHPExcel->getActiveSheet());
  2056. // 表格内容
  2057. $objActSheet->setCellValue('C' . $k, date('Y-m-d', $v['end_date']));
  2058. $objActSheet->setCellValue('D' . $k, $v['game_name']);
  2059. $objActSheet->setCellValue('E' . $k, $v['channel_name']);
  2060. $objActSheet->setCellValue('F' . $k, $v['first_point'] . '%');
  2061. $objActSheet->setCellValue('G' . $k, $v['common_point'] . '%');
  2062. $objActSheet->setCellValue('H' . $k, $v['cash_point'] . '%');
  2063. $objActSheet->setCellValue('I' . $k, $v['cash_profit_point'] . '%');
  2064. $objActSheet->setCellValue('J' . $k, $v['remark']);
  2065. $objActSheet->setCellValue('K' . $k, date('Y-m-d H:i:s', $v['add_time']));
  2066. $statusStr = '已过期';
  2067. if ($v['status']) {
  2068. $statusStr = '已审核';
  2069. }
  2070. $objActSheet->setCellValue('L' . $k, $statusStr);
  2071. // 表格高度
  2072. $objActSheet->getRowDimension($k)->setRowHeight(20);
  2073. }
  2074. $width = array(10, 20, 15, 10, 10, 30, 10, 15, 15, 20, 20);
  2075. //设置表格的宽度
  2076. $objActSheet->getColumnDimension('A')->setWidth($width[0]);
  2077. $objActSheet->getColumnDimension('B')->setWidth($width[1]);
  2078. $objActSheet->getColumnDimension('C')->setWidth($width[1]);
  2079. $objActSheet->getColumnDimension('D')->setWidth($width[1]);
  2080. $objActSheet->getColumnDimension('E')->setWidth($width[1]);
  2081. $objActSheet->getColumnDimension('F')->setWidth($width[2]);
  2082. $objActSheet->getColumnDimension('G')->setWidth($width[2]);
  2083. $objActSheet->getColumnDimension('H')->setWidth($width[2]);
  2084. $objActSheet->getColumnDimension('I')->setWidth($width[2]);
  2085. $objActSheet->getColumnDimension('J')->setWidth($width[5]);
  2086. $objActSheet->getColumnDimension('K')->setWidth($width[1]);
  2087. $objActSheet->getColumnDimension('L')->setWidth($width[5]);
  2088. $YM = str_replace('-', '_', session('year_month'));
  2089. $outfile = '游戏补点详情_' . $YM . ".xls";
  2090. ob_end_clean();
  2091. header("Content-Type: application/force-download");
  2092. header("Content-Type: application/octet-stream");
  2093. header("Content-Type: application/download");
  2094. header('Content-Disposition:inline;filename="' . $outfile . '"');
  2095. header("Content-Transfer-Encoding: binary");
  2096. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  2097. header("Pragma: no-cache");
  2098. $objWriter->save('php://output');
  2099. $this->success('下载成功!');
  2100. } else {
  2101. $monthid = session('year_month');
  2102. // dump(url('fillPointDetails',['monthid'=>$monthid]));
  2103. $this->error('查无数据,不支持下载', url('fillPointDetails', ['monthid' => $monthid]));
  2104. // $this->error('查无数据,不支持下载');
  2105. }
  2106. }
  2107. /**
  2108. * 补点详情--改变状态
  2109. */
  2110. public function changePointRatioStatus()
  2111. {
  2112. if (!request()->isAjax()) {
  2113. return;
  2114. }
  2115. $runnable = true;
  2116. $msg = '';
  2117. $monthid = session('year_month');
  2118. $status = $this->request->param('status');
  2119. $id = $this->request->param('dataid');
  2120. $departid = $this->request->param('departid');
  2121. $game_id = $this->request->param('game_id');
  2122. if (empty($id) || ($status != '0' && $status != '1') || empty($departid) || empty($game_id)) {
  2123. $runnable = false;
  2124. $code = 0;
  2125. $msg = '参数错误';
  2126. }
  2127. if ($runnable) {
  2128. // 补点记录改为已审核,和已审核的补点进行时间、渠道的判断,看有无冲突
  2129. if ($status != '0') {
  2130. $moder_PR = model('GameExtraPointRatio');
  2131. $map_2 = [
  2132. 'status' => ['eq', 1],
  2133. 'game_id' => ['eq', $game_id],
  2134. 'year_month' => ['eq', session('year_month')]
  2135. ];
  2136. $pdList = $moder_PR->where($map_2)->field('id,game_id,channel_id,begin_date,end_date')->select();
  2137. // 查有该游戏,可以进行对比判断
  2138. if (count($pdList)) {
  2139. // 1、判断时间有没有冲突
  2140. $thisGame = $moder_PR->where("id=" . $id)->field('id,game_id,channel_id,begin_date,end_date')->find();
  2141. $topDP = model('Department')->where('id=' . $departid)->field('id,id_path')->find();
  2142. $map_1 = [];
  2143. $map_1 = [
  2144. 'id_path' => ['like', '%,' . $departid . ',%']
  2145. ];
  2146. $downDP_1 = model('Department')->where($map_1)->field('id')->select();
  2147. $downDP = '';
  2148. foreach ($downDP_1 as $key => $value) {
  2149. $downDP .= ',' . $value['id'] . ',';
  2150. }
  2151. foreach ($pdList as $v_pdlist) {
  2152. // 只要 $thisGame 的开始时间或结束时间 在对方的开始时间和结束时间之间,哪就发生了时间冲突
  2153. // 2、判断渠道有没有冲突
  2154. // 2.1判断上级渠道有没有冲突
  2155. if (strpos($topDP['id_path'], ',' . $v_pdlist['channel_id'] . ',') !== false) {
  2156. $runnable = false;
  2157. $status = false;
  2158. $msg = '上级渠道已经添加补点信息,冲突ID:' . $v_pdlist['id'];
  2159. break;
  2160. }
  2161. // 2.2判断下级渠道有没有冲突
  2162. $downDP = str_replace($departid, ",", $downDP);
  2163. if (strpos($downDP, ',' . $v_pdlist['channel_id'] . ',') !== false) {
  2164. $runnable = false;
  2165. $status = false;
  2166. $msg = '下级渠道已经添加补点信息,冲突ID:' . $v_pdlist['id'];
  2167. break;
  2168. }
  2169. if ((($thisGame['begin_date'] >= $v_pdlist['begin_date'] && $thisGame['begin_date'] < $v_pdlist['end_date']) || ($thisGame['end_date'] > $v_pdlist['begin_date'] && $thisGame['end_date'] <= $v_pdlist['end_date']) || ($thisGame['begin_date'] < $v_pdlist['begin_date'] && $thisGame['end_date'] > $v_pdlist['end_date'])) && $thisGame['channel_id'] == $v_pdlist['channel_id']) {
  2170. // 1.如果游戏相同,渠道相同,时间冲突,提示“补点时间有冲突,冲突ID:xxx”;
  2171. $runnable = false;
  2172. $status = false;
  2173. $msg = '补点时间有冲突,冲突ID:' . $v_pdlist['id'];
  2174. break;
  2175. }
  2176. }
  2177. }
  2178. }
  2179. if ($runnable) {
  2180. // 开启事物
  2181. Db::startTrans();
  2182. $result = model('GameExtraPointRatio')->save(['status' => $status, 'update_time' => time(), 'update_user' => session('ADMIN_ID')], ['id' => $id]);
  2183. $map['year_month'] = $monthid;
  2184. $res = model('GameExtraPoint')->save(['update_user' => session('ADMIN_ID'), 'update_time' => time()], $map);
  2185. if (empty($result) || empty($res)) {
  2186. $runnable = false;
  2187. $msg = '操作失败';
  2188. Db::rollback();
  2189. } else {
  2190. //$this->insertLog( session('username'), 3, MODULE_NAME, ACTION_NAME, NOW_TIMESTAMP, '更新了游戏补点月表一条记录,状态改为了:'. $status,session_id());
  2191. $statusStr = '已过期';
  2192. if ($status) {
  2193. $statusStr = '已审核';
  2194. }
  2195. // 获取游戏名和渠道名
  2196. $channel_obj = model('Department')->getCondition(['id' => $departid]);
  2197. $Game_name = model('Game')->where(['id' => $game_id])->field('name')->find();
  2198. $this->insertLog($this->current_node, '修改补点状态,ID:' . $id . ',游戏名:' . $Game_name['name'] . ',渠道名:' . $channel_obj['name'] . ',状态:' . $statusStr, 14);
  2199. $status = true;
  2200. $msg = '操作成功';
  2201. Db::commit();
  2202. }
  2203. }
  2204. }
  2205. $code = 1;
  2206. if (!$status) {
  2207. $code = 0;
  2208. }
  2209. $this->result([], $code, $msg);
  2210. }
  2211. /**
  2212. * 加载添加游戏补点页面
  2213. */
  2214. public function fillPointAddPage()
  2215. {
  2216. $this->assign('gamelist', $this->cyModel('game')->field('id,name')->select());
  2217. $channelList = model('Channel')->getAllByCondition('id,name', ['status' => 1, 'flag' => 3]);
  2218. $this->assign('departmentlist', $channelList);
  2219. $monthid = session('year_month');
  2220. $this->assign('YearMonth', $monthid);
  2221. return $this->fetch('fillPointAddPage');
  2222. }
  2223. /**
  2224. * 添加游戏补点
  2225. */
  2226. public function batchAddPointList()
  2227. {
  2228. $data['game_id'] = $this->request->param('game_id', 0, 'intval');
  2229. $data['channel_id'] = $this->request->param('channel_id', 0, 'intval');
  2230. $data['type'] = $this->request->param('type', 0, 'intval');
  2231. $datarange = $this->request->param('datarange', '', 'trim');
  2232. $time_line = strtotime(date('Y-m-d', time()));
  2233. if (empty($data['game_id'])) {
  2234. $this->error('游戏不能为空!');
  2235. }
  2236. if (empty($data['channel_id'])) {
  2237. $this->error('渠道不能为空!');
  2238. }
  2239. if (empty($datarange)) {
  2240. $this->error('生效时间不能为空!');
  2241. }
  2242. $data['begin_time'] = strtotime($datarange);
  2243. if ($time_line > $data['begin_time']) {
  2244. $this->error('生效时间不得小于当天0点!');
  2245. }
  2246. // 按结算方式获取 参数
  2247. if (empty($data['type'])) {
  2248. $this->error('结算类型不能为空!');
  2249. } elseif ($data['type'] == 1) {
  2250. // 折扣结算
  2251. $data['first_point'] = $this->request->param('first_point');
  2252. $data['common_point'] = $this->request->param('common_point');
  2253. $data['extra_point'] = $this->request->param('extra_point');
  2254. $data['extra_profit_point'] = $this->request->param('extra_profit_point');
  2255. $this->numPD($data['first_point'], '请输入正确的首充补点!', '0<=首充补点<100,保留两位小数');
  2256. $this->numPD($data['common_point'], '请输入正确的续充补点!', '0<=续充补点<100,保留两位小数');
  2257. $this->numPD($data['extra_profit_point'], '请输入正确的充值返利!', '0<=充值返利<100,保留两位小数');
  2258. $this->numPD($data['extra_point'], '请输入正确的充值补点!', '0<=充值补点<100,保留两位小数');
  2259. } elseif ($data['type'] == 2) {
  2260. $data['extra_point'] = $this->request->param('extra_point');
  2261. $data['extra_profit_point'] = $this->request->param('extra_profit_point');
  2262. $this->numPD($data['extra_profit_point'], '请输入正确的充值总额返利!', '0<=充值总额返利<100,保留两位小数');
  2263. $this->numPD($data['extra_point'], '请输入正确的充值总额补点!', '0<=充值总额补点<100,保留两位小数');
  2264. } elseif ($data['type'] == 3) {
  2265. $data['first_point'] = $this->request->param('first_point');
  2266. $data['common_point'] = $this->request->param('common_point');
  2267. $data['extra_point'] = $this->request->param('extra_point');
  2268. $data['extra_profit_point'] = $this->request->param('extra_profit_point');
  2269. $first_date = $this->request->param('sc_supply_date', '', 'trim');
  2270. $this->numPD($data['first_point'], '请输入正确的首充补点!', '0<=首充补点<100,保留两位小数');
  2271. $this->numPD($data['common_point'], '请输入正确的续充补点!', '0<=续充补点<100,保留两位小数');
  2272. $this->numPD($data['extra_profit_point'], '请输入正确的充值返利!', '0<=充值返利<100,保留两位小数');
  2273. $this->numPD($data['extra_point'], '请输入正确的充值补点!', '0<=充值补点<100,保留两位小数');
  2274. if (empty($first_date)) {
  2275. $this->error('请选择首充补点时间区间!');
  2276. }
  2277. /*$first_date = '2019-04-15 00:00:00 - 2019-05-15 00:00:00';
  2278. $common_date = '2019-04-15 00:20:00 - 2019-05-15 00:00:00';*/
  2279. $first_date_arr = explode(' - ', $first_date);
  2280. $data['first_begin_time'] = strtotime($first_date_arr[0]);
  2281. if ($time_line > $data['first_begin_time']) {
  2282. $this->error('首充补点时间不得小于当天0点!');
  2283. }
  2284. $data['first_end_time'] = strtotime($first_date_arr[1]);
  2285. } elseif ($data['type'] == 4) {
  2286. $data['first_point'] = $this->request->param('first_point');
  2287. $data['common_point'] = $this->request->param('common_point');
  2288. $data['extra_profit_point'] = $this->request->param('extra_profit_point');
  2289. $this->numPD($data['first_point'], '请输入正确的首充补点!', '0<=首充补点<100,保留两位小数');
  2290. $this->numPD($data['common_point'], '请输入正确的续充补点!', '0<=续充补点<100,保留两位小数');
  2291. $this->numPD($data['extra_profit_point'], '请输入正确的充值总额返利!', '0<=充值总额返利<100,保留两位小数');
  2292. $first_date = $this->request->param('sc_supply_date', '', 'trim');
  2293. /*$first_date = '2019-04-15 00:00:00 - 2019-05-15 00:00:00';
  2294. $common_date = '2019-04-15 00:20:00 - 2019-05-15 00:00:00';
  2295. $profit_date = '2019-04-15 00:20:00 - 2019-05-15 00:00:00';*/
  2296. $first_date_arr = explode(' - ', $first_date);
  2297. $data['first_begin_time'] = strtotime($first_date_arr[0]);
  2298. if ($time_line > $data['first_begin_time']) {
  2299. $this->error('首充补点时间不得小于当天0点!');
  2300. }
  2301. $data['first_end_time'] = strtotime($first_date_arr[1]);
  2302. } else {
  2303. $this->error('请选择正确的结算类型');
  2304. }
  2305. $data['add_user'] = session('ADMIN_ID');
  2306. $data['year_month'] = session('year_month');
  2307. $data['create_time'] = time();
  2308. $GameExtraPointObj = model('GameExtraPoint')->where(['year_month' => session('year_month')])->field('id')->find();
  2309. $data['game_extra_point_id'] = $GameExtraPointObj['id'];
  2310. // 判断 同游戏 同月份 的是否有上下级渠道
  2311. $numArr = model('GameExtraPointRatio')
  2312. ->where(['game_id' => $data['game_id'], 'year_month' => $data['year_month'], 'channel_id' => ['neq', $data['channel_id']], 'game_extra_point_id' => $data['game_extra_point_id']])->column('channel_id');
  2313. if (count($numArr) > 0) {
  2314. $channelArr = array_unique($numArr);
  2315. // 获取当前渠道下的所有子渠道
  2316. $childids = model('Channel')->getChildIds($data['channel_id']);
  2317. // 获取 父级部门ID路径 有当前渠道 的所有渠道
  2318. $channel_aOrc = model('Channel')->where(['id' => $data['channel_id']])->column('id_path');
  2319. $channel_aOrc_arr = [];
  2320. foreach ($channel_aOrc as $v) {
  2321. $arr = [];
  2322. $arr = explode(',', $v);
  2323. $channel_aOrc_arr = array_unique(array_merge($arr, $channel_aOrc_arr));
  2324. }
  2325. $channel_all = array_unique(array_merge($channel_aOrc_arr, $childids));
  2326. // 判断查询出来的 $channelArr 有没有在 当前渠道的归属渠道里(上下级)
  2327. foreach ($channelArr as $value) {
  2328. if (in_array($value, $channel_all)) {
  2329. $gameName = model('Game')->getName($data['game_id']);
  2330. $channelName = model('Channel')->where(['id' => $value])->value('name');
  2331. $this->error('《' . $gameName . '》同归属渠道“' . $channelName . '”已配置补点信息,请核实确认');
  2332. }
  2333. }
  2334. //$this->result(['当前渠道'=>$data['channel_id'],'列表渠道'=>$channelArr,'子渠道'=>$childids,'所有'=>$channel_all,'上级'=>$channel_aOrc_arr,'数量'=>count($channel_all)]);
  2335. }
  2336. // 存数据
  2337. $res = model('GameExtraPointRatio')->add($data);
  2338. if ($res) {
  2339. $this->success('保存成功', 'fillPointDetails');
  2340. }
  2341. $this->error('保存失败');
  2342. }
  2343. /**
  2344. * 判断数字是否在指定区间内,两位小数
  2345. *
  2346. * @param $first_point
  2347. * @param string $msg1
  2348. * @param string $msg2
  2349. * @param int $mix
  2350. * @param int $max
  2351. */
  2352. public function numPD($num, $msg1 = '', $msg2 = '', $mix = 0, $max = 100)
  2353. {
  2354. if (is_numeric($num)) {
  2355. $first_point_1 = (float)$num * 100;
  2356. $res_num = $first_point_1 - (float)((int)$first_point_1);
  2357. if ($first_point_1 < $mix || $first_point_1 >= $max * 100 || $res_num > 1e-7) {
  2358. $this->result([], 0, $msg2);
  2359. }
  2360. } else {
  2361. $this->result([], 0, $msg1);
  2362. }
  2363. }
  2364. /**
  2365. * 游戏冻结信息列表
  2366. */
  2367. public function bannedList()
  2368. {
  2369. $banned = new GameBanned;
  2370. $where = [];
  2371. //游戏名称
  2372. if (input('request.game_id') != '') {
  2373. $where['n.game_id'] = input('request.game_id', '', 'trim');
  2374. }
  2375. //标题
  2376. if (input('request.banned_device') != '') {
  2377. $where['n.banned_device'] = input('request.banned_device', '', 'trim');
  2378. }
  2379. //冻结类型
  2380. if (input('request.banned_type') != '') {
  2381. $where['n.banned_type'] = input('request.banned_type', '', 'trim');
  2382. }
  2383. $start = $this->request->param('start');
  2384. $end = $this->request->param('end');
  2385. //开始时间和结束时间不为空时
  2386. if ($start != '' && $end != '') {
  2387. $where['n.create_time'] = [
  2388. ['>=', strtotime($start)],
  2389. ['<=', strtotime($end . ' 23:59:59')],
  2390. ];
  2391. } //开始时间不为空时
  2392. elseif ($start != '') {
  2393. $where['n.create_time'] = ['>=', strtotime($start)];
  2394. } //结束时间不为空时
  2395. elseif ($end != '') {
  2396. $where['n.create_time'] = ['<=', strtotime($end . ' 23:59:59')];
  2397. } else {
  2398. /*
  2399. $start = date('Y-m-d', time());
  2400. $end = date('Y-m-d', time());
  2401. $where['n.create_time'] = [
  2402. ['>=', strtotime($start)],
  2403. ['<=', strtotime($end . ' 23:59:59')],
  2404. ];
  2405. */
  2406. }
  2407. //查询参数
  2408. $param = input('get.');
  2409. $banned_list = $banned->alias('n')->field('n.*,g.name game_name')->join('cy_game g', 'g.id=n.game_id', 'left')
  2410. ->where($where)->order('n.create_time desc')
  2411. ->paginate(10, false, array('query' => $param));
  2412. // echo $banned->getLastSql()."----getLastSql------<Br>";
  2413. $this->assign('banned_list', $banned_list);
  2414. $this->assign('page', $banned_list->render());
  2415. $gameList = $this->selfGameList;
  2416. $gameList[0] = array('id' => 0, 'name' => '所有游戏');
  2417. $this->assign('gameList', $gameList);
  2418. return $this->fetch('banned_list');
  2419. }
  2420. /**
  2421. * 删除游戏冻结信息
  2422. *
  2423. */
  2424. public function bannedDelete()
  2425. {
  2426. $id = input('id', 0, 'intval');
  2427. if (empty($id)) $this->error('删除记录的ID不能为空');
  2428. $banned = new GameBanned;
  2429. if ($banned->where(['id' => $id])->delete()) {
  2430. $this->success('删除成功');
  2431. } else {
  2432. $this->error('删除失败');
  2433. }
  2434. }
  2435. /**
  2436. * 新增游戏冻结信息
  2437. */
  2438. public function bannedCreate()
  2439. {
  2440. if (request()->isPost()) {
  2441. $banned = new GameBanned;
  2442. $data = [
  2443. 'game_id' => input('post.game_id', '', 'trim'),
  2444. 'banned_type' => input('post.banned_type', '', 'trim'),
  2445. 'banned_device' => input('post.banned_device', '', 'trim'),
  2446. 'notes' => input('post.notes', ''),
  2447. ];
  2448. $result = $this->validate($data, [
  2449. ['game_id', 'require|integer', '请选择游戏|游戏ID必须为整型'],
  2450. ['banned_type', 'require', '请选择冻结类型'],
  2451. ['banned_device', 'require', '请输入IP或IMEI'],
  2452. ]);
  2453. if (true !== $result) {
  2454. $this->error($result);
  2455. }
  2456. //检查是否已存在记录
  2457. $condis = array();
  2458. $condis['game_id'] = intval($data['game_id']);
  2459. $condis['banned_type'] = $data['banned_type'];
  2460. $condis['banned_device'] = $data['banned_device'];
  2461. $bannedInfo = $banned->where($condis)->find();
  2462. if (!empty($bannedInfo)) {
  2463. $this->error('已添加过该冻结信息!');
  2464. }
  2465. $data['create_time'] = time();
  2466. $data['update_time'] = time();
  2467. if ($banned->insert($data)){
  2468. $this->success('新增成功', 'game/bannedList');
  2469. } else {
  2470. $this->error('新增失败');
  2471. }
  2472. }
  2473. $gameList = $this->selfGameList;
  2474. $gameList[0] = array('id' => 0, 'name' => '所有游戏');
  2475. $this->assign('game_list', $gameList);
  2476. return $this->fetch('banned_new');
  2477. }
  2478. /**
  2479. * 编辑游戏冻结信息
  2480. */
  2481. public function bannedEdit()
  2482. {
  2483. $id = input('id', 0, 'intval');
  2484. $bannedModel = new GameBanned;
  2485. if (empty($id)) $this->error('游戏冻结的ID不能为空');
  2486. $bannedInfo = $bannedModel->where(['id' => $id])->find();
  2487. if (empty($bannedInfo)) $this->error('记录不存在');
  2488. if (request()->isPost()) {
  2489. $banned = new GameBanned;
  2490. $data = [
  2491. 'game_id' => input('post.game_id', '', 'intval'),
  2492. 'banned_type' => input('post.banned_type'),
  2493. 'banned_device' => input('post.banned_device'),
  2494. 'notes' => input('post.notes', ''),
  2495. ];
  2496. $result = $this->validate($data, [
  2497. ['game_id', 'require|integer', '请选择游戏|游戏ID必须为整型'],
  2498. ['banned_type', 'require', '请选择冻结类型'],
  2499. ['banned_device', 'require', '请输入IP或IMEI'],
  2500. ]);
  2501. if (true !== $result) {
  2502. $this->error($result);
  2503. }
  2504. //检查是否已存在记录
  2505. $condis = array();
  2506. $condis['game_id'] = intval($data['game_id']);
  2507. $condis['banned_type'] = $data['banned_type'];
  2508. $condis['banned_device'] = $data['banned_device'];
  2509. $condis['id'] = array('neq', $id);
  2510. $bannedInfo = model('GameBanned')->where($condis)->find();
  2511. if (!empty($bannedInfo)) {
  2512. $this->error('已存在该冻结信息!');
  2513. }
  2514. if ($bannedModel->update($data, ['id' => $id])) {
  2515. $this->success('编辑成功', 'game/bannedList');
  2516. } else
  2517. $this->error('编辑失败');
  2518. }
  2519. $game_list = array(array('id' => 0, 'name' => '所有游戏'));
  2520. $game_list = array_merge($game_list, $this->selfGameList);
  2521. $this->assign('game_list', $game_list);
  2522. $this->assign('data', $bannedInfo);
  2523. return $this->fetch('banned_edit');
  2524. }
  2525. /**
  2526. * 点位提审
  2527. */
  2528. public function examinePoint()
  2529. {
  2530. $id = $this->request->param('id', 0, 'intval');
  2531. $countType = [
  2532. '1' => '折扣类结算',
  2533. '2' => '自然类结算',
  2534. '3' => '首充补点结算',
  2535. '4' => '新用户补点结算',
  2536. ];
  2537. if (empty($id)) {
  2538. $this->error('参数错误!');
  2539. }
  2540. $info = model('GameExtraPointRatio')->alias('a')
  2541. ->join('cy_game b', 'b.id = a.game_id')
  2542. ->join('nw_channel c', 'c.id = a.channel_id')
  2543. ->field('a.*, c.name channel_name, b.name game_name')
  2544. ->where('a.id=' . $id)->find();
  2545. // 同游戏通渠道 至多只能有一条数据 在审核当中
  2546. $numInfo = model('GameExtraPointRatio')
  2547. ->where(['game_id' => $info['game_id'], 'year_month' => $info['year_month'], 'channel_id' => $info['channel_id'], 'game_extra_point_id' => $info['game_extra_point_id'], 'status' => 1])->select();
  2548. if (count($numInfo) >= 1) {
  2549. $this->error('《' . $info['game_name'] . '》《' . $info['channel_name'] . '》已有结算补点审核中,请联系上级确认。');
  2550. }
  2551. $today = strtotime(date('Y-m-d')); // 今日 0点0分 时间戳
  2552. if ($today > $info['begin_time']) {
  2553. $data = ['status' => 5, 'update_user' => session('ADMIN_ID'), 'update_time' => time()];
  2554. model('GameExtraPointRatio')->save($data, ['id' => $id]);
  2555. $this->success('《' . $info['game_name'] . '》《' . $info['channel_name'] . '》“' . $countType[$info['type']] . '”生效时间小于当日时间,无法通过。');
  2556. }
  2557. $data = ['status' => 1, 'update_user' => session('ADMIN_ID'), 'update_time' => time()];
  2558. $res = model('GameExtraPointRatio')->save($data, ['id' => $id]);
  2559. if ($res) {
  2560. $this->success('操作成功!');
  2561. }
  2562. $this->error('操作失败');
  2563. }
  2564. /**
  2565. * 点位审核
  2566. */
  2567. public function examineAction()
  2568. {
  2569. $id = $this->request->param('id', 0, 'intval');
  2570. $type = $this->request->param('type', '', 'trim');
  2571. $remark = $this->request->param('remark', '', 'trim');
  2572. $countType = [
  2573. '1' => '折扣类结算',
  2574. '2' => '自然类结算',
  2575. '3' => '首充补点结算',
  2576. '4' => '新用户补点结算',
  2577. ];
  2578. if (empty($id) || empty($type)) {
  2579. $this->error('参数错误!');
  2580. }
  2581. if (!in_array($type, ['refuse', 'pass'])) {
  2582. $this->error('参数错误!');
  2583. }
  2584. // 拒绝
  2585. if ($type == 'refuse') {
  2586. $data = ['status' => 4, 'update_user' => session('ADMIN_ID'), 'update_time' => time(), 'remark' => $remark];
  2587. model('GameExtraPointRatio')->save($data, ['id' => $id]);
  2588. $this->success('操作成功!');
  2589. }
  2590. // 判断 同游戏 同月份 的是否有上下级渠道
  2591. $info = model('GameExtraPointRatio')->where('id=' . $id)->find();
  2592. $numArr = model('GameExtraPointRatio')
  2593. ->where(['game_id' => $info['game_id'], 'year_month' => $info['year_month'], 'channel_id' => ['neq', $info['channel_id']], 'game_extra_point_id' => $info['game_extra_point_id']])->column('channel_id');
  2594. if (count($numArr) > 0) {
  2595. $channelArr = array_unique($numArr);
  2596. // 获取当前渠道下的所有子渠道
  2597. $childids = model('Channel')->getChildIds($info['channel_id']);
  2598. // 获取 父级部门ID路径 有当前渠道 的所有渠道
  2599. $channel_aOrc = model('Channel')->where(['id' => $info['channel_id']])->column('id_path');
  2600. $channel_aOrc_arr = [];
  2601. foreach ($channel_aOrc as $v) {
  2602. $arr = [];
  2603. $arr = explode(',', $v);
  2604. $channel_aOrc_arr = array_unique(array_merge($arr, $channel_aOrc_arr));
  2605. }
  2606. $channel_all = array_unique(array_merge($channel_aOrc_arr, $childids));
  2607. // 判断查询出来的 $channelArr 有没有在 当前渠道的归属渠道里(上下级)
  2608. foreach ($channelArr as $value) {
  2609. if (in_array($value, $channel_all)) {
  2610. $gameName = model('Game')->getName($info['game_id']);
  2611. $channelName = model('Channel')->where(['id' => $value])->value('name');
  2612. $this->error('《' . $gameName . '》同归属渠道“' . $channelName . '”已配置补点信息,请核实确认');
  2613. }
  2614. }
  2615. }
  2616. // 通过的判断----
  2617. $info = model('GameExtraPointRatio')->alias('a')
  2618. ->join('cy_game b', 'b.id = a.game_id')
  2619. ->join('nw_channel c', 'c.id = a.channel_id')
  2620. ->field('a.*, c.name channel_name, b.name game_name')
  2621. ->where('a.id=' . $id)->find();
  2622. // 通过审核 1、判断生效时间是否大于今天0点0分
  2623. $today = strtotime(date('Y-m-d')); // 今日 0点0分 时间戳
  2624. if ($today > $info['begin_time']) {
  2625. $data = ['status' => 5, 'update_user' => session('ADMIN_ID'), 'update_time' => time(), 'remark' => $remark];
  2626. model('GameExtraPointRatio')->save($data, ['id' => $id]);
  2627. $this->success('《' . $info['game_name'] . '》《' . $info['channel_name'] . '》“' . $countType[$info['type']] . '”生效时间小于当日时间,无法通过。');
  2628. }
  2629. // 判断当前同游戏通渠道同结算模式生效的规则 的生效时间 和 审核的规则的生效时间 大小关系( 若审核的 小于 生效的 ,则生效的规则状态变为5)( $nowInfo 不为空表示有历史记录 )
  2630. $nowInfo = model('GameExtraPointRatio')->where(['game_id' => $info['game_id'], 'year_month' => $info['year_month'], 'channel_id' => $info['channel_id'], 'game_extra_point_id' => $info['game_extra_point_id'], 'status' => 2])->find();
  2631. // 不存在覆盖,直接生效
  2632. if (!$nowInfo) {
  2633. $data = ['status' => 2, 'update_user' => session('ADMIN_ID'), 'update_time' => time(), 'remark' => $remark];
  2634. model('GameExtraPointRatio')->save($data, ['id' => $id]);
  2635. $this->success('操作成功!');
  2636. }
  2637. if ($nowInfo['begin_time'] < $info['begin_time']) {
  2638. $data_1 = ['status' => 3, 'update_user' => session('ADMIN_ID'), 'update_time' => time(), 'end_time' => $info['begin_time'] - 1];
  2639. } else {
  2640. $data_1 = ['status' => 5, 'update_user' => session('ADMIN_ID'), 'update_time' => time()];
  2641. }
  2642. // session 暂时保存 一下 $data_1,用于前端确认覆盖后的SQL条件
  2643. session('examineAction_data', ['data' => $data_1, 'id' => $nowInfo['id']]);
  2644. // 提示 《游戏名》《渠道名》“结算类型”“生效时间”已存在是否覆盖该信息。
  2645. $msg = '《' . $info['game_name'] . '》《' . $info['channel_name'] . '》“' . $countType[$info['type']] . '”已存在是否覆盖该信息?';
  2646. $this->result([], 2, $msg);
  2647. /*Db::startTrans();
  2648. try{
  2649. model('GameExtraPointRatio')->save($data_1,['id'=>$nowInfo['id']]);
  2650. $data = ['status'=>2,'update_user'=>session('ADMIN_ID'),'update_time'=>time(),'remark'=>$remark];
  2651. model('GameExtraPointRatio')->save($data,['id'=>$id]);
  2652. // 提交事务
  2653. Db::commit();
  2654. $this->success('操作成功!');
  2655. } catch (\Exception $e) {
  2656. // 回滚事务
  2657. Db::rollback();
  2658. $this->error('操作失败');
  2659. }*/
  2660. }
  2661. /**
  2662. * 二次确认后,游戏点位审核通过
  2663. */
  2664. public function examineActionDo()
  2665. {
  2666. $id = $this->request->param('id', 0, 'intval');
  2667. $remark = $this->request->param('remark', '', 'trim');
  2668. if (empty($id)) {
  2669. $this->error('参数错误!');
  2670. }
  2671. $data_1 = session('examineAction_data')['data'];
  2672. $nowId = session('examineAction_data')['id'];
  2673. Db::startTrans();
  2674. try {
  2675. model('GameExtraPointRatio')->save($data_1, ['id' => $nowId]);
  2676. $data = ['status' => 2, 'update_user' => session('ADMIN_ID'), 'update_time' => time(), 'remark' => $remark];
  2677. model('GameExtraPointRatio')->save($data, ['id' => $id]);
  2678. // 提交事务
  2679. Db::commit();
  2680. } catch (\Exception $e) {
  2681. // 回滚事务
  2682. Db::rollback();
  2683. $this->error('操作失败');
  2684. }
  2685. $this->success('操作成功!');
  2686. }
  2687. /**
  2688. * 审核界面
  2689. *
  2690. * @param string $value [description]
  2691. *
  2692. * @return [type] [description]
  2693. */
  2694. public function examine()
  2695. {
  2696. $applyid = request()->get('applyid');
  2697. $data = Db::name('nw_game_package_apply')->where(['id' => $applyid])->find();
  2698. $this->assign('applyid', $applyid);
  2699. $this->assign('list', $data);
  2700. return $this->fetch();
  2701. }
  2702. /**
  2703. * 更改审核状态
  2704. */
  2705. public function doExamine()
  2706. {
  2707. $data = request()->post();
  2708. $status = $data['apply_status'];
  2709. $applyid = $data['applyid'];
  2710. if (empty($status)) {
  2711. $this->error("系统错误");
  2712. }
  2713. $msg = '';
  2714. $res = Db::name('nw_game_package_apply')->where(['id' => $applyid])->find();
  2715. $gameId = $res['game_id'];
  2716. $channel_id = $res['channel_id'];
  2717. $applicant_id = $res['applicant_id'];
  2718. //同意审核状态下 分包
  2719. if ($status == 1) {
  2720. $subPackageInfo = $this->sdkgamelistModel->where(['gameid' => $gameId, 'channel_id' => $channel_id])->find();
  2721. $game_info = GameModel::get($gameId);
  2722. if ($subPackageInfo['upload_status'] == 1) {
  2723. $msg = '分包情况:已经存在分包,请删包后再分包!';
  2724. $code = 400;
  2725. }
  2726. if (!empty($subPackageInfo['filename'])) {
  2727. $msg = '分包情况:文件名已生成无法分包,请等待后端分包完成!';
  2728. $code = 400;
  2729. }
  2730. $gameInfoModel = new GameInfo;
  2731. //游戏平台
  2732. $platform = $gameInfoModel->where(['game_id' => $gameId])->value('platform');
  2733. $platform = ($platform == false) ? 0 : $platform;
  2734. $subPath = $this->subChannel->index($channel_id, $gameId, 'cps' . $applicant_id, $platform, 0);
  2735. //如果有异常 分包任务给sdklist
  2736. $result = Db::name('cy_sdkgamelist')->where(['gameid' => $gameId, 'channel_id' => $channel_id, 'package_type' => 0])->find();
  2737. if (empty($result)) {
  2738. Db::startTrans();
  2739. try {
  2740. $cont = [
  2741. 'gameid' => $gameId,
  2742. 'channel_id' => $channel_id,
  2743. 'update_time' => time(),
  2744. 'create_time' => time(),
  2745. 'channel_version' => $game_info['channel_version'],
  2746. 'package_type' => 4,
  2747. ];
  2748. Db::name('cy_sdkgamelist')->insert($cont);
  2749. (new PromotionShortLink())->insertData($gameId, $channel_id, 0);
  2750. Db::commit();
  2751. } catch (Exception $e) {
  2752. Db::rollback();
  2753. $this->error('游戏信息编辑失败' . $e->getMessage());
  2754. }
  2755. }else{
  2756. Db::name('cy_sdkgamelist')->where(['gameid' => $gameId, 'channel_id' => $channel_id])->update(['upload_status' => 4]);
  2757. }
  2758. }
  2759. $data['apply_time'] = NOW_TIMESTAMP;
  2760. unset($data['applyid']);
  2761. $resultChannel = Db::name('nw_game_package_apply')->where(['id' => $applyid])->update($data);
  2762. if ($resultChannel) {
  2763. if ($status == 1) {
  2764. $this->success("审核成功,已经提交分包任务");
  2765. } else {
  2766. Db::name('cy_sdkgamelist')->where(['gameid' => $gameId, 'channel_id' => $channel_id])->update(['upload_status' => 3]);
  2767. $this->success("已审核完成");
  2768. }
  2769. }
  2770. }
  2771. /**
  2772. * 游戏管理下载
  2773. */
  2774. public function gameManagerDown()
  2775. {
  2776. if (request()->isAjax()) {
  2777. $where = $this->_indexParam();
  2778. $num = $this->gameModel->alias('game')
  2779. ->join('cy_gameinfo info', 'game.id = info.game_id', 'left')
  2780. ->join('nw_android_sdk_config sdk', 'game.android_sdk_id = sdk.id', 'left')
  2781. ->where($where)->count('game.id');
  2782. if (!$num) {
  2783. $this->error('查无数据,不支持下载');
  2784. }
  2785. $sql = $this->gameModel->alias('game')
  2786. ->join('cy_gameinfo info', 'game.id = info.game_id', 'left')
  2787. ->join('nw_android_sdk_config sdk', 'game.android_sdk_id = sdk.id', 'left')
  2788. ->field('game.id,game.name,game.origin_name,game.pinyin,game.cooperation_status,game.create_time,game.remarks,game.is_show,info.platform,sdk.version as sdk_version')
  2789. ->where($where)
  2790. ->order('game.id desc')
  2791. ->fetchSql(true)->select();
  2792. if ((new MakeReportGo())->addTask('gameManagerDown', $sql, session_id())) {
  2793. $this->jsonResult('', 1, '报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
  2794. } else {
  2795. $this->jsonResult('', 0, '报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  2796. }
  2797. }
  2798. $this->error('非法请求');
  2799. }
  2800. /**
  2801. * 批量通过
  2802. */
  2803. public function approved()
  2804. {
  2805. $data = request()->post();
  2806. $status = $data['apply_status'];
  2807. $ids = explode(',', $data['ids']);
  2808. unset($data['ids']);
  2809. if (empty($status)) {
  2810. $this->error("系统错误");
  2811. }
  2812. if (empty($ids)) {
  2813. $this->error("请选择记录");
  2814. }
  2815. $msg = '';
  2816. foreach ($ids as $k => $v) {
  2817. $res = Db::name('nw_game_package_apply')->where(['id' => $v])->find();
  2818. $gameId = $res['game_id'];
  2819. $channel_id = $res['channel_id'];
  2820. if ($status == 1 && $v > 1) {
  2821. $applicant_id = $res['applicant_id'];
  2822. $subPackageInfo = $this->sdkgamelistModel->where(['gameid' => $gameId, 'channel_id' => $channel_id])->find();
  2823. $game_info = GameModel::get($gameId);
  2824. if ($subPackageInfo['upload_status'] == 1) {
  2825. $msg = '分包情况:已经存在分包,请删包后再分包!';
  2826. $code = 400;
  2827. }
  2828. if (!empty($subPackageInfo['filename'])) {
  2829. $msg = '分包情况:文件名已生成无法分包,请等待后端分包完成!';
  2830. $code = 400;
  2831. }
  2832. $gameInfoModel = new GameInfo;
  2833. //游戏平台
  2834. $platform = $gameInfoModel->where(['game_id' => $gameId])->value('platform');
  2835. $platform = ($platform == false) ? 0 : $platform;
  2836. $subPath = $this->subChannel->index($channel_id, $gameId, 'cps' . $applicant_id, $platform, 0);
  2837. //如果有异常 分包任务给sdklist
  2838. $result = Db::name('cy_sdkgamelist')->where(['gameid' => $gameId, 'channel_id' => $channel_id, 'package_type' => 0])->find();
  2839. if (empty($result)) {
  2840. Db::startTrans();
  2841. try {
  2842. $cont = [
  2843. 'gameid' => $gameId,
  2844. 'channel_id' => $channel_id,
  2845. 'update_time' => time(),
  2846. 'create_time' => time(),
  2847. 'channel_version' => $game_info['channel_version'],
  2848. 'package_type' => 0,
  2849. 'upload_status' => 4
  2850. ];
  2851. Db::name('cy_sdkgamelist')->insert($cont);
  2852. (new PromotionShortLink())->insertData($gameId, $channel_id, 0);
  2853. Db::commit();
  2854. } catch (Exception $e) {
  2855. Db::rollback();
  2856. $this->error('游戏信息编辑失败' . $e->getMessage());
  2857. }
  2858. }
  2859. }else{
  2860. $this->sdkgamelistModel->where(['gameid' => $gameId, 'channel_id' => $channel_id])->update(['upload_status' => 3]);
  2861. }
  2862. $data['apply_time'] = NOW_TIMESTAMP;
  2863. unset($data['applyid']);
  2864. $resultChannel = Db::name('nw_game_package_apply')->where(['id' => $v])->update($data);
  2865. }
  2866. if ($status == 1) {
  2867. $this->success("审核成功,已经提交分包任务");
  2868. } else {
  2869. $this->success("已审核完成");
  2870. }
  2871. }
  2872. /**
  2873. * 设置游戏归属
  2874. *
  2875. * @return mixed
  2876. * @throws \think\exception\DbException
  2877. */
  2878. public function gameBelong(){
  2879. $param = input('get.');
  2880. $list = $this->gameBelongModel->alias('gb')
  2881. ->join('cy_game g', 'gb.game_id = g.id', 'left')
  2882. // , FROM_UNIXTIME(create_time, "%Y-%m-%d %H:%i:%s") as create_time
  2883. ->field('gb.*,g.name,g.cooperation_status')
  2884. ->order('gb.id desc')
  2885. ->paginate(25, false, array('query' => $param));
  2886. $this->assign('list', $list);
  2887. $this->assign('page', $list->render());
  2888. return $this->fetch();
  2889. }
  2890. public function gameBelongEdit(){
  2891. $id = input('id', '');
  2892. if(request()->isPost()){
  2893. $param = input('post.');
  2894. $result = $this->validate($param, [
  2895. 'game_id' => 'require',
  2896. 'start_date' => 'require',
  2897. 'end_date' => 'require',
  2898. ], [
  2899. 'game_id' => '请选择游戏',
  2900. 'start_date' => '开始时间参数有误',
  2901. 'end_date' => '结束时间参数有误',
  2902. ]);
  2903. if (true !== $result) {
  2904. $this->error($result);
  2905. }
  2906. if(empty($param['status'])){
  2907. $param['status'] = 0;
  2908. }
  2909. $data = [
  2910. 'game_id' => $param['game_id'],
  2911. 'status' => $param['status']==1?1:0,
  2912. 'start_date' => $param['start_date'],
  2913. 'end_date' => $param['end_date'],
  2914. 'remarks' => $param['remarks'],
  2915. ];
  2916. if($id){
  2917. $res = $this->gameBelongModel->update($data, ['id' => $id]);
  2918. }else{
  2919. if($id && $this->gameBelongModel->where(['game_id' => $param['game_id']])->find()){
  2920. $this->error("当前游戏已存在!");
  2921. }
  2922. $res = $this->gameBelongModel->create($data);
  2923. }
  2924. if($res){
  2925. $this->success("操作成功!", url('game/gameBelong'));
  2926. }
  2927. $this->error("操作失败!");
  2928. }
  2929. $info = $this->gameBelongModel->where(['id' => $id])->find();
  2930. $this->assign('info', $info??"");
  2931. $tmpGameList = $this->cyModel('game')->field('id,name')->select();
  2932. $gameList = array_column($tmpGameList, 'name', 'id');
  2933. $this->assign('gameList', $gameList);
  2934. return $this->fetch();
  2935. }
  2936. public function gameBelongDelete(){
  2937. $id = input('id', '');
  2938. if(!$id){
  2939. $this->error("操作有误!");
  2940. }
  2941. if(!$this->gameBelongModel->where(['id' => $id])->find()){
  2942. $this->error("操作游戏不存在!");
  2943. }
  2944. $res = $this->gameBelongModel->where(['id' => $id])->delete();
  2945. if($res){
  2946. $this->success("操作成功!", url('game/gameBelong'));
  2947. }
  2948. $this->error("操作有误!");
  2949. }
  2950. // 公司游戏管理
  2951. /**
  2952. * 公司游戏列表 查询条件 列表页面和报表下载共用
  2953. */
  2954. public function _companyGameParam()
  2955. {
  2956. $where = [];
  2957. // 公司名搜索
  2958. if (input('request.company_name') != '') {
  2959. $where['company_name'] = ['like', '%' . input('request.company_name') . '%'];
  2960. }
  2961. // 公司别名搜索
  2962. if (input('request.company_alias') != '') {
  2963. $where['company_alias'] = ['like', '%' . input('request.company_alias') . '%'];
  2964. }
  2965. return $where;
  2966. }
  2967. public function companyGame()
  2968. {
  2969. $where = $this->_companyGameParam();
  2970. $param = input('get.');
  2971. $list = (new CompanyGameBind())
  2972. ->where($where)
  2973. ->order('id desc')
  2974. ->paginate(10, false, array('query' => $param))
  2975. ->each(function($item, $key) {
  2976. // 计算游戏数量
  2977. if (!empty($item['game_ids'])) {
  2978. $gameIds = explode(',', $item['game_ids']);
  2979. $item['game_count'] = count(array_filter($gameIds));
  2980. } else {
  2981. $item['game_count'] = 0;
  2982. }
  2983. });
  2984. $this->assign('list', $list);
  2985. $this->assign('page', $list->render());
  2986. return $this->fetch('game/company_game/index');
  2987. }
  2988. /**
  2989. * 新增公司游戏绑定
  2990. */
  2991. public function companyGameCreate()
  2992. {
  2993. if (request()->isPost()) {
  2994. $data = [
  2995. 'company_name' => input('post.company_name', '', 'trim'),
  2996. 'company_alias' => input('post.company_alias', '', 'trim'),
  2997. // 'game_ids' => input('post.game_ids', '', 'trim'),
  2998. 'remark' => input('post.remark', '', 'trim'),
  2999. ];
  3000. $result = $this->validate($data, [
  3001. ['company_name', 'require|max:150', '请输入公司全称|公司全称不能超过150个字符'],
  3002. ['company_alias', 'require|max:50', '请输入公司别名|公司别名不能超过50个字符'],
  3003. ['remark', 'max:255', '备注不能超过255个字符'],
  3004. ]);
  3005. if (true !== $result) {
  3006. $this->error($result);
  3007. }
  3008. $companyGameBind = new CompanyGameBind();
  3009. if ($companyGameBind->save($data)) {
  3010. $this->success('新增成功', 'game/companyGame');
  3011. } else {
  3012. $this->error('新增失败');
  3013. }
  3014. }
  3015. return $this->fetch('game/company_game/edit');
  3016. }
  3017. /**
  3018. * 编辑公司游戏绑定
  3019. */
  3020. public function companyGameEdit()
  3021. {
  3022. $id = input('id', 0, 'intval');
  3023. if (empty($id)) {
  3024. $this->error('参数错误');
  3025. }
  3026. $companyGameBind = new CompanyGameBind();
  3027. $info = $companyGameBind->where(['id' => $id])->find();
  3028. if (empty($info)) {
  3029. $this->error('记录不存在');
  3030. }
  3031. if (request()->isPost()) {
  3032. $data = [
  3033. 'company_name' => input('post.company_name', '', 'trim'),
  3034. 'company_alias' => input('post.company_alias', '', 'trim'),
  3035. // 'game_ids' => input('post.game_ids', '', 'trim'),
  3036. 'remark' => input('post.remark', '', 'trim'),
  3037. ];
  3038. $result = $this->validate($data, [
  3039. ['company_name', 'require|max:150', '请输入公司全称|公司全称不能超过150个字符'],
  3040. ['company_alias', 'require|max:50', '请输入公司别名|公司别名不能超过50个字符'],
  3041. ['remark', 'max:255', '备注不能超过255个字符'],
  3042. ]);
  3043. if (true !== $result) {
  3044. $this->error($result);
  3045. }
  3046. if ($companyGameBind->save($data, ['id' => $id])) {
  3047. $this->success('编辑成功', 'game/companyGame');
  3048. } else {
  3049. $this->error('编辑失败');
  3050. }
  3051. }
  3052. $this->assign('info', $info);
  3053. return $this->fetch('game/company_game/edit');
  3054. }
  3055. /**
  3056. * 删除公司游戏绑定
  3057. */
  3058. public function companyGameDelete()
  3059. {
  3060. $id = input('id', 0, 'intval');
  3061. if (empty($id)) {
  3062. $this->error('参数错误');
  3063. }
  3064. $companyGameBind = new CompanyGameBind();
  3065. if (!$companyGameBind->where(['id' => $id])->find()) {
  3066. $this->error('记录不存在');
  3067. }
  3068. if ($companyGameBind->where(['id' => $id])->delete()) {
  3069. $this->success('删除成功');
  3070. } else {
  3071. $this->error('删除失败');
  3072. }
  3073. }
  3074. /**
  3075. * 查看公司绑定的游戏列表(弹窗)
  3076. */
  3077. public function companyGameShowGames()
  3078. {
  3079. $id = input('id', 0, 'intval');
  3080. if (empty($id)) {
  3081. $this->error('参数错误');
  3082. }
  3083. $companyGameBind = new CompanyGameBind();
  3084. $companyInfo = $companyGameBind->where(['id' => $id])->find();
  3085. if (empty($companyInfo)) {
  3086. $this->error('记录不存在');
  3087. }
  3088. $gameList = [];
  3089. if (!empty($companyInfo['game_ids'])) {
  3090. $gameIds = explode(',', $companyInfo['game_ids']);
  3091. $gameIds = array_filter($gameIds);
  3092. if (!empty($gameIds)) {
  3093. $gameList = $this->gameModel
  3094. ->field('id, name, type, cooperation_status')
  3095. ->whereIn('id', $gameIds)
  3096. ->order('id desc')
  3097. ->select();
  3098. }
  3099. }
  3100. $this->assign('companyInfo', $companyInfo);
  3101. $this->assign('gameList', $gameList);
  3102. return $this->fetch('game/company_game/show_games');
  3103. }
  3104. /**
  3105. * 导出公司游戏数据
  3106. */
  3107. public function companyGameExport()
  3108. {
  3109. if (!request()->isAjax()) {
  3110. $this->error('非法请求');
  3111. }
  3112. $id = input('id', 0, 'intval');
  3113. if (empty($id)) {
  3114. $this->error('参数错误');
  3115. }
  3116. // 查询公司信息
  3117. $companyGameBind = new CompanyGameBind();
  3118. $companyInfo = $companyGameBind->where(['id' => $id])->find();
  3119. if (empty($companyInfo)) {
  3120. $this->error('记录不存在');
  3121. }
  3122. // 构建导出SQL - 查询公司绑定的游戏
  3123. $gameIds = [];
  3124. if (!empty($companyInfo['game_ids'])) {
  3125. $gameIds = explode(',', $companyInfo['game_ids']);
  3126. $gameIds = array_filter($gameIds);
  3127. }
  3128. // 构建SQL - 使用 fetchSql(true) 获取SQL而不执行
  3129. $sql = Db::table('cy_company_game_bind')
  3130. ->alias('cgb')
  3131. ->where('cgb.id', $id)
  3132. ->field("
  3133. cgb.company_name,
  3134. cgb.company_alias,
  3135. cgb.game_ids
  3136. ")
  3137. ->fetchSql(true)
  3138. ->select();
  3139. // 通过队列投递导出任务
  3140. if ((new MakeReportGo())->addTask('companyGameExport', $sql, session_id())) {
  3141. $this->success('报表生成的任务已经提交,报表生成完成后,会及时通知您,请耐心稍等');
  3142. } else {
  3143. $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
  3144. }
  3145. }
  3146. /**
  3147. * AJAX获取公司绑定的游戏ID列表
  3148. */
  3149. public function ajaxGetCompanyGames()
  3150. {
  3151. if (request()->isAjax()) {
  3152. $company_id = input('company_id', 0, 'intval');
  3153. if (empty($company_id)) {
  3154. $this->result([], 0, '公司ID不能为空');
  3155. }
  3156. $companyGameBind = new CompanyGameBind();
  3157. $companyInfo = $companyGameBind->where(['id' => $company_id])->find();
  3158. if (empty($companyInfo)) {
  3159. $this->result([], 0, '公司不存在');
  3160. }
  3161. if (empty($companyInfo['game_ids'])) {
  3162. $this->result([], 1, '该公司未绑定游戏');
  3163. }
  3164. $gameIds = explode(',', $companyInfo['game_ids']);
  3165. $gameIds = array_filter($gameIds);
  3166. $this->result($gameIds, 1, '获取成功');
  3167. } else {
  3168. $this->error('非法请求');
  3169. }
  3170. }
  3171. /**
  3172. * 游戏组管理 - 列表页
  3173. */
  3174. public function gameBand()
  3175. {
  3176. $groupId = input('id', '', 'trim');
  3177. $gameId = input('game_id', '', 'trim');
  3178. $filters = [
  3179. 'keyword' => input('keyword', '', 'trim'),
  3180. 'id' => $groupId === '' ? '' : intval($groupId),
  3181. 'game_id' => $gameId === '' ? '' : intval($gameId),
  3182. 'platform' => input('platform', '', 'trim'),
  3183. ];
  3184. $gameBandModel = new GameBand();
  3185. $list = $gameBandModel->getGroupList($filters);
  3186. $this->assign('list', $list);
  3187. $this->assign('page', $list->render());
  3188. $this->assign('filters', $filters);
  3189. $this->assign('keyword', $filters['keyword']);
  3190. $this->assign('activeTags', $this->buildGameBandFilterTags($filters));
  3191. return $this->fetch('game/game_band');
  3192. }
  3193. /**
  3194. * 构建游戏组列表当前筛选标签
  3195. */
  3196. private function buildGameBandFilterTags(array $filters)
  3197. {
  3198. $tags = [];
  3199. if (!empty($filters['keyword'])) {
  3200. $tags[] = ['label' => '关键词', 'value' => $filters['keyword']];
  3201. }
  3202. if (!empty($filters['id'])) {
  3203. $tags[] = ['label' => '分组ID', 'value' => $filters['id']];
  3204. }
  3205. if (!empty($filters['game_id'])) {
  3206. $tags[] = ['label' => '游戏ID', 'value' => $filters['game_id']];
  3207. }
  3208. $platformMap = [
  3209. 'android' => '已绑安卓',
  3210. 'ios' => '已绑iOS',
  3211. 'h5' => '已绑H5',
  3212. 'unbound' => '未绑定任何端',
  3213. ];
  3214. if (!empty($filters['platform']) && isset($platformMap[$filters['platform']])) {
  3215. $tags[] = ['label' => '平台', 'value' => $platformMap[$filters['platform']]];
  3216. }
  3217. return $tags;
  3218. }
  3219. /**
  3220. * 游戏组管理 - 生成历史游戏自动绑定预览
  3221. */
  3222. public function gameBandAutoPreview()
  3223. {
  3224. if (!request()->isAjax()) {
  3225. $this->error('非法请求');
  3226. }
  3227. $platformFields = [
  3228. 1 => 'ios_game_id',
  3229. 2 => 'android_game_id',
  3230. 3 => 'h5_game_id',
  3231. ];
  3232. $platformKeys = [
  3233. 1 => 'ios',
  3234. 2 => 'android',
  3235. 3 => 'h5',
  3236. ];
  3237. $gameList = (new GameModel())
  3238. ->field('id,name,type,cooperation_status')
  3239. ->where('type', 'in', [1, 2, 3])
  3240. ->order('id asc')
  3241. ->select();
  3242. $games = is_object($gameList) && method_exists($gameList, 'toArray')
  3243. ? $gameList->toArray()
  3244. : (array)$gameList;
  3245. $bandList = (new GameBand())
  3246. ->field('id,game_name,android_game_id,ios_game_id,h5_game_id,status')
  3247. ->order('id asc')
  3248. ->select();
  3249. $bands = is_object($bandList) && method_exists($bandList, 'toArray')
  3250. ? $bandList->toArray()
  3251. : (array)$bandList;
  3252. $bandByName = [];
  3253. $boundGameGroups = [
  3254. 1 => [],
  3255. 2 => [],
  3256. 3 => [],
  3257. ];
  3258. foreach ($bands as $band) {
  3259. if (trim($band['game_name']) !== '' && !isset($bandByName[$band['game_name']])) {
  3260. $bandByName[$band['game_name']] = $band;
  3261. }
  3262. foreach ($platformFields as $type => $field) {
  3263. $boundGameId = (int)$band[$field];
  3264. if ($boundGameId > 0) {
  3265. $boundGameGroups[$type][$boundGameId] = (int)$band['id'];
  3266. }
  3267. }
  3268. }
  3269. $gameOptions = [
  3270. 'android' => [],
  3271. 'ios' => [],
  3272. 'h5' => [],
  3273. ];
  3274. $candidateBuckets = [];
  3275. $ungroupedCount = 0;
  3276. foreach ($games as $game) {
  3277. $type = (int)$game['type'];
  3278. $gameId = (int)$game['id'];
  3279. $game['id'] = $gameId;
  3280. $game['type'] = $type;
  3281. $game['bound_group_id'] = $boundGameGroups[$type][$gameId] ?? 0;
  3282. $gameOptions[$platformKeys[$type]][] = $game;
  3283. if (!empty($game['bound_group_id'])) {
  3284. continue;
  3285. }
  3286. $cleanName = cleanGameName((string)$game['name']);
  3287. if ($cleanName === '') {
  3288. continue;
  3289. }
  3290. if (!isset($candidateBuckets[$cleanName])) {
  3291. $candidateBuckets[$cleanName] = [
  3292. 1 => [],
  3293. 2 => [],
  3294. 3 => [],
  3295. ];
  3296. }
  3297. $candidateBuckets[$cleanName][$type][] = $game;
  3298. $ungroupedCount++;
  3299. }
  3300. ksort($candidateBuckets);
  3301. $rows = [];
  3302. $conflictCount = 0;
  3303. foreach ($candidateBuckets as $groupName => $platformGames) {
  3304. $existingBand = $bandByName[$groupName] ?? null;
  3305. $row = [
  3306. 'group_id' => $existingBand ? (int)$existingBand['id'] : 0,
  3307. 'action' => $existingBand ? 'update' : 'create',
  3308. 'group_name' => $groupName,
  3309. 'android_game_id' => $existingBand ? (int)$existingBand['android_game_id'] : 0,
  3310. 'ios_game_id' => $existingBand ? (int)$existingBand['ios_game_id'] : 0,
  3311. 'h5_game_id' => $existingBand ? (int)$existingBand['h5_game_id'] : 0,
  3312. 'warnings' => [],
  3313. ];
  3314. foreach ($platformFields as $type => $field) {
  3315. $candidates = $platformGames[$type];
  3316. if (count($candidates) > 1) {
  3317. $candidateNames = array_map(function ($item) {
  3318. return $item['name'] . '(ID:' . $item['id'] . ')';
  3319. }, $candidates);
  3320. $row['warnings'][] = '同平台存在多个候选:' . implode('、', $candidateNames);
  3321. continue;
  3322. }
  3323. if (count($candidates) === 0) {
  3324. continue;
  3325. }
  3326. $candidate = $candidates[0];
  3327. if ((int)$row[$field] > 0 && (int)$row[$field] !== (int)$candidate['id']) {
  3328. $row['warnings'][] = '已有分组的对应平台已被占用,候选游戏:'
  3329. . $candidate['name'] . '(ID:' . $candidate['id'] . ')';
  3330. continue;
  3331. }
  3332. $row[$field] = (int)$candidate['id'];
  3333. }
  3334. if (!empty($row['warnings'])) {
  3335. $conflictCount++;
  3336. }
  3337. $rows[] = $row;
  3338. }
  3339. $invalidPlatformCount = (new GameModel())
  3340. ->where('type', 'not in', [1, 2, 3])
  3341. ->count();
  3342. $this->result([
  3343. 'rows' => $rows,
  3344. 'games' => $gameOptions,
  3345. 'summary' => [
  3346. 'ungrouped_games' => $ungroupedCount,
  3347. 'candidate_groups' => count($rows),
  3348. 'conflict_groups' => $conflictCount,
  3349. 'invalid_platform_games' => (int)$invalidPlatformCount,
  3350. ],
  3351. ], 1, '绑定方案生成成功');
  3352. }
  3353. /**
  3354. * 游戏组管理 - 批量保存历史游戏绑定方案
  3355. */
  3356. public function gameBandAutoSave()
  3357. {
  3358. if (!request()->isAjax()) {
  3359. $this->error('非法请求');
  3360. }
  3361. $rowsJson = input('rows', '', 'trim');
  3362. $rows = json_decode($rowsJson, true);
  3363. if (!is_array($rows) || empty($rows)) {
  3364. $this->result([], 0, '没有需要保存的绑定方案');
  3365. }
  3366. if (count($rows) > 200) {
  3367. $this->result([], 0, '单次最多处理200个游戏组');
  3368. }
  3369. $platformFields = [
  3370. 1 => 'ios_game_id',
  3371. 2 => 'android_game_id',
  3372. 3 => 'h5_game_id',
  3373. ];
  3374. $preparedRows = [];
  3375. $usedNames = [];
  3376. $usedGameIds = [];
  3377. $usedGroupIds = [];
  3378. foreach ($rows as $index => $row) {
  3379. $line = $index + 1;
  3380. $groupId = isset($row['group_id']) ? (int)$row['group_id'] : 0;
  3381. $groupName = trim((string)($row['group_name'] ?? ''));
  3382. if ($groupName === '') {
  3383. $this->result([], 0, "第{$line}行游戏组名称不能为空");
  3384. }
  3385. if (mb_strlen($groupName, 'UTF-8') > 100) {
  3386. $this->result([], 0, "第{$line}行游戏组名称不能超过100个字符");
  3387. }
  3388. $nameKey = mb_strtolower($groupName, 'UTF-8');
  3389. if (isset($usedNames[$nameKey])) {
  3390. $this->result([], 0, "第{$line}行游戏组名称与第{$usedNames[$nameKey]}行重复");
  3391. }
  3392. $usedNames[$nameKey] = $line;
  3393. if ($groupId > 0) {
  3394. if (isset($usedGroupIds[$groupId])) {
  3395. $this->result([], 0, "游戏组ID {$groupId} 在方案中重复");
  3396. }
  3397. $usedGroupIds[$groupId] = true;
  3398. }
  3399. $prepared = [
  3400. 'group_id' => $groupId,
  3401. 'game_name' => $groupName,
  3402. 'android_game_id' => (int)($row['android_game_id'] ?? 0),
  3403. 'ios_game_id' => (int)($row['ios_game_id'] ?? 0),
  3404. 'h5_game_id' => (int)($row['h5_game_id'] ?? 0),
  3405. 'line' => $line,
  3406. ];
  3407. if (empty($prepared['android_game_id'])
  3408. && empty($prepared['ios_game_id'])
  3409. && empty($prepared['h5_game_id'])) {
  3410. $this->result([], 0, "第{$line}行至少需要绑定一个平台的游戏");
  3411. }
  3412. foreach ($platformFields as $type => $field) {
  3413. $gameId = $prepared[$field];
  3414. if ($gameId <= 0) {
  3415. continue;
  3416. }
  3417. if (isset($usedGameIds[$gameId])) {
  3418. $this->result([], 0, "游戏ID {$gameId} 在第{$usedGameIds[$gameId]}行和第{$line}行重复");
  3419. }
  3420. $usedGameIds[$gameId] = $line;
  3421. $gameInfo = (new GameModel())->field('id,name,type')->where('id', $gameId)->find();
  3422. if (!$gameInfo) {
  3423. $this->result([], 0, "第{$line}行游戏ID {$gameId} 不存在");
  3424. }
  3425. if ((int)$gameInfo['type'] !== $type) {
  3426. $this->result([], 0, "第{$line}行游戏[{$gameInfo['name']}]的平台类型不匹配");
  3427. }
  3428. }
  3429. $preparedRows[] = $prepared;
  3430. }
  3431. Db::startTrans();
  3432. try {
  3433. foreach ($preparedRows as $row) {
  3434. $groupId = $row['group_id'];
  3435. $line = $row['line'];
  3436. $gameBandModel = new GameBand();
  3437. if ($groupId > 0 && !$gameBandModel->where('id', $groupId)->find()) {
  3438. throw new \Exception("第{$line}行游戏组不存在或已被删除");
  3439. }
  3440. $nameWhere = ['game_name' => $row['game_name']];
  3441. if ($groupId > 0) {
  3442. $nameWhere['id'] = ['neq', $groupId];
  3443. }
  3444. if ($gameBandModel->where($nameWhere)->find()) {
  3445. throw new \Exception("第{$line}行游戏组名称[{$row['game_name']}]已存在");
  3446. }
  3447. foreach ($platformFields as $field) {
  3448. $gameId = $row[$field];
  3449. if ($gameId <= 0) {
  3450. continue;
  3451. }
  3452. $bindWhere = [$field => $gameId];
  3453. if ($groupId > 0) {
  3454. $bindWhere['id'] = ['neq', $groupId];
  3455. }
  3456. $bindExists = $gameBandModel->where($bindWhere)->find();
  3457. if ($bindExists) {
  3458. throw new \Exception(
  3459. "第{$line}行游戏ID {$gameId} 已被游戏组[{$bindExists['game_name']}]绑定"
  3460. );
  3461. }
  3462. }
  3463. $data = [
  3464. 'game_name' => $row['game_name'],
  3465. 'android_game_id' => $row['android_game_id'],
  3466. 'ios_game_id' => $row['ios_game_id'],
  3467. 'h5_game_id' => $row['h5_game_id'],
  3468. ];
  3469. if ($groupId > 0) {
  3470. $result = $gameBandModel->save($data, ['id' => $groupId]);
  3471. } else {
  3472. $data['status'] = GameBand::STATUS_ENABLE;
  3473. $data['create_time'] = NOW_TIMESTAMP;
  3474. $result = $gameBandModel->save($data);
  3475. }
  3476. if ($result === false) {
  3477. throw new \Exception("第{$line}行保存失败");
  3478. }
  3479. }
  3480. Db::commit();
  3481. $this->result([], 1, '一键绑定完成,共处理' . count($preparedRows) . '个游戏组');
  3482. } catch (\Exception $e) {
  3483. Db::rollback();
  3484. $this->result([], 0, $e->getMessage());
  3485. }
  3486. }
  3487. /**
  3488. * 游戏组管理 - AJAX 编辑/新增
  3489. */
  3490. public function gameBandEdit()
  3491. {
  3492. if (!request()->isAjax()) {
  3493. $this->error('非法请求');
  3494. }
  3495. $id = input('id', 0, 'intval');
  3496. $gameName = input('game_name', '', 'trim');
  3497. $androidGameId = input('android_game_id', 0, 'intval');
  3498. $iosGameId = input('ios_game_id', 0, 'intval');
  3499. $h5GameId = input('h5_game_id', 0, 'intval');
  3500. if (empty($gameName)) {
  3501. $this->result([], 0, '游戏名称不能为空');
  3502. }
  3503. if (empty($androidGameId) && empty($iosGameId) && empty($h5GameId)) {
  3504. $this->result([], 0, '至少需要绑定一个平台的游戏');
  3505. }
  3506. $gameBandModel = new GameBand();
  3507. // 检查游戏名是否重复(排除自身)
  3508. $nameWhere = ['game_name' => $gameName];
  3509. if ($id > 0) {
  3510. $nameWhere['id'] = ['neq', $id];
  3511. }
  3512. $exists = $gameBandModel->where($nameWhere)->find();
  3513. if ($exists) {
  3514. $this->result([], 0, '游戏名已存在');
  3515. }
  3516. // 检查游戏是否已被其他分组绑定
  3517. $checkFields = [
  3518. 'android_game_id' => $androidGameId,
  3519. 'ios_game_id' => $iosGameId,
  3520. 'h5_game_id' => $h5GameId,
  3521. ];
  3522. foreach ($checkFields as $field => $gameId) {
  3523. if ($gameId > 0) {
  3524. $bindWhere = [$field => $gameId];
  3525. if ($id > 0) {
  3526. $bindWhere['id'] = ['neq', $id];
  3527. }
  3528. $bindExists = $gameBandModel->where($bindWhere)->find();
  3529. if ($bindExists) {
  3530. $this->result([], 0, "该游戏已被分组[{$bindExists['game_name']}]绑定");
  3531. }
  3532. }
  3533. }
  3534. $data = [
  3535. 'game_name' => $gameName,
  3536. 'android_game_id' => $androidGameId,
  3537. 'ios_game_id' => $iosGameId,
  3538. 'h5_game_id' => $h5GameId,
  3539. ];
  3540. if ($id > 0) {
  3541. // 编辑
  3542. $result = $gameBandModel->save($data, ['id' => $id]);
  3543. } else {
  3544. // 新增
  3545. $data['status'] = GameBand::STATUS_ENABLE;
  3546. $data['create_time'] = NOW_TIMESTAMP;
  3547. $result = $gameBandModel->save($data);
  3548. }
  3549. if ($result !== false) {
  3550. $this->result([], 1, '操作成功');
  3551. } else {
  3552. $this->result([], 0, '操作失败');
  3553. }
  3554. }
  3555. /**
  3556. * 游戏组管理 - 获取分组详情
  3557. */
  3558. public function gameBandDetail()
  3559. {
  3560. if (!request()->isAjax()) {
  3561. $this->error('非法请求');
  3562. }
  3563. $id = input('id', 0, 'intval');
  3564. if (empty($id)) {
  3565. $this->result([], 0, '参数错误');
  3566. }
  3567. $gameBandModel = new GameBand();
  3568. $detail = $gameBandModel->getGroupDetail($id);
  3569. if ($detail) {
  3570. $this->result($detail, 1, '获取成功');
  3571. } else {
  3572. $this->result([], 0, '分组不存在');
  3573. }
  3574. }
  3575. /**
  3576. * 游戏组管理 - 获取游戏列表(用于下拉选择)
  3577. */
  3578. public function gameBandGameList()
  3579. {
  3580. if (!request()->isAjax()) {
  3581. $this->error('非法请求');
  3582. }
  3583. $platform = input('platform', 0, 'intval'); // 1=iOS 2=Android 3=H5
  3584. $keyword = input('keyword', '', 'trim');
  3585. $selectedId = input('selected_id', 0, 'intval');
  3586. if (empty($platform)) {
  3587. $this->result([], 0, '平台参数错误');
  3588. }
  3589. $where = [
  3590. 'type' => $platform,
  3591. 'cooperation_status' => ['<>', 3], // 排除下架
  3592. ];
  3593. if (!empty($keyword)) {
  3594. $where['name'] = ['like', "%{$keyword}%"];
  3595. }
  3596. $list = (new GameModel())
  3597. ->field('id, name')
  3598. ->where($where)
  3599. ->order('name asc, id asc')
  3600. ->select();
  3601. $listArr = is_object($list) && method_exists($list, 'toArray')
  3602. ? $list->toArray()
  3603. : (array)$list;
  3604. if ($selectedId > 0) {
  3605. $found = false;
  3606. foreach ($listArr as $item) {
  3607. if ((int)$item['id'] === $selectedId) {
  3608. $found = true;
  3609. break;
  3610. }
  3611. }
  3612. if (!$found) {
  3613. $selected = (new GameModel())
  3614. ->field('id, name')
  3615. ->where('id', $selectedId)
  3616. ->find();
  3617. if ($selected) {
  3618. $selectedArr = is_object($selected) && method_exists($selected, 'toArray')
  3619. ? $selected->toArray()
  3620. : (array)$selected;
  3621. array_unshift($listArr, $selectedArr);
  3622. }
  3623. }
  3624. }
  3625. $this->result($listArr, 1, '获取成功');
  3626. }
  3627. // /**
  3628. // * 批量添加游戏补点
  3629. // */
  3630. // public function batchAddPointList(){
  3631. //
  3632. // $listNum = $this->request->param('listNum');
  3633. // $listArr = $_POST;
  3634. // $begin_date = [];
  3635. // $end_date = [];
  3636. // $first_point = [];
  3637. // $common_point = [];
  3638. // $cash_point = [];
  3639. // $cash_profit_point = [];
  3640. // $remark = [];
  3641. // $game_id = [];
  3642. // $channel_id = [];
  3643. // $runable = true;
  3644. // $status = '';
  3645. // $msg = '';
  3646. //
  3647. // for ($i=0; $i<$listNum; $i++){
  3648. // // 获取补点月 月初 和月末的时间戳
  3649. // $month_st = strtotime(session('year_month'));
  3650. //
  3651. // // 时间戳转换 确保 选则的不是今年的时间 也能转为正确的时间戳
  3652. // $monthArr = explode('-',session('year_month'));
  3653. // $monthArr[1] = (int)$monthArr[1] +1;
  3654. // $monthArr[1] = (string)$monthArr[1];
  3655. // if (strlen($monthArr[1]) < 2 ){
  3656. // $monthArr[1] = '0'.$monthArr[1];
  3657. // }
  3658. // $monthStr = $monthArr[0].$monthArr[1]."01 00:00:00";
  3659. // $month_end = strtotime($monthStr) -1;
  3660. //
  3661. // // 开始时间判断
  3662. // if (empty($listArr['begin_date'][$i])){
  3663. // $this->result(['i'=>$i],0,'请选择正确的开始时间');
  3664. // break;
  3665. // }else{
  3666. // $listArr['begin_date'][$i] = $listArr['begin_date'][$i].' 00:00:00';
  3667. // $catimeNew = strtotime($listArr['begin_date'][$i]);
  3668. //
  3669. // if ($catimeNew < $month_st || $catimeNew > $month_end) {
  3670. // $this->result(['i'=>$i],0,'请选择正确的开始时间');
  3671. // break;
  3672. // }
  3673. // $listArr['begin_date'][$i] = $catimeNew;
  3674. // }
  3675. // // 结束时间判断
  3676. // if (empty($listArr['end_date'][$i])){
  3677. // $this->result(['i'=>$i],0,'请选择正确的结束时间');
  3678. // break;
  3679. // }else{
  3680. // $listArr['end_date'][$i] = $listArr['end_date'][$i].' 23:59:59';
  3681. // $entTime = strtotime($listArr['end_date'][$i]);
  3682. // $listArr['end_date'][$i] = $entTime;
  3683. //
  3684. // if ($entTime < $month_st || $entTime > $month_end) {
  3685. // $this->result(['i'=>$i],0,'请选择正确的结束时间');
  3686. // break;
  3687. // }
  3688. //
  3689. // if ($listArr['end_date'][$i] <= $listArr['begin_date'][$i]) {
  3690. // $this->result(['i'=>$i],0,'开始时间不能大于结束时间');
  3691. // break;
  3692. // }
  3693. //
  3694. // }
  3695. // // 游戏id不能为空
  3696. // if (empty($listArr['game_id'][$i])){
  3697. // $this->result(['i'=>$i],0,'请选择游戏');
  3698. // break;
  3699. // }
  3700. // // 渠道不能为空
  3701. // if (empty($listArr['channel_id'][$i])){
  3702. // $this->result(['i'=>$i],0,'请选择渠道');
  3703. // break;
  3704. // }
  3705. // // 对几个补点进行验证
  3706. // if (is_numeric($listArr['first_point'][$i])) {
  3707. // $first_point_1 = (float)$listArr['first_point'][$i] * 100;
  3708. // $res_num = $first_point_1 - (float)((int)$first_point_1);
  3709. //
  3710. // if ( $first_point_1 <0 || $first_point_1 > 10000 || $res_num > 1e-7 ) {
  3711. // $this->result(['i'=>$i],0,'请输入正确的首充补点');
  3712. // break;
  3713. // }
  3714. // }else{
  3715. // $this->result(['i'=>$i],0,'请输入正确的首充补点');
  3716. // break;
  3717. // }
  3718. //
  3719. // if (is_numeric($listArr['common_point'][$i])) {
  3720. // $common_point_1 = (float)$listArr['common_point'][$i] * 100;
  3721. // $res_num = $common_point_1 - (float)((int)$common_point_1);
  3722. // if ( $common_point_1 <0 || $common_point_1 > 10000 || $res_num > 1e-7 ) {
  3723. // $this->result(['i'=>$i],0,'请输入正确的续充补点');
  3724. // break;
  3725. // }
  3726. // }else{
  3727. // $this->result(['i'=>$i],0,'请输入正确的续充补点');
  3728. // break;
  3729. // }
  3730. //
  3731. // if (is_numeric($listArr['cash_point'][$i])) {
  3732. // $cash_point_1 = (float)$listArr['cash_point'][$i] * 100;
  3733. // $res_num = $cash_point_1 - (float)((int)$cash_point_1);
  3734. // if ( $cash_point_1 <0 || $cash_point_1 > 10000 || $res_num > 1e-7 ) {
  3735. // $this->result(['i'=>$i],0,'请输入正确的自然补点');
  3736. // break;
  3737. // }
  3738. // }else{
  3739. // $this->result(['i'=>$i],0,'请输入正确的自然补点');
  3740. // break;
  3741. // }
  3742. //
  3743. // if (is_numeric($listArr['cash_profit_point'][$i])) {
  3744. // $cash_profit_point_1 = (float)$listArr['cash_profit_point'][$i] * 100;
  3745. // $res_num = $cash_profit_point_1 - (float)((int)$cash_profit_point_1);
  3746. // if ( $cash_profit_point_1 <0 || $cash_profit_point_1 > 10000 || $res_num > 1e-7 ) {
  3747. // $this->result(['i'=>$i],0,'请输入正确的返利补点');
  3748. // break;
  3749. // }
  3750. // }else{
  3751. // $this->result(['i'=>$i],0,'请输入正确的返利补点');
  3752. // break;
  3753. // }
  3754. //
  3755. // $begin_date[] = $listArr['begin_date'][$i];
  3756. // $end_date[] = $listArr['end_date'][$i];
  3757. // $first_point[] = $listArr['first_point'][$i];
  3758. // $common_point[] = $listArr['common_point'][$i];
  3759. // $cash_point[] = $listArr['cash_point'][$i];
  3760. // $cash_profit_point[] = $listArr['cash_profit_point'][$i];
  3761. // $remark[] = $listArr['remark'][$i];
  3762. // $game_id[] = $listArr['game_id'][$i];
  3763. // $channel_id[] = $listArr['channel_id'][$i];
  3764. // }
  3765. //
  3766. // // 开启事物
  3767. // Db::startTrans();
  3768. //
  3769. // foreach ($begin_date as $key => $value) {
  3770. // $departid = $channel_id[$key];
  3771. // $game_id_1 = $game_id[$key];
  3772. //
  3773. // $moder_PR = model('GameExtraPointRatio');
  3774. // $map_2 = [
  3775. // 'status' => ['eq',1],
  3776. // 'game_id' => ['eq',$game_id_1],
  3777. // 'year_month' => ['eq',session('year_month')]
  3778. // ];
  3779. // $pdList = $moder_PR->where($map_2)->field('id,game_id,channel_id,begin_date,end_date')->select();
  3780. //
  3781. // // 查有该游戏,可以进行对比判断
  3782. // $thisGame = ['year_month'=>session('year_month'),'game_id'=>$game_id_1,'channel_id'=>$departid,'begin_date'=>$begin_date[$key],'end_date'=>$end_date[$key],'first_point'=>$first_point[$key],'common_point'=>$common_point[$key],'cash_point'=>$cash_point[$key],'cash_profit_point'=>$cash_profit_point[$key],'remark'=>$remark[$key],'add_user'=>session('ADMIN_ID'),'add_time'=>time()];
  3783. // if (count($pdList)){
  3784. // $topDP = model('Department')->where(['id'=>$departid])->field('id,id_path')->find();
  3785. //
  3786. // // 查出下级渠道
  3787. // $map_1 = [];
  3788. // $map_1 = [
  3789. // 'id_path'=>['like','%,'.$departid.',%']
  3790. // ];
  3791. // $downDP_1 = model('Department')->where($map_1)->field('id')->select();
  3792. // $downDP = '';
  3793. // foreach ($downDP_1 as $key => $value) {
  3794. // $downDP .= ','.$value['id'].',';
  3795. // }
  3796. //
  3797. // // 验证
  3798. // foreach ($pdList as $v_pdlist){
  3799. // // 只要 $thisGame 的开始时间或结束时间 在对方的开始时间和结束时间之间,哪就发生了时间冲突
  3800. // $v_pdlist['begin_date'] =(int)$v_pdlist['begin_date'];
  3801. // $v_pdlist['end_date'] =(int)$v_pdlist['end_date'];
  3802. //
  3803. // // 2、判断渠道有没有冲突
  3804. // // 2.1判断上级渠道有没有冲突----如果游戏相同,时间冲突,上级渠道已经添加补点,提示“上级渠道已经添加该补点信息,冲突ID:xxx”;
  3805. // if ( strpos($topDP['id_path'],','.$v_pdlist['channel_id'].',') !== false ){
  3806. // $msg = '上级渠道已经添加补点信息,冲突ID:' . $v_pdlist['id'];
  3807. // $this->result(['i'=>$key],0,$msg);
  3808. // break;
  3809. // }
  3810. //
  3811. // // 2.2判断下级渠道有没有冲突
  3812. // $downDP = str_replace($departid,",",$downDP);
  3813. // if ( strpos($downDP,','.$v_pdlist['channel_id'].',') !== false ){
  3814. // $msg = '下级渠道已经添加补点信息,冲突ID:' . $v_pdlist['id'];
  3815. // $this->result(['i'=>$key],0,$msg);
  3816. // break;
  3817. // }
  3818. //
  3819. // /*var_dump($topDP['id_path']);
  3820. // var_dump($downDP);*/
  3821. //
  3822. // // 时间发生冲突
  3823. // if( (($thisGame['begin_date'] >= $v_pdlist['begin_date'] && $thisGame['begin_date'] < $v_pdlist['end_date']) || ($thisGame['end_date'] > $v_pdlist['begin_date'] && $thisGame['end_date'] <= $v_pdlist['end_date']) || ($thisGame['begin_date'] < $v_pdlist['begin_date'] && $thisGame['end_date'] > $v_pdlist['end_date'] )) && $thisGame['channel_id'] == $v_pdlist['channel_id']){
  3824. // // 1.如果游戏相同,渠道相同,时间冲突,提示“补点时间有冲突,冲突ID:xxx”;
  3825. // $msg = '补点时间有冲突,冲突ID:' . $v_pdlist['id'];
  3826. // $this->result(['i'=>$key],0,$msg);
  3827. // break;
  3828. // }
  3829. //
  3830. // }
  3831. // }
  3832. // // 开始入库操作
  3833. // $GameExtraPointObj = model('GameExtraPoint')->where(['year_month'=>session('year_month')])->field('id')->find();
  3834. // $thisGame['game_extra_point_id'] = $GameExtraPointObj['id'];
  3835. //// $pointRatioM = model('GameExtraPointRatio');
  3836. //// $res = $pointRatioM->add($thisGame);
  3837. // $pointRatioM = new GameExtraPointRatio;
  3838. // $pointRatioM->data($thisGame);
  3839. // $res = $pointRatioM->save();
  3840. //
  3841. // // 获取游戏名和渠道名
  3842. // $channel_obj = model('Department')->getCondition(['id'=>$departid]);
  3843. // $Game_name = model('Game')->where(['id'=>$game_id_1])->field('name')->find();
  3844. //
  3845. // $res_log = $this->insertLog($this->current_node,'添加游戏补点,ID:'.$pointRatioM->id.',游戏名:'.$Game_name['name'].',渠道名:'.$channel_obj['name'], 14);
  3846. // // 判断是否写入库
  3847. // if(!$res || !$res_log){
  3848. // Db::rollback();
  3849. // $this->result([],0,'网络出现错误'.$res_log);
  3850. // }
  3851. // }
  3852. // Db::commit();
  3853. // $map['year_month'] = session('year_month');
  3854. // model('GameExtraPoint')->save(['update_user'=>session('ADMIN_ID'),'update_time'=>time()],$map);
  3855. //
  3856. // $this->result([],1,'操作成功');
  3857. // }
  3858. // /**
  3859. // * 消费折扣点位列表
  3860. // *
  3861. // */
  3862. // public function payPointList()
  3863. // {
  3864. // $payPointModel = new PayPoint;
  3865. //
  3866. // $where = [];
  3867. //
  3868. // //游戏名称
  3869. // if (input('request.name') != '') {
  3870. // $where['g.name'] = ['like', '%' . input('request.name', '', 'trim') . '%'];
  3871. // }
  3872. //
  3873. // //查询参数
  3874. // $param = input('get.');
  3875. //
  3876. // $list = $this->gameModel->alias('g')
  3877. // ->field('g.name as game_name,g.id as game_id,p.id,p.third_party_pay_point,p.create_time,p.update_time,p.status')
  3878. // ->join('cy_pay_point p', 'g.id=p.game_id', 'left')
  3879. // ->where(['g.cooperation_status' => ['<>', 0]])->where($where)->order('g.id desc')
  3880. // ->paginate(10, false, array('query' => $param));
  3881. //
  3882. // $this->assign('list', $list);
  3883. // $this->assign('page', $list->render());
  3884. //
  3885. // return $this->fetch('pay_point_list');
  3886. // }
  3887. //
  3888. // /**
  3889. // * 设置折扣点
  3890. // *
  3891. // */
  3892. // public function ajaxSetPayPoint()
  3893. // {
  3894. // if (request()->isAjax()) {
  3895. //
  3896. // $gameId = input('post.pk', 0, 'intval');
  3897. // $field = input('post.name', '', 'trim');
  3898. // $value = input('post.value', '', 'trim');
  3899. //
  3900. // if (empty($gameId)) {
  3901. // $this->result('', 0, '游戏ID不能为空');
  3902. // } elseif (empty($field)) {
  3903. // $this->result('', 0, '未指定要编辑的字段');
  3904. // } elseif (empty($value)) {
  3905. // $this->result('', 0, '更新的值不能为空');
  3906. // } elseif (!is_numeric($value)) {
  3907. // $this->result('', 0, '更新的值格式不正确');
  3908. // } else {
  3909. // $payPointModel = new PayPoint;
  3910. //
  3911. // $payPointInfo = $payPointModel->where(['game_id' => $gameId])->find();
  3912. //
  3913. // //编辑
  3914. // if ($payPointInfo) {
  3915. // if ($payPointModel->where(['game_id' => $gameId])->update([
  3916. // $field => $value,
  3917. // 'update_time' => time(),
  3918. // ])) {
  3919. // $this->result('', 1, '设置成功');
  3920. // } else {
  3921. // $this->result('', 0, '设置失败');
  3922. // }
  3923. // } //新增
  3924. // else {
  3925. // if ($payPointModel->insert([
  3926. // 'game_id' => $gameId,
  3927. // $field => $value,
  3928. // 'create_time' => time(),
  3929. // 'update_time' => time(),
  3930. // ])) {
  3931. // $this->result('', 1, '设置成功');
  3932. // } else {
  3933. // $this->result('', 0, '设置失败');
  3934. // }
  3935. // }
  3936. // }
  3937. // } else {
  3938. // $this->error('非法操作');
  3939. // }
  3940. // }
  3941. // /**
  3942. // * 新增游戏自动上架
  3943. // */
  3944. // public function autoUpdateCreate()
  3945. // {
  3946. // if (request()->isPost()) {
  3947. //
  3948. // $data = [
  3949. // 'gameid' => input('post.gameid'),
  3950. // 'putaway_status' => input('post.putaway_status'), //上架类型
  3951. // 'putaway_time' => input('post.putaway_time'),
  3952. // ];
  3953. //
  3954. // $result = $this->validate($data, [
  3955. // ['gameid', 'require|integer', '请选择游戏|游戏ID必须为整型'],
  3956. // ['putaway_status', 'integer', '上架类型必须为整型'],
  3957. // ['putaway_time', 'require|date|after:' . date('Y-m-d H:i:s'), '上架时间不能为空|上架时间的格式不正确|上架时间需大于当前时间'],
  3958. // ]);
  3959. //
  3960. // if (true !== $result) {
  3961. //
  3962. // $this->error($result);
  3963. // } //上架类型不是新增时
  3964. // elseif ($data['putaway_status'] != 0) {
  3965. // if (empty(input('post.target_filename')) || empty(input('post.source_filename'))) {
  3966. // $this->error('请完整填写新旧文件名');
  3967. // }
  3968. // } elseif ($data['putaway_status'] == 1) {
  3969. // if (empty(input('post.version'))) {
  3970. // $this->error('请输入强更版本号');
  3971. // }
  3972. // }
  3973. //
  3974. // $data['target_filename'] = input('post.target_filename', '', 'trim');
  3975. // $data['source_filename'] = input('post.source_filename', '', 'trim');
  3976. // $data['version'] = input('post.version');
  3977. // $data['batch_subpackage_days'] = input('post.batch_subpackage_days'); //批量分包
  3978. // $data['create_time'] = time();
  3979. // $data['putaway_time'] = input('post.putaway_time', 0, 'strtotime');
  3980. // $data['token'] = $this->createAutoUpdateGameToken();
  3981. //
  3982. // if (Db::table('cy_game_auto_update')->insert($data)) $this->success('新增成功', 'game/autoUpdateList'); else
  3983. // $this->error('新增失败');
  3984. // }
  3985. //
  3986. // $game_list = $this->gameModel->field('id,name')->order('name asc')->select();
  3987. //
  3988. // $this->assign('game_list', $game_list);
  3989. //
  3990. // return $this->fetch('auto_update_new');
  3991. // }
  3992. //
  3993. // /**
  3994. // * 游戏推荐
  3995. // *
  3996. // */
  3997. // public function articleIndex()
  3998. // {
  3999. // $articleInfo = Db::table('cy_admin_article')->where(['status' => 1, 'open_time' => ['<', time()]])
  4000. // ->order('open_time DESC')->find();
  4001. //
  4002. // $this->assign('articleInfo', $articleInfo);
  4003. //
  4004. // return $this->fetch('article_index');
  4005. // }
  4006. //
  4007. // /**
  4008. // * 游戏推荐列表
  4009. // */
  4010. // public function articleList()
  4011. // {
  4012. // $where = [];
  4013. //
  4014. // //游戏名称
  4015. // if (input('request.title') != '') {
  4016. // $where['title'] = ['like', '%' . input('request.title', '', 'trim') . '%'];
  4017. // }
  4018. //
  4019. // //推送类型
  4020. // if (input('request.status') != '') {
  4021. // $where['status'] = input('request.status', 0, 'intval');
  4022. // }
  4023. //
  4024. // //查询参数
  4025. // $param = input('get.');
  4026. //
  4027. // $article_list = Db::table('cy_admin_article')->where($where)->order('id desc')
  4028. // ->paginate(10, false, array('query' => $param));
  4029. //
  4030. // $this->assign('article_list', $article_list);
  4031. // $this->assign('page', $article_list->render());
  4032. //
  4033. // return $this->fetch('article_list');
  4034. // }
  4035. //
  4036. // /**
  4037. // * 更改文章上架状态
  4038. // */
  4039. // public function changeArticleStatus()
  4040. // {
  4041. //
  4042. // if (request()->isAjax()) {
  4043. //
  4044. // $id = input('post.id', 0, 'intval');
  4045. // $status = input('post.status', 0, 'intval');
  4046. //
  4047. // if (empty($id)) {
  4048. //
  4049. // $this->result('', 0, '文章ID不能为空');
  4050. // } else {
  4051. //
  4052. // if (Db::table('cy_admin_article')->where(['id' => $id])->update(['status' => $status])) {
  4053. // $this->result('', 1, '操作成功');
  4054. // } else {
  4055. // $this->result('', 0, '操作失败');
  4056. // }
  4057. // }
  4058. // } else {
  4059. // $this->error('非法操作');
  4060. // }
  4061. // }
  4062. //
  4063. // /**
  4064. // * 删除游戏文章
  4065. // *
  4066. // */
  4067. // public function articleDelete()
  4068. // {
  4069. // $id = input('id', 0, 'intval');
  4070. //
  4071. // if (empty($id)) $this->error('删除记录的ID不能为空');
  4072. //
  4073. // if (Db::table('cy_admin_article')->where(['id' => $id])->delete()) {
  4074. // $this->success('删除成功');
  4075. // } else {
  4076. // $this->error('删除失败');
  4077. // }
  4078. // }
  4079. //
  4080. // /**
  4081. // * 新增文章
  4082. // */
  4083. // public function articleCreate()
  4084. // {
  4085. // if (request()->isPost()) {
  4086. //
  4087. // $data = [
  4088. // 'status' => input('post.status'),
  4089. // 'title' => input('post.title'),
  4090. // 'open_time' => input('post.open_time'),
  4091. // 'sort' => input('post.sort'),
  4092. // 'content' => input('post.content'),
  4093. // ];
  4094. //
  4095. // $result = $this->validate($data, [
  4096. // ['status', 'require|integer', '状态不能为空|状态必须为整型'],
  4097. // ['title', 'require|max:32', '标题不能为空|标题不能超过32个字符'],
  4098. // ['open_time', 'require|date|after:' . date('Y-m-d H:i:s'), '上架时间不能为空|上架时间的格式不正确|上架时间需大于当前时间'],
  4099. // ['sort', 'require|integer', '排序不能为空|排序必须为整型'],
  4100. // ]);
  4101. //
  4102. // if (true !== $result) {
  4103. // $this->error($result);
  4104. // }
  4105. //
  4106. // $data['create_time'] = time();
  4107. // $data['open_time'] = strtotime($data['open_time']);
  4108. //
  4109. // if (Db::table('cy_admin_article')->insert($data)) $this->success('新增成功', 'game/articleList'); else
  4110. // $this->error('新增失败');
  4111. // }
  4112. //
  4113. // return $this->fetch('article_new');
  4114. // }
  4115. //
  4116. // /**
  4117. // * 编辑文章
  4118. // */
  4119. // public function articleEdit()
  4120. // {
  4121. // $id = input('id', 0, 'intval');
  4122. //
  4123. // if (empty($id)) $this->error('文章ID不能为空');
  4124. //
  4125. // $articleInfo = Db::table('cy_admin_article')->where(['id' => $id])->find();
  4126. //
  4127. // if (empty($articleInfo)) $this->error('记录不存在');
  4128. //
  4129. // if (request()->isPost()) {
  4130. //
  4131. // $data = [
  4132. // 'status' => input('post.status'),
  4133. // 'title' => input('post.title'),
  4134. // 'open_time' => input('post.open_time'),
  4135. // 'sort' => input('post.sort'),
  4136. // 'content' => input('post.content'),
  4137. // ];
  4138. //
  4139. // $result = $this->validate($data, [
  4140. // ['status', 'require|integer', '状态不能为空|状态必须为整型'],
  4141. // ['title', 'require|max:32', '标题不能为空|标题不能超过32个字符'],
  4142. // ['open_time', 'require|date|after:' . date('Y-m-d H:i:s'), '上架时间不能为空|上架时间的格式不正确|上架时间需大于当前时间'],
  4143. // ['sort', 'require|integer', '排序不能为空|排序必须为整型'],
  4144. // ]);
  4145. //
  4146. // if (true !== $result) {
  4147. // $this->error($result);
  4148. // }
  4149. //
  4150. // $data['open_time'] = strtotime($data['open_time']);
  4151. //
  4152. // if (Db::table('cy_admin_article')->where(['id' => $id])
  4153. // ->update($data)) $this->success('编辑成功', 'game/articleList'); else
  4154. // $this->error('编辑失败');
  4155. // }
  4156. //
  4157. // $this->assign('articleInfo', $articleInfo);
  4158. //
  4159. // return $this->fetch('article_edit');
  4160. // }
  4161. //
  4162. // /**
  4163. // * 生成游戏自动更新token
  4164. // */
  4165. // private function createAutoUpdateGameToken()
  4166. // {
  4167. // return md5(time() . 'gameAutoUpdate');
  4168. // }
  4169. //
  4170. // /**
  4171. // * 编辑游戏自动上架
  4172. // */
  4173. // public function autoUpdateEdit()
  4174. // {
  4175. // $id = input('id', 0, 'intval');
  4176. //
  4177. // if (empty($id)) $this->error('游戏自动更新记录的ID不能为空');
  4178. //
  4179. // $autoInfo = Db::table('cy_game_auto_update')->where(['id' => $id])->find();
  4180. //
  4181. // if (empty($autoInfo)) $this->error('游戏自动更新记录不存在');
  4182. //
  4183. // if (request()->isPost()) {
  4184. //
  4185. // $data = [
  4186. // 'gameid' => input('post.gameid'),
  4187. // 'putaway_status' => input('post.putaway_status'), //上架类型
  4188. // 'putaway_time' => input('post.putaway_time'),
  4189. // ];
  4190. //
  4191. // $result = $this->validate($data, [
  4192. // ['gameid', 'require|integer', '请选择游戏|游戏ID必须为整型'],
  4193. // ['putaway_status', 'integer', '上架类型必须为整型'],
  4194. // ['putaway_time', 'require|date|after:' . date('Y-m-d H:i:s'), '上架时间不能为空|上架时间的格式不正确|上架时间需大于当前时间'],
  4195. // ]);
  4196. //
  4197. // if (true !== $result) {
  4198. //
  4199. // $this->error($result);
  4200. // } //上架类型不是新增时
  4201. // elseif ($data['putaway_status'] != 0) {
  4202. // if (empty(input('post.target_filename')) || empty(input('post.source_filename'))) {
  4203. // $this->error('请完整填写新旧文件名');
  4204. // }
  4205. // } elseif ($data['putaway_status'] == 1) {
  4206. // if (empty(input('post.version'))) {
  4207. // $this->error('请输入强更版本号');
  4208. // }
  4209. // }
  4210. //
  4211. // $data['target_filename'] = input('post.target_filename', '', 'trim');
  4212. // $data['source_filename'] = input('post.source_filename', '', 'trim');
  4213. // $data['version'] = input('post.version');
  4214. // $data['batch_subpackage_days'] = input('post.batch_subpackage_days'); //批量分包
  4215. // $data['putaway_time'] = input('post.putaway_time', 0, 'strtotime');
  4216. //
  4217. // if (Db::table('cy_game_auto_update')->where(['id' => $id])
  4218. // ->update($data)) $this->success('编辑成功', 'game/autoUpdateList'); else
  4219. // $this->error('编辑失败');
  4220. // }
  4221. //
  4222. // $game_list = $this->gameModel->field('id,name')->order('name asc')->select();
  4223. //
  4224. // $this->assign('game_list', $game_list);
  4225. // $this->assign('autoInfo', $autoInfo);
  4226. //
  4227. // return $this->fetch('auto_update_edit');
  4228. // }
  4229. //
  4230. // /**
  4231. // * 游戏自动更新列表
  4232. // */
  4233. // public function autoUpdateList()
  4234. // {
  4235. // $where = [];
  4236. //
  4237. // //游戏名称
  4238. // if (input('request.name') != '') {
  4239. // $where['g.name'] = ['like', '%' . input('request.name') . '%'];
  4240. // }
  4241. //
  4242. // //对接状态
  4243. // if (input('request.cooperation_status') != '') {
  4244. // $where['cooperation_status'] = input('request.cooperation_status');
  4245. // }
  4246. //
  4247. // //查询参数
  4248. // $param = input('get.');
  4249. //
  4250. // $list = $this->gameModel->table('cy_game g,cy_game_auto_update a')->field('g.name,a.*')->where('g.id=a.gameid')
  4251. // ->where($where)->order('a.id desc')->paginate(10, false, array('query' => $param));
  4252. //
  4253. // $this->assign('list', $list);
  4254. // $this->assign('page', $list->render());
  4255. //
  4256. // return $this->fetch('auto_update_list');
  4257. // }
  4258. //
  4259. //
  4260. // /**
  4261. // * 游戏自动上架记录删除
  4262. // */
  4263. // public function autoUpdateDelete()
  4264. // {
  4265. //
  4266. // $id = input('id', 0, 'intval');
  4267. //
  4268. // if (empty($id)) $this->error('删除记录的ID不能为空');
  4269. //
  4270. // if (Db::table('cy_game_auto_update')->where(['id' => $id])->delete()) {
  4271. // $this->success('删除成功');
  4272. // } else {
  4273. // $this->error('删除失败');
  4274. // }
  4275. // }
  4276. /**
  4277. * 不进行父类的登录验证,所以增加构造方法重写了父类的初始化方法
  4278. */
  4279. protected function _initialize()
  4280. {
  4281. parent::_initialize();
  4282. $this->subChannel = new SubChannel;
  4283. $this->gameModel = new GameModel;
  4284. $this->gameBelongModel = new GameBelong;
  4285. $this->sdkgamelistModel = $this->cyModel('sdkgamelist');
  4286. $this->gameList = model('Common/Game')->getAllByCondition('id,name');
  4287. $tmpSelfGameList = model('Common/Game')->getAllByCondition('id,name', [], '', 'self');
  4288. $selfGameList = array();
  4289. foreach ($tmpSelfGameList as $game) {
  4290. $selfGameList[$game['id']] = $game;
  4291. }
  4292. $this->selfGameList = $selfGameList;
  4293. }
  4294. }