Browse Source

修改代码

马铁龙 6 years ago
parent
commit
517865d516

+ 21 - 25
application/admin/controller/Protector.php

@@ -320,35 +320,31 @@ class Protector extends Backend
     /**
      * 签单
      */
-    public function sign() {
-        try{
-            //1.获取id
-            $id = $this->request->post("id");
+    public function sign($ids = NULL) {
+        //1.protector表 通过id 查找出数据
+        $protector = \app\admin\model\Protector::get($ids);
 
-            //2.protector表 通过id 查找出数据
-            $protector = \app\admin\model\Protector::get($id);
+        //2.获取用户id
+        $usr_id = Session::get('admin')['id'];
 
-            //3.获取用户id
-            $usr_id = Session::get('admin')['id'];
-
-            //4.判断用户id和 protector的用户id是否一致 保存状态
-            if ($usr_id != 1 && $protector['usr_id'] != $usr_id) {
-                $this->error('请操作自己的数据!');
-            }
-
-            $param['id'] = $id;
+        //3.判断用户id和 protector的用户id是否一致 保存状态
+        if ($usr_id != 1 && $protector['usr_id'] != $usr_id) {
+            $this->error('请操作自己的数据!');
+        }
+        if($_POST){
+            $data = $this->request->post();
             $param['status'] = $this->status['SIGN'];
-
-            //5.入库
-            $res = $this->model->allowField(true)->isUpdate(true)->save($param);
-            if ($res) {
-                $this->success('签单成功!');
-            }
-            $this->error();
-
-        } catch (\think\exception\PDOException $e){
-            $this->error($e->getMessage());
+            $param['again_date'] = $data['row']['again_date'];
+            $res = Db::table('protector')->where('id',$data['id'])->update($param);
+            if($res){
+                $this->success();
+            }else{
+                $this->error('数据修改失败');
+            } 
         }
+        $this->view->assign("id", $ids);
+
+        return $this->view->fetch();
 
     }
 

+ 5 - 2
application/admin/model/Protector.php

@@ -33,7 +33,7 @@ class Protector extends Model
     public static function unitNameIsExist($unit_name)
     {
         $res = self::where('unit_name',$unit_name)
-            ->field('status,unit_name,usr_nickname')
+            ->field('status,unit_name,usr_nickname,again_date')
             ->find();
 
         if($res){
@@ -45,7 +45,10 @@ class Protector extends Model
                     $msg = $unit_name.'已经过期,请到已过期列表再次保护!';
                     break;
                 case 2:
-                    $msg = $unit_name.'已经签单,无法保护!';
+                    if((time() - strtotime($res['again_date'])) >= 0){
+                        return false;
+                    }
+                    $msg = $unit_name.'已经进入签单冷却期,无法保护!';
                     break;
                 case 4:
                     $msg = $unit_name.'已经放弃,请到已放弃列表再次保护!';

+ 16 - 0
application/admin/view/protector/sign.html

@@ -0,0 +1,16 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="protector/sign">
+    <input type="hidden" name="id" value="{$id}">
+    <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-again_date"  class="form-control datetimepicker" name="row[again_date]" type="datetime">
+        </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>

+ 10 - 17
public/assets/js/backend/protector.js

@@ -11,6 +11,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage', 'bootst
                     edit_url: 'protector/edit',
                     follow_url: 'protector/follow',
                     del_url: 'protector/del',
+                    sign_url: 'protector/sign',
                     multi_url: 'protector/multi',
                     table: 'protector',
                 }
@@ -79,6 +80,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage', 'bootst
         follow: function () {
             Controller.api.bindevent();
         },
+        sign: function () {
+            Controller.api.bindevent();
+        },
         api: {
             bindevent: function () {
                 Form.api.bindevent($("form[role=form]"));
@@ -146,23 +150,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'selectpage', 'bootst
                     },
                     // 签单
                     'click .btn-sign': function(e, value, row) {
-                        Layer.confirm('您确定签单吗?',function (index) {
-                            var id = row.id;
-                            $.ajax({
-                                url: 'protector/sign',
-                                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);
-                                    }
-                                }
-                            });
+                        e.stopPropagation();
+                        e.preventDefault();
+                        var options = $(this).closest('table').bootstrapTable('getOptions');
+                        var open = Fast.api.open(options.extend.sign_url + (options.extend.sign_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + row[options.pk], __('Sign'), {
+                            title: '签单',
+                            maxmin: false
                         });
                     },
                     // 再次保护