123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993 |
- <?php
- require_once "application/config/common.php";
- require_once "application/models/Hashids.php";
- /**
- * 自定义核心类
- */
- class MY_Controller extends CI_Controller
- {
- protected $_wenenv = 'webenv';//网站的环境 内网/外网
- protected $env = 1;//默认为1,外网
- protected $oldAnPackageList = [];
- protected $oldIosPackageList = [];
- protected $pageConfig = array(
- 'first_tag_open' => '<li>',
- 'first_tag_close' => '</li>',
- 'last_tag_open' => '<li>',
- 'last_tag_close' => '</li>',
- 'next_tag_open' => '<li>',
- 'next_tag_close' => '</li>',
- 'prev_tag_open' => '<li>',
- 'prev_tag_close' => '</li>',
- 'cur_tag_open' => "<li class='active'><a hef='#'>",
- 'cur_tag_close' => "</a></li>",
- 'num_tag_open' => "<li>",
- 'num_tag_close' => "</li>",
- );
- protected $androidPackageList = [ 1=>'安卓',2=>'IOS'];
- protected $iosPackageList = [];//10 => '泰语(th2)'
- public $_langList;
- protected $gameList = [1=>'德州场',3 => '奥马哈场', 4 => '百人场'];
- protected $texasBlindList = [500, 1000, 2500, 5000, 10000, 50000, 100000, '私人房'];//德州开放场次的盲注列表
- protected $omahaBlindList = [2000, 5000, 10000, 50000];//奥马哈开放的场次盲注列表
- public static $inputFieldTypeText = 'text';
- public static $inputFieldTypeSelector = 'selector';
- public static $inputFieldTypeSelectorMultiple = 'selectorMultiple';
- public $staticPath = "./public/game/config/";
- public $propsConfig = null;
- public $_url = "";
- public $actGroupMapping = [];
- public $multiNumTypeReward = [
- '随机金卡',
- '随机星光卡',
- '随机限时金卡',
- '随机限时星光卡',
- '金币'
- ];
- public $rewardNames = [
- "木质宝箱" =>1 ,
- "白银宝箱" =>2 ,
- "黄金宝箱" =>3 ,
- "魔幻宝箱" =>4 ,
- "宠物经验" =>8 ,
- "宠物食物" =>9 ,
- "随机金卡" =>13 ,
- "金币" =>14 ,
- "体力" =>15 ,
- "小丑卡" =>18 ,
- "通行证经验" =>38 ,
- "拼图碎片" =>44 ,
- "玛雅转盘代币" =>45 ,
- "随机星光卡" =>50 ,
- "随机限时金卡" =>49 ,
- "随机限时星光卡" =>50 ,
- "幸运小丑代币" =>51 ,
- "幸运狐狸代币" =>51 ,
- "超级扭蛋代币" =>60,
- "随机公会表情" =>61,
- "皮纳塔代币" =>62,
- "塔罗牌代币" =>70,
- "推币机代币" =>72,
- "暴走兔子代币" => 74,
- "星图代币" => 77,
- "西部矿洞代币" => 79,
- ];
- public $needSkinRewards = [
- "皮肤宝箱" =>19 ,
- "建筑大师活动" =>25 ,
- "气球活动" =>26 ,
- "体力加速活动" =>27 ,
- "金币大爆炸活动" =>28 ,
- "疯狂加倍" =>31 ,
- "建筑打折" =>32 ,
- "卡片爆炸" =>33 ,
- "商场优惠" =>34 ,
- "超级收集活动" =>35 ,
- "超级气球活动" =>36 ,
- "首冲优惠" =>37 ,
- "通行证倍率活动" =>39 ,
- "收集翻倍活动" =>40 ,
- "四选一活动" =>41 ,
- "金币老虎机活动" =>43 ,
- "疯狂的卡组" =>46 ,
- "疯狂建造活动" =>52,
- "超级攻击活动" =>53,
- "回归签到" =>54,
- "完美偷袭活动" =>55,
- "小丑卡保底值" =>56,
- "完美打活动" =>57,
- "皮肤宝箱最大体力" =>58,
- "richking最大金币" =>59,
- "幸运骰子活动券" =>71,
- "Jackpot老虎机活动券" =>73,
- "每日成就任务道具券" => 75,
- "付费成就活动道具券" => 76,
- "推币机道具券" => 78,
- ];
- public function __construct()
- {
- parent::__construct();
- $this->load->helper('cookie');
- $this->load->helper('url');
- $this->load->library('session');
- // ini_set("session.gc_maxlifetime",86400);
- define('IS_POST',strtolower($_SERVER["REQUEST_METHOD"]) == 'post');//判断是否是post方法
- define('IS_GET',strtolower($_SERVER["REQUEST_METHOD"]) == 'get');//判断是否是get方法
- //判断model是否存在
- if (file_exists(APPPATH.'models/Common.php'))
- {
- $this->load->model('common');
- }
- $curUrl = strtolower(uri_string());
- if(!($curUrl == 'robot/main' || $curUrl == 'robot/makerobotrule')){
- $this->verify();
- }
- $this->load->model('oo');
- if(IS_POST && !empty($curUrl)){
- $url = current_url();
- $reason = '';
- $postData = $this->input->post();
- oo::logs()->adminlog($reason,$url,$curUrl,$postData);
- }
- $this->_url = $this->config->item('officialUrl');
- $this->_langList = oo::cfg('lang')['en_zh'];
- }
- /**
- * 数据导出
- * @param $header [ $k => $text] 表头
- * @param $listData [ [$k => $v ],[$k => $v]...] 数据
- * @return bool
- */
- protected function exportData(array $header,array $listData, $fileName){
- $objPHPExcel = new PHPExcel();
- //处理表头
- $char = 'A';
- foreach ($header as $v) {
- $objPHPExcel->getActiveSheet()->setCellValue($char++.'1', $v);
- }
- //处理数据
- $i = 2;
- foreach ($listData as $row) {
- $char = 'A';
- foreach ($header as $k => $t){
- $objPHPExcel->getActiveSheet()->setCellValue($char++.$i, $row[$k] ?? '');
- }
- $i++;
- }
- $objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
- $outPutFileName = $fileName . date('Y-m-d');
- $objPHPExcel->setActiveSheetIndex(0);
- header('Content-Type: applicationnd.ms-excel');
- header('Content-Disposition: attachment;filename="'.$outPutFileName.'.xls"');
- header('Cache-Control: max-age=0');
- $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel2007');
- $objWriter->save('php://output');
- exit;
- }
- /**
- * 获取所有的sid
- * @return array
- */
- protected function getAllSid()
- {
- $oldAnSid = array_keys($this->oldAnPackageList);
- $oldIosSid = array_keys($this->oldIosPackageList);
- $anSid = array_keys($this->androidPackageList);
- $iosSid = array_keys($this->iosPackageList);
- $sidList = array_merge($oldAnSid, $oldIosSid, $anSid, $iosSid);
- return $sidList;
- }
- /**
- * 获取td数据
- * @return array
- */
- public function get_td_array($table) {
- $table = preg_replace("'<table[^>]*?>'si","",$table);
- $table = preg_replace("'<tr[^>]*?>'si","",$table);
- $table = preg_replace("'<td[^>]*?>'si","",$table);
- $table = str_replace("</tr>","{tr}",$table);
- $table = str_replace("</td>","{td}",$table);
- //去掉 HTML 标记
- $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);
- //去掉空白字符
- $table = preg_replace("'([rn])[s]+'","",$table);
- $table = str_replace(" ","",$table);
- $table = str_replace(" ","",$table);
- $table = str_replace("\n","",$table);
- $table = str_replace("","0",$table);
- //去掉删除
- $table = str_replace("删除{td}", "", $table);
- $table = explode('{tr}', $table);
- array_pop($table);
- print_r($table);
- unset($table[0]);
- foreach ($table as $key=>$tr) {
- $tds = explode('{td}', $tr);
- array_pop($tds);
- $td_array[] = $tds;
- }
- return $td_array;
- }
- /**
- * 是否选了所有包
- * @param $sidList
- * @return bool
- */
- protected function isAllSid($sidList)
- {
- if(in_array(999, $sidList)) {
- return true;
- }
- return false;
- }
- /**
- * 获取sid列表
- * @return array|mixed
- */
- protected function _getSidList()
- {
- $temp = get_cookie('sidlist');
- if(!is_array($temp)){
- $sidList = json_decode($temp, 1);
- }
-
- if(empty($sidList)) {
- if($this->isAdmin()) {
- $sidList = [1,2];
- }else {
- $sidList = $this->getPermissionSidList();
- }
- set_cookie('sidlist', json_encode($sidList), 86400);
- }
- //判断如果全选了所有的sid,则把sid置成999
- $diff = array_diff([1,2], $sidList);
- if(empty($diff)) {
- $sidList = [1,2];
- }
- return $sidList;
- }
- /**
- * 获取所以包名列表
- * @return array
- */
- protected function __getSidNameList()
- {
- $anListTmp = $this->oldAnPackageList + $this->androidPackageList;
- $iosListTmp = $this->oldIosPackageList + $this->iosPackageList;
- if(!$this->isAdmin()) {
- $anList = $iosList = [];
- foreach ($this->getPermissionSidList() as $sid) {
- if($sid % 2 == 0) {
- $iosList[$sid] = $iosListTmp[$sid];
- }else {
- $anList[$sid] = $anListTmp[$sid];
- }
- }
- }else {
- $anList = $anListTmp;
- $iosList = $iosListTmp;
- }
- $list = [];
- foreach ($anList as $ka => $va) {
- $list[$ka] = '安卓'.$va;
- }
- foreach ($iosList as $ki => $vi) {
- $list[$ki] = '苹果'.$vi;
- }
- return $list;
- }
- /**
- * 选择的包名列表
- * @return array
- */
- protected function __getSelectSidNameList()
- {
- $sidList = $this->_getSidList();
- if(in_array(999, $sidList)) {
- return [999=>'全部'];
- }
- $list = [];
- if(!empty($sidList)) {
- $allSidNameList = $this->__getSidNameList();
- foreach ($sidList as $sid) {
- $list[$sid] = $allSidNameList[$sid];
- }
- }else {
- $list = [0 =>'无'];
- }
- return $list;
- }
- /**
- * 设置sidlist
- * @param array $sidList
- * @return bool
- */
- protected function _setSidList(array $sidList)
- {
- set_cookie('sidlist', json_encode($sidList), 86400);
- return true;
- }
- /**
- * 是否是管理员
- * @return bool
- */
- protected function isAdmin()
- {
- $isAdmin = $this->session->userdata('isAdmin');
- if($isAdmin) {
- return true;
- }
- return false;
- }
- /**
- * 获取非管理员有权限的包列表
- * @return array|mixed
- */
- protected function getPermissionSidList()
- {
- $adminid = $this->session->userdata('adminid');
- if(empty($adminid)){
- return [-1];
- }
- $query2 = $this->db->query("SELECT sidList FROM permission WHERE adminid = {$adminid} LIMIT 1");
- $ret = $query2->row_array();
- $sidList = json_decode($ret['sidList'], 1);
- if(empty($ret) || empty($sidList)) {//权限错误
- $sidList = [-1];
- }
- return $sidList;
- }
- /**
- * 验证用户登陆
- */
- public function verify()
- {
- $url = rtrim($this->uri->segment(1).'/'.$this->uri->segment(2), '/');
- # 每次访问,刷新cookie
- $cacheKeys = [
- 'adminid',
- 'username',
- 'chinesename',
- 'reqenv',
- ];
- foreach ($cacheKeys as $key){
- $cacheV = get_cookie($key);
- if(empty($cacheV)){
- redirect('qazwsxcde');
- die();
- }
- set_cookie($key, $cacheV, 86400);
- }
- if($this->session->userdata('username')){
- if($this->session->userdata('isAdmin')){ //管理员
- return true;
- }
- $checkUrls = [
- 'payment/index',
- 'abnormal/moneySpinsSource',
- 'abnormal/upStarsLine',
- 'user/activityData',
- 'user/actionProps',
- 'user/actionCard',
- 'user/setLevel',
- 'user/setVipPoint',
- 'user/chatLock',
- 'user/suspendAccount',
- 'abnormal/moneySpinsSource',
- 'activity/hadd',
- 'activity/hedit',
- 'activitysta/index',
- 'user/clearAccount',
- 'user/actionusermoney',
- 'activity/hExitCommonCfg',
- 'config/polymerization',
- 'config/crazyBet',
- 'config/userGroupList',
- 'config/slotWeightCfg',
- 'permission/list',
- 'fermission/roleList',
- 'permission/role',
- ];
- if(in_array($url, $checkUrls) && !$this->checkPermission($url)){
- redirect('permission/forbidpage');
- exit;
- }
- }else{
- redirect('qazwsxcde');
- die();
- }
- }
- /**
- * 检查是否有权限
- */
- public function checkPermission($url){
- if($this->isAdmin()) {
- return true;
- }
- $role = $this->db->get_where('cmsrole', array('id' => $this->session->userdata("role")))->row_array();
- //内部员工
- if(!empty($role['is_internal'])){
- return true;
- }
- $permission = $this->getPermissionList();
- return in_array($url, $permission);
- }
- /**
- * 获取用户权限列表
- * @return array
- */
- public function getPermissionList(array $role = []) {
- $adminid = $this->session->userdata('adminid');
- if(empty($adminid)){
- return [];
- }
- if(empty($role)){
- $role = $this->db->get_where('cmsrole', array('id' => $this->session->userdata("role")))->row_array();
- }
- $permission = $role['rule'] ? unserialize($role['rule']) : [];
- return $permission;
- }
- /**
- * 统一输出返回json内容
- *
- * @access public
- * @date 2016-08-16
- * @param int $ret 状态码,0成功
- * @param string $msg 错误信息
- * @param array $data 返回数据内容
- * @return json;
- */
- public function response($ret = 0, $msg = '', array $data = array(),$type = false)
- {
- $result = [
- 'ret' => $ret,
- 'msg' => $msg,
- 'data' => $data,
- 'state'=> $ret ? "error" :'success'
- ];
- // header('Content-type:text/json');
- if($type){
- die(json_encode($result));
- }else{
- die(json_encode($result,JSON_NUMERIC_CHECK));
- }
- }
- /**
- * 返回空的data table 格式数据
- * @return array
- */
- function withNodata()
- {
- $tableData = array();
- $tableData['recordsTotal'] = 0;
- $tableData['recordsFiltered'] = 0;
- $tableData['data'] = array();
- return $tableData;
- }
- protected function getSerialStr($keyName, $data, $isVisible = true)
- {
- $visibleStr = $isVisible ? '' : "visible:false,";
- $str = "{
- ".$visibleStr."
- name: '".$keyName."',
- data: [".implode(',', $data)."]
- }";
- return $str;
- }
- protected function getSerialStrPer($keyName, $data)
- {
- $str = "{
- name: '".$keyName."',
- yAxis: 1,
- data: [".implode(',', $data)."],
- tooltip: {
- valueSuffix: '%'
- }}";
- return $str;
- }
- /**
- * 柱状图的
- * @param $keyName
- * @param $data
- * @return string
- */
- protected function getSerialColumnStr($keyName, $data, $stack='normal', $isVisible=true)
- {
- $visibleStr = $isVisible ? '' : "visible:false,";
- $str = "{
- type: 'column',".$visibleStr."
- name: '".$keyName."',
- data: [".implode(',', $data)."],
- stack: '".$stack."'
- }";
- return $str;
- }
- /**
- * 格式化筹码
- * @param $value
- * @return string
- */
- protected function formatChip($value)
- {
- if(1 <= abs($valueB =$value / 1000000000)) {
- return $valueB . 'B';
- }else if(1 <= abs($valueM=$value / 1000000)) {
- return $valueM . 'M';
- }else if(1 <= abs($valueK = $value / 1000)) {
- return $valueK . 'K';
- }else {
- return $value;
- }
- }
- /**
- * 格式化筹码
- * @param $value
- * @return string
- */
- protected function formatChipRound($value, $round=2)
- {
- if(1 <= abs($valueB = round($value / 1000000000, $round))) {
- return $valueB . 'B';
- }else if(1 <= abs($valueM=round($value / 1000000, $round))) {
- return $valueM . 'M';
- }else if(1 <= abs($valueK = round($value / 1000), $round)) {
- return $valueK . 'K';
- }else {
- return $value;
- }
- }
- /**
- * 获取两个时间的日期差多少天
- * @param $stime
- * @param $etime
- * @return float
- */
- public function betweenDays($stime, $etime)
- {
- if($stime >= $etime) {
- return 0;
- }
- $between = $etime - $stime;
- $days = ceil($between / 86400);
- return $days;
- }
- public function SaveJson($data,$filename,$t=0){
- $dir = $this->staticPath;
- if (!is_dir($dir))
- {
- $old = umask(0);
- //mkdir($dir, PRODUCTION_SERVER ? 0775 : 0777, true);
- mkdir($dir,0775 , true);
- umask($old);
- }
- $filepath = "{$dir}{$filename}";
- if($t==1){
- $json = str_replace("\/", "/", json_encode($data,32));
- }else{
- $json = json_encode($data,32);
- }
- $res = file_put_contents($filepath, $json);
- if(method_exists($this->common,'upToOss')){
- $dir = str_replace("./","",$dir);
- $file_path = str_replace("\\","/",FCPATH . $dir.$filename);
- $this->common->upToOss($dir.$filename,$file_path);
- }
- return $res;
- }
- public function AjaxContent($info){
- $data = array('referer' =>true, 'refresh' => 'false', 'state' => 'error', 'message' => '');
- foreach ($info as $key=>$row){
- $data[$key] = $row;
- }
- die(json_encode($data));
- }
- /**
- * 计算天数差
- * $format = 1 Y-m-d else Ymd
- */
- protected function getDays($day1, $day2, $format = 2)
- {
- $second1 = $day1;
- $second2 = $day2;
- if ($second1 < $second2) {
- $tmp = $second2;
- $second2 = $second1;
- $second1 = $tmp;
- }
- $days = ($second1 - $second2) / 86400;
- $dayList = array();
- for ($i=0; $i <= $days ; $i++) {
- if($format == 1) {
- $dayList[] = date('Y-m-d', $second2 + 86400*$i);
- }else {
- $dayList[] = date('Ymd', $second2 + 86400*$i);
- }
- }
- return $dayList;
- }
- public function getDateFromServer($postData){
- $data = $this->curl->req($this->_url, $postData);
- return json_decode($data,true);
- }
- public function httpPost($postData, $url = "")
- {
- $data = $this->curl->req($url ?: $this->_url, $postData);
- return json_decode($data, true);
- }
- # 编辑字段通用化
- protected function inputField($column,$lable , $type, $default = '', $options = '')
- {
- switch ($type){
- case self::$inputFieldTypeText:
- return $this->textField($column, $lable, $default, $options);
- case self::$inputFieldTypeSelector:
- return $this->selectorField($column, $lable, $default, $options);
- case self::$inputFieldTypeSelectorMultiple:
- return $this->selectorField($column, $lable, $default, $options, true);
- }
- }
- private function textField($column, $lable, $default, $placeHolder = ''){
- return "<div class=\"row\">
- <div class=\"col-sm-3 \" style=\"text-align: right;vertical-align: center\">
- <label class=\"form-control \" style=\"border: none\">{$lable}</label>
- </div>
- <div class=\"col-sm-5\">
- <input class=\" form-control\" name='{$column}' value='{$default}' placeholder='{$placeHolder}' />
- </div>
- </div>";
- }
- private function selectorField($column, $lable, $default, $options, $isMultiple = false){
- $multiple = '';
- if($isMultiple)$multiple = 'multiple';
- $html = '';
- $html .= "<div class=\"row\">
- <div class=\"col-sm-3 \" style=\"text-align: right;vertical-align: center\">
- <label class=\"form-control \" style=\"border: none\">{$lable}</label>
- </div>
- <div class=\"col-sm-5\">
- <select class=\"select2 form-control\" name='{$column}' {$multiple}>";
- $html .= "<option hidden value=''>下拉选择</option>";
- $options = (array)$options;
- foreach ($options as $k=>$v){
- $selected = '';
- if((is_array($default) && in_array($k, $default)) || ($k == $default))$selected = 'selected';
- $html .= "<option {$selected} value='{$k}'>{$v}({$k})</option>";
- }
- $html .= " </select>
- </div>
- </div>";
- return $html;
- }
- /**
- * Notes:获取推送配置
- * User: wsc
- * Time: 2020/11/11 9:40
- * @param bool $db
- * @return array
- */
- public function getPushConf($db=false){
- $tb = otable::fasebasePushConf();
- $key = okeys::fasebasePushConf();
- $key2 = okeys::fasebasePushConfByKey();//根据类型缓存
- $cache =oo::commonOprRedis('games')->hGetAll($key);
- if(empty($cache)||$db){
- oo::commonOprDb('slavedb')->query("set names utf8mb4");
- $sql = "SELECT * FROM {$tb}";
- $arr = oo::commonOprDb('slavedb')->getAll($sql,1);
- if(!empty($arr)){
- foreach ($arr as $v){
- $cache2[$v['type']] = $v['conf'];
- $v['conf'] = json_decode($v['conf'],true);
- $cache[$v['id']] = json_encode($v,256);
- }
- oo::commonOprRedis('games')->hMset($key,$cache);
- oo::commonOprRedis('games')->hMset($key2,$cache2);
- }
- }
- $cache = $cache?funs::getArrFromJsonArr($cache):[];
- if(!empty($cache)){
- // array_multisort(array_column($cache,'id'),SORT_ASC,$cache);
- // array_column($cache,null,'id');
- }
- return $cache;
- }
- /**
- * Notes:推送nsq队列
- * User: xwy
- * Time: 2022/04/08
- * @param string $topic 消息队列topic
- * @param array $body 消息队列 body 数据
- * @return bool 推送状态
- */
- public function sendNsqMsg($topic, $body){
- //目前只在测试条件下开启
- if(!class_exists('Nsq')){
- oo::logs()->debug3(['nsq 扩展不存在'],"publishNsq.log");
- return false;
- }
- $nsqdAddrs = $this->config->item('nsqAddress');
- $body = json_encode($body);
- $data =array_values( unpack("C*", $body));
- $nsq = new Nsq();
- $isTrue = false;
- foreach ($nsqdAddrs as $nsqdAddr){
- $isTrue = $nsq->connectNsqd([$nsqdAddr]);
- if($isTrue)break;
- }
- // echo "Is connect:".$isTrue;
- if($isTrue){
- $res = $nsq->publish($topic,json_encode($data));
- if(!$res)
- oo::logs()->debug3(['nsqdAddrs' => $nsqdAddrs, "msg"=>"publish failed","topic"=>$topic,"info"=>$body],"publishNsq.log");
- else
- oo::logs()->debug3(['nsqdAddrs' => $nsqdAddrs, "msg"=>"publish successed","topic"=>$topic,"info"=>$body],"publishNsq.log");
- $nsq->closeNsqdConnection();
- }else{
- $res = false;
- oo::logs()->debug3(['nsqdAddrs' => $nsqdAddrs, "msg"=>"lose connect...","topic"=>$topic,"info"=>$body],"publishNsq.log");
- }
- return $res;
- }
- # 获取导入的sheet 数组
- public function getExcelSheetsArray(){
- $file = $this->uploader->getFileInfo();
- $extensionType = $this->getExtensionType($file['originalName']);
- $xlsReader = IOFactory::createReader($extensionType);
- $xlsReader->setReadDataOnly(true);
- $xlsReader->setLoadSheetsOnly(true);
- $Sheets = $xlsReader->load($file['url']);
- $sheetsCnt = $Sheets->getSheetCount();
- $dataArray = [];
- for($i=0 ; $i< $sheetsCnt; $i++){
- $tmpData = $Sheets->getSheet($i)->toArray() ?? [];
- foreach ($tmpData as $k => $item){
- foreach ($item as $k1 => $value){
- $item[$k1] = trim($value);
- }
- $line = array_filter($item);
- if(empty($line))unset($tmpData[$k]);
- }
- $dataArray[$i] = $tmpData;
- }
- return $dataArray;
- }
- # 获取文件扩展对应的excel类型
- public function getExtensionType($fileName){
- $pathinfo = pathinfo($fileName);
- $extensionType = NULL;
- switch (strtolower($pathinfo['extension'])) {
- case 'xlsx': // Excel (OfficeOpenXML) Spreadsheet
- case 'xlsm': // Excel (OfficeOpenXML) Macro Spreadsheet (macros will be discarded)
- case 'xltx': // Excel (OfficeOpenXML) Template
- case 'xltm': // Excel (OfficeOpenXML) Macro Template (macros will be discarded)
- $extensionType = 'Excel2007';
- break;
- case 'xls': // Excel (BIFF) Spreadsheet
- case 'xlt': // Excel (BIFF) Template
- $extensionType = 'Excel5';
- break;
- case 'ods': // Open/Libre Offic Calc
- case 'ots': // Open/Libre Offic Calc Template
- $extensionType = 'OOCalc';
- break;
- case 'slk':
- $extensionType = 'SYLK';
- break;
- case 'xml': // Excel 2003 SpreadSheetML
- $extensionType = 'Excel2003XML';
- break;
- case 'gnumeric':
- $extensionType = 'Gnumeric';
- break;
- case 'htm':
- case 'html':
- $extensionType = 'HTML';
- break;
- case 'csv':
- $extensionType = 'CSV';
- break;
- default:
- $this->response(-1, '文件格式异常');
- break;
- }
- return $extensionType;
- }
- # 通过奖励名 解析奖励类型以及皮肤id
- public function parseRewardTypeAndSkinId($rewardName, $line = 0){
- #常规奖励 无皮肤
- if(!empty($this->rewardNames[$rewardName])){
- return [$this->rewardNames[$rewardName], ''];
- }
- $prizeList = oo::commonOprModel('config')->getPropsConfigFromLocal();
- foreach ($prizeList as $item){
- if(empty($item['skinList']))continue;
- foreach ($item['skinList'] as $skinItem){
- if($skinItem['name'] == $rewardName ){
- return [$item['id'], $skinItem['id']];
- }
- }
- }
- #判断奖励是否存在
- $this->response(-1, "第{$line}行,奖励或皮肤不存在:'{$rewardName}'", $prizeList);
- }
- # 通过分组名,解析分组id
- public function parseShushuGroups($shushuGroups,$line = 0){
- if(empty($shushuGroups))$this->response(-1, $line.'行,数数分组为空');
- if(is_string($shushuGroups)){
- $shushuGroups = strtr($shushuGroups,[',' => ',']);
- $shushuGroups = explode(',', $shushuGroups);
- }
- $allGroups = array_column(oo::commonOprModel('config')->getUserGroupConfigByCid(5),'name','id');
- $shushuGroupIds = [];
- foreach ($shushuGroups as $shushuGroup){
- if(!in_array($shushuGroup, $allGroups))$this->response(-1, "第{$line}行,数数分组不存在:'{$shushuGroup}'");
- $shushuGroupIds[] = array_search( $shushuGroup, $allGroups);
- }
- return $shushuGroupIds;
- }
- # 解析分层映射的每层idx
- public function getGroupMappingIdx($type, $val, $parentsKey = 0){
- $this->actGroupMapping[$type] = $this->actGroupMapping[$type] ?? [];
- $this->actGroupMapping[$type][$parentsKey] = $this->actGroupMapping[$type][$parentsKey] ?? [];
- if(empty($this->actGroupMapping[$type][$parentsKey][$val])){
- $this->actGroupMapping[$type][$parentsKey][$val] = count($this->actGroupMapping[$type][$parentsKey]) + 1;
- }
- return intval($this->actGroupMapping[$type][$parentsKey][$val]);
- }
- public function parseLineRewards(array $rewards, $line = 0){
- $rewardsTemp = [];
- $i = 0;
- while($i < count($rewards)){
- $reward = $rewards[$i++];
- $isFixNum = $rewards[$i++];
- $rewardNum = intval($rewards[$i++]);
- if(!empty($reward)){
- if(!in_array($reward, $this->multiNumTypeReward))$isFixNum = '是'; #非金币奖励,全部固定值奖励
- $isFixNum = ($isFixNum == '是') ? 1 : 2;#固定值奖励 1 按等级取值 2
- if(empty($rewardNum))self::response(-1, "第{$line}行,奖励数为空", $rewards);
- list($type, $skin) = $this->parseRewardTypeAndSkinId($reward, $line);
- $currentId = count($rewardsTemp)+1;
- $rewardsTemp[] = [
- 'id' => $currentId,
- "num" => $rewardNum,
- "type" => $type,
- "rtype" => $isFixNum,
- "skin" => $skin
- ];
- }
- }
- return $rewardsTemp;
- }
- public function prizesShowHtml( array $prizes): string
- {
- $htmlStr = '<div>';
- foreach ($prizes as $prize) {
- $prizeStr = $this->singlePrizeHtml($prize);
- $htmlStr .= '<button style="margin-bottom: 5px" class="btn btn-outline btn-info btn-sm">' . $prizeStr . '</button><br>';
- }
- $htmlStr .= '</div>';
- return $htmlStr;
- }
- public function singlePrizeHtml( array $prizes): string
- {
- $this->propsConfig = $this->propsConfig ?? oo::commonOprModel('config')->getPropsConfigFromLocal() ;
- $name = '';
- $prizeTypeInfo = [];
- foreach ($this->propsConfig as $oneProp) {
- if ($oneProp['id'] == $prizes['propsId']) {
- $prizeTypeInfo = $oneProp;
- if (empty($prizes['skin'])) {
- $name = $oneProp['name'];
- break;
- }
- foreach ($oneProp['skinList'] as $oneSkin) {
- if ($prizes['skin'] == $oneSkin['id']) {
- $name = $oneSkin['name'];
- break;
- }
- }
- }
- }
- $name .= ':' . $prizes['num'] ;
- if($prizeTypeInfo['type'] == 'act'){
- $name .= '分钟';
- }else if($prizes['rtype'] == 2){
- $name .= '倍';
- }
- return $name ;
- }
- }
|