马铁龙 6 anni fa
parent
commit
fafc1701a7

+ 73 - 2
application/admin/controller/Intention.php

@@ -15,6 +15,13 @@ use think\Session;
  */
 class Intention extends Backend
 {
+    private $status = [
+        "PROTECTOR" => 0 , //保护中
+        "OVERDUE" => 1, // 已过期
+        "SIGN" => 2, // 已签单
+        "FREE" => 3, // 冻结中
+        "GIVEUP" => 4, // 已放弃
+    ];
     //快速搜索的字段
     protected $searchFields = ['unit_name','contacts'];
 
@@ -22,7 +29,7 @@ class Intention extends Backend
      * 无需鉴权的方法,但需要登录
      * @var array
      */
-    protected $noNeedRight = ['unittypelist'];
+    protected $noNeedRight = ['again','giveup','unittypelist'];
     
     /**
      * Intention模型对象
@@ -53,14 +60,16 @@ class Intention extends Backend
                 return $this->selectpage();
             }
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-
+            $where1 = array('isdel'=>0);
             $total = $this->model
                 ->where($where)
+                ->where($where1)
                 ->order($sort, $order)
                 ->count();
 
             $list = $this->model
                 ->where($where)
+                ->where($where1)
                 ->order($sort, $order)
                 ->limit($offset, $limit)
                 ->select();
@@ -145,7 +154,69 @@ class Intention extends Backend
         $data = ['rows' => $searchlist];
         return $data;
     }
+    /**
+     * 放弃
+     */
+    public function giveup() {
+        try {
+            //1.获取id
+            $id = $this->request->post("id");
+
+            //2.protector表 通过id 查找出数据
+            $protector = \app\admin\model\Intention::get($id);
+            //3.获取用户id
+            $usr_id = Session::get('admin')['id'];
+            //4.判断用户id和 protector的用户id是否一致 保存状态
+            if ($usr_id != 1 && $protector['usr_id'] != $usr_id) {
+                $this->error('请操作自己的数据!');
+            }
+
+            //5.保护到期时间设置现在 冻结算一下
+            $free_day = Session::get('admin')['free_day'];
+            $param['ex_date'] = date('Y-m-d');
+            $param['free_date'] = date('Y-m-d', strtotime("+" . $free_day . " day"));
+
+            // $param['status'] = $this->status['GIVEUP'];
+            $param['isdel'] = 1;
+            $param['id'] = $id;
+
 
+            //6.入库
+            $res = $this->model->allowField(true)->isUpdate(true)->save($param);
+            if ($res) {
+                $this->success('放弃成功!');
+            }
+            $this->error();
+        } catch (\think\exception\PDOException $e)
+        {
+            $this->error($e->getMessage());
+        }
+    }
+    public function follow($ids = NULL){
+        $info = Db::table('follow')->where('type',1)->where('protect_id',$ids)->field('created_at','main')->select();
+        if($_POST){
+            $data = $this->request->post();
+            $unit = Db::table('protector')->where('id',$data['id'])->field('unit_name')->find();
+            $param['protect_id'] = $data['id'];
+            $param['usr_id'] = Session::get('admin')['id'];
+            $param['usr_nickname'] = $data['nickname'];
+            $param['protect_name'] = $unit['unit_name'];
+            $param['follow_time'] = $data['row']['follow_time'];
+            $param['main'] = $data['row']['main'];
+            $param['created_at'] = date('Y-m-d H:i:s');
+            $param['type'] = 1;
+            $res = Db::table('follow')->insert($param);
+            if($res){
+                $this->success();
+            }else{
+                $this->error('数据存储失败');
+            } 
+        }
+        $this->view->assign("info", $info);
+        $this->view->assign("id", $ids);
+        $this->view->assign("nickname", Session::get('admin')['nickname']);
+        return $this->view->fetch();
+    }
 
     
 

+ 32 - 6
application/admin/controller/Protector.php

@@ -179,7 +179,7 @@ class Protector extends Backend
                     $protect_count = Session::get('admin')['protect_count'];    //保护个数
                     $protect_day = Session::get('admin')['protect_day'];        //保护天数
                     $free_day = Session::get('admin')['free_day'];              // 冻结天数
-                    $params['pro_date'] = date('Y-m-d');    //保护时间
+                    $params['pro_date'] = date('Y-m-d H:i:s');    //保护时间
                     $params['total'] = ($params['number'] * $params['price']);      //总价
 
 
@@ -188,8 +188,8 @@ class Protector extends Backend
                     $params['depart_id'] = Session::get('admin')['depart_id'];   //获取所属组id
 
                     //  获取到期时间和冻结到期时间
-                    $params['ex_date'] = date('Y-m-d',strtotime("+".$protect_day." day"));    //保护到期时间
-                    $params['free_date'] = date('Y-m-d',strtotime("{$params['ex_date']} "."+".$free_day." day"));    //保护到期时间
+                    $params['ex_date'] = date('Y-m-d H:i:s',strtotime("+".$protect_day." day"));    //保护到期时间
+                    $params['free_date'] = date('Y-m-d H:i:s',strtotime("{$params['ex_date']} "."+".$free_day." day"));    //保护到期时间
 
                     // 根据单位名称判断是否已经存在(已被保护)
                     $res = \app\admin\model\Protector::unitNameIsExist($params['unit_name']);
@@ -292,7 +292,7 @@ class Protector extends Backend
             $usr_id = Session::get('admin')['id'];
 
             //4.判断用户id和 protector的用户id是否一致 保存状态
-            if ($protector['usr_id'] != $usr_id) {
+            if ($usr_id != 1 && $protector['usr_id'] != $usr_id) {
                 $this->error('请操作自己的数据!');
             }
 
@@ -332,7 +332,7 @@ class Protector extends Backend
             $usr_id = Session::get('admin')['id'];
 
             //4.判断用户id和 protector的用户id是否一致 保存状态
-            if ($protector['usr_id'] != $usr_id) {
+            if ($usr_id != 1 && $protector['usr_id'] != $usr_id) {
                 $this->error('请操作自己的数据!');
             }
 
@@ -414,6 +414,32 @@ class Protector extends Backend
         }
     }
 
+    public function follow($ids = NULL){
+        $info = Db::table('follow')->where('type',0)->where('protect_id',$ids)->field('created_at','main')->select();
+        if($_POST){
+            $data = $this->request->post();
+            $unit = Db::table('protector')->where('id',$data['id'])->field('unit_name')->find();
+            $param['protect_id'] = $data['id'];
+            $param['usr_id'] = Session::get('admin')['id'];
+            $param['usr_nickname'] = $data['nickname'];
+            $param['protect_name'] = $unit['unit_name'];
+            $param['follow_time'] = $data['row']['follow_time'];
+            $param['main'] = $data['row']['main'];
+            $param['created_at'] = date('Y-m-d H:i:s');
+            $param['type'] = 0;
+            $res = Db::table('follow')->insert($param);
+            if($res){
+                $this->success();
+            }else{
+                $this->error('数据存储失败');
+            } 
+        }
+        $this->view->assign("info", $info);
+        $this->view->assign("id", $ids);
+        $this->view->assign("nickname", Session::get('admin')['nickname']);
+        return $this->view->fetch();
+    }
+
     /**
      * 查看所有的跟进
      */
@@ -456,7 +482,7 @@ class Protector extends Backend
                 '        <div class="form-group col-xs-12">' .
                 '            <label for="follow_time" class="control-label col-xs-12 col-sm-3">跟进时间:</label>' .
                 '            <div class="col-xs-12 col-sm-7">' .
-                '                <input id="follow_time" onclick="showDatetime()" class="form-control datetimepicker" name="follow_time" type="text" data-rule="required">' .
+                '                <input id="follow_time" class="form-control datetimepicker" name="follow_time" type="text" data-rule="required">' .
                 '            </div>' .
                 '        </div>';
             $html .=

+ 45 - 0
application/admin/view/intention/follow.html

@@ -0,0 +1,45 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="intention/follow">
+    <input type="hidden" name="id" value="{$id}">
+    <input type="hidden" name="nickname" value="{$nickname}">
+
+    {foreach $info as $i}
+        <div class="form-group">
+            <label class="control-label col-xs-12 col-sm-2">跟进时间:</label>
+            <div class="col-xs-12 col-sm-8">
+                <input id="c-follow_time"   class="form-control" value="{$i.follow_time}" type="datetime" readonly>
+            </div>
+        </div>
+        <div class="form-group">
+            <label class="control-label col-xs-12 col-sm-2">跟进内容:</label>
+            <div class="col-xs-12 col-sm-8">
+                <textarea id="c-main" class="form-control " rows="5" cols="50" readonly>{$i.main}</textarea>
+            </div>
+        </div>
+    {/foreach}
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">跟进时间:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-follow_time"  class="form-control datetimepicker" name="row[follow_time]" type="datetime">
+        </div>
+    </div>
+    <!--<div class="form-group">-->
+        <!--<label class="control-label col-xs-12 col-sm-2">总价:</label>-->
+        <!--<div class="col-xs-12 col-sm-8">-->
+            <!--<input id="c-total" onchange="makeTotal()" class="form-control" name="row[total]" type="number" disabled>-->
+        <!--</div>-->
+    <!--</div>-->
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">跟进内容:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-main" class="form-control " rows="5" name="row[main]" cols="50"></textarea>
+        </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">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 45 - 0
application/admin/view/protector/follow.html

@@ -0,0 +1,45 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="protector/follow">
+    <input type="hidden" name="id" value="{$id}">
+    <input type="hidden" name="nickname" value="{$nickname}">
+
+    {foreach $info as $i}
+        <div class="form-group">
+            <label class="control-label col-xs-12 col-sm-2">跟进时间:</label>
+            <div class="col-xs-12 col-sm-8">
+                <input id="c-follow_time"   class="form-control" value="{$i.follow_time}" type="datetime" readonly>
+            </div>
+        </div>
+        <div class="form-group">
+            <label class="control-label col-xs-12 col-sm-2">跟进内容:</label>
+            <div class="col-xs-12 col-sm-8">
+                <textarea id="c-main" class="form-control " rows="5" cols="50" readonly>{$i.main}</textarea>
+            </div>
+        </div>
+    {/foreach}
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">跟进时间:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-follow_time"  class="form-control datetimepicker" name="row[follow_time]" type="datetime">
+        </div>
+    </div>
+    <!--<div class="form-group">-->
+        <!--<label class="control-label col-xs-12 col-sm-2">总价:</label>-->
+        <!--<div class="col-xs-12 col-sm-8">-->
+            <!--<input id="c-total" onchange="makeTotal()" class="form-control" name="row[total]" type="number" disabled>-->
+        <!--</div>-->
+    <!--</div>-->
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">跟进内容:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-main" class="form-control " rows="5" name="row[main]" cols="50"></textarea>
+        </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">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 135 - 3
public/assets/js/backend/intention.js

@@ -9,6 +9,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                     add_url: 'intention/add',
                     edit_url: 'intention/edit',
                     del_url: 'intention/del',
+                    follow_url: 'intention/follow',
                     multi_url: 'intention/multi',
                     table: 'intention',
                 }
@@ -32,9 +33,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                                 return row.usr_depart;
                         }},
                         {field: 'created_at', title: '创建时间', operate:'RANGE', addclass:'datetimerange', searchable: false},
-                        {field: 'operate', title: __('Operate'),
-                            table: table, events: Table.api.events.operate,
-                            formatter: Table.api.formatter.operate,
+                        {field: 'operate', title: __('Operate'),searchable: false,
+                            table: table,
+                            events: Controller.api.events.operate,
+                            formatter: Controller.api.formatter.operate
                         }
                     ]
                 ]
@@ -62,9 +64,139 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
         edit: function () {
             Controller.api.bindevent();
         },
+        follow: function () {
+            Controller.api.bindevent();
+        },
         api: {
             bindevent: function () {
                 Form.api.bindevent($("form[role=form]"));
+            },
+            formatter:{
+                operate: function (value, row, index) {
+                    var table = this.table;
+                    // 操作配置
+                    var options = table ? table.bootstrapTable('getOptions') : {};
+                    // 默认按钮组
+                    var buttons = $.extend([], this.buttons || []);
+                    switch (row.status){
+                        case 0:         //保护中
+                            buttons.push({text: '放弃', classname: 'btn btn-xs btn-danger btn-giveup'});
+                            buttons.push({text:'跟进', classname: 'btn btn-xs btn-info btn-follow'});
+                            buttons.push({text:'修改', classname: 'btn btn-xs btn-primary btn-editone'});
+                            buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'});
+                            buttons.push({
+                                name: 'del',
+                                icon: 'fa fa-trash',
+                                title: __('Del'),
+                                extend: 'data-toggle="tooltip"',
+                                classname: 'btn btn-xs btn-danger btn-delone'
+                            });
+                            break;
+                        case 1:
+                            buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'});
+                            break;
+                        case 2:
+                            buttons.push({text:'修改', classname: 'btn btn-xs btn-primary btn-editone'});
+                            buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'});
+                            break;
+                        case 4:
+                            buttons.push({text:'详情', classname: 'btn btn-xs btn-warning btn-detail'});
+                            break;
+                    }
+
+                    return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
+                },
+
+            },
+            events:{
+                operate: {
+                    // 放弃
+                    'click .btn-giveup': function(e, value, row) {
+                        Layer.confirm('您确定放弃吗?',function (index) {
+                            var id = row.id;
+                            $.ajax({
+                                url: 'intention/giveup',
+                                type: 'post',
+                                data: { id:id },
+                                dataType: 'json',
+                                success: function success(res) {
+                                    Layer.close(index);
+                                    if(res.code == 1){
+                                        Toastr.success(res.msg);
+                                        $('.btn-refresh').click();
+                                    } else {
+                                        Toastr.error(res.msg);
+                                    }
+                                }
+                            });
+                        });
+                    },
+                    // 跟进
+                    'click .btn-follow': function (e, value, row) {
+                        e.stopPropagation();
+                        e.preventDefault();
+                        var options = $(this).closest('table').bootstrapTable('getOptions');
+                        var open = Fast.api.open(options.extend.follow_url + (options.extend.follow_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Follow'), {
+                            title: '跟进',
+                            maxmin: false
+                        });
+                    },
+                    // 修改
+                    'click .btn-editone': function clickBtnEditone(e, value, row, index) {
+                        e.stopPropagation();
+                        e.preventDefault();
+                        var options = $(this).closest('table').bootstrapTable('getOptions');
+                        var open = Fast.api.open(options.extend.edit_url + (options.extend.edit_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Edit'), {
+                            title: '修改',
+                            maxmin: false
+                        });
+                    },
+
+                    'click .btn-detail': function clickBtnEditone(e, value, row, index) {
+                        var html = '<table class="table table-striped table-bordered table-hover">';
+                        html += '<tr><td>公司名称</td><td>'+ row.unit_name +'</td></tr>';
+                        html += '<tr><td>联系人</td><td>'+ row.contacts +'</td></tr>';
+                        html += '<tr><td>手机</td><td>'+ row.phone +'</td></tr>';
+                        html += '<tr><td>固定电话</td><td>'+ row.fixed_phone +'</td></tr>';
+                        html += '<tr><td>地址</td><td>'+ row.address +'</td></tr>';
+                        html += '<tr><td>联系人职位</td><td>'+ row.con_position +'</td></tr>';
+                        html += '<tr><td>单位性质</td><td>'+ row.unit_type +'</td></tr>';
+                        html += '<tr><td>人数</td><td>'+ row.number +'</td></tr>';
+                        html += '<tr><td>单价</td><td>'+ row.price +'</td></tr>';
+                        html += '<tr><td>备注</td><td>'+ row.remark +'</td></tr>';
+                        html += '<tr><td>操作人</td><td>'+ row.usr_nickname +'</td></tr>';
+                        html += '<tr><td>操作人部门</td><td>'+ row.usr_depart +'</td></tr>';
+                        html += '</table>';
+                        Layer.open({
+                            content :   html,
+                            area    :   ['500px'],
+                        })
+                    },
+
+                    'click .btn-delone': function (e, value, row, index) {
+                        e.stopPropagation();
+                        e.preventDefault();
+                        var that = this;
+                        var top = $(that).offset().top - $(window).scrollTop();
+                        var left = $(that).offset().left - $(window).scrollLeft() - 260;
+                        if (top + 154 > $(window).height()) {
+                            top = top - 154;
+                        }
+                        if ($(window).width() < 480) {
+                            top = left = undefined;
+                        }
+                        Layer.confirm(
+                            __('Are you sure you want to delete this item?'),
+                            {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true},
+                            function (index) {
+                                var table = $(that).closest('table');
+                                var options = table.bootstrapTable('getOptions');
+                                Table.api.multi("del", row[options.pk], table, that);
+                                Layer.close(index);
+                            }
+                        );
+                    }
+                }
             }
         }
     };

+ 11 - 19
public/assets/js/backend/protector.js

@@ -1,4 +1,4 @@
-define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], function ($, undefined, Backend, Table, Form, Selectpage) {
+define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage', 'bootstrap-datetimepicker'], function ($, undefined, Backend, Table, Form, Selectpage, Datetimepicker) {
 
     var Controller = {
         index: function () {
@@ -9,6 +9,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                     index_url: 'protector/index' + '/status/' + status,
                     add_url: 'protector/add',
                     edit_url: 'protector/edit',
+                    follow_url: 'protector/follow',
                     del_url: 'protector/del',
                     multi_url: 'protector/multi',
                     table: 'protector',
@@ -75,6 +76,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
             });
             Controller.api.bindevent();
         },
+        follow: function () {
+            Controller.api.bindevent();
+        },
         api: {
             bindevent: function () {
                 Form.api.bindevent($("form[role=form]"));
@@ -184,25 +188,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                     },
                     // 跟进
                     'click .btn-follow': function (e, value, row) {
-                        var id = row.id;
-                        $.ajax({
-                            url: 'protector/showFollow',
-                            type: 'post',
-                            data: { id:id },
-                            dataType: 'json',
-                            success: function success(res) {
-                                Layer.open({
-                                    area: ['600px','100%'],
-                                    content:res.data,
-                                    yes: function(index){
-                                        addFollow(row.id,row.unit_name);
-
-                                        layer.close(index); //如果设定了yes回调,需进行手工关闭
-                                    }
-                                })
-                            }
+                        e.stopPropagation();
+                        e.preventDefault();
+                        var options = $(this).closest('table').bootstrapTable('getOptions');
+                        var open = Fast.api.open(options.extend.follow_url + (options.extend.follow_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Follow'), {
+                            title: '跟进',
+                            maxmin: false
                         });
-
                     },
                     // 修改
                     'click .btn-editone': function clickBtnEditone(e, value, row, index) {