sugangqiang 2 年之前
父节点
当前提交
38fad31ef4
共有 2 个文件被更改,包括 200 次插入0 次删除
  1. 107 0
      app/admin/controller/Policy.php
  2. 93 0
      app/admin/view/policy/index.html

+ 107 - 0
app/admin/controller/Policy.php

@@ -0,0 +1,107 @@
+<?php
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+namespace app\admin\controller;
+
+use app\admin\common\AdminController;
+use think\facade\Db;
+
+/**
+ * Description of Policy
+ *
+ * @author sgq
+ */
+class Policy extends AdminController {
+
+    protected $companyId;
+
+    public function __construct(\think\App $app) {
+        parent::__construct($app);
+        $this->companyId = $this->user["companyId"];
+    }
+
+    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");
+        $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;
+            }
+        }
+        return view("", ["company" => $company, "policys" => $policys]);
+    }
+
+    public function checked() {
+        if ($this->request->isPost()) {
+            $policyId = $this->request->param("id");
+            $uniqueId = sprintf("%s_%s", $policyId, $this->companyId);
+            $checked = $this->request->param("checked") ?: 1;
+            $lockFileName = sprintf("storage/policy_logs/%s.lock", $uniqueId);
+            if (!file_exists("storage/policy_logs")) {
+                mkdir("storage/policy_logs");
+            }
+            $lockFile = fopen($lockFileName, "a");
+            if (flock($lockFile, LOCK_EX | LOCK_NB)) {//文件锁(独占)
+                try {
+                    $record = Db::table("new_policy_tmp")->where("id", "=", $uniqueId)->findOrEmpty();
+                    if ($checked == 1) {
+                        //需要本单位审核
+                        if ($record) {
+                            $log = sprintf("[%s][account:%s][ERR]Already checked!", date("Y-m-d H:i:s"), $this->user["account"]);
+                            fwrite($lockFile, $log . "\n");
+                            return json(["msg" => "已经添加审核,不需要重复添加"]);
+                        } else {
+                            $data["id"] = $uniqueId;
+                            $data["companyId"] = $this->companyId;
+                            $data["policyId"] = $policyId;
+                            $data["createUser"] = $this->user["uid"];
+                            $data["createTime"] = date("Y-m-d H:i:s");
+                            if (Db::table("new_policy_tmp")->insert($data)) {
+                                $log = sprintf("[%s][account:%s][INFO]Checked!", date("Y-m-d H:i:s"), $this->user["account"]);
+                                fwrite($lockFile, $log . "\n");
+                                return json(["msg" => "添加审核成功", "code" => 200]);
+                            } else {
+                                $log = sprintf("[%s][account:%s][ERR]Check failure!", date("Y-m-d H:i:s"), $this->user["account"]);
+                                fwrite($lockFile, $log . "\n");
+                                return json(["msg" => "添加审核失败"]);
+                            }
+                        }
+                    } else {
+                        //取消本单位审核
+                        if ($record) {
+                            if (Db::table("new_policy_tmp")->delete($uniqueId)) {
+                                $log = sprintf("[%s][account:%s][INFO]Deleted!", date("Y-m-d H:i:s"), $this->user["account"]);
+                                fwrite($lockFile, $log . "\n");
+                                return json(["msg" => "取消审核成功", "code" => 200]);
+                            } else {
+                                $log = sprintf("[%s][account:%s][ERR]Delete failure!", date("Y-m-d H:i:s"), $this->user["account"]);
+                                fwrite($lockFile, $log . "\n");
+                                return json(["msg" => "取消审核失败"]);
+                            }
+                        } else {
+                            $log = sprintf("[%s][account:%s][ERR]Already deleted!", date("Y-m-d H:i:s"), $this->user["account"]);
+                            fwrite($lockFile, $log . "\n");
+                            return json(["msg" => "已经取消审核,不需要重复取消"]);
+                        }
+                    }
+                } catch (\Exception $e) {
+                    $log = sprintf("[%s][account:%s][ERR]%s", date("Y-m-d H:i:s"), $this->user["account"], $e->getMessage());
+                    fwrite($lockFile, $log . "\n");
+                    return json(["msg" => $e->getMessage()]);
+                } finally {
+                    flock($lockFile, LOCK_UN);
+                }
+            } else {
+                return json(["msg" => "已经有同单位的人员在操作同一条记录,请稍候片刻"]);
+            }
+        }
+    }
+
+}

+ 93 - 0
app/admin/view/policy/index.html

@@ -0,0 +1,93 @@
+<!DOCTYPE html>
+<!--
+To change this license header, choose License Headers in Project Properties.
+To change this template file, choose Tools | Templates
+and open the template in the editor.
+-->
+<html>
+    <head>
+        <title>审核单位设置</title>
+        <meta charset="UTF-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+        <script src="/static/js/jquery.min.js"></script>
+        <style>
+            *{margin:0;padding:0;transition:background-color .25s ease;}
+            body{color:#434343;}
+            .content{width:1210px;margin:0 auto;padding:20px;}
+            table{border-collapse:collapse;}
+            td,th{border:1px solid #ddd;padding:5px 5px;text-align:center;}
+            td:nth-child(3){text-align:left;}
+            tr:hover{background:#e0edff}
+            select{background:#fff;border:1px solid #ddd;padding:5px;}
+            input[type=checkbox]{width:30px;height:30px;cursor:pointer;}
+        </style>
+    </head>
+    <body>
+        <div class="content">
+            <div style="text-align:right;color:#ac0835;padding:5px;">设置单位:{$company.name}</div>
+            <table>
+                <thead>
+                    <tr>
+                        <th width="15%">人才层次
+                            <select id="level" onchange="Policy.levelChange(event);" autocomplete="off">
+                                <option value="1">一</option>
+                                <option value="2">二</option>
+                                <option value="3">三</option>
+                                <option value="4">四</option>
+                                <option value="5">五</option>
+                                <option value="6">六</option>
+                                <option value="7">七</option>
+                                <option value="">全部</option>
+                            </select>
+                        </th>
+                        <th width="10%">标签</th>
+                        <th width="70%">人才认定标准</th>
+                        <th width="10%">选择</th>
+                    </tr>
+                </thead>
+                <tbody>
+                    {volist name="policys" id="policy"}
+                    <tr data-level="{$policy.level}" {gt name="policy.level" value="1"}style="display:none;"{/gt}>
+                        <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>
+                    </tr>
+                    {/volist}
+                </tbody>
+            </table>
+        </div
+    </body>
+    <script>
+        $(document).ready(function () {
+            $("input[type=checkbox]").change(function () {
+                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 = {};
+        Policy.levelChange = function (e) {
+            var that = e.target;
+            var selLvl = $(that).val();
+            if (selLvl) {
+                $("tbody tr[data-level!='" + selLvl + "']").css("display", "none");
+                $("tbody tr[data-level='" + selLvl + "']").css("display", "table-row");
+            }else{
+                $("tbody tr[data-level]").css("display", "table-row");
+            }
+        }
+    </script>
+</html>