Browse Source

礼物模块修改

lizhen_gitee 3 years ago
parent
commit
28d75fdc88

+ 74 - 0
application/admin/controller/Gift.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\common\controller\Backend;
+
+/**
+ * 礼物管理
+ *
+ * @icon fa fa-gift
+ */
+class Gift extends Backend
+{
+    
+    /**
+     * Gift模型对象
+     * @var \app\admin\model\Gift
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\Gift;
+
+    }
+
+    public function import()
+    {
+        parent::import();
+    }
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+    
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = true;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+
+            $list = $this->model
+                    ->with(['gifttype'])
+                    ->where($where)
+                    ->order($sort, $order)
+                    ->paginate($limit);
+
+            foreach ($list as $row) {
+                
+                $row->getRelation('gifttype')->visible(['name']);
+            }
+
+            $result = array("total" => $list->total(), "rows" => $list->items());
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+}

+ 15 - 0
application/admin/lang/zh-cn/gift.php

@@ -0,0 +1,15 @@
+<?php
+
+return [
+    'Id'            => '主键ID',
+    'No'            => '编号',
+    'Name'          => '名称',
+    'Type'          => '类别',
+    'Value'         => '价值',
+    'Image'         => '图片',
+    'Special'       => '特效',
+    'Sort'          => '排序',
+    'Updatetime'    => '更新时间',
+    'Createtime'    => '创建时间',
+    'Gifttype.name' => '礼物类型'
+];

+ 44 - 0
application/admin/model/Gift.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class Gift extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'gift';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+
+    ];
+    
+
+    
+
+
+
+
+
+
+
+    public function gifttype()
+    {
+        return $this->belongsTo('GiftType', 'type', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+}

+ 12 - 0
application/admin/model/GiftType.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+class GiftType extends Model
+{
+    // 表名
+    protected $name = 'gift_type';
+    
+}

+ 27 - 0
application/admin/validate/Gift.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\validate;
+
+use think\Validate;
+
+class Gift extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+    ];
+    /**
+     * 提示消息
+     */
+    protected $message = [
+    ];
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+        'add'  => [],
+        'edit' => [],
+    ];
+    
+}

+ 60 - 0
application/admin/view/gift/add.html

@@ -0,0 +1,60 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('No')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-no" data-rule="required" class="form-control" name="row[no]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-type" data-rule="required" class="form-control" name="row[type]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Value')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-value" data-rule="required" class="form-control" name="row[value]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <div class="input-group">
+                <input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text">
+                <div class="input-group-addon no-border no-padding">
+                    <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
+                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
+                </div>
+                <span class="msg-box n-right" for="c-image"></span>
+            </div>
+            <ul class="row list-inline faupload-preview" id="p-image"></ul>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Special')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-special" class="form-control" name="row[special]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sort')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sort" class="form-control" name="row[sort]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 60 - 0
application/admin/view/gift/edit.html

@@ -0,0 +1,60 @@
+<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('No')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-no" data-rule="required" class="form-control" name="row[no]" type="number" value="{$row.no|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-type" data-rule="required" class="form-control" name="row[type]" type="number" value="{$row.type|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Value')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-value" data-rule="required" class="form-control" name="row[value]" type="number" value="{$row.value|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <div class="input-group">
+                <input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="{$row.image|htmlentities}">
+                <div class="input-group-addon no-border no-padding">
+                    <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
+                    <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
+                </div>
+                <span class="msg-box n-right" for="c-image"></span>
+            </div>
+            <ul class="row list-inline faupload-preview" id="p-image"></ul>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Special')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-special" class="form-control" name="row[special]" type="text" value="{$row.special|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Sort')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-sort" class="form-control" name="row[sort]" type="number" value="{$row.sort|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 35 - 0
application/admin/view/gift/index.html

@@ -0,0 +1,35 @@
+<div class="panel panel-default panel-intro">
+    {:build_heading()}
+
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+                <div class="widget-body no-padding">
+                    <div id="toolbar" class="toolbar">
+                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                        <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('gift/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('gift/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('gift/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('gift/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
+
+                        <div class="dropdown btn-group {:$auth->check('gift/multi')?'':'hide'}">
+                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
+                            <ul class="dropdown-menu text-left" role="menu">
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
+                            </ul>
+                        </div>
+
+                        
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit="{:$auth->check('gift/edit')}" 
+                           data-operate-del="{:$auth->check('gift/del')}" 
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 2 - 6
application/api/controller/Gift.php

@@ -26,17 +26,13 @@ class Gift extends Api
      * 获取礼物列表
      */
     public function getGiftList() {
-        $type = $this->request->request("type"); // 礼物类型:0=活动,1=常规,2=人气,3=浪漫,4=豪华
-        $page = $this->request->request('page',1); // 分页
-        $pageNum = $this->request->request('pageNum',100); // 分页
-        // 分页搜索构建
-        $pageStart = ($page-1)*$pageNum;
+        $type = $this->request->request("type");
 
         // 获取基本信息
         $where = [];
         $type != '' && $where["type"] = $type;
-//        $giftList = $this->giftModel->where($where)->limit($pageStart,$pageNum)->select();
         $giftList = $this->giftModel->where($where)->order("value","asc")->select();
+        $giftList = list_domain_image($giftList,['image','special']);
         $this->success("获取成功!",$giftList);
     }
 

+ 195 - 0
application/index/controller/Test.php

@@ -0,0 +1,195 @@
+<?php
+
+namespace app\index\controller;
+
+use think\Db;
+class Index
+{
+
+    /**
+     * 全麦/单独赠送礼物
+     */
+    public function giveGiftToYou() {
+        // 接口防并发
+        if (!$this->apiLimit(1, 1000)) {
+            $this->error(__('Operation frequently'));
+        }
+
+        //
+        $user_ids = $this->request->request("user_id");// 赠送对象
+        $gift_id = $this->request->request("gift_id");// 礼物ID
+        $party_id = $this->request->request("party_id",0);// 派对ID
+        $number = $this->request->request("number");// 赠送数量
+        $room_type = 1; // 房间类型
+        $is_back = 0;// 是否背包赠送: 1=是,0=否
+        if (!$user_ids || !$gift_id || !$number)
+        {
+            $this->error(__('Invalid parameters'));
+        }
+
+        //
+        $user_id_arr = explode(',',$user_ids);
+        $userCount = count($user_id_arr);
+        $userauthid = $this->auth->id;
+
+
+        // 获取礼物信息
+        $giftInfo = Db::name('gift')->where('id',$gift_id)->find();
+        if (!$giftInfo) {$this->error("请选择礼物!");}
+        $giftValue = $giftInfo["value"] * $number;
+        $giftCountValue = $giftInfo["value"] * $number * $userCount;
+
+
+        // 判断当前用户余额
+        $user_gold = model('wallet')->getWallet($userauthid,'gold');
+        if($user_gold < $giftCountValue) {$this->error("您的金币余额不足!");}
+
+
+        if($party_id){
+            $partyInfo = \app\common\model\Party::field("user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
+            if(!$partyInfo){
+                $this->error('不存在的语聊间');
+            }
+        }
+
+        $returnData = [];
+        Db::startTrans();
+        try {
+            $redis = new Redis();
+            $redisconfig = config("redis");
+            $redis->connect($redisconfig["host"], $redisconfig["port"], 86400 * 31);
+
+            // 获取当天零点
+            $day = date("Ymd");
+            // 获取本周第一天
+            $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
+            // 获取本月第一天
+            $monthday = date("Ym01");
+
+            $allVal = 0;
+            $i = 0;
+            foreach($user_id_arr as $user_id) {
+
+                // 添加礼物赠送记录表
+                $data = [];
+                $data["user_id"] = $userauthid;
+                $data["user_to_id"] = $user_id;
+                $data["party_id"] = $party_id;
+                $data["gift_id"] = $gift_id;
+                $data["gift_give_type"] = 2;
+                $data["gift_name"] = $giftInfo["name"];
+                $data["gift_gif_image"] = $giftInfo["image"];
+                $data["number"] = $number;
+                $data["price"] = $giftInfo["value"];
+                $data["value"] = $giftValue;
+
+                $data["createtime"] = time();
+                $log_id = Db::name('gift_user_party')->insertGetId($data);
+                if(!$log_id){
+                    Db::rollback();
+                    $this->error('赠送失败');
+                }
+
+                if($giftValue > 0){
+                    // 扣除当前用户钻石余额
+                    $wallet_rs = model('wallet')->lockChangeAccountRemain($userauthid,'gold',-$giftValue,51,'赠送礼物:'.$giftInfo["name"],'gift_user_party',$log_id);
+                    if($wallet_rs['status'] === false){
+                        Db::rollback();
+                        $this->error($wallet_rs['msg']);
+                    }
+
+
+                    // 添加赠送用户余额
+                    $money_to_gold = config('site.money_to_gold');
+                    $gift_plat_scale = config('site.gift_plat_scale');
+                    $giftmoney = bcdiv($giftValue,$money_to_gold,2);
+                    $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
+
+                    $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$money,52,'获得礼物:'.$giftInfo["name"],'gift_user_party',$log_id);
+                    if($wallet_rs['status'] === false){
+                        Db::rollback();
+                        $this->error($wallet_rs['msg']);
+                    }
+                }
+
+
+                $res6 = true;
+
+                if ($res6) {
+                    $i++;
+                    if($party_id > 0) {
+                        // 添加redis记录做财富排行榜日榜用
+                        $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $day . "d", $giftValue, $user_id);
+                        // 添加redis记录做财富排行榜周榜用
+                        $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $weekday . "w", $giftValue, $user_id);
+                        // 添加redis记录做财富排行榜月榜用
+                        $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $monthday . "m", $giftValue, $user_id);
+                        // 添加redis记录做贡献排行榜日榜用
+                        $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $day . "d", $giftValue, $userauthid);
+                        // 添加redis记录做贡献排行榜周榜用
+                        $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $weekday . "w", $giftValue, $userauthid);
+                        // 添加redis记录做贡献排行榜月榜用
+                        $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $monthday . "m", $giftValue, $userauthid);
+
+                        // tcp 更新用户魅力值
+                        $this->updateUserCharm($party_id, $user_id, $giftValue);
+
+
+                    }
+
+                    $allVal = $allVal + $giftValue;
+
+                }
+            }
+
+            // 获取用户魅力值
+            $users = $redis->zRange("hourCharm_".$party_id,0,-1,true);
+            $u = [];
+            if($users) {
+                foreach($users as $k => $v) $u[] = [
+                    "user_id"=>$k,
+                    "charm"=>$this->changeW($v)
+                ];
+            }
+            $userCharm = $u;
+            // tcp 更新房间热度
+            $partyHot = $this->updatePartyHot($party_id, $allVal, $room_type);
+
+            // 如果是派对,则添加派对热度值记录做榜单统计
+            if($room_type == 1) {
+                $data = [];
+                $data["party_id"] = $party_id;
+                $data["hot"] = $allVal;
+                $data["createtime"] = time();
+                \app\common\model\PartyHot::insert($data);
+            }
+
+
+            // tcp 获取房间用户周前三名
+            $partyUserTop = $this->getPartyUserTop($party_id, $room_type);
+
+            if($i == $userCount) {
+                $returnData["userCharm"] = $userCharm;
+                $returnData["partyHot"] = $this->changeW($partyHot);
+                $returnData["partyUserTop"] = $partyUserTop;
+                $returnData["image"] = $giftInfo["image"];
+                $returnData["gif_image"] = $giftInfo["special"];
+
+                Db::commit();
+                $this->success("赠送成功!",$returnData);
+            } else {
+                $this->success("赠送失败!");
+            }
+        } catch (ValidateException $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        } catch (PDOException $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+    }
+
+}

+ 60 - 0
public/assets/js/backend/gift.js

@@ -0,0 +1,60 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'gift/index' + location.search,
+                    add_url: 'gift/add',
+                    edit_url: 'gift/edit',
+                    del_url: 'gift/del',
+                    multi_url: 'gift/multi',
+                    import_url: 'gift/import',
+                    table: 'gift',
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                sortName: 'id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id')},
+                        {field: 'no', title: __('No')},
+                        {field: 'name', title: __('Name'), operate: 'LIKE'},
+                        {field: 'type', title: __('Type')},
+                        {field: 'value', title: __('Value')},
+                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
+                        {field: 'special', title: __('Special'), operate: 'LIKE'},
+                        {field: 'sort', title: __('Sort')},
+                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'gifttype.name', title: __('Gifttype.name'), operate: 'LIKE'},
+                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});