马铁龙 7 năm trước cách đây
mục cha
commit
629e46fa78

+ 6 - 0
application/admin/controller/Intention.php

@@ -103,6 +103,12 @@ class Intention extends Backend
                     $params['depart_id'] = Session::get('admin')['depart_id'];   //获取所属组id
                     \app\admin\model\Intention::addUnitType($params['unit_type']);
 
+                    // 根据单位名称判断是否已经存在(已被保护)
+                    $res = \app\admin\model\Protector::unitNameIsExist($params['unit_name']);
+                    if($res){
+                        $this->error('"'.$res.'"已经被保护!');
+                    }
+
 
                     $result = $this->model->allowField(true)->save($params);
                     if ($result !== false)

+ 68 - 14
application/admin/controller/Protector.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller;
 
+use app\admin\model\AuthGroup;
 use app\admin\model\AuthGroupAccess;
 use app\common\controller\Backend;
 use think\Db;
@@ -47,13 +48,23 @@ class Protector extends Backend
         $this->request->filter(['strip_tags']);
         if ($this->request->isAjax())
         {
+            // 先统一处理过期保护客户
+            \app\admin\model\Protector::updateOverdue();
+
             //如果发送的来源是Selectpage,则转发到Selectpage
             if ($this->request->request('keyField'))
             {
                 return $this->selectpage();
             }
             list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-            $where_usr_id = ['usr_id'=>Session::get('admin')['id']];    //只能查看自己的数据
+
+            $rules = AuthGroup::getRulesByGroupId(Session::get('admin')['depart_id']);
+            if($rules == '*'){
+                $where_usr_id = false;      // 管理员可以看到所有
+            } else {
+                $where_usr_id = ['usr_id'=>Session::get('admin')['id']];    //只能查看自己的保护客户和签单客户
+            }
+
             switch ($status){
                 case 'protect':                 //保护中
                     $total = $this->model
@@ -73,15 +84,11 @@ class Protector extends Backend
                 case 'overdue':                 //已过期
                     $total = $this->model
                         ->where('status',$this->status['OVERDUE'])
-                        ->whereOr('status',$this->status['GIVEUP'])
-                        ->where($where_usr_id)
                         ->where($where)
                         ->order($sort, $order)
                         ->count();
                     $list = $this->model
                         ->where('status',$this->status['OVERDUE'])
-                        ->whereOr('status',$this->status['GIVEUP'])
-                        ->where($where_usr_id)
                         ->where($where)
                         ->order($sort, $order)
                         ->limit($offset, $limit)
@@ -105,13 +112,11 @@ class Protector extends Backend
                 case 'giveup':                 //已放弃
                     $total = $this->model
                         ->where('status',$this->status['GIVEUP'])
-                        ->where($where_usr_id)
                         ->where($where)
                         ->order($sort, $order)
                         ->count();
                     $list = $this->model
                         ->where('status',$this->status['GIVEUP'])
-                        ->where($where_usr_id)
                         ->where($where)
                         ->order($sort, $order)
                         ->limit($offset, $limit)
@@ -172,7 +177,7 @@ class Protector extends Backend
                     // 根据单位名称判断是否已经存在(已被保护)
                     $res = \app\admin\model\Protector::unitNameIsExist($params['unit_name']);
                     if($res){
-                        $this->error('"'.$res.'"已经被保护!');
+                        $this->error($res);
                     }
 
                     // 判断是否超出保护个数
@@ -202,6 +207,58 @@ class Protector extends Backend
         return $this->view->fetch();
     }
 
+    /**
+     * 编辑
+     */
+    public function edit($ids = NULL)
+    {
+        $row = $this->model->get($ids);
+        if (!$row)
+            $this->error(__('No Results were found'));
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds))
+        {
+            if (!in_array($row[$this->dataLimitField], $adminIds))
+            {
+                $this->error(__('You have no permission'));
+            }
+        }
+        if ($this->request->isPost())
+        {
+            $params = $this->request->post("row/a");
+            if ($params)
+            {
+                try
+                {
+                    //是否采用模型验证
+                    if ($this->modelValidate)
+                    {
+                        $name = basename(str_replace('\\', '/', get_class($this->model)));
+                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : true) : $this->modelValidate;
+                        $row->validate($validate);
+                    }
+                    $params['total'] = ($params['number'] * $params['price']);      //总价
+                    $result = $row->allowField(true)->save($params);
+                    if ($result !== false)
+                    {
+                        $this->success();
+                    }
+                    else
+                    {
+                        $this->error($row->getError());
+                    }
+                }
+                catch (\think\exception\PDOException $e)
+                {
+                    $this->error($e->getMessage());
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $this->view->assign("row", $row);
+        return $this->view->fetch();
+    }
+
 
     /**
      * 放弃
@@ -295,7 +352,7 @@ class Protector extends Backend
             //4.判断用户保护个数是否达到上限
             $res = \app\admin\model\Protector::proCountIsExceed($usr_id, Session::get('admin')['protect_count']);
             if($res){
-                $this->error($res);
+                $this->error('用户保护人数已经达到上限('.Session::get('admin')['protect_count'].'个)');
             }
 
             //5 判断 protector表 状态 如果是已签单返回
@@ -312,7 +369,7 @@ class Protector extends Backend
              if($protector['usr_id'] == $usr_id) {
                 // 同一个人操作,判断是否结束冻结
                  if(strtotime(date('Y-m-d')) < strtotime($protector['free_date'])){
-                     $this->error('未过冻结时间!无法再次保护');
+                     $this->error('未过冻结时间('.$protector['free_date'].')!无法再次保护');
                  }
              }
 
@@ -382,7 +439,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" class="form-control datetimepicker" name="follow_time" type="text" data-rule="required">' .
+                '                <input id="follow_time" onclick="showDatetime()" class="form-control datetimepicker" name="follow_time" type="text" data-rule="required">' .
                 '            </div>' .
                 '        </div>';
             $html .=
@@ -429,10 +486,7 @@ class Protector extends Backend
         }
     }
 
-    public function departList()
-    {
 
-    }
 
 
 

+ 11 - 5
application/admin/controller/auth/Admin.php

@@ -4,9 +4,11 @@ namespace app\admin\controller\auth;
 
 use app\admin\model\AuthGroup;
 use app\admin\model\AuthGroupAccess;
+use app\admin\model\Protector;
 use app\common\controller\Backend;
 use fast\Random;
 use fast\Tree;
+use think\Session;
 
 /**
  * 管理员管理
@@ -110,6 +112,7 @@ class Admin extends Backend
             {
                 $groups = isset($adminGroupName[$v['id']]) ? $adminGroupName[$v['id']] : [];
                 $v['groups'] = implode(',', array_keys($groups));
+                $v['surplus_count'] = ($v['protect_count'] - Protector::getProtectCount($v['id']));
                 $v['groups_text'] = implode(',', array_values($groups));
             }
             unset($v);
@@ -133,7 +136,10 @@ class Admin extends Backend
                 $params['salt'] = Random::alnum();
                 $params['password'] = md5(md5($params['password']) . $params['salt']);
                 $params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。
-                $this->makeProtect($params);
+
+                // 获取所属组别的保护天数
+                $protect_count = AuthGroup::getProtectCountById($this->request->post("group/a")[0]);
+                $this->makeProtect($params,['protect_count'=>$protect_count]);
 
                 $result = $this->model->validate('Admin.add')->save($params);
                 if ($result === false)
@@ -271,11 +277,11 @@ class Admin extends Backend
         return parent::selectpage();
     }
 
-    private function makeProtect(&$params)
+    private function makeProtect(&$params,$arr)
     {
-        $params['protect_count'] = 20;
-        $params['protect_day'] = 90;
-        $params['free_day'] = 30;
+        $params['protect_count'] = isset($arr['protect_count']) ? $arr['protect_count'] : 30;  // 保护个数
+        $params['protect_day'] = isset($arr['protect_day']) ? $arr['protect_day'] : 90;        // 保护天数
+        $params['free_day'] = isset($arr['free_day']) ? $arr['free_day'] : 30;                  // 冻结保护天数
     }
 
 }

+ 21 - 0
application/admin/model/AuthGroup.php

@@ -18,4 +18,25 @@ class AuthGroup extends Model
         return __($value);
     }
 
+    /**
+     * 获取角色组权限
+     * @param $group_id
+     * @return mixed
+     */
+    public static function getRulesByGroupId($group_id)
+    {
+        $rules = self::where('id',$group_id)
+            ->value('rules');
+
+        return $rules;
+    }
+
+    public static function getProtectCountById($id)
+    {
+        $protect_count = self::where('id',$id)
+            ->value('protect_count');
+
+        return $protect_count;
+    }
+
 }

+ 54 - 9
application/admin/model/Protector.php

@@ -22,17 +22,32 @@ class Protector extends Model
     ];
 
 
-    /**
-     * 判断单位是否存在,存在返回name
-     * @param $unit_name
-     * @return bool|mixed
-     */
+
     public static function unitNameIsExist($unit_name)
     {
         $res = self::where('unit_name',$unit_name)
-            ->value('unit_name');
+            ->field('status,unit_name,usr_nickname')
+            ->find();
+
+        if($res){
+            switch ($res['status']){
+                case 0:
+                    $msg = $unit_name.'已被"'.$res['usr_nickname'].'"保护,无法保护!';
+                    break;
+                case 1:
+                    $msg = $unit_name.'已经过期,请到已过期列表再次保护!';
+                    break;
+                case 2:
+                    $msg = $unit_name.'已经签单,无法保护!';
+                    break;
+                case 4:
+                    $msg = $unit_name.'已经放弃,请到已放弃列表再次保护!';
+                    break;
+            }
+            return $msg;
+        }
 
-        return $res;
+        return false;
 
     }
 
@@ -48,15 +63,45 @@ class Protector extends Model
             ->where('status',0)
             ->count();
         if($exist_count >= $count){
-            return '保护客户个数已超出上限!';
+            return true;
         }
         return false;
 
     }
 
+    /**
+     * 更新过期的保护客户
+     */
+    public static function updateOverdue()
+    {
+        $now = date('Y-m-d');
+        $ids = self::where('status',0)
+            ->where('ex_date','<=',$now)
+            ->column('id');
+        if(!empty($ids)){
+            self::whereIn('id',$ids)
+                ->update(['status'=>1]);
+        }
+    }
+
+    /**
+     * 根据usr_id获取已经保护的个数
+     * @param $usr_id
+     * @return int|string
+     */
+    public static function getProtectCount($usr_id)
+    {
+        $count = self::where('usr_id',$usr_id)
+            ->where('status',0)
+            ->count();
+
+        return $count;
+
+    }
+
+
 
 
-    
 
 
 

+ 2 - 3
application/admin/validate/Admin.php

@@ -14,7 +14,6 @@ class Admin extends Validate
         'username' => 'require|max:50|unique:admin',
         'nickname' => 'require',
         'password' => 'require',
-        'email'    => 'require|email|unique:admin,email',
     ];
 
     /**
@@ -33,8 +32,8 @@ class Admin extends Validate
      * 验证场景
      */
     protected $scene = [
-        'add'  => ['username', 'email', 'nickname', 'password'],
-        'edit' => ['username', 'email', 'nickname'],
+        'add'  => ['username', 'nickname', 'password'],
+        'edit' => ['username', 'nickname'],
     ];
 
     public function __construct(array $rules = [], $message = [], $field = [])

+ 2 - 7
application/admin/view/auth/admin/add.html

@@ -2,7 +2,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Group')}:</label>
         <div class="col-xs-12 col-sm-8">
-            {:build_select('group[]', $groupdata, null, ['class'=>'form-control selectpicker', 'multiple'=>'', 'data-rule'=>'required'])}
+            {:build_select('group[]', $groupdata, null, ['class'=>'form-control selectpicker', 'data-rule'=>'required'])}
         </div>
     </div>
     <div class="form-group">
@@ -11,12 +11,7 @@
             <input type="text" class="form-control" id="username" name="row[username]" value="" data-rule="required;username" />
         </div>
     </div>
-    <div class="form-group">
-        <label for="email" class="control-label col-xs-12 col-sm-2">{:__('Email')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input type="email" class="form-control" id="email" name="row[email]" value="" data-rule="required;email" />
-        </div>
-    </div>
+
     <div class="form-group">
         <label for="nickname" class="control-label col-xs-12 col-sm-2">{:__('Nickname')}:</label>
         <div class="col-xs-12 col-sm-8">

+ 8 - 13
application/admin/view/auth/admin/edit.html

@@ -2,7 +2,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Group')}:</label>
         <div class="col-xs-12 col-sm-8">
-            {:build_select('group[]', $groupdata, $groupids, ['class'=>'form-control selectpicker', 'multiple'=>'', 'data-rule'=>'required'])}
+            {:build_select('group[]', $groupdata, $groupids, ['class'=>'form-control selectpicker',  'data-rule'=>'required'])}
         </div>
     </div>
     <div class="form-group">
@@ -11,12 +11,7 @@
             <input type="text" class="form-control" id="username" name="row[username]" value="{$row.username}" data-rule="required;username" />
         </div>
     </div>
-    <div class="form-group">
-        <label for="email" class="control-label col-xs-12 col-sm-2">{:__('Email')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input type="email" class="form-control" id="email" name="row[email]" value="{$row.email}" data-rule="required;email" />
-        </div>
-    </div>
+
     <div class="form-group">
         <label for="nickname" class="control-label col-xs-12 col-sm-2">{:__('Nickname')}:</label>
         <div class="col-xs-12 col-sm-8">
@@ -29,12 +24,12 @@
             <input type="password" class="form-control" id="password" name="row[password]" autocomplete="new-password" value="" data-rule="password" />
         </div>
     </div>
-    <div class="form-group">
-        <label for="loginfailure" class="control-label col-xs-12 col-sm-2">{:__('Loginfailure')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input type="number" class="form-control" id="loginfailure" name="row[loginfailure]" value="{$row.loginfailure}" data-rule="required" />
-        </div>
-    </div>
+    <!--<div class="form-group">-->
+        <!--<label for="loginfailure" class="control-label col-xs-12 col-sm-2">{:__('Loginfailure')}:</label>-->
+        <!--<div class="col-xs-12 col-sm-8">-->
+            <!--<input type="number" class="form-control" id="loginfailure" name="row[loginfailure]" value="{$row.loginfailure}" data-rule="required" />-->
+        <!--</div>-->
+    <!--</div>-->
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
         <div class="col-xs-12 col-sm-8">

+ 6 - 0
application/admin/view/auth/group/add.html

@@ -21,6 +21,12 @@
             <div id="treeview"></div>
         </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 type="number" class="form-control" id="protect_count" name="row[protect_count]" value="0" data-rule="required" />
+        </div>
+    </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
         <div class="col-xs-12 col-sm-8">

+ 6 - 0
application/admin/view/auth/group/edit.html

@@ -21,6 +21,12 @@
             <div id="treeview"></div>
         </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 type="number" class="form-control" id="protect_count" name="row[protect_count]" value="{$row.protect_count}" data-rule="required" />
+        </div>
+    </div>
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
         <div class="col-xs-12 col-sm-8">

+ 0 - 9
application/admin/view/general/profile/index.html

@@ -48,15 +48,6 @@
                         
                         <h3 class="profile-username text-center">{$admin.username}</h3>
 
-                        <p class="text-muted text-center">{$admin.email}</p>
-                        <div class="form-group">
-                            <label for="username" class="control-label">{:__('Username')}:</label>
-                            <input type="text" class="form-control" name="row[username]" value="{$admin.username}" disabled />
-                        </div>
-                        <div class="form-group">
-                            <label for="email" class="control-label">{:__('Email')}:</label>
-                            <input type="text" class="form-control" name="row[email]" value="{$admin.email}" data-rule="required;email" />
-                        </div>
                         <div class="form-group">
                             <label for="nickname" class="control-label">{:__('Nickname')}:</label>
                             <input type="text" class="form-control" name="row[nickname]" value="{$admin.nickname}" data-rule="required" />

+ 1 - 1
application/admin/view/protector/edit.html

@@ -3,7 +3,7 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Unit_name')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-unit_name" class="form-control" name="row[unit_name]" value="{$row.unit_name}" type="text" data-rule="required;">
+            <input id="c-unit_name" class="form-control" disabled name="row[unit_name]" value="{$row.unit_name}" type="text" data-rule="required;">
         </div>
     </div>
     <div class="form-group">

+ 5 - 3
public/assets/js/backend/auth/admin.js

@@ -29,12 +29,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                 url: $.fn.bootstrapTable.defaults.extend.index_url,
                 columns: [
                     [
-                        {field: 'state', checkbox: true, },
-                        {field: 'id', title: 'ID'},
+                        // {field: 'state', checkbox: true, },
+                        // {field: 'id', title: 'ID'},
                         {field: 'username', title: __('Username')},
                         {field: 'nickname', title: __('Nickname')},
                         {field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label},
-                        {field: 'email', title: __('Email')},
+                        {field: 'protect_count', title: '保护名额',formatter:function (value,row) {
+                                return value + '(剩余'+ row.surplus_count +')';
+                            }},
                         {field: 'status', title: __("Status"), formatter: Table.api.formatter.status},
                         {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                         {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {

+ 3 - 2
public/assets/js/backend/auth/group.js

@@ -45,10 +45,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function (
                 escape: false,
                 columns: [
                     [
-                        {field: 'state', checkbox: true, },
-                        {field: 'id', title: 'ID'},
+                        // {field: 'state', checkbox: true, },
+                        // {field: 'id', title: 'ID'},
                         {field: 'pid', title: __('Parent')},
                         {field: 'name', title: __('Name'), align: 'left'},
+                        {field: 'protect_count', title: '保护名额'},
                         {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
                         {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function (value, row, index) {
                                 if (Config.admin.group_ids.indexOf(parseInt(row.id)) > -1) {

+ 30 - 4
public/assets/js/backend/protector.js

@@ -31,14 +31,15 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                         {field: 'con_position', title: __('Con_position'),searchable: false},
                         {field: 'unit_type', title: __('Unit_type'),searchable: false},
                         {field: 'number', title: __('Number'),searchable: false},
+                        {field: 'price', title: '单价',searchable: false},
+                        {field: 'total', title: '总价',searchable: false},
                         {field: 'depart_id', title: '操作人部门',searchList: $.getJSON('auth/group/departList'),formatter:function (value, row) {
                                 return row.usr_depart;
                             }},
                         {field: 'usr_nickname', title: '操作人'},
-                        {field: 'total', title: '总价'},
                         {field: 'pro_date', title: __('Pro_date'), operate:'RANGE', addclass:'datetimerange',searchable: false},
                         {field: 'ex_date', title: __('Ex_date'),searchable: false, operate:'RANGE', addclass:'datetimerange'},
-                        {field: 'operate', title: __('Operate'),searchable: false,
+                        {field: 'operate', title: __('Operate'),searchable: false,visible: status!='contract' ? true : false,
                             table: table,
                             events: Controller.api.events.operate,
                             formatter: Controller.api.formatter.operate
@@ -66,6 +67,18 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
             Controller.api.bindevent();
         },
         edit: function () {
+            $.ajax({
+                url: 'intention/unitTypeList',
+                type: 'post',
+                dataType: 'json',
+                success: function success(res) {
+                    var data = res.rows;
+                    $('#c-unit_type').selectPage({
+                        data : data,
+                    });
+                    console.log(data);
+                }
+            });
             Controller.api.bindevent();
         },
         api: {
@@ -83,6 +96,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                         case 0:         //保护中
                             buttons.push({name: 'giveup', text: '放弃', classname: 'btn btn-xs btn-danger btn-giveup'});
                             buttons.push({name: 'sign', text: '签单', classname: 'btn btn-xs btn-success btn-sign'});
+                            buttons.push({name: 'follow', text:'跟进', classname: 'btn btn-xs btn-info btn-follow'});
+                            buttons.push({name: 'edit', text:'修改', classname: 'btn btn-xs btn-warning btn-editone'});
                             break;
                         case 1:
                             buttons.push({name: 'again', text: '再次保护', classname: 'btn btn-xs btn-success btn-again'});
@@ -91,7 +106,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                             buttons.push({name: 'again', text:'再次保护', classname: 'btn btn-xs btn-success btn-again'});
                             break;
                     }
-                    buttons.push({name: 'follow', text:'跟进', classname: 'btn btn-xs btn-info btn-follow'});
 
                     return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
                 },
@@ -176,13 +190,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
                                     content:res.data,
                                     yes: function(index){
                                         addFollow(row.id,row.unit_name);
+
                                         layer.close(index); //如果设定了yes回调,需进行手工关闭
                                     }
                                 })
                             }
                         });
 
-                    }
+                    },
+                    // 修改
+                    '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
+                        });
+                    },
                 }
             }
         }
@@ -210,5 +235,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage'], functi
 
 
 
+
     return Controller;
 });