shq1016 6 лет назад
Родитель
Сommit
59dc31651b

+ 207 - 2
app/admin/controller/MessageController.php

@@ -66,7 +66,28 @@ class MessageController extends AdminBaseController{
                 $cates = $fenpei['cates'];
                 $from = $fenpei['tiaoshu'];
                 $map[] = ['create_time','>',$fenpei['from_time']];
-                $lists = Db::name('message')->where('catid','in',$cates)->where($map)->order('id')->limit(0,$from)->select();
+
+                //ppppp
+                if($fenpei['enable']==1){
+                    $map2[] = ['p1.create_time','>',$fenpei['from_time']];
+                    $field=['p1.*','concat(LEFT(p1.mobile,4),"****",RIGHT(p1.mobile,3))'=>'mobile','count(p2.id)'=> 'vid' ];
+                    $lists = Db::name('message')
+                        ->alias('p1')
+                        ->leftJoin('mobile_log p2','p1.`id`=p2.`msg_id`')
+                        ->group('p1.`id`')
+                        ->field($field)->where('p1.catid','in',$cates)->where($map2)->limit(0,$from)->select();
+                     
+                }else{
+
+                    $field=['*'];
+                     $lists = Db::name('message')->field($field)->where('catid','in',$cates)->where($map)->order('id')->limit(0,$from)->select();
+                }
+
+           
+
+              //  $lists = Db::name('message')->field($field)->where('catid','in',$cates)->where($map)->order('id')->limit(0,$from)->select();
+                $this->assign('fenpei',$fenpei);
+            //ppppp
             	// if($from<20){
             	// 	$lists = Db::name('message')->where('catid','in',$cates)->where($map)->order('id desc')->limit(0,$from)->select();
             		
@@ -82,10 +103,156 @@ class MessageController extends AdminBaseController{
         }
         return $this->fetch();
     }
+
+    public function tomobile()
+    {
+     
+        $param = $this->request->param();
+        $username = $_SESSION['think']['name'];
+        $userinfo = Db::name('user')->where('user_login',$username)->find();
+        $userid = $userinfo['id'];
+            //分配的信息id
+        $fenpei  = Db::name('user_fp')->where('userid',$userid)->find();
+        $bol=0;
+        if(!empty($fenpei))
+        {
+                $cates = $fenpei['cates'];
+                $from = $fenpei['tiaoshu'];
+                $map[] = ['create_time','>',$fenpei['from_time']];
+                $fromid=['id'=>$param['id']];
+                 $lists = Db::name('message')->field(['id'])->where('catid','in',$cates)->where($map)->order('id')->limit(0,$from)->select()->toArray();
+                $message = Db::name('message')->field(['id','mobile'])->where('catid','in',$cates)->where($map)->where($fromid)->limit(0,$from)->find();
+                      // dump(Db::table('message')->getLastSql());
+                foreach ($lists as $value) {
+                    if(in_array($message['id'], $value)){
+                        $bol=$message['mobile'];
+                    }
+                }
+                //检查记录
+                if(!empty($message)){
+                    $mobile_where=['user_id'=>$userid,'msg_id'=>$message['id']];
+                    $mobile_log=Db::name('mobile_log')->where($mobile_where)->find();
+                    if(empty($mobile_log))
+                    {
+                        //如果为空则需要插入记录并在user_fp减少一个点数
+                        //先判断是否还有点数
+                        if($fenpei['points']>0){
+                            $mobile_in['user_id']=$userid;
+                            $mobile_in['msg_id']=$message['id'];
+                            $mobile_in['create_time']=time();
+                            $res=Db::name('mobile_log')->insert($mobile_in);
+                            if($res){
+                              
+                                Db::name('user_fp')->where('userid',$userid)->dec('points', 1)->update();
+                                $this->success($message['mobile']);
+                            }
+
+                        }else{
+                           $this->error('你的点数已经用尽');
+                        }
+                        
+
+                    }else{
+                        $this->success($message['mobile']);
+                    }
+
+                }else{
+                    $this->error('数据获取错误');
+                }
+                
+        }
+       
+
+    }
+
 	
 	public function add(){
 		return $this->fetch();
 	}
+
+
+    public function export()
+    {
+        $map  = array();
+        $username = $_SESSION['think']['name'];
+        $userinfo = Db::name('user')->where('user_login',$username)->find();
+        $userid = $userinfo['id'];
+        //分配的信息id
+        $fenpei  = Db::name('user_fp')->where('userid',$userid)->find();
+        if(!empty($fenpei))
+        {
+            $cates = $fenpei['cates'];
+            $from = $fenpei['tiaoshu'];
+            $map[] = ['create_time','>',$fenpei['from_time']];
+            if($fenpei['enable']==1){
+                $map2[] = ['p1.create_time','>',$fenpei['from_time']];
+                $field=['p1.*','FROM_UNIXTIME(p1.create_time)'=>'create_time' ];
+                $data = Db::name('message')
+                    ->alias('p1')
+                    ->leftJoin('mobile_log p2','p1.`id`=p2.`msg_id`')
+                    ->field($field)->where('p1.catid','in',$cates)->where($map2)->where('p2.user_id',$userid)->limit(0,$from)->select();
+
+
+            }else{
+
+                $field=['*'];
+                $data = Db::name('message')->field($field)->where('catid','in',$cates)->where($map)->order('id')->limit(0,$from)->select();
+            }
+
+
+        }
+        $field = array(
+            'A' => array('jm_title', '品牌'),
+            'B' => array('news_kw', '新闻'),
+            'C' => array('catname', '分类'),
+            'D' => array('name', '姓名'),
+            'E' => array('ip', 'IP'),
+            'F' => array('area', '所在区域'),
+            'G' => array('tzed', '投资额度'),
+            'H' => array('mobile', '电话'),
+            'I' => array('content', '留言内容'),
+            'J' => array('create_time', '留言时间'),
+
+        );
+
+       $this->exportExcel($field, $data,date('Y-m-d'));
+
+
+    }
+
+
+
+    private function exportExcel($field, $list, $title='name')
+    {
+
+        $objPHPExcel = new \PHPExcel();
+        $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel); //设置保存版本格式
+        $objPHPExcel->getActiveSheet()->setTitle('用户信息表');
+        foreach ($list as $key => $value) {
+            foreach ($field as $k => $v) {
+                if ($key == 0) {
+                    $objPHPExcel->getActiveSheet()->setCellValue($k . '1', $v[1]);
+                }
+                $i = $key + 2;
+                $objPHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
+            }
+
+        }
+        ob_end_clean();
+        header("Pragma: public");
+        header("Expires: 0");
+        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
+        header("Content-Type:application/force-download");
+        header("Content-Type:application/vnd.ms-execl");
+        header("Content-Type:application/octet-stream");
+        header("Content-Type:application/download");;
+        header('Content-Disposition:attachment;filename='.$title.'.xls');
+        header("Content-Transfer-Encoding:binary");
+        $objWriter->save('php://output');
+    }
+
+
+
 	
 	public function addPost(){
 		$param = $this->request->param();
@@ -97,6 +264,21 @@ class MessageController extends AdminBaseController{
 				$param['jm_title'] = $info['title'];
 			}
 		}
+        // ppppppppp
+        if($param['catname']){
+            $cat=Db::name('category')->where('catname',$param['catname'])->find();
+            if(!empty($cat)){
+
+                $param['catid']=$cat['id'];
+
+            }else{
+               $this->error('添加失败'); 
+            }
+
+
+        }
+        // ppppppppp
+
 		$param['create_time'] = time();
 		$res = Db::name('message')->insert($param);
 		if($res){
@@ -162,7 +344,9 @@ class MessageController extends AdminBaseController{
     public function editPost(){
         $param = $this->request->param();
         isset($param['id']) or $this->error('需要id');
+      
         //先删掉
+
         Db::name('Message_fp')->where('msg_id',$param['id'])->delete();
         foreach($param['members'] as $kk=>$vv){
             $data = array(
@@ -190,7 +374,22 @@ class MessageController extends AdminBaseController{
         $param = $this->request->param();
         isset($param['id']) or $this->error('需要id');
         //先删掉
-  
+      
+          // ppppppppp
+        if($param['catname']){
+            $cat=Db::name('category')->where('catname',$param['catname'])->find();
+            if(!empty($cat)){
+
+                $param['catid']=$cat['id'];
+
+            }else{
+               $this->error('添加失败,没有该分类'); 
+            }
+
+
+        }
+        // ppppppppp
+
         $res = Db::name('message')->update($param);
         $this->success('修改成功');
     }
@@ -302,11 +501,17 @@ class MessageController extends AdminBaseController{
         $param['cates'] = implode(",",$param['cates']);
         $param['from_time'] = strtotime($param['from_time']);
         $param['end_time'] = strtotime($param['end_time']);
+        //pppppp
+        if(!$param['enable']){
+             $param['enable']='2';   
+        }
+        //pppppp
         if($param['ypz']==1){
             //更新
             unset($param['ypz']);
             $param['update_time'] = time();
             $res = Db::name('user_fp')->where('userid',$param['userid'])->update($param);
+
         }else{
             //添加
             unset($param['ypz']);

+ 91 - 3
public/themes/admin_simpleboot3/admin/message/index.html

@@ -39,11 +39,16 @@
     </if>
     <div style="float:left; width:80%;">
        
-        <form method="post" action="{:url('Message/fenpei')}" class="form-horizontal js-ajax-form margin-top-20">
+        <form method="post" action="{:url('Message/export')}" class="form-horizontal js-ajax-form margin-top-20">
+           
         <table class="table table-hover table-bordered">
             <thead>
             <tr>
+                <?php if($qx){ ?>
                 <th width="40"><input type="checkbox"  onclick="checkall(this.form);"></th>
+                <?php }else{ ?>
+                <th width="40">序号</th>
+                <?php }?>
                 <th width="150">品牌</th>
                 <th width="130">新闻</th>
                 <th width="70">分类</th>
@@ -52,7 +57,7 @@
                 <th width="80">IP</th>
                 <th width="100">所在区域</th>
                 <th width="80">投资额度</th>
-                <th width="120">电话</th>
+                <th width="180">电话</th>
                 <!-- <th width="80">回访时间</th> -->
                 <th>留言内容</th>
                 <th width="180">留言时间</th>
@@ -65,7 +70,11 @@
             <tbody>
             <foreach name="lists" item="vo">
                 <tr>
+                    <?php if($qx){ ?>
                     <td><input type="checkbox" name="msg[]"  value="{$vo.id}"></td>
+                    <?php }else{ ?>
+                    <td width="40"><?php echo $i=$i+1; ?></td>
+                    <?php }?>
                     <td><a target="_blank" href="/b{$vo.jm_id}">{$vo.jm_title}</a></td>
                     <?php if($vo['news_id']>0){ ?>
                     	<td><a target="_blank" href="/news{$vo.news_id}">{$vo.news_kw} </td>
@@ -79,7 +88,12 @@
                     <td>{$vo.ip}</td>
                     <td>{$vo.area}</td>
                     <td>{$vo.tzed}</td>
-                    <td>{$vo.mobile}</td>
+                    <td id="m{$vo.id}" >{$vo.mobile} 
+                        <if condition="$fenpei.enable==1">
+                        <a class="mobile"  data="{$vo.id}" href="javascript:;" > 查看</a>
+                        <span class="label label-success" title="已被查看{$vo.vid}次">{$vo.vid}</span>
+                        </if>
+                    </td>
                     
                     <!-- <td>{$vo.lxsj}</td> -->
                     <td>{$vo.content}</td>
@@ -94,6 +108,21 @@
                 </tr>
             </foreach>
             </tbody>
+
+
+        <?php if(!$qx){ ?>
+            <tbody><tr>
+                <td colspan="11">
+                    <if condition="$fenpei.enable==1">
+                    <input class="btn btn-sm btn-primary js-ajax-submit" type="submit" name="export" value="导出已查看信息">
+                    <else/>
+                        <input class="btn btn-sm btn-primary js-ajax-submit" type="submit" name="export" value="导出信息">
+                    </if>
+                
+                </td>
+            </tr>
+    </tbody>
+    <?php }?>
             <?php if($qx){ ?>
             <!-- <tr>
                 <td colspan="10">
@@ -117,6 +146,65 @@
     </div>
     <script src="__STATIC__/js/admin.js"></script>
     <script>
+
+    $(".mobile").click(function () {
+
+        Wind.css('layer');
+
+        var getid=$(this).attr("data");
+        var $_this  = this,
+                    $this   = $($_this),
+                    href    = $this.data('href'),
+                    refresh = $this.data('refresh'),
+                    msg     = $this.data('msg');
+                    href    = href ? href : $this.attr('href');
+          art.dialog({
+                    title: false,
+                    icon: 'question',
+                    content: "提示" ? "查看隐藏号码需扣除一次点数,重复查看不扣点数" : '确定要删除吗?',
+                    close: function () {
+                        $_this.focus(); //关闭时让触发弹窗的元素获取焦点
+                        return true;
+                    },
+                    okVal: "确定",
+                ok: function () { 
+                    $.ajax({
+                        url:'tomobile.html',
+                        type:'get',
+                        data:{id:getid},
+                        beforeSend: function (xhr) {
+                            // $('#loading').modal('show');
+                            //加载层
+                                            
+                        }
+                        ,
+                        success: function (res) {
+                             if(res.code=='1'){ 
+                           // $("#m"+getid).html('数据获取错误');
+                            
+                            $("#m"+getid).html(res.msg);
+                            console.log(res);
+
+                         }else{
+                                Wind.use("layer", function () {
+                                    layer.msg(res.msg, {icon: 5});
+                                });
+                         }
+                         // $('#loading').modal('hide');
+                        }
+                    }); 
+                },
+                    cancelVal: '关闭',
+                    cancel: true
+            });
+   
+        
+       
+
+    });
+
+</script>
+    <script>
         function checkall(f, t) {
             var t = t ? t : 1;
             for(var i = 0; i < f.elements.length; i++) {

+ 35 - 1
public/themes/admin_simpleboot3/admin/message/shanghu_edit.html

@@ -42,7 +42,20 @@
         <div class="form-group">
             <label for="input-user_tiaoshu" class="col-sm-2 control-label">可以查看的条数</label>
             <div class="col-md-6 col-sm-10">
-                <input type="text" name="tiaoshu" value="{$info.tiaoshu}" />
+                <input type="text" name="tiaoshu" value="{$info.tiaoshu}" /><i> 0为无限制</i>
+            </div>
+        </div>
+
+          <div class="form-group">
+            <label for="input-user_enable" class="col-sm-2 control-label">是否开启点数</label>
+            <div class="col-md-6 col-sm-10">
+                <input type="checkbox" name="enable" value="1" id="enable" <if condition="$info.enable==1"> checked="checked"</if> >
+            </div>
+        </div>
+        <div class="form-group">
+            <label for="input-user_points" class="col-sm-2 control-label">可以查看的点数</label>
+            <div class="col-md-6 col-sm-10">
+                <input type="text" name="points" id="points" <if condition="$info.enable==2"> disabled</if>  value="{$info.points}" />
             </div>
         </div>
         <div class="form-group">
@@ -52,6 +65,27 @@
         </div>
     </form>
 </div>
+
+
+<script>
+
+    $("#enable").click(function(){
+        if(this.checked == true){
+
+     
+        $('#points').prop('disabled', false); // 禁用input
+        $("#enable").attr("value","1");;
+
+        }else{
+       
+           $('#points').prop('disabled', true); // 禁用input
+             $("#enable").attr("value","2");;
+        }
+    });
+ 
+
+ 
+</script>
 <script src="__STATIC__/js/admin.js"></script>
 </body>
 </html>