فهرست منبع

add company api

wang jun 3 سال پیش
والد
کامیت
2dc3b6286c

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

@@ -0,0 +1,66 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 10:57:14
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-18 16:56:01
+ * 微信类
+ */
+namespace app\index\controller;
+
+use app\index\logic\companylogic;
+use think\Controller;
+
+class Company extends Base
+{
+    /**
+     * 设置请求数据规则
+     * 20220107
+     * wj
+     */
+    protected function setrules()
+    {
+        $list = [
+            'newinfo' => [
+                ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
+            ],
+            'getinfobyid' => [
+                ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'string'],
+            ],
+            'updatebyid' => [
+                ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'string'],
+            ],
+        ];
+        return $list;
+    }
+    public function newinfo()
+    {
+        $param = request()->param();
+        $l_c = new companylogic();
+        $result = $l_c->newinfo($param);
+        if (1 != $result['status']) {
+            return backjson(0, $result['msg']);
+        }
+        return backjson(200, $result['data']);
+    }
+    public function getinfobyid()
+    {
+        $param = request()->param();
+        $l_c = new companylogic();
+        $result = $l_c->getinfobyid($param);
+        if (1 != $result['status']) {
+            return backjson(0, $result['msg']);
+        }
+        return backjson(200, $result['data']);
+    }
+    public function updatebyid()
+    {
+        $param = request()->param();
+        $l_c = new companylogic();
+        $result = $l_c->updatebyid($param);
+        if (1 != $result['status']) {
+            return backjson(0, $result['msg']);
+        }
+        return backjson(200, $result['data']);
+    }
+}

+ 70 - 0
application/index/logic/companylogic.php

@@ -0,0 +1,70 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 11:12:23
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-18 16:44:19
+ * 微信类
+ */
+namespace app\index\logic;
+
+use app\index\model\companymodel;
+use app\index\model\usermodel;
+
+class companylogic
+{
+    /**
+     * 新建信息
+     * wj
+     * 20220118
+     */
+    public function newinfo($arr)
+    {
+        $m_u = new usermodel();
+        $m_c = new companymodel();
+        $openid = $arr['openid'];
+        $info = $m_u->getinfobyopenid($openid);
+        if (empty($info)) {
+            return backarr(0, "用户不存在");
+        }
+        if (empty($info['is_company'])) {
+            return backarr(0, "非企业用户");
+        }
+        unset($arr['openid']);
+        $id = $m_c->insertData($arr);
+        $updateDate = ['company_id' => $id];
+        $row = $m_u->updatebyid($info['id'], $updateDate);
+        return backarr(1, "新增成功", ['id' => $id]);
+    }
+    /**
+     * 根据id获取企业信息
+     * wj
+     * 20220118
+     */
+    public function getinfobyid($arr)
+    {
+        $id = $arr['id'];
+        $m_c = new companymodel();
+        $info = $m_c->getinfobyid($id);
+        if (empty($info)) {
+            return backarr(0, "无数据");
+        }
+        return backarr(1, "获取成功", $info);
+    }
+    /**
+     * 根据id修改企业信息
+     * wj
+     * 20220118
+     */
+    public function updatebyid($arr)
+    {
+        $id = $arr['id'];
+        unset($arr['id']);
+        $m_c = new companymodel();
+        $row = $m_c->updatebyid($id, $arr);
+        if (empty($row)) {
+            return backarr(0, "修改失败");
+        }
+        return backarr(1, "获取成功", ['id' => $id]);
+    }
+}

+ 86 - 0
application/index/model/companymodel.php

@@ -0,0 +1,86 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 09:43:33
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-18 16:58:11
+ */
+namespace app\index\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");
+        }
+        $id = $this->insertGetId($data);
+        return empty($id) ? false : $id;
+    }
+
+    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;
+    }
+
+    /**
+     * 根据id获取信息
+     * wj
+     * 20220118
+     */
+    public function getinfobyid($id)
+    {
+        $where = ['id' => $id];
+        $info = $this->where($where)->find();
+        return $info;
+    }
+    /**
+     * 根据id修改数据
+     * wj
+     * 20220118
+     */
+    public function updatebyid($id, $updateData)
+    {
+        $where = ['id' => $id];
+        $row = $this->where($where)->update($updateData);
+        return $row;
+    }
+}

+ 2 - 2
application/index/model/usermodel.php

@@ -3,7 +3,7 @@
  * @Author: wang jun
  * @Date: 2022-01-18 09:43:33
  * @Last Modified by: wang jun
- * @Last Modified time: 2022-01-18 15:49:13
+ * @Last Modified time: 2022-01-18 16:10:40
  */
 namespace app\index\model;
 
@@ -118,7 +118,7 @@ class usermodel extends Model
         return $row;
     }
     /**
-     * 根据openid获取修改iscompany
+     * 根据id修改数据
      * wj
      * 20220118
      */