ソースを参照

add admin api

wang jun 3 年 前
コミット
ed47289f7f

+ 35 - 0
application/admin/controller/Company.php

@@ -0,0 +1,35 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2021-11-09 09:39:05
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-18 13:29:22
+ */
+namespace app\admin\controller;
+
+use app\admin\logic\companylogic;
+use think\Controller;
+
+class Company extends AdminBase
+{
+    public function audit()
+    {
+        $param = request()->param();
+        $l_c = new companylogic();
+        $result = $l_c->auditcompany($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    public function getlistbywhere()
+    {
+        $param = request()->param();
+        $l_c = new companylogic();
+        $result = $l_c->getlistbywhere($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+}

+ 106 - 0
application/admin/logic/baselogic.php

@@ -0,0 +1,106 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 11:12:23
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-19 15:58:46
+ * 微信类
+ */
+namespace app\admin\logic;
+
+use think\facade\Log;
+
+class baselogic
+{
+    /**
+     * 根据配置验证param
+     * wj
+     * 20220119
+     * [[name=>'',title=>'',type=>'',regex=>"",require=>booler]]
+     */
+    protected function checkparam($functionname, $arr)
+    {
+        $param = $arr;
+        $rules = $this->setrules();
+        if (isset($rules[$functionname])) {
+            try {
+                $list = $rules[$functionname];
+                $namelist = array_column($list, 'name');
+                if (count($namelist) != count($list) || count($list) != count(array_filter($namelist))) {
+                    throw new \Exception("规则name设置错误");
+                }
+                $titlelist = array_column($list, 'title');
+                if (count($titlelist) != count($list) || count($list) != count(array_filter($titlelist))) {
+                    throw new \Exception("规则title设置错误");
+                }
+                foreach ($list as $key => $value) {
+                    $name = $value['name'];
+                    $title = $value['title'];
+                    //必填
+                    if (isset($value['require']) && $value['require']) {
+                        if (!isset($param[$name])) {
+                            throw new \Exception($title . '未填');
+                        }
+                    }
+                    if (!isset($param[$name])) {
+                        continue;
+                    }
+                    $paramvalue = $param[$name];
+                    //类型
+                    if (isset($value['type'])) {
+                        $tpe = $value['type'];
+                        switch ($tpe) {
+                            case 'string':
+                                if (!is_string($paramvalue) || empty($paramvalue)) {
+                                    throw new \Exception($title . '格式错误');
+                                }
+                                break;
+                            case 'numeric':
+                                if (!is_numeric($paramvalue)) {
+                                    throw new \Exception($title . '格式错误');
+                                }
+                                break;
+                            case 'array':
+                                if (!is_array($paramvalue)) {
+                                    throw new \Exception($title . '格式错误');
+                                }
+                                break;
+                            case 'datetime':
+                                if (!isDate($paramvalue, 'Y-m-d H:i:s')) {
+                                    throw new \Exception($title . '格式错误');
+                                }
+                                break;
+                            case 'date':
+                                if (!isDate($paramvalue, 'Y-m-d')) {
+                                    throw new \Exception($title . '格式错误');
+                                }
+                                break;
+                        }
+                    }
+                    //正则
+                    if (isset($value['regex'])) {
+                        $regex = $value['regex'];
+                        if (!preg_match($regex, $paramvalue)) {
+                            throw new \Exception($title . '正则格式错误');
+                        }
+                    }
+                }
+                return backarr(1, 'success');
+            } catch (\Exception $e) {
+                $msg = $e->getMessage();
+                Log::error($msg);
+                return backarr(0, "请求错误");
+            }
+        }
+        return backarr(1, 'success');
+    }
+    /**
+     * 设置请求参数验证规则
+     *
+     * @return void
+     */
+    protected function setrules()
+    {
+        return [];
+    }
+}

+ 101 - 0
application/admin/logic/companylogic.php

@@ -0,0 +1,101 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 11:12:23
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-19 15:51:59
+ */
+namespace app\admin\logic;
+
+use app\admin\model\companymodel;
+use think\facade\Log;
+
+class companylogic extends baselogic
+{
+    /**
+     * 设置请求数据规则
+     * 20220107
+     * wj
+     */
+    protected function setrules()
+    {
+        $list = [
+            'auditcompany' => [
+                ['name' => 'ids', 'title' => 'id', 'require' => true, 'type' => 'array'],
+                ['name' => 'ispass', 'title' => 'ispass', 'require' => true, 'type' => 'numeric', 'regex' => '/[1|2]{1}/'],
+            ],
+            'getlistbywhere' => [
+                ['name' => 'ispass', 'title' => 'ispass', 'type' => 'numeric', 'regex' => '/[0|1|2]{1}/'],
+                ['name' => 'companyname', 'title' => 'companyname', 'type' => 'string'],
+                ['name' => 'starttime', 'title' => 'starttime', 'type' => 'datetime'],
+                ['name' => 'endtime', 'title' => 'starttime', 'type' => 'datetime'],
+                ['name' => 'page', 'title' => 'page', 'type' => 'numeric'],
+                ['name' => 'size', 'title' => 'size', 'type' => 'numeric'],
+            ],
+        ];
+        return $list;
+    }
+    /**
+     * 审核公司
+     * 20220208
+     * wj
+     */
+    public function auditcompany($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        $ids = $arr['ids'];
+        if (is_string($ids)) {
+            $ids = [$ids];
+        }
+        $ispass = $arr['ispass'];
+        $m_c = new companymodel();
+        foreach ($ids as $key => $value) {
+            $where = ['id' => $value];
+            $info = $m_c->getInfo($where);
+            if (empty($info)) {
+                log::error("company_id " . $value . " 无对应企业");
+                continue;
+            }
+            if ($ispass != $info['ispass']) {
+                $update = ['ispass' => $ispass];
+                $m_c->updateinfo($where, $update);
+            }
+        }
+        return backarr(1, "操作成功");
+    }
+    /**
+     * 获取公司列表
+     * 20220208
+     * wj
+     */
+    public function getlistbywhere($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        $where = [];
+        if (isset($arr['ispass'])) {
+            $where[] = ['ispass', '=', $arr['ispass']];
+        }
+        if (isset($arr['companyname'])) {
+            $where[] = ['companyname', 'like', '%' . $arr['companyname'] . '%'];
+        }
+        if (isset($arr['starttime']) && isset($arr['endtime'])) {
+            $where[] = ['create_time', '>=', $arr['starttime']];
+            $where[] = ['create_time', '<=', $arr['endtime']];
+        }
+        $m_c = new companymodel();
+        $count = $m_c->getList($where, 'count');
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
+        $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
+        $list = $m_c->getList($where, '*', $page, $size);
+        return backarr(1, "查询成功", $list);
+    }
+}

+ 1 - 1
application/admin/logic/webuserlogic.php

@@ -10,7 +10,7 @@ namespace app\admin\logic;
 use app\admin\model\rolesmodel;
 use app\admin\model\roleusermodel;
 use app\admin\model\webusermodel;
-use think\Log;
+use think\facade\Log;
 
 class webuserlogic
 {

+ 82 - 0
application/admin/model/companymodel.php

@@ -0,0 +1,82 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 09:43:33
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-19 14:11:48
+ */
+namespace app\admin\model;
+
+use think\Model;
+
+class companymodel extends Model
+{
+    protected $table = 't_company';
+
+    public function insertData($data)
+    {
+        if (!isset($data['create_time']) || empty($data['create_time']) || !is_string($data['create_time'])) {
+            $data['create_time'] = date("Y-m-d H:i:s");
+        }
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return empty($id) ? false : $id;
+    }
+
+    /**
+     * 校验入库数据
+     * 20220119
+     */
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+
+    public function deleteinfo($where)
+    {
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj = $sqlObj->count();
+        }
+        return $data;
+    }
+}

+ 15 - 0
application/index/controller/Company.php

@@ -88,4 +88,19 @@ class Company extends Base
         }
         return backjson(200, $result['data']);
     }
+    /**
+     * 审核公司
+     * 20220208
+     * wj
+     */
+    public function auditcompany()
+    {
+        $param = request()->param();
+        $l_c = new companylogic();
+        $result = $l_c->auditcompany($param);
+        if (1 != $result['status']) {
+            return backjson(0, $result['msg']);
+        }
+        return backjson(200, $result['data']);
+    }
 }

+ 1 - 1
application/index/controller/Resume.php

@@ -111,7 +111,7 @@ class Resume extends Base
             $where = ['id' => $value['resume_id']];
             $result = $l_r->getallinfobyid($where);
             $info = $result['data'];
-            $info['inventid'] = $value['invent_id'];
+            $info['sendid'] = $value['id'];
             $rlist[] = $info;
         }
         return backjson(200, $rlist);

+ 3 - 2
application/index/logic/partylogic.php

@@ -144,11 +144,12 @@ class partylogic extends baselogic
         $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
         $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
         $m_pr = new partyrecordmodel();
-        $count = $m_pr->getList($where, 'count');
+        //$count = $m_pr->getList($where, 'count');
+        $count = $m_pr->getListjoincompany($where, 'count');
         if ($count <= 0) {
             return backarr(0, "无数据");
         }
-        $list = $m_pr->getList($where, '*', $page, $size);
+        $list = $m_pr->getListjoincompany($where, '*', $page, $size);
         return backarr(1, "查询成功", $list);
     }
     /**

+ 25 - 0
application/index/model/partyrecordmodel.php

@@ -93,4 +93,29 @@ class partyrecordmodel extends Model
         $info = $this->where($where)->find();
         return !empty($info);
     }
+    /**
+     * 获取列表 join company
+     * 20220209
+     * wj
+     */
+    public function getListjoincompany($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $useWhere = ['c.ispass' => 1];
+        if (isset($where['party_id'])) {
+            $useWhere['pr.party_id'] = $where['party_id'];
+        }
+        $sqlObj = $this->alias('pr')->join('t_company c', 'c.id = pr.company_id')->where($useWhere);
+        $order = "pr.id desc";
+        if ("count" != $field) {
+            $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj = $sqlObj->count();
+        }
+        return $data;
+    }
 }