소스 검색

集卡操作

xiaosongshu007 5 년 전
부모
커밋
42fe6e6d97

+ 206 - 0
Application/Admin/Controller/CollectController.class.php

@@ -0,0 +1,206 @@
+<?php
+
+namespace Admin\Controller;
+
+/**
+ * 样式管理
+ * @author   brent
+ * @version  0.0.1
+ */
+class CollectController extends CommonController {
+
+    protected $table = ''; //表名
+
+    /**
+     * [_initialize 前置操作-继承公共前置方法]
+     * @author   Devil
+     * @blog     http://gong.gg/
+     * @version  0.0.1
+     * @datetime 2016-12-03T12:39:08+0800
+     */
+
+    public function _initialize() {
+        // 调用父类前置方法
+        parent::_initialize();
+
+        // 登录校验
+        $this->Is_Login();
+
+        // 权限校验
+        $this->Is_Power();
+        //要执行的表
+        $this->table = M('activity_collect');
+    }
+
+    /**
+     * [Index 文章列表]
+     * @author   Devil
+     * @blog     http://gong.gg/
+     * @version  0.0.1
+     * @datetime 2016-12-06T21:31:53+0800
+     */
+    public function Index() {
+        //关键字
+        $keyword = I('keyword');
+        if($keyword){
+            $where['uid'] = ['like',"%$keyword%"];
+        }
+        $listRows = I('listRows',100,'intval');
+        if($p = I('p',1,'intval')){
+            $offset = ($p-1)*$listRows;
+        }
+        $acts = M('activity_v2')->field('id,activity_name')->select();
+        $this->assign('acts', $acts);
+
+        //活动id
+        $act_id = trim(I('act_id'));
+  
+        if($act_id){
+            $where['act_id'] = $act_id;
+        }else{
+            $act_id = M('activity_v2')->max('id');
+        }
+
+        $List = $this->table
+                ->where($where)
+                ->order('id desc')
+                ->limit($offset,$listRows)
+                ->select();
+        $activitys = M('activity_v2')->where(['id'=>$act_id])->find();
+        foreach($activitys as $row){
+            $activity_info[$row['id']] = ['activity_name'=>$row['activity_name']];
+        }
+        if($activitys['collect_list']){
+            $collects = json_decode($activitys['collect_list'],true);
+            $collects = array_column($collects, null,'collect_id');
+        }
+
+        foreach ($List as $key=>$row) {
+            $List[$key]['activity_name'] = $activity_info[$row['act_id']]['activity_name'];
+            if($collects){
+                $List[$key]['collect_name']  = $collects[$row['collect_id']]['collect_name'];
+            }
+        }
+//        var_dump($List);die;
+        $count = $this->table->where($where)->count();
+        $Page = new \Think\Page($count, $listRows);
+        $Page->parameter .= "&p=[PAGE]";
+        $Page->parameter .= "&act_id=".$act_id;
+        $Page->parameter .= "&keyword=".$keyword;
+        $Page = $this->page_config($Page);
+        $show = $Page->show();
+        $this->assign('page', $show);
+        $this->assign('List', $List);
+        //获取所有活动
+        $this->assign('keyword', $keyword);
+        $this->assign('act_id', $act_id);
+        $this->display('Index');
+    }
+    
+    /**
+     * [SaveInfo 文章添加/编辑页面]
+     * @author   Devil
+     * @blog     http://gong.gg/
+     * @version  0.0.1
+     * @datetime 2016-12-14T21:37:02+0800
+     */
+    public function SaveInfo() {
+        // 文章信息
+        if (empty($_REQUEST['id'])) {
+            $data = array();
+        } else {
+            $data = $this->table->find(I('id'));
+            if (empty($data)) {
+                $data = array('id' => I('id'));
+            }
+        }
+        $data = M('Activity_v2')->field('id,activity_name')->select();
+        $this->assign('Acts', $data);
+        $this->assign('data', $data);
+        $this->display('SaveInfo');
+    }
+
+    /**
+     * [Save 文章添加/编辑]
+     * @author   Devil
+     * @blog     http://gong.gg/
+     * @version  0.0.1
+     * @datetime 2016-12-14T21:37:02+0800
+     */
+    public function Save() {
+        // 是否ajax请求
+        if (!IS_AjAX) {
+            $this->error(L('common_unauthorized_access'));
+        }
+        // 添加
+        if (empty($_POST['id'])) {
+            $this->Add();
+
+            // 编辑
+        } else {
+            $this->Edit();
+        }
+    }
+
+    /**
+     * [Add 文章添加]
+     * @author   Devil
+     * @blog     http://gong.gg/
+     * @version  0.0.1
+     * @datetime 2016-12-18T16:20:59+0800
+     */
+    private function Add() {
+        $m = $this->table;
+        $data = I('post.');
+        $data['created_at'] = $data['collect_date'] ?  : date('Y-m-d H:i:s');
+        $data['operate'] = 1;
+        // 数据添加
+        if ($m->add($data)) {
+            $this->ajaxReturn('更新成功');
+        } else {
+            $this->ajaxReturn('更新失败',400);
+        }
+    }
+
+    /**
+     * [Delete 删除]
+     * @author   Devil
+     * @blog     http://gong.gg/
+     * @version  0.0.1
+     * @datetime 2016-12-15T11:03:30+0800
+     */
+    public function Delete() {
+        // 是否ajax请求
+        if (!IS_AJAX) {
+            $this->error(L('common_unauthorized_access'));
+        }
+
+        // 删除数据
+        if (!empty($_POST['id'])) {
+            // 更新
+            if ($this->table->delete(I('id'))) {
+                $this->ajaxReturn(L('common_operation_delete_success'));
+            } else {
+                $this->ajaxReturn(L('common_operation_delete_error'), -100);
+            }
+        } else {
+            $this->ajaxReturn(L('common_param_error'), -1);
+        }
+    }
+
+    public function Search()
+    {
+        $act_id = I('act_id');
+        if(empty($act_id)){
+            echo json_encode(array());
+            die;
+        }
+        $data['activity'] = M('Activity_v2')->where(['id'=>$act_id])->find();
+        
+        $data['activity']['start_at'] = $data['activity']['start_at'];        
+        $data['activity']['end_at'] = $data['activity']['end_at'];
+//         dump(json_decode($data['activity']['prize_list'],true));
+        $data['collects'] = json_decode($data['activity']['collect_list'],true);
+        echo json_encode($data);
+    }
+}

+ 80 - 0
Application/Admin/View/Default/Collect/Index.html

@@ -0,0 +1,80 @@
+<!-- header start -->
+<include file="Public/Header" />
+<!-- header end -->
+
+<!-- right content start  -->
+<div class="content-right">
+	<div class="content">
+            <!-- form start -->
+            <form class="am-form view-list" action="{{:U('Admin/Collect/Index')}}" method="post">
+                <div class="am-g">
+                    <input type="text" class="am-radius form-keyword" placeholder="用户uid" name="keyword" value="{{$keyword}}" style="display: inline-block;width: 20rem;">
+                    <select name="act_id" style="display: inline-block;width: 10rem;">
+                            <option value="">全部活动</option>
+                            <?php foreach($acts as $act):?>
+                            <option value="<?php echo $act['id'];?>" <?php if($act_id == $act['id']):?>selected<?php endif;?>><?php echo $act['activity_name'];?></option>
+                            <?php endforeach;?>
+                    </select>
+                    <a href="{{:U('Admin/Collect/SaveInfo')}}" class="am-btn am-btn-success am-btn-xs m-l-10 am-radius">增加集卡</a> 
+<!--                     <if condition="!IsMobile()">
+                         <a href="#" id="export" class="am-btn am-btn-success am-btn-xs m-l-10 am-icon-file-excel-o am-radius"> {{:L('common_operation_excel_export_name')}}</a> 
+                    </if> -->
+                    <button type="submit" class="am-btn am-btn-secondary am-btn-sm am-radius form-submit">查询</button>
+                </div>
+            </form>
+		<table class="am-table am-table-striped am-table-hover am-text-middle m-t-10">
+                    <thead>
+                        <tr>
+                            <th>ID</th>
+                            <th class="am-hide-sm-only">用户id</th>
+                            <th class="am-hide-sm-only">集卡名称</th>
+                            <th class="am-hide-sm-only">活动名称</th>
+                            <th class="am-hide-sm-only">收支情况</th>
+                            <th class="am-hide-sm-only">时间</th>
+                            <th>{{:L('common_operation_name')}}</th>
+                        </tr>
+                    </thead>
+                    <tbody>
+                            <if condition="!empty($List)">
+                                <foreach name="List" item="v">
+                                    <tr id="data-list-{{$v.id}}">
+                                        <input type="hidden" value="{{$v.id}}" />
+                                        <td class="am-hide-sm-only">{{$v.id}}</td>
+                                        <td class="am-hide-sm-only">{{$v.uid}}</td>
+                                        <td class="am-hide-sm-only">{{$v.collect_name}}</td>
+                                        <td class="am-hide-sm-only">{{$v.activity_name}}</td>
+                                        <td class="am-hide-sm-only">{{$v.operate}}</td>
+                                        <td class="am-hide-sm-only">{{$v.created_at}}</td>
+                                        <td class="view-operation">
+                                            <button class="am-btn am-btn-default am-btn-xs am-radius am-icon-trash-o submit-delete" data-url="{{:U('Admin/Collect/Delete')}}" data-am-popover="{content: '{{:L('common_operation_delete')}}', trigger: 'hover focus'}" data-id="{{$v.id}}"></button>
+                                        </td>
+                                    </tr>
+                                </foreach>
+                            <else />
+                                    <tr><td colspan="10" class="table-no">{{$act_id ? '没有记录':'请先选择活动'}}</td></tr>
+                            </if>
+                    </tbody>
+		</table>
+		<!-- list end -->
+
+		<!-- page start -->
+		<div id="pages" class="p">{{$page}}</div>
+		<!-- page end -->
+	</div>
+</div>
+<!-- right content end  -->
+<script type="text/javascript">
+$("#export").on("click",function(){
+        var keyword = $("input[name=keyword]").val();
+        var prize_status = $("select[name=prize_status]").val();
+        var act_id = $("select[name=act_id]").val();
+        
+        var params = '&keyword='+keyword+'&prize_status='+prize_status+'&act_id='+act_id;
+        var url = 'index.php?m=Admin&c=PrizeLog&a=Index&model=exportExcel'+params;
+//        alert(url);return ;
+        window.open(url);
+});    
+</script>		
+<!-- footer start -->
+<include file="Public/Footer" />
+<!-- footer end

+ 102 - 0
Application/Admin/View/Default/Collect/SaveInfo.html

@@ -0,0 +1,102 @@
+<!-- header start -->
+<include file="Public/Header" />
+<!-- header end -->
+<!-- right content start  -->
+<div class="content-right">
+    <div class="content">
+        <!-- form start -->
+        <div id="success" style="color:#fff;display: none;background: limegreen;height: 3rem;text-align: center;"></div>
+        <form class="am-form form-validation view-save" action="{{:U('Admin/Collect/Save')}}" method="POST" request-type="ajax-reload" enctype="multipart/form-data">
+            <legend>
+                <span class="fs-16">
+                    <if condition="empty($data['id'])">
+                        增加集卡信息
+                        <else />
+                        编辑集卡信息
+                    </if>
+                </span>
+                <a href="{{:U('Admin/Collect/Index')}}" class="fr fs-14 m-t-5 am-icon-mail-reply"> {{:L('common_operation_back')}}</a>
+            </legend>
+
+            <div class="am-g">
+                <label>活动绑定</label>
+                <select name="act_id" id="act_id" class="am-radius c-p" required>
+                    <option value="">请绑定活动</option>
+                    <foreach name="Acts" item="v">
+                        <option value="{{$v.id}}" <if condition="isset($data['act_id']) and $data['act_id'] eq $v['id']">selected</if> >{{$v.activity_name}}</option>
+                    </foreach>
+                </select>
+            </div>
+
+            <div class="am-form-group">
+                <label>集卡绑定</label>
+                <select class="form-control input-sm" id="collect_id" name="collect_id" required>
+                    <if condition = "$collects">
+                        <foreach name="collects" item ="p">
+                            <option value="{{$p.id}}" <if condition="isset($data['prize_id']) and $data['collect_id'] eq $p['id']">selected</if>>{{$p.collect_name}}</option>
+                        </foreach>
+                        <else/>
+                        <option value="">请先选择活动</option>
+                    </if>	
+                </select>
+            </div>
+            <div class="am-g">
+                <label>UID设定</label>
+                <input type="text" name="uid" placeholder="UID,注意号段" data-validation-message="请填UID,注意号段" class="am-form-field am-radius" required
+                       <notempty name="data"> value="{{$data.uid}}" </notempty>/>
+            </div>
+
+            <div class="am-form-group">
+                <label>抽卡日期设定</label> <label><font color="red" id="warning"></font></label>
+                <input type="text" name="collect_date" placeholder="格式 2018-12-18 12:23:33" class="am-form-field am-radius" 
+                       <notempty name="data"> value="{{$data.collect_date}}" </notempty>/>
+            </div>
+
+            <div class="am-form-group" style="padding-top: 2rem">
+                <input type="hidden" name="id" <notempty name="data"> value="{{$data.id}}"</notempty>" />
+                <button class="am-btn am-btn-primary">保存</button>
+            </div>
+        </form>
+        <!-- form end -->
+    </div>
+</div>
+<!-- right content end  -->
+
+<!-- footer start -->
+<include file="Public/Footer" />
+<!-- footer end -->
+<script src="__PUBLIC__/Common/Lib/uploader/jquery-1.9.1.min.js" type="text/javascript"></script>
+<script type="text/javascript">
+//two AJAX获取数据方式(每次请求)
+$("#act_id").on("change", function () {
+    var act_id = $("#act_id").val();
+    // console.log(act_id);	
+    $.ajax({
+        url: "{{:U('Admin/Collect/Search')}}",
+        type: 'POST',
+        dateType: 'JSON',
+        data: {"act_id": act_id},
+        success: function (data) //服务器成功响应处理函数
+        {
+            var obj = jQuery.parseJSON(data);
+//             console.log(obj);     return ;
+            $("#collect_id").html('');
+            var html = '<option value ="">请选择集卡</option>';
+            for (var i = obj.collects.length - 1; i >= 0; i--) {
+                html += '<option value ="' + obj.collects[i]['collect_id'] + '">' + obj.collects[i]['collect_name'] + '</option>';
+            }
+            // console.log(html);
+            $("#collect_id").html(html);
+            
+            var warning = obj.activity['start_at'] + ' 至 ' +obj.activity['end_at'];
+            $('#warning').html(warning);
+        },
+    })
+});
+
+</script>
+<script>
+    jeDate("input[name=collect_date]",{
+        format: "YYYY-MM-DD hh:mm:ss"
+    });
+</script>