sugangqiang há 2 anos atrás
pai
commit
83d0d4b76e

+ 38 - 0
app/common/Redis.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace app\common;
+
+use think\facade\Config;
+use think\cache\driver\Redis as TpRedis;
+
+/**
+ * Description of Redis
+ *
+ * @author sgq
+ */
+class Redis extends TpRedis {
+
+    protected $db;
+    protected static $instance = [];
+
+    public function __construct($db) {
+        $options = Config::get("cache.stores.redis");
+        $this->db = $db;
+        $options["select"] = $db;
+        $this->options = array_merge($this->options, $options);
+        parent::__construct();
+    }
+
+    public static function instance($db = 0) {
+        if (!isset(self::$instance[$db])) {
+            self::$instance[$db] = new self($db);
+        }
+        return self::$instance[$db];
+    }
+
+    public function __destruct() {
+        self::$instance[$this->db]->close();
+        unset(self::$instance[$this->db]);
+    }
+
+}

+ 4 - 3
app/common/api/IntegralItemApi.php

@@ -41,6 +41,7 @@ class IntegralItemApi {
     }
 
     public static function edit($params) {
+        $model = new IntegralItem();
         $data["projectId"] = $params["projectId"];
         $data["name"] = $params["name"];
         $data["unit"] = $params["unit"];
@@ -56,14 +57,14 @@ class IntegralItemApi {
             $data["stepGainPoints"] = 0;
         }
         if ($params["id"]) {
-            $data["id"] = $params["id"];
+            $item = $model->find($params["id"]);
             $data["updateTime"] = date("Y-m-d H:i:s");
             $data["updateUser"] = session("user")["uid"];
-            return IntegralItem::update($data);
+            return $item->save($data);
         } else {
             $data["createTime"] = date("Y-m-d H:i:s");
             $data["createUser"] = session("user")["uid"];
-            return IntegralItem::insert($data);
+            return $model->save($data);
         }
     }
 

+ 4 - 3
app/common/api/IntegralProjectApi.php

@@ -39,6 +39,7 @@ class IntegralProjectApi {
     }
 
     public static function edit($params) {
+        $model = new IntegralProject();
         $data["type"] = $params["type"];
         $data["name"] = $params["name"];
         $data["projectType"] = $params["projectType"];
@@ -52,14 +53,14 @@ class IntegralProjectApi {
             $data["max"] = 0;
         }
         if ($params["id"]) {
-            $data["id"] = $params["id"];
+            $project = $model->find($params["id"]);
             $data["updateTime"] = date("Y-m-d H:i:s");
             $data["updateUser"] = session("user")["uid"];
-            return IntegralProject::update($data);
+            return $project->save($data);
         } else {
             $data["createTime"] = date("Y-m-d H:i:s");
             $data["createUser"] = session("user")["uid"];
-            return IntegralProject::insert($data);
+            return $model->save($data);
         }
     }
 

+ 4 - 0
app/common/api/IntegralRecordApi.php

@@ -26,6 +26,10 @@ class IntegralRecordApi {
         $limit = $params["limit"] ?: 10;
         $count = IntegralRecord::where($where)->count();
         $list = IntegralRecord::where($where)->field("*,if(updateTime is not null,updateTime,createTime) as orderTime")->limit($offset, $limit)->order("orderTime " . $order)->select();
+        foreach ($list as $key => $item) {
+            var_dump($item->detail->toArray());exit();
+            $list[$key]["detail"] = $item->detail();
+        }
         return ["total" => $count, "rows" => $list];
     }
 

+ 1 - 3
app/common/model/IntegralItem.php

@@ -2,14 +2,12 @@
 
 namespace app\common\model;
 
-use think\Model;
-
 /**
  * Description of IntegralItem
  *
  * @author sgq
  */
-class IntegralItem extends Model {
+class IntegralItem extends RedisBaseModel {
 
     protected $table = "new_integral_item";
 

+ 1 - 3
app/common/model/IntegralProject.php

@@ -2,14 +2,12 @@
 
 namespace app\common\model;
 
-use think\Model;
-
 /**
  * Description of IntegralProject
  *
  * @author sgq
  */
-class IntegralProject extends Model {
+class IntegralProject extends RedisBaseModel {
 
     protected $table = "new_integral_project";
 

+ 32 - 0
app/common/model/RedisBaseModel.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+use app\common\Redis;
+use think\facade\Config;
+
+/**
+ * Description of RedisBaseModel
+ *
+ * @author sgq
+ */
+class RedisBaseModel extends Model {
+
+    protected static function onAfterWrite(Model $model): void {
+        $data = $model->toArray();
+        if ($data["id"]) {
+            $redis = Redis::instance(Config::get("cache.stores.redis.select"));
+            $redis->hSet($model->name, $data["id"], json_encode($data));
+        }
+    }
+
+    protected static function onAfterDelete(Model $model): void {
+        $data = $model->toArray();
+        if ($data["id"]) {
+            $redis = Redis::instance(Config::get("cache.stores.redis.select"));
+            $redis->hDel($model->name, $data["id"]);
+        }
+    }
+
+}

+ 1 - 0
app/enterprise/controller/Integral.php

@@ -36,6 +36,7 @@ class Integral extends EnterpriseController {
         $param = $request->param();
         $id = isset($param["id"]) ? $param["id"] : 0;
         $info = IntegralRecordApi::getOne($id);
+        $info["detail"] = $info->detail->toArray();
         $ep = EnterpriseApi::getOne($this->user["uid"]);
         if ($info) {
             $info["real_state"] = TalentLogApi::getLastLog($id, ProjectState::INTEGRAL)["state"];

+ 21 - 8
config/cache.php

@@ -7,23 +7,36 @@
 return [
     // 默认缓存驱动
     'default' => env('cache.driver', 'file'),
-
     // 缓存连接方式配置
-    'stores'  => [
+    'stores' => [
         'file' => [
             // 驱动方式
-            'type'       => 'File',
+            'type' => 'File',
             // 缓存保存目录
-            'path'       => '',
+            'path' => '',
             // 缓存前缀
-            'prefix'     => '',
+            'prefix' => '',
             // 缓存有效期 0表示永久缓存
-            'expire'     => 0,
+            'expire' => 0,
             // 缓存标签前缀
             'tag_prefix' => 'tag:',
             // 序列化机制 例如 ['serialize', 'unserialize']
-            'serialize'  => [],
+            'serialize' => [],
+        ],
+        // 配置Reids
+        'redis' => [
+            'type' => 'redis',
+            'host' => '127.0.0.1',
+            'port' => '6379',
+            'password' => '',
+            'select' => 0,
+            //全局缓存有效期(0为永久有效)
+            'expire' => 0,
+            'persistent' => false,
+            //缓存前缀
+            'prefix' => '',
+            'timeout' =>  0,
         ],
-        // 更多的缓存连接
+    // 更多的缓存连接
     ],
 ];

+ 1 - 3
public/static/modular/gate/integral/integral.js

@@ -40,10 +40,8 @@ Integral.initColumn = function () {
                 }
             }
         },
-        {title: '人才层次', field: 'talentArrangeName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px", },
-        {title: '单位标签', field: 'enterpriseTagName', visible: isShow, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px"},
         {title: '证件号码', field: 'card_number', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
-        {title: '认定条件', field: 'identifyConditionText', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
+        {title: '申报标准', field: 'identifyConditionText', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
         {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle', width: "100px",
             formatter: function (value, row, index) {
                 if (row.real_state != row.checkState) {