Преглед изворни кода

Merge remote-tracking branch 'origin/dev' into dev

Sven_x пре 1 година
родитељ
комит
a64418d39e

+ 4 - 0
application/config/menu.php

@@ -313,6 +313,10 @@ $config['menu'] = [
                         "t" => "推金币收集物概率配置",
                         "url" => "activity/coinPushPro",
                     ],
+                    [
+                        "t"=>"概率干预修正区间",
+                        "url"=>"slot/ceProConf",
+                    ],
                 ]
             ],
             [

+ 166 - 52
application/controllers/Slot.php

@@ -14,6 +14,7 @@ class Slot extends MY_Controller
     private $_role_title3 =['关卡','攻击<br/>(权重)','偷袭<br/>(权重)','体力<br/>(权重)','护盾<br/>(权重)','金币<br/>(权重)','金币袋<br/>(权重)','收集物<br/>(权重)','事件牌<br/>(权重)','万能福<br/>(权重)'];
 
     private $treasurepro_title = ['关卡','转盘','小王子*3','狐狸*3','小王子*2','王冠*3','小王子*1','黑桃*3','红桃*3','方块*3','黑桃+红桃+方块','没有奖励','转盘1','转盘2','转盘3','转盘4','转盘5','转盘6','转盘7'];
+    private $editUserList = [];
 
     public function __construct()
     {
@@ -249,116 +250,207 @@ class Slot extends MY_Controller
 
 
     //老虎机权重配置
-    public function realGroupWeights($gid,$type=1, $page = 0)
+    public function realGroupWeights($gid, $type = 1, $page = 0, $ceProb = "weight")
     {
         $length = 50;
-        $start = (ceil($page/$length)) * $length;
         $title = $this->_role_title3;
-        $tb = otable::realSlotWeightGroupsCfg();
-        $where = " where gid='{$gid}' and type='{$type}' ";
-        $sql = "SELECT * from {$tb} {$where} LIMIT {$start},{$length}";
-        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
-        $arr = [];
-        foreach ($rs as $k=>$v){
-            $arr[$v['levelId']] = json_decode($v['slotpro'],true);
-        }
-        $sql = "SELECT COUNT(*) as num from {$tb} {$where} ";
-        $rs = oo::commonOprDb('slavedb')->getOne($sql,1);
-        $retData = [
-            'total'=>$rs['num'],
-            'data'=>$arr,
-        ];
 
-        if($retData['total'] == 0){
-            $list = [];
-        }else{
-            $list = $retData['data'];
+        switch ($ceProb) {
+            case "weight":
+                list("total" => $total, "list" => $list) = self::groupWeightList($gid, $type, $page, $length);
+                break;
+            case "ceProb":
+                list("total" => $total, "list" => $list) = self::ceProConfList($gid, $type);
+                break;
+            default:
+                $total = 0;
+                $list = [];
+                break;
         }
+
         $data['title'] = $title;
         $data['list'] = $list;
-        $data['total'] = $retData['total'];
+        $data['total'] = $total;
         $data['page'] = $page/50;
         $data['editUserList'] = $this->editUserList;
         $pageConfig = $this->pageConfig;
         $pageConfig['base_url'] = base_url('#slot/realGroupWeights/'.$gid."/".$type);
-        $pageConfig['total_rows'] = $data['total'];
+        $pageConfig['total_rows'] = $total;
         $pageConfig['per_page'] = $length;
         $this->pagination->initialize($pageConfig);
         $pageurl = $this->pagination->create_links();
         $data['pageurl'] = $pageurl;
         $data['gid'] = $gid;
         $data['type'] = $type;
+        $data['ceProb'] = $ceProb;
         $this->load->view('slot/realGroupWeights', $data);
     }
 
+    private static function groupWeightList($gid, $type, $page,$length): array
+    {
+        $start = (ceil($page / $length)) * $length;
+
+        $tb = otable::realSlotWeightGroupsCfg();
+        $where = " Where gid='{$gid}' and type='{$type}' ";
+        $rs = oo::commonOprDb('slavedb')->getAll("SELECT * from {$tb} {$where} LIMIT {$start},{$length}");
+
+        $arr = [];
+        foreach ($rs as $k => $v) {
+            $arr[$v['levelId']] = json_decode($v['slotpro'], true);
+        }
+
+        $sql = "SELECT COUNT(*) as num from {$tb} {$where} ";
+        $rs = oo::commonOprDb('slavedb')->getOne($sql, 1);
+
+        return [
+            'total' => $rs['num'],
+            'list' => $arr,
+        ];
+    }
+
+    // 老虎机概率干预事件
+    private static function ceProConfList($gid, $type):array
+    {
+        $tb = otable::realSlotCeProConf();
+        $where = " Where gid='{$gid}' and type='{$type}' ";
+        $rs = oo::commonOprDb('slavedb')->getAll("SELECT * from {$tb} {$where}");
+
+        $arrMap = [];
+        foreach ($rs as $k => $v) {
+            $arrMap[$v['levelId']] = json_decode($v['slotpro'], true);
+        }
+
+        $arr = [];
+        for ($i = 1; $i <= 3; $i++) {
+            $arr[$i] = $arrMap[$i] ?? [
+                ["id" => 1, "v" => 0],
+                ["id" => 2, "v" => 0],
+                ["id" => 3, "v" => 0],
+                ["id" => 4, "v" => 0],
+                ["id" => 5, "v" => 0],
+                ["id" => 6, "v" => 0],
+                ["id" => 7, "v" => 0],
+                ["id" => 8, "v" => 0],
+                ["id" => 99, "v" => 0]];
+        }
+
+        return [
+            'total' => 3,
+            'list' => $arr,
+        ];
+    }
+
     /**
      * Notes: 设置老虎机权重配置
      * User: wsc
      * Time: 2021/2/27 13:23
      * @return json
      */
-    public function actionRealSlotWeightcfg($gid,$type){
+    public function actionRealSlotWeightcfg($gid, $type, $ceProb)
+    {
         $postData = $this->input->post();
         $data = json_decode($postData['data']);
+
         $upload = [];
         $level = [];
-        foreach ($data as $row){
+        foreach ($data as $row) {
             $level[] = $row->id;
             $upload[] = [
-                'level'=>$row->id,
-                'slotpro' =>$row->data,
+                'level' => $row->id,
+                'slotpro' => $row->data,
             ];
         }
         $nLevel = array_unique($level);
         if(count($nLevel) != count($level)){
             return $this->response(1, 'levelId 重复');
         }
-
-        $retData = $this->saveRealSlotWeightCfg($gid,$type, $upload);
+        file_put_contents("/tmp/xzxcmserr.log", json_encode($upload) . PHP_EOL, FILE_APPEND);
+        switch ($ceProb) {
+            case "weight":
+                $retData = $this->saveRealSlotWeightCfg($upload, $gid, $type);
+                break;
+            case "ceProb":
+                $retData = $this->saveRealSlotCeProbCfg($upload, $gid, $type);
+                break;
+            default:
+                return $this->response(1, "cePron 类型错误:{$ceProb}");
+        }
         oo::logs()->adminlog($this->router->fetch_method());
 
-        if($retData == 0){
+        if ($retData == 0) {
             return $this->response(1, '操作失败');
-        }else{
-//            $this->makeBeginGuideJson();
+        } else {
             return $this->response(0, '操作成功');
         }
     }
 
     /**
      * Notes:保存老虎机权重配置
-     * User: wsc
-     * Time: 2021/2/27 13:24
-     * @param $data
-     * @return array|int
      */
-    public function saveRealSlotWeightCfg($gid,$type, $data){
+    public function saveRealSlotWeightCfg($data, $gid, $type)
+    {
         $tb = otable::realSlotWeightGroupsCfg();
         $sql = "SELECT levelId from {$tb} where gid={$gid} and type ={$type}";
-        $rs = oo::commonOprDb('slavedb')->getAll($sql,1);
+        $rs = oo::commonOprDb('slavedb')->getAll($sql);
+
         $temp = [];
-        foreach ($rs as $row){
-            array_push($temp,(int)$row['levelId']);
+        foreach ($rs as $row) {
+            $temp[] = (int)$row['levelId'];
         }
-        $data = json_decode(json_encode($data,32));
-        foreach ($data as $row){
-//            $slotPro = [];
-//            foreach ($row->slotpro as $k => $items){
-//                echo json_encode([$k => $items]);die;
-//            }
-            $tempData = json_encode($row->slotpro,JSON_UNESCAPED_UNICODE);
-//            echo $tempData;die;
-            if(in_array($row->level,$temp)){
+
+        $data = json_decode(json_encode($data, 32));
+        foreach ($data as $row) {
+
+            $tempData = json_encode($row->slotpro, JSON_UNESCAPED_UNICODE);
+            if (in_array($row->level, $temp)) {
                 $sql = "UPDATE {$tb} SET slotpro='{$tempData}' WHERE levelId={$row->level} and gid={$gid} and type ={$type}";
-            }else{
+            } else {
                 $sql = "INSERT INTO {$tb} (gid, levelId,type,slotpro) VALUES ({$gid}, {$row->level},{$type},'{$tempData}')";
             }
-//            echo $sql;die;
             $rs = oo::commonOprDb('games')->query($sql);
-            oo::commonOprRedis('games')->hset(okeys::RealSlotWeightConfig($gid,$row->level),$type, $tempData);
+            oo::commonOprRedis('games')->hset(okeys::RealSlotWeightConfig($gid, $row->level), $type, $tempData);
         }
 
-        return $rs ? $rs : 0;
+        return $rs ?: 0;
+    }
+
+    /**
+     * Notes:保存老虎机修正概率配置
+     */
+    public function saveRealSlotCeProbCfg($data, $gid, $type)
+    {
+        $tb = otable::realSlotCeProConf();
+
+        $sql = "SELECT levelId from {$tb} where gid={$gid} and type ={$type}";
+        $rs = oo::commonOprDb('slavedb')->getAll($sql);
+
+        $temp = [];
+        foreach ($rs as $row) {
+            $temp[] = (int)$row['levelId'];
+        }
+
+        foreach ($data as $row) {
+            if (!in_array($row['level'], [1, 2, 3])) {
+                return 0;
+            }
+            $upMap = [];
+            foreach ($row['slotpro'] as $item) {
+                $upMap[$item->id] = $item->v;
+            }
+            oo::commonOprRedis('games')->hMset(okeys::RealSloCeProbConfig($gid, $row['level']), $upMap);
+
+            $tempData = json_encode($row['slotpro'], JSON_NUMERIC_CHECK);
+
+            if (in_array($row['level'], $temp)) {
+                $sql = "UPDATE {$tb} SET slotpro='{$tempData}' WHERE levelId={$row['level']} and gid={$gid} and type ={$type}";
+            } else {
+                $sql = "INSERT INTO {$tb} (gid, levelId,type,slotpro) VALUES ({$gid}, {$row['level']},{$type},'{$tempData}')";
+            }
+
+            $rs = oo::commonOprDb('games')->query($sql);
+        }
+
+        return $rs ?: 0;
     }
 
     /**
@@ -433,4 +525,26 @@ class Slot extends MY_Controller
             return $this->response(1, '操作失败',$data);
         }
     }
+
+    const CONFIG_SlOT_LS_CONF="CONFIG_SlOT_LS_CONF";
+
+    // 概率干预修正区间
+    public function ceProConf()
+    {
+        $data['conf'] = oo::commonOprModel('config')->getCommonConf(self::CONFIG_SlOT_LS_CONF);
+
+        $this->load->view('slot/ceProConf', $data);
+    }
+
+    // 概率干预修正区间 更新
+    public function ceProConfUpdate()
+    {
+        $posts =  $this->input->post();
+
+        oo::commonOprModel('config')->saveCommonConf(self::CONFIG_SlOT_LS_CONF, $posts['conf'], "收集活动等级体力分组修正等级配置");
+
+        oo::commonOprRedis('games')->delete(self::CONFIG_SlOT_LS_CONF);
+
+        return $this->response(0, '操作成功');
+    }
 }

+ 27 - 0
application/models/Funs.php

@@ -336,6 +336,33 @@ class funs extends CI_Model
         return "INSERT INTO " . $tb . " ({$fields}) VALUES({$values})";
     }
 
+    /**
+     * Notes:格式化 插入sql语句
+     * @param $tb
+     * @param $data
+     * @return string
+     */
+    public static function db_upsertSQL($tb, $data): string
+    {
+        self::db_serialization($data);
+
+        $arr = self::db_fieldAllow($data);
+
+        $fields = [];
+        $values = [];
+        $duplicates = [];
+        foreach ($arr as $key => $val) {
+            $fields[] = "`{$key}`";
+            $values[] = $val;
+            $duplicates[] = "`{$key}` = $val";
+        }
+
+        $fields = implode(",", $fields);
+        $values = implode(",", $values);
+        $duplicates = implode(",", $duplicates);
+        return "INSERT INTO " . $tb . " ({$fields}) VALUES({$values}) ON DUPLICATE KEY UPDATE {$duplicates}";
+    }
+
     public static function db_serialization(&$data)
     {
         foreach ($data as &$item) {

+ 6 - 0
application/models/Okeys.php

@@ -1983,6 +1983,12 @@ class okeys extends CI_Model
         return "REAL_SLOT_WEIGHT_SHUSHU_CONFIG:{$groupId}_{$lv}";
     }
 
+    // RealSloCeProbConfig 真老虎机修正概率配置
+    static public function RealSloCeProbConfig($gid, $lv): string
+    {
+        return "CONFIG_SlOT_CEPRO_CONF:{$gid}_{$lv}";
+    }
+
     // RealSlotWeightShushu 真老虎机数数分组
     static public function RealSlotWeightShushu() {
         return "REAL_SLOT_WEIGHT_SHUSHU";

+ 5 - 0
application/models/Otable.php

@@ -1952,7 +1952,12 @@ class otable extends CI_Model
     static function realSlotWeightGroupsCfg()
     {
         return oo::$config['dbindex'] . "api_config.t_real_slot_weight_groups_config";
+    }
 
+    //真老虎机概率干预事件配置
+    static function realSlotCeProConf(): string
+    {
+        return oo::$config['dbindex'] . "api_config.t_real_slot_ce_prob_conf";
     }
 
     //副老虎机奖励基准配置

+ 211 - 0
application/views/slot/ceProConf.php

@@ -0,0 +1,211 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>修改活动</title>
+
+    <style type="text/css">
+        table {
+            table-layout: fixed !important;
+        }
+
+        th {
+            background: rgb(146, 208, 80);
+        }
+
+        td, th {
+            max-width: 400px;
+            word-wrap: break-word;
+        }
+
+        .table-hover > tbody > tr:hover {
+            background-color: #c8bd6d;
+        }
+
+        input {
+            width: 60px;
+        }
+
+    </style>
+</head>
+
+<body>
+<div class="content_wrapper">
+    <div id="msg-tip"></div>
+    <div class="container-fluid ">
+        <div class="row">
+            <div class="col-sm-12">
+                <aside>
+                    <header><i class="fa fa-fw fa-file"></i>概率干预修正区间</header>
+                    <section>
+                        <div class="container-fluid">
+                            <div class="row" style="margin:5px;0">
+                                <button type="button" class="btn btn-primary" id="goodsSubmitBtn">提交</button>
+                            </div>
+                            <hr>
+                            <div class="row">
+                                <div class="col-sm-12">
+                                    <form class="form-horizontal" method="post" id="goodForm" action="">
+                                        <div class="form-group">
+                                            <div id="ceProConfList"></div>
+                                        </div>
+                                    </form>
+                                </div>
+                            </div>
+                        </div>
+                    </section>
+                </aside>
+            </div>
+        </div>
+    </div>
+</div>
+</body>
+
+<script>
+    var ceOptions = buildCeOptions()
+    initReward()
+
+    function initReward() {
+        $("#ceProConfList").empty();
+        initCeProWrap();
+        const confData = JSON.parse('<?php echo json_encode($conf);?>')
+
+        $.each(confData, (lvIdx, item) => {
+            $('#addCeProLvWrapBtn').click()
+            $(`input[name="conf[${lvIdx}][s_lv]"]`).val(item.s_lv)
+            $(`input[name="conf[${lvIdx}][e_lv]"]`).val(item.e_lv)
+
+            $.each(item.conf, (stageKey, rewardItem) => {
+                $('.addCeProSpinsTrBtn:last').click()
+
+                $(`input[name="conf[${lvIdx}][conf][${stageKey}][s_sp]"]`).val(rewardItem.s_sp)
+                $(`input[name="conf[${lvIdx}][conf][${stageKey}][e_sp]"]`).val(rewardItem.e_sp)
+                $(`select[name="conf[${lvIdx}][conf][${stageKey}][ce]"]`).val(rewardItem.ce)
+            })
+        })
+    }
+
+    function buildCeOptions() {
+        return `<option value="0">正常概率</option>
+                <option value="1">一级概率干预</option>
+                <option value="2">二级概率干预</option>
+                <option value="3">三级概率干预</option>`
+    }
+
+    function initCeProWrap() {
+        CeProLvCnt = 0;
+        CeProSpinsStages = {}
+
+        var html = CeProWrapStageTable();
+        $("#ceProConfList").append(html);
+    }
+
+    function CeProWrapStageTable() {
+        return `
+         <div class="text-center" style="margin:5px;padding:5px;">
+            <button style="margin-top: 20px" id="addCeProLvWrapBtn" class="btn btn-primary" onclick="addCeProLvWrap(this)" type="button">添加等级区间</button>
+            <button style="margin-top: 20px" class="btn btn-danger" onclick="delCeProLvWrap()" type="button">删除等级区间</button>
+         </div>`
+    }
+
+    function addCeProLvWrap(obj) {
+        var lvIdx = CeProLvCnt++
+
+        CeProSpinsStages[lvIdx] = 0
+        var html = `
+        <div class="CeProLvWrap" id="CeProlvWrap_${lvIdx}" data-idx="${lvIdx}" style="margin:10px;padding:5px;border:solid 1px goldenrod;">
+            <table class="table table-bordered" >
+                <thead>
+                    <tr>
+                        <td colspan="3">
+                             <div class="form-group">
+                                <label class="col-sm-1 control-label m-b">等级区间: </label>
+                                <div class="col-sm-3 input-group">
+                                    <input type="text" style="text-align: center" class="form-control" name="conf[${lvIdx}][s_lv]" value="0">
+                                    <span class="input-group-addon">-</span>
+                                    <input type="text" style="text-align: center" class="form-control" name="conf[${lvIdx}][e_lv]" value="0">
+                                </div>
+                            </div>
+                        </td>
+                    </tr>
+                    <tr>
+                        <th width="120">体力下限</th>
+                        <th width="120">体力上限</th>
+                        <th >干预等级</th>
+                    </tr>
+                </thead>
+                <tbody id="CeProRewardBody_${lvIdx}"></tbody>
+                <tr>
+                    <td colspan="3">
+                        <div class="text-center" style="margin-top: 20px">
+                            <botton class="btn btn-primary addCeProSpinsTrBtn" onclick="addCeProRewardTr(this)">添加</botton>
+                            <botton class="btn btn-danger del-tr" onclick="delCeProRewardTr(this)">删除</botton>
+                        </div>
+                    </td>
+                </tr>
+           </table>
+        </div>`
+        $(obj).before(html)
+    }
+
+    function delCeProLvWrap(obj) {
+        if (CeProLvCnt < 0) {
+            return;
+        }
+
+        $('#CeProlvWrap_' + (CeProLvCnt - 1)).remove();
+        CeProLvCnt--;
+    }
+
+    function addCeProRewardTr(obj) {
+        var lvIdx = $(obj).parents('.CeProLvWrap').data('idx')
+        var rewardStage = CeProSpinsStages[lvIdx]++
+        var rewardKey = lvIdx + '_' + rewardStage
+
+        var html = `
+        <tr class="CeProRewardInfoTr" id="CeProRewardInfo_${rewardKey}" data-idx="${rewardStage}">
+            <td><input name="conf[${lvIdx}][conf][${rewardStage}][s_sp]" type="number" class="form-control" value="0"></td>
+            <td><input name="conf[${lvIdx}][conf][${rewardStage}][e_sp]" type="number" class="form-control" value="0"></td>
+            <td>
+                <select name="conf[${lvIdx}][conf][${rewardStage}][ce]" class="form-control">
+                   ${ceOptions}
+                </select>
+            </td>
+        </tr>`;
+
+        $('#CeProRewardBody_' + lvIdx).append(html)
+    }
+
+    function delCeProRewardTr(obj) {
+        var lvIdx = $(obj).parents('.CeProLvWrap').data('idx')
+        var rewardKey = lvIdx + '_' + (CeProSpinsStages[lvIdx] - 1)
+
+        if (CeProSpinsStages[lvIdx] < 0) return;
+        $('#CeProRewardInfo_' + rewardKey).remove()
+        CeProSpinsStages[lvIdx]--
+    }
+
+    $(function () {
+        $('#goodsSubmitBtn').click(function () {
+            const data = $('#goodForm').toObject()
+            $.ajax({
+                url: rootPath + 'slot/ceProConfUpdate',
+                type: 'POST',
+                data: data,
+                dataType: 'json',
+                success: function (data) {
+                    alert(data.msg);
+
+                    if (data.ret == 0) {
+                        window.location.reload();
+                    }
+                },
+                error: function (data) {
+                    alert(data.msg);
+                }
+            });
+        });
+    });
+
+
+</script>

+ 2 - 3
application/views/slot/realGroupWeights.php

@@ -71,6 +71,7 @@
                                 <a class="btn btn-success" href="/#slot/realGroupWeights/<?=$gid?>/1">1号位</a>
                                 <a class="btn btn-success" href="/#slot/realGroupWeights/<?=$gid?>/2">2号位</a>
                                 <a class="btn btn-success" href="/#slot/realGroupWeights/<?=$gid?>/3">3号位</a>
+                                <a class="btn btn-warning" href="/#slot/realGroupWeights/<?=$gid?>/1/0/ceProb">1号位概率干预事件</a>
                             </div>
                             <button type="button" style="margin-bottom: 10px;width: 80px;" class="btn btn-danger" disabled id="commitBtn">提交</button>
                             <div class="row">
@@ -132,8 +133,6 @@
             </div>
         </div>
     </div>
-
-
 </div>
 
 
@@ -378,7 +377,7 @@
                 data: JSON.stringify(arr),
                 page: '<?php echo $page; ?>'
             },
-            url:'slot/actionRealSlotWeightCfg/<?echo $gid."/".$type?>',
+            url:'slot/actionRealSlotWeightCfg/<?echo $gid."/".$type."/".$ceProb?>',
             success: function(data){
                 hideLoading()
                 if(data.ret == 0){