MY_Controller.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. <?php
  2. require_once "application/config/common.php";
  3. require_once "application/models/Hashids.php";
  4. /**
  5. * 自定义核心类
  6. */
  7. class MY_Controller extends CI_Controller
  8. {
  9. protected $_wenenv = 'webenv';//网站的环境 内网/外网
  10. protected $env = 1;//默认为1,外网
  11. protected $oldAnPackageList = [];
  12. protected $oldIosPackageList = [];
  13. protected $pageConfig = array(
  14. 'first_tag_open' => '<li>',
  15. 'first_tag_close' => '</li>',
  16. 'last_tag_open' => '<li>',
  17. 'last_tag_close' => '</li>',
  18. 'next_tag_open' => '<li>',
  19. 'next_tag_close' => '</li>',
  20. 'prev_tag_open' => '<li>',
  21. 'prev_tag_close' => '</li>',
  22. 'cur_tag_open' => "<li class='active'><a hef='#'>",
  23. 'cur_tag_close' => "</a></li>",
  24. 'num_tag_open' => "<li>",
  25. 'num_tag_close' => "</li>",
  26. );
  27. protected $androidPackageList = [ 1=>'安卓',2=>'IOS'];
  28. protected $iosPackageList = [];//10 => '泰语(th2)'
  29. public $_langList;
  30. protected $gameList = [1=>'德州场',3 => '奥马哈场', 4 => '百人场'];
  31. protected $texasBlindList = [500, 1000, 2500, 5000, 10000, 50000, 100000, '私人房'];//德州开放场次的盲注列表
  32. protected $omahaBlindList = [2000, 5000, 10000, 50000];//奥马哈开放的场次盲注列表
  33. public static $inputFieldTypeText = 'text';
  34. public static $inputFieldTypeSelector = 'selector';
  35. public static $inputFieldTypeSelectorMultiple = 'selectorMultiple';
  36. public $staticPath = "./public/game/config/";
  37. public $propsConfig = null;
  38. public $_url = "";
  39. public $actGroupMapping = [];
  40. public $multiNumTypeReward = [
  41. '随机金卡',
  42. '随机星光卡',
  43. '随机限时金卡',
  44. '随机限时星光卡',
  45. '金币'
  46. ];
  47. public $rewardNames = [
  48. "木质宝箱" =>1 ,
  49. "白银宝箱" =>2 ,
  50. "黄金宝箱" =>3 ,
  51. "魔幻宝箱" =>4 ,
  52. "宠物经验" =>8 ,
  53. "宠物食物" =>9 ,
  54. "随机金卡" =>13 ,
  55. "金币" =>14 ,
  56. "体力" =>15 ,
  57. "小丑卡" =>18 ,
  58. "通行证经验" =>38 ,
  59. "拼图碎片" =>44 ,
  60. "玛雅转盘代币" =>45 ,
  61. "随机星光卡" =>50 ,
  62. "随机限时金卡" =>49 ,
  63. "随机限时星光卡" =>50 ,
  64. "幸运小丑代币" =>51 ,
  65. "幸运狐狸代币" =>51 ,
  66. "超级扭蛋代币" =>60,
  67. "随机公会表情" =>61,
  68. "皮纳塔代币" =>62,
  69. "塔罗牌代币" =>70,
  70. "推币机代币" =>72,
  71. "暴走兔子代币" => 74,
  72. "星图代币" => 77,
  73. "西部矿洞代币" => 79,
  74. ];
  75. public $needSkinRewards = [
  76. "皮肤宝箱" =>19 ,
  77. "建筑大师活动" =>25 ,
  78. "气球活动" =>26 ,
  79. "体力加速活动" =>27 ,
  80. "金币大爆炸活动" =>28 ,
  81. "疯狂加倍" =>31 ,
  82. "建筑打折" =>32 ,
  83. "卡片爆炸" =>33 ,
  84. "商场优惠" =>34 ,
  85. "超级收集活动" =>35 ,
  86. "超级气球活动" =>36 ,
  87. "首冲优惠" =>37 ,
  88. "通行证倍率活动" =>39 ,
  89. "收集翻倍活动" =>40 ,
  90. "四选一活动" =>41 ,
  91. "金币老虎机活动" =>43 ,
  92. "疯狂的卡组" =>46 ,
  93. "疯狂建造活动" =>52,
  94. "超级攻击活动" =>53,
  95. "回归签到" =>54,
  96. "完美偷袭活动" =>55,
  97. "小丑卡保底值" =>56,
  98. "完美打活动" =>57,
  99. "皮肤宝箱最大体力" =>58,
  100. "richking最大金币" =>59,
  101. "幸运骰子活动券" =>71,
  102. "Jackpot老虎机活动券" =>73,
  103. "每日成就任务道具券" => 75,
  104. "付费成就活动道具券" => 76,
  105. "推币机道具券" => 78,
  106. ];
  107. public function __construct()
  108. {
  109. parent::__construct();
  110. $this->load->helper('cookie');
  111. $this->load->helper('url');
  112. $this->load->library('session');
  113. // ini_set("session.gc_maxlifetime",86400);
  114. define('IS_POST',strtolower($_SERVER["REQUEST_METHOD"]) == 'post');//判断是否是post方法
  115. define('IS_GET',strtolower($_SERVER["REQUEST_METHOD"]) == 'get');//判断是否是get方法
  116. //判断model是否存在
  117. if (file_exists(APPPATH.'models/Common.php'))
  118. {
  119. $this->load->model('common');
  120. }
  121. $curUrl = strtolower(uri_string());
  122. if(!($curUrl == 'robot/main' || $curUrl == 'robot/makerobotrule')){
  123. $this->verify();
  124. }
  125. $this->load->model('oo');
  126. if(IS_POST && !empty($curUrl)){
  127. $url = current_url();
  128. $reason = '';
  129. $postData = $this->input->post();
  130. oo::logs()->adminlog($reason,$url,$curUrl,$postData);
  131. }
  132. $this->_url = $this->config->item('officialUrl');
  133. $this->_langList = oo::cfg('lang')['en_zh'];
  134. }
  135. /**
  136. * 数据导出
  137. * @param $header [ $k => $text] 表头
  138. * @param $listData [ [$k => $v ],[$k => $v]...] 数据
  139. * @return bool
  140. */
  141. protected function exportData(array $header,array $listData, $fileName){
  142. $objPHPExcel = new PHPExcel();
  143. //处理表头
  144. $char = 'A';
  145. foreach ($header as $v) {
  146. $objPHPExcel->getActiveSheet()->setCellValue($char++.'1', $v);
  147. }
  148. //处理数据
  149. $i = 2;
  150. foreach ($listData as $row) {
  151. $char = 'A';
  152. foreach ($header as $k => $t){
  153. $objPHPExcel->getActiveSheet()->setCellValue($char++.$i, $row[$k] ?? '');
  154. }
  155. $i++;
  156. }
  157. $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  158. $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  159. $outPutFileName = $fileName . date('Y-m-d');
  160. $objPHPExcel->setActiveSheetIndex(0);
  161. header('Content-Type: applicationnd.ms-excel');
  162. header('Content-Disposition: attachment;filename="'.$outPutFileName.'.xls"');
  163. header('Cache-Control: max-age=0');
  164. $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel2007');
  165. $objWriter->save('php://output');
  166. exit;
  167. }
  168. /**
  169. * 获取所有的sid
  170. * @return array
  171. */
  172. protected function getAllSid()
  173. {
  174. $oldAnSid = array_keys($this->oldAnPackageList);
  175. $oldIosSid = array_keys($this->oldIosPackageList);
  176. $anSid = array_keys($this->androidPackageList);
  177. $iosSid = array_keys($this->iosPackageList);
  178. $sidList = array_merge($oldAnSid, $oldIosSid, $anSid, $iosSid);
  179. return $sidList;
  180. }
  181. /**
  182. * 获取td数据
  183. * @return array
  184. */
  185. public function get_td_array($table) {
  186. $table = preg_replace("'<table[^>]*?>'si","",$table);
  187. $table = preg_replace("'<tr[^>]*?>'si","",$table);
  188. $table = preg_replace("'<td[^>]*?>'si","",$table);
  189. $table = str_replace("</tr>","{tr}",$table);
  190. $table = str_replace("</td>","{td}",$table);
  191. //去掉 HTML 标记
  192. $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);
  193. //去掉空白字符
  194. $table = preg_replace("'([rn])[s]+'","",$table);
  195. $table = str_replace(" ","",$table);
  196. $table = str_replace(" ","",$table);
  197. $table = str_replace("\n","",$table);
  198. $table = str_replace("","0",$table);
  199. //去掉删除
  200. $table = str_replace("删除{td}", "", $table);
  201. $table = explode('{tr}', $table);
  202. array_pop($table);
  203. print_r($table);
  204. unset($table[0]);
  205. foreach ($table as $key=>$tr) {
  206. $tds = explode('{td}', $tr);
  207. array_pop($tds);
  208. $td_array[] = $tds;
  209. }
  210. return $td_array;
  211. }
  212. /**
  213. * 是否选了所有包
  214. * @param $sidList
  215. * @return bool
  216. */
  217. protected function isAllSid($sidList)
  218. {
  219. if(in_array(999, $sidList)) {
  220. return true;
  221. }
  222. return false;
  223. }
  224. /**
  225. * 获取sid列表
  226. * @return array|mixed
  227. */
  228. protected function _getSidList()
  229. {
  230. $temp = get_cookie('sidlist');
  231. if(!is_array($temp)){
  232. $sidList = json_decode($temp, 1);
  233. }
  234. if(empty($sidList)) {
  235. if($this->isAdmin()) {
  236. $sidList = [1,2];
  237. }else {
  238. $sidList = $this->getPermissionSidList();
  239. }
  240. set_cookie('sidlist', json_encode($sidList), 86400);
  241. }
  242. //判断如果全选了所有的sid,则把sid置成999
  243. $diff = array_diff([1,2], $sidList);
  244. if(empty($diff)) {
  245. $sidList = [1,2];
  246. }
  247. return $sidList;
  248. }
  249. /**
  250. * 获取所以包名列表
  251. * @return array
  252. */
  253. protected function __getSidNameList()
  254. {
  255. $anListTmp = $this->oldAnPackageList + $this->androidPackageList;
  256. $iosListTmp = $this->oldIosPackageList + $this->iosPackageList;
  257. if(!$this->isAdmin()) {
  258. $anList = $iosList = [];
  259. foreach ($this->getPermissionSidList() as $sid) {
  260. if($sid % 2 == 0) {
  261. $iosList[$sid] = $iosListTmp[$sid];
  262. }else {
  263. $anList[$sid] = $anListTmp[$sid];
  264. }
  265. }
  266. }else {
  267. $anList = $anListTmp;
  268. $iosList = $iosListTmp;
  269. }
  270. $list = [];
  271. foreach ($anList as $ka => $va) {
  272. $list[$ka] = '安卓'.$va;
  273. }
  274. foreach ($iosList as $ki => $vi) {
  275. $list[$ki] = '苹果'.$vi;
  276. }
  277. return $list;
  278. }
  279. /**
  280. * 选择的包名列表
  281. * @return array
  282. */
  283. protected function __getSelectSidNameList()
  284. {
  285. $sidList = $this->_getSidList();
  286. if(in_array(999, $sidList)) {
  287. return [999=>'全部'];
  288. }
  289. $list = [];
  290. if(!empty($sidList)) {
  291. $allSidNameList = $this->__getSidNameList();
  292. foreach ($sidList as $sid) {
  293. $list[$sid] = $allSidNameList[$sid];
  294. }
  295. }else {
  296. $list = [0 =>'无'];
  297. }
  298. return $list;
  299. }
  300. /**
  301. * 设置sidlist
  302. * @param array $sidList
  303. * @return bool
  304. */
  305. protected function _setSidList(array $sidList)
  306. {
  307. set_cookie('sidlist', json_encode($sidList), 86400);
  308. return true;
  309. }
  310. /**
  311. * 是否是管理员
  312. * @return bool
  313. */
  314. protected function isAdmin()
  315. {
  316. $isAdmin = $this->session->userdata('isAdmin');
  317. if($isAdmin) {
  318. return true;
  319. }
  320. return false;
  321. }
  322. /**
  323. * 获取非管理员有权限的包列表
  324. * @return array|mixed
  325. */
  326. protected function getPermissionSidList()
  327. {
  328. $adminid = $this->session->userdata('adminid');
  329. if(empty($adminid)){
  330. return [-1];
  331. }
  332. $query2 = $this->db->query("SELECT sidList FROM permission WHERE adminid = {$adminid} LIMIT 1");
  333. $ret = $query2->row_array();
  334. $sidList = json_decode($ret['sidList'], 1);
  335. if(empty($ret) || empty($sidList)) {//权限错误
  336. $sidList = [-1];
  337. }
  338. return $sidList;
  339. }
  340. /**
  341. * 验证用户登陆
  342. */
  343. public function verify()
  344. {
  345. $url = rtrim($this->uri->segment(1).'/'.$this->uri->segment(2), '/');
  346. # 每次访问,刷新cookie
  347. $cacheKeys = [
  348. 'adminid',
  349. 'username',
  350. 'chinesename',
  351. 'reqenv',
  352. ];
  353. foreach ($cacheKeys as $key){
  354. $cacheV = get_cookie($key);
  355. if(empty($cacheV)){
  356. redirect('qazwsxcde');
  357. die();
  358. }
  359. set_cookie($key, $cacheV, 86400);
  360. }
  361. if($this->session->userdata('username')){
  362. if($this->session->userdata('isAdmin')){ //管理员
  363. return true;
  364. }
  365. $checkUrls = [
  366. 'payment/index',
  367. 'abnormal/moneySpinsSource',
  368. 'abnormal/upStarsLine',
  369. 'user/activityData',
  370. 'user/actionProps',
  371. 'user/actionCard',
  372. 'user/setLevel',
  373. 'user/setVipPoint',
  374. 'user/chatLock',
  375. 'user/suspendAccount',
  376. 'abnormal/moneySpinsSource',
  377. 'activity/hadd',
  378. 'activity/hedit',
  379. 'activitysta/index',
  380. 'user/clearAccount',
  381. 'user/actionusermoney',
  382. 'activity/hExitCommonCfg',
  383. 'config/polymerization',
  384. 'config/crazyBet',
  385. 'config/userGroupList',
  386. 'config/slotWeightCfg',
  387. 'permission/list',
  388. 'fermission/roleList',
  389. 'permission/role',
  390. ];
  391. if(in_array($url, $checkUrls) && !$this->checkPermission($url)){
  392. redirect('permission/forbidpage');
  393. exit;
  394. }
  395. }else{
  396. redirect('qazwsxcde');
  397. die();
  398. }
  399. }
  400. /**
  401. * 检查是否有权限
  402. */
  403. public function checkPermission($url){
  404. if($this->isAdmin()) {
  405. return true;
  406. }
  407. $role = $this->db->get_where('cmsrole', array('id' => $this->session->userdata("role")))->row_array();
  408. //内部员工
  409. if(!empty($role['is_internal'])){
  410. return true;
  411. }
  412. $permission = $this->getPermissionList();
  413. return in_array($url, $permission);
  414. }
  415. /**
  416. * 获取用户权限列表
  417. * @return array
  418. */
  419. public function getPermissionList(array $role = []) {
  420. $adminid = $this->session->userdata('adminid');
  421. if(empty($adminid)){
  422. return [];
  423. }
  424. if(empty($role)){
  425. $role = $this->db->get_where('cmsrole', array('id' => $this->session->userdata("role")))->row_array();
  426. }
  427. $permission = $role['rule'] ? unserialize($role['rule']) : [];
  428. return $permission;
  429. }
  430. /**
  431. * 统一输出返回json内容
  432. *
  433. * @access public
  434. * @date 2016-08-16
  435. * @param int $ret 状态码,0成功
  436. * @param string $msg 错误信息
  437. * @param array $data 返回数据内容
  438. * @return json;
  439. */
  440. public function response($ret = 0, $msg = '', array $data = array(),$type = false)
  441. {
  442. $result = [
  443. 'ret' => $ret,
  444. 'msg' => $msg,
  445. 'data' => $data,
  446. 'state'=> $ret ? "error" :'success'
  447. ];
  448. // header('Content-type:text/json');
  449. if($type){
  450. die(json_encode($result));
  451. }else{
  452. die(json_encode($result,JSON_NUMERIC_CHECK));
  453. }
  454. }
  455. /**
  456. * 返回空的data table 格式数据
  457. * @return array
  458. */
  459. function withNodata()
  460. {
  461. $tableData = array();
  462. $tableData['recordsTotal'] = 0;
  463. $tableData['recordsFiltered'] = 0;
  464. $tableData['data'] = array();
  465. return $tableData;
  466. }
  467. protected function getSerialStr($keyName, $data, $isVisible = true)
  468. {
  469. $visibleStr = $isVisible ? '' : "visible:false,";
  470. $str = "{
  471. ".$visibleStr."
  472. name: '".$keyName."',
  473. data: [".implode(',', $data)."]
  474. }";
  475. return $str;
  476. }
  477. protected function getSerialStrPer($keyName, $data)
  478. {
  479. $str = "{
  480. name: '".$keyName."',
  481. yAxis: 1,
  482. data: [".implode(',', $data)."],
  483. tooltip: {
  484. valueSuffix: '%'
  485. }}";
  486. return $str;
  487. }
  488. /**
  489. * 柱状图的
  490. * @param $keyName
  491. * @param $data
  492. * @return string
  493. */
  494. protected function getSerialColumnStr($keyName, $data, $stack='normal', $isVisible=true)
  495. {
  496. $visibleStr = $isVisible ? '' : "visible:false,";
  497. $str = "{
  498. type: 'column',".$visibleStr."
  499. name: '".$keyName."',
  500. data: [".implode(',', $data)."],
  501. stack: '".$stack."'
  502. }";
  503. return $str;
  504. }
  505. /**
  506. * 格式化筹码
  507. * @param $value
  508. * @return string
  509. */
  510. protected function formatChip($value)
  511. {
  512. if(1 <= abs($valueB =$value / 1000000000)) {
  513. return $valueB . 'B';
  514. }else if(1 <= abs($valueM=$value / 1000000)) {
  515. return $valueM . 'M';
  516. }else if(1 <= abs($valueK = $value / 1000)) {
  517. return $valueK . 'K';
  518. }else {
  519. return $value;
  520. }
  521. }
  522. /**
  523. * 格式化筹码
  524. * @param $value
  525. * @return string
  526. */
  527. protected function formatChipRound($value, $round=2)
  528. {
  529. if(1 <= abs($valueB = round($value / 1000000000, $round))) {
  530. return $valueB . 'B';
  531. }else if(1 <= abs($valueM=round($value / 1000000, $round))) {
  532. return $valueM . 'M';
  533. }else if(1 <= abs($valueK = round($value / 1000), $round)) {
  534. return $valueK . 'K';
  535. }else {
  536. return $value;
  537. }
  538. }
  539. /**
  540. * 获取两个时间的日期差多少天
  541. * @param $stime
  542. * @param $etime
  543. * @return float
  544. */
  545. public function betweenDays($stime, $etime)
  546. {
  547. if($stime >= $etime) {
  548. return 0;
  549. }
  550. $between = $etime - $stime;
  551. $days = ceil($between / 86400);
  552. return $days;
  553. }
  554. public function SaveJson($data,$filename,$t=0){
  555. $dir = $this->staticPath;
  556. if (!is_dir($dir))
  557. {
  558. $old = umask(0);
  559. //mkdir($dir, PRODUCTION_SERVER ? 0775 : 0777, true);
  560. mkdir($dir,0775 , true);
  561. umask($old);
  562. }
  563. $filepath = "{$dir}{$filename}";
  564. if($t==1){
  565. $json = str_replace("\/", "/", json_encode($data,32));
  566. }else{
  567. $json = json_encode($data,32);
  568. }
  569. $res = file_put_contents($filepath, $json);
  570. if(method_exists($this->common,'upToOss')){
  571. $dir = str_replace("./","",$dir);
  572. $file_path = str_replace("\\","/",FCPATH . $dir.$filename);
  573. $this->common->upToOss($dir.$filename,$file_path);
  574. }
  575. return $res;
  576. }
  577. public function AjaxContent($info){
  578. $data = array('referer' =>true, 'refresh' => 'false', 'state' => 'error', 'message' => '');
  579. foreach ($info as $key=>$row){
  580. $data[$key] = $row;
  581. }
  582. die(json_encode($data));
  583. }
  584. /**
  585. * 计算天数差
  586. * $format = 1 Y-m-d else Ymd
  587. */
  588. protected function getDays($day1, $day2, $format = 2)
  589. {
  590. $second1 = $day1;
  591. $second2 = $day2;
  592. if ($second1 < $second2) {
  593. $tmp = $second2;
  594. $second2 = $second1;
  595. $second1 = $tmp;
  596. }
  597. $days = ($second1 - $second2) / 86400;
  598. $dayList = array();
  599. for ($i=0; $i <= $days ; $i++) {
  600. if($format == 1) {
  601. $dayList[] = date('Y-m-d', $second2 + 86400*$i);
  602. }else {
  603. $dayList[] = date('Ymd', $second2 + 86400*$i);
  604. }
  605. }
  606. return $dayList;
  607. }
  608. public function getDateFromServer($postData){
  609. $data = $this->curl->req($this->_url, $postData);
  610. return json_decode($data,true);
  611. }
  612. public function httpPost($postData, $url = "")
  613. {
  614. $data = $this->curl->req($url ?: $this->_url, $postData);
  615. return json_decode($data, true);
  616. }
  617. # 编辑字段通用化
  618. protected function inputField($column,$lable , $type, $default = '', $options = '')
  619. {
  620. switch ($type){
  621. case self::$inputFieldTypeText:
  622. return $this->textField($column, $lable, $default, $options);
  623. case self::$inputFieldTypeSelector:
  624. return $this->selectorField($column, $lable, $default, $options);
  625. case self::$inputFieldTypeSelectorMultiple:
  626. return $this->selectorField($column, $lable, $default, $options, true);
  627. }
  628. }
  629. private function textField($column, $lable, $default, $placeHolder = ''){
  630. return "<div class=\"row\">
  631. <div class=\"col-sm-3 \" style=\"text-align: right;vertical-align: center\">
  632. <label class=\"form-control \" style=\"border: none\">{$lable}</label>
  633. </div>
  634. <div class=\"col-sm-5\">
  635. <input class=\" form-control\" name='{$column}' value='{$default}' placeholder='{$placeHolder}' />
  636. </div>
  637. </div>";
  638. }
  639. private function selectorField($column, $lable, $default, $options, $isMultiple = false){
  640. $multiple = '';
  641. if($isMultiple)$multiple = 'multiple';
  642. $html = '';
  643. $html .= "<div class=\"row\">
  644. <div class=\"col-sm-3 \" style=\"text-align: right;vertical-align: center\">
  645. <label class=\"form-control \" style=\"border: none\">{$lable}</label>
  646. </div>
  647. <div class=\"col-sm-5\">
  648. <select class=\"select2 form-control\" name='{$column}' {$multiple}>";
  649. $html .= "<option hidden value=''>下拉选择</option>";
  650. $options = (array)$options;
  651. foreach ($options as $k=>$v){
  652. $selected = '';
  653. if((is_array($default) && in_array($k, $default)) || ($k == $default))$selected = 'selected';
  654. $html .= "<option {$selected} value='{$k}'>{$v}({$k})</option>";
  655. }
  656. $html .= " </select>
  657. </div>
  658. </div>";
  659. return $html;
  660. }
  661. /**
  662. * Notes:获取推送配置
  663. * User: wsc
  664. * Time: 2020/11/11 9:40
  665. * @param bool $db
  666. * @return array
  667. */
  668. public function getPushConf($db=false){
  669. $tb = otable::fasebasePushConf();
  670. $key = okeys::fasebasePushConf();
  671. $key2 = okeys::fasebasePushConfByKey();//根据类型缓存
  672. $cache =oo::commonOprRedis('games')->hGetAll($key);
  673. if(empty($cache)||$db){
  674. oo::commonOprDb('slavedb')->query("set names utf8mb4");
  675. $sql = "SELECT * FROM {$tb}";
  676. $arr = oo::commonOprDb('slavedb')->getAll($sql,1);
  677. if(!empty($arr)){
  678. foreach ($arr as $v){
  679. $cache2[$v['type']] = $v['conf'];
  680. $v['conf'] = json_decode($v['conf'],true);
  681. $cache[$v['id']] = json_encode($v,256);
  682. }
  683. oo::commonOprRedis('games')->hMset($key,$cache);
  684. oo::commonOprRedis('games')->hMset($key2,$cache2);
  685. }
  686. }
  687. $cache = $cache?funs::getArrFromJsonArr($cache):[];
  688. if(!empty($cache)){
  689. // array_multisort(array_column($cache,'id'),SORT_ASC,$cache);
  690. // array_column($cache,null,'id');
  691. }
  692. return $cache;
  693. }
  694. /**
  695. * Notes:推送nsq队列
  696. * User: xwy
  697. * Time: 2022/04/08
  698. * @param string $topic 消息队列topic
  699. * @param array $body 消息队列 body 数据
  700. * @return bool 推送状态
  701. */
  702. public function sendNsqMsg($topic, $body){
  703. //目前只在测试条件下开启
  704. if(!class_exists('Nsq')){
  705. oo::logs()->debug3(['nsq 扩展不存在'],"publishNsq.log");
  706. return false;
  707. }
  708. $nsqdAddrs = $this->config->item('nsqAddress');
  709. $body = json_encode($body);
  710. $data =array_values( unpack("C*", $body));
  711. $nsq = new Nsq();
  712. $isTrue = false;
  713. foreach ($nsqdAddrs as $nsqdAddr){
  714. $isTrue = $nsq->connectNsqd([$nsqdAddr]);
  715. if($isTrue)break;
  716. }
  717. // echo "Is connect:".$isTrue;
  718. if($isTrue){
  719. $res = $nsq->publish($topic,json_encode($data));
  720. if(!$res)
  721. oo::logs()->debug3(['nsqdAddrs' => $nsqdAddrs, "msg"=>"publish failed","topic"=>$topic,"info"=>$body],"publishNsq.log");
  722. else
  723. oo::logs()->debug3(['nsqdAddrs' => $nsqdAddrs, "msg"=>"publish successed","topic"=>$topic,"info"=>$body],"publishNsq.log");
  724. $nsq->closeNsqdConnection();
  725. }else{
  726. $res = false;
  727. oo::logs()->debug3(['nsqdAddrs' => $nsqdAddrs, "msg"=>"lose connect...","topic"=>$topic,"info"=>$body],"publishNsq.log");
  728. }
  729. return $res;
  730. }
  731. # 获取导入的sheet 数组
  732. public function getExcelSheetsArray(){
  733. $file = $this->uploader->getFileInfo();
  734. $extensionType = $this->getExtensionType($file['originalName']);
  735. $xlsReader = IOFactory::createReader($extensionType);
  736. $xlsReader->setReadDataOnly(true);
  737. $xlsReader->setLoadSheetsOnly(true);
  738. $Sheets = $xlsReader->load($file['url']);
  739. $sheetsCnt = $Sheets->getSheetCount();
  740. $dataArray = [];
  741. for($i=0 ; $i< $sheetsCnt; $i++){
  742. $tmpData = $Sheets->getSheet($i)->toArray() ?? [];
  743. foreach ($tmpData as $k => $item){
  744. foreach ($item as $k1 => $value){
  745. $item[$k1] = trim($value);
  746. }
  747. $line = array_filter($item);
  748. if(empty($line))unset($tmpData[$k]);
  749. }
  750. $dataArray[$i] = $tmpData;
  751. }
  752. return $dataArray;
  753. }
  754. # 获取文件扩展对应的excel类型
  755. public function getExtensionType($fileName){
  756. $pathinfo = pathinfo($fileName);
  757. $extensionType = NULL;
  758. switch (strtolower($pathinfo['extension'])) {
  759. case 'xlsx': // Excel (OfficeOpenXML) Spreadsheet
  760. case 'xlsm': // Excel (OfficeOpenXML) Macro Spreadsheet (macros will be discarded)
  761. case 'xltx': // Excel (OfficeOpenXML) Template
  762. case 'xltm': // Excel (OfficeOpenXML) Macro Template (macros will be discarded)
  763. $extensionType = 'Excel2007';
  764. break;
  765. case 'xls': // Excel (BIFF) Spreadsheet
  766. case 'xlt': // Excel (BIFF) Template
  767. $extensionType = 'Excel5';
  768. break;
  769. case 'ods': // Open/Libre Offic Calc
  770. case 'ots': // Open/Libre Offic Calc Template
  771. $extensionType = 'OOCalc';
  772. break;
  773. case 'slk':
  774. $extensionType = 'SYLK';
  775. break;
  776. case 'xml': // Excel 2003 SpreadSheetML
  777. $extensionType = 'Excel2003XML';
  778. break;
  779. case 'gnumeric':
  780. $extensionType = 'Gnumeric';
  781. break;
  782. case 'htm':
  783. case 'html':
  784. $extensionType = 'HTML';
  785. break;
  786. case 'csv':
  787. $extensionType = 'CSV';
  788. break;
  789. default:
  790. $this->response(-1, '文件格式异常');
  791. break;
  792. }
  793. return $extensionType;
  794. }
  795. # 通过奖励名 解析奖励类型以及皮肤id
  796. public function parseRewardTypeAndSkinId($rewardName, $line = 0){
  797. #常规奖励 无皮肤
  798. if(!empty($this->rewardNames[$rewardName])){
  799. return [$this->rewardNames[$rewardName], ''];
  800. }
  801. $prizeList = oo::commonOprModel('config')->getPropsConfigFromLocal();
  802. foreach ($prizeList as $item){
  803. if(empty($item['skinList']))continue;
  804. foreach ($item['skinList'] as $skinItem){
  805. if($skinItem['name'] == $rewardName ){
  806. return [$item['id'], $skinItem['id']];
  807. }
  808. }
  809. }
  810. #判断奖励是否存在
  811. $this->response(-1, "第{$line}行,奖励或皮肤不存在:'{$rewardName}'", $prizeList);
  812. }
  813. # 通过分组名,解析分组id
  814. public function parseShushuGroups($shushuGroups,$line = 0){
  815. if(empty($shushuGroups))$this->response(-1, $line.'行,数数分组为空');
  816. if(is_string($shushuGroups)){
  817. $shushuGroups = strtr($shushuGroups,[',' => ',']);
  818. $shushuGroups = explode(',', $shushuGroups);
  819. }
  820. $allGroups = array_column(oo::commonOprModel('config')->getUserGroupConfigByCid(5),'name','id');
  821. $shushuGroupIds = [];
  822. foreach ($shushuGroups as $shushuGroup){
  823. if(!in_array($shushuGroup, $allGroups))$this->response(-1, "第{$line}行,数数分组不存在:'{$shushuGroup}'");
  824. $shushuGroupIds[] = array_search( $shushuGroup, $allGroups);
  825. }
  826. return $shushuGroupIds;
  827. }
  828. # 解析分层映射的每层idx
  829. public function getGroupMappingIdx($type, $val, $parentsKey = 0){
  830. $this->actGroupMapping[$type] = $this->actGroupMapping[$type] ?? [];
  831. $this->actGroupMapping[$type][$parentsKey] = $this->actGroupMapping[$type][$parentsKey] ?? [];
  832. if(empty($this->actGroupMapping[$type][$parentsKey][$val])){
  833. $this->actGroupMapping[$type][$parentsKey][$val] = count($this->actGroupMapping[$type][$parentsKey]) + 1;
  834. }
  835. return intval($this->actGroupMapping[$type][$parentsKey][$val]);
  836. }
  837. public function parseLineRewards(array $rewards, $line = 0){
  838. $rewardsTemp = [];
  839. $i = 0;
  840. while($i < count($rewards)){
  841. $reward = $rewards[$i++];
  842. $isFixNum = $rewards[$i++];
  843. $rewardNum = intval($rewards[$i++]);
  844. if(!empty($reward)){
  845. if(!in_array($reward, $this->multiNumTypeReward))$isFixNum = '是'; #非金币奖励,全部固定值奖励
  846. $isFixNum = ($isFixNum == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
  847. if(empty($rewardNum))self::response(-1, "第{$line}行,奖励数为空", $rewards);
  848. list($type, $skin) = $this->parseRewardTypeAndSkinId($reward, $line);
  849. $currentId = count($rewardsTemp)+1;
  850. $rewardsTemp[] = [
  851. 'id' => $currentId,
  852. "num" => $rewardNum,
  853. "type" => $type,
  854. "rtype" => $isFixNum,
  855. "skin" => $skin
  856. ];
  857. }
  858. }
  859. return $rewardsTemp;
  860. }
  861. public function prizesShowHtml( array $prizes): string
  862. {
  863. $htmlStr = '<div>';
  864. foreach ($prizes as $prize) {
  865. $prizeStr = $this->singlePrizeHtml($prize);
  866. $htmlStr .= '<button style="margin-bottom: 5px" class="btn btn-outline btn-info btn-sm">' . $prizeStr . '</button><br>';
  867. }
  868. $htmlStr .= '</div>';
  869. return $htmlStr;
  870. }
  871. public function singlePrizeHtml( array $prizes): string
  872. {
  873. $this->propsConfig = $this->propsConfig ?? oo::commonOprModel('config')->getPropsConfigFromLocal() ;
  874. $name = '';
  875. $prizeTypeInfo = [];
  876. foreach ($this->propsConfig as $oneProp) {
  877. if ($oneProp['id'] == $prizes['propsId']) {
  878. $prizeTypeInfo = $oneProp;
  879. if (empty($prizes['skin'])) {
  880. $name = $oneProp['name'];
  881. break;
  882. }
  883. foreach ($oneProp['skinList'] as $oneSkin) {
  884. if ($prizes['skin'] == $oneSkin['id']) {
  885. $name = $oneSkin['name'];
  886. break;
  887. }
  888. }
  889. }
  890. }
  891. $name .= ':' . $prizes['num'] ;
  892. if($prizeTypeInfo['type'] == 'act'){
  893. $name .= '分钟';
  894. }else if($prizes['rtype'] == 2){
  895. $name .= '倍';
  896. }
  897. return $name ;
  898. }
  899. }