sugangqiang 2 лет назад
Родитель
Сommit
82a01c0717

+ 52 - 2
app/admin/controller/Policy.php

@@ -27,17 +27,67 @@ class Policy extends AdminController {
 
     public function index() {
         $company = \app\common\api\CompanyApi::getOne($this->companyId);
-        $tmps = Db::table("new_policy_tmp")->where("companyId", "=", $this->companyId)->select()->toArray();
-        $policyIds = array_column($tmps, "policyId");
+        $tmps = Db::table("new_policy_tmp")->where("companyId", "=", $this->companyId)->column("files", "policyId");
+        $policyIds = array_keys($tmps);
         $policys = Db::table("new_policy")->order("level asc")->select()->toArray();
         foreach ($policys as $key => $policy) {
             if (in_array($policy["id"], $policyIds)) {
                 $policys[$key]["checked"] = true;
             }
+            $policys[$key]["files"] = $tmps[$policy["id"]];
         }
         return view("", ["company" => $company, "policys" => $policys]);
     }
 
+    public function submit() {
+        if ($this->request->isPost()) {
+            $datas = $this->request["data"];
+            $success = 0;
+            $error = 0;
+            foreach ($datas as $key => $data) {
+                $policyId = $data["id"];
+                $uniqueId = sprintf("%s_%s", $policyId, $this->companyId);
+                $record = Db::table("new_policy_tmp")->where("id", "=", $uniqueId)->findOrEmpty();
+                if ($data["checked"] == 1) {
+                    //需要本单位审核
+                    $save["id"] = $uniqueId;
+                    $save["companyId"] = $this->companyId;
+                    $save["policyId"] = $policyId;
+                    $save["files"] = $data["files"];
+                    if ($record) {
+                        $save["updateUser"] = $this->user["uid"];
+                        $save["updateTime"] = date("Y-m-d H:i:s");
+                        if (Db::table("new_policy_tmp")->update($save)) {
+                            $success++;
+                        } else {
+                            $error++;
+                        }
+                    } else {
+                        $save["createUser"] = $this->user["uid"];
+                        $save["createTime"] = date("Y-m-d H:i:s");
+                        if (Db::table("new_policy_tmp")->insert($save)) {
+                            $success++;
+                        } else {
+                            $error++;
+                        }
+                    }
+                } else {
+                    //取消本单位审核
+                    if ($record) {
+                        if (Db::table("new_policy_tmp")->delete($uniqueId)) {
+                            $success++;
+                        } else {
+                            $error++;
+                        }
+                    } else {
+                        $success++;
+                    }
+                }
+            }
+            return json(["msg" => sprintf("共处理{%d}条审核单位设置,成功{%d}条,失败{%d}条", count($datas), $success, $error)]);
+        }
+    }
+
     public function checked() {
         if ($this->request->isPost()) {
             $policyId = $this->request->param("id");

+ 63 - 19
app/admin/view/policy/index.html

@@ -20,6 +20,8 @@ and open the template in the editor.
             tr:hover{background:#e0edff}
             select{background:#fff;border:1px solid #ddd;padding:5px;}
             input[type=checkbox]{width:30px;height:30px;cursor:pointer;}
+            .btnBox{width:1210px;position:fixed;bottom:0;left:50%;margin-left:-605px;}
+            #submit{width:100px;height:40px;border:none;background:#078ef0;;color:#fff;float:right;box-shadow:2px 2px 1px #ddd;margin:0 15px 15px 0;}
         </style>
     </head>
     <body>
@@ -40,9 +42,10 @@ and open the template in the editor.
                                 <option value="">全部</option>
                             </select>
                         </th>
-                        <th width="10%">标签</th>
-                        <th width="70%">人才认定标准</th>
-                        <th width="10%">选择</th>
+                        <th width="5%">标签</th>
+                        <th width="40%">人才认定标准</th>
+                        <th width="5%">选择</th>
+                        <th width="35%">附件(多个换行)</th>
                     </tr>
                 </thead>
                 <tbody>
@@ -51,31 +54,72 @@ and open the template in the editor.
                         <td>{$policy.level}</td>
                         <td>{$policy.tag}</td>
                         <td>{$policy.policy_name}</td>
-                        <td><input type="checkbox" data-id="{$policy.id}" {if condition="$policy['checked']"}checked="checked"{/if}></td>
+                        <td><input type="checkbox" data-id="{$policy.id}" {if condition="$policy['checked']"}checked="checked"{/if} autocomplete="off"></td>
+                        <td>
+                            <textarea class="files" style="width:100%;height:100%;" placeholder="一个材料清单一行,多个请换行" autocomplete="off">{$policy.files}</textarea>
+                        </td>
                     </tr>
                     {/volist}
                 </tbody>
             </table>
+            <div class="btnBox">
+                <button type="button" id="submit">提交</button>
+            </div>
         </div
     </body>
     <script>
         $(document).ready(function () {
+            var lock = false;
+            $("#submit").click(function () {
+                lock = true;
+                if (lock) {
+                    var data = [];
+                    var selLvl = $("#level").val();
+                    if (selLvl) {
+                        lines = $("tbody tr[data-level='" + selLvl + "']");
+                    } else {
+                        lines = $("tbody tr[data-level]");
+                    }
+                    for (var i = 0; i < lines.length; i++) {
+                        let line = lines.eq(i);
+                        let d = {};
+                        d.id = line.find("[data-id]").data("id");
+                        d.checked = line.find("[data-id]").is(":checked") ? 1 : 2;
+                        d.files = line.find("textarea.files").val();
+                        data.push(d);
+                    }
+                    if (confirm("确定提交当前页面共" + data.length + "条人才认定标准?")) {
+                        $.ajax({
+                            url: "/admin/policy/submit",
+                            type: "post",
+                            data: {data: data},
+                            success: function (res) {
+                                alert(res.msg);
+                                lock = false;
+                            }
+                        })
+                    }
+                }
+            })
             $("input[type=checkbox]").change(function () {
-                var data = {};
-                data.id = $(this).data("id");
-                data.checked = 2;
-                if ($(this).is(":checked")) {
-                    data.checked = 1;
+                if ($(this).is(":checked") == false) {
+                    $(this).parents("tr").find("textarea").val("");
                 }
-                $.ajax({
-                    url: "/admin/policy/checked",
-                    type: "post",
-                    data: data,
-                    success: function (res) {
-                        if (res.code != 200)
-                            alert(res.msg);
-                    }
-                })
+                /*var data = {};
+                 data.id = $(this).data("id");
+                 data.checked = 2;
+                 if ($(this).is(":checked")) {
+                 data.checked = 1;
+                 }
+                 $.ajax({
+                 url: "/admin/policy/checked",
+                 type: "post",
+                 data: data,
+                 success: function (res) {
+                 if (res.code != 200)
+                 alert(res.msg);
+                 }
+                 })*/
             })
         })
         var Policy = {};
@@ -85,7 +129,7 @@ and open the template in the editor.
             if (selLvl) {
                 $("tbody tr[data-level!='" + selLvl + "']").css("display", "none");
                 $("tbody tr[data-level='" + selLvl + "']").css("display", "table-row");
-            }else{
+            } else {
                 $("tbody tr[data-level]").css("display", "table-row");
             }
         }

+ 2 - 1
app/common/middleware/Auth.php

@@ -23,7 +23,8 @@ class Auth {
         if (strtolower($controller) != "auth" && empty(session('user'))) {
             if ($request->isJson())
                 return json(["msg" => "登录已失效"]);
-            return redirect('/index/auth/login');
+            $redirect_url = getHostWithProtocol() . $_SERVER["REQUEST_URI"];
+            return redirect('/index/auth/login?redirect=' . urlencode($redirect_url));
         }
         return $next($request);
     }

+ 10 - 2
app/index/controller/Auth.php

@@ -18,7 +18,10 @@ class Auth extends BaseController {
      * @return type
      */
     public function login() {
-
+        $redirect_url = $this->request["redirect"];
+        if ($redirect_url) {
+            cookie("redirect", $redirect_url);
+        }
         if ($user = session("user")) {
             if ($user['usertype'] == 2) {
                 return redirect("/enterprise");
@@ -70,6 +73,11 @@ class Auth extends BaseController {
 
             if (!$msg) {
                 $user->setSession();
+                $redirect_url = cookie("redirect");
+                if ($redirect_url) {
+                    cookie("redirect", null);
+                    return redirect($redirect_url);
+                }
                 return redirect($url);
             }
         }
@@ -154,7 +162,7 @@ class Auth extends BaseController {
         }
     }
 
-    public function yj9xr2mKT8(){
+    public function yj9xr2mKT8() {
         $params = $this->request->param();
         $type = $params["type"] ?: 2;
         $id = $params["id"] ?: "1455101079799754754";