wang jun 3 lat temu
rodzic
commit
abb27c5071

+ 83 - 0
application/admin/controller/Party.php

@@ -0,0 +1,83 @@
+<?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\partylogic;
+use app\admin\logic\webuserloglogic;
+use think\Controller;
+use think\facade\Log;
+
+class Party extends AdminBase
+{
+    /**
+     * 保存活动信息
+     * 20220210
+     * wj
+     */
+    public function saveinfo()
+    {
+        $param = request()->param();
+        $l_p = new partylogic();
+        $result = $l_p->saveinfo($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        }
+        //日志保存
+        $data = $result['data'];
+        $id = $data['id'];
+        $isupdate = $data['isupdate'];
+        $node = "新增活动";
+        if ($isupdate) {
+            $node = "修改活动";
+        }
+        $logData = [
+            'wuid' => $this->webuserid,
+            'type' => 3,
+            'node' => $node,
+            'refid' => $id,
+            'tablename' => 'party',
+        ];
+        $l_wl = new webuserloglogic();
+        $reulstlog = $l_wl->addlog($logData);
+        if (1 != $reulstlog['status']) {
+            Log::info($logData);
+            Log::error("用户日志添加失败");
+        }
+        return backjson2(200, '操作成功', $result['data']);
+    }
+    /**
+     * 根据id获取信息
+     * 20220210
+     * wj
+     */
+    public function getinfobyid()
+    {
+        $param = request()->param();
+        $l_p = new partylogic();
+        $result = $l_p->getinfobyid($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 根据id获取信息
+     * 20220210
+     * wj
+     */
+    public function getlistbywhere()
+    {
+        $param = request()->param();
+        $l_p = new partylogic();
+        $result = $l_p->getlistbywhere($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+}

+ 146 - 0
application/admin/logic/partylogic.php

@@ -0,0 +1,146 @@
+<?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\partymodel;
+use think\facade\Log;
+
+class partylogic extends baselogic
+{
+    /**
+     * 设置请求数据规则
+     * 20220107
+     * wj
+     */
+    protected function setrules()
+    {
+        $list = [
+            'saveinfo' => [
+                ['name' => 'id', 'title' => 'id', 'type' => 'numeric'],
+            ],
+            'getinfobyid' => [
+                ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'numeric'],
+            ],
+            'getlistbywhere' => [
+                ['name' => 'isactive', 'title' => 'isactive', 'type' => 'numeric', 'regex' => '/[0|1]{1}/'],
+                ['name' => 'name', 'title' => 'name', 'type' => 'string'],
+                ['name' => 'createdate', 'title' => 'createdate', 'type' => 'array'],
+                ['name' => 'page', 'title' => 'page', 'type' => 'numeric'],
+                ['name' => 'size', 'title' => 'size', 'type' => 'numeric'],
+            ],
+        ];
+        return $list;
+    }
+    /**
+     * 保存活动信息
+     * 20220210
+     * wj
+     */
+    public function saveinfo($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        $id = $arr['id'];
+        $m_p = new partymodel();
+        $isupdate = false;
+        if (empty($id)) {
+            //创建
+            unset($arr['id']);
+            $insertData = [
+                'name' => $arr['name'],
+                'start_time' => $arr['createdate'][0],
+                'end_time' => $arr['createdate'][0],
+                'banner_photo' => $arr['bannerphoto'],
+            ];
+            $id = $m_p->insertData($insertData);
+            if (empty($id)) {
+                return backarr(0, "添加失败");
+            }
+        } else {
+            //修改
+            $isupdate = true;
+            $where = ['id' => $id];
+            $info = $m_p->getInfo($where);
+            if (empty($info)) {
+                return backarr(0, "数据不存在");
+            }
+            $fields = ['name', 'start_time', 'end_time', 'isactive', 'banner_photo'];
+            $updateData = [];
+            foreach ($arr as $key => $value) {
+                if (in_array($key, $fields) && !empty($value) && $value != $info[$key]) {
+                    $updateData[$key] = $value;
+                }
+            }
+            log::info($updateData);
+            if (!empty($updateData)) {
+                $m_p->updateinfo($where, $updateData);
+            }
+        }
+        return backarr(1, "操作成功", ['id' => $id, 'isupdate' => $isupdate]);
+    }
+    /**
+     * 根据id获取信息
+     * 20220210
+     * wj
+     */
+    public function getinfobyid($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        $id = $arr['id'];
+        $m_p = new partymodel();
+        $where = ['id' => $id];
+        $info = $m_p->getInfo($where);
+        if (empty($info)) {
+            return backarr(0, "数据不存在");
+        }
+        return backarr(1, "操作成功", $info);
+    }
+    /**
+     * 根据条件获取列表
+     * 20220210
+     * wj
+     */
+    public function getlistbywhere($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        if (isset($arr['isactive'])) {
+            $where[] = ['isactive', '=', $arr['isactive']];
+        }
+        if (isset($arr['name'])) {
+            $where[] = ['name', 'like', '%' . $arr['name'] . '%'];
+        }
+        if (isset($arr['createdate'])) {
+            $createdate = $arr['createdate'];
+            if (count($createdate) == count(array_filter($createdate))) {
+                $where[] = ['create_time', '>=', $createdate[0]];
+                $where[] = ['create_time', '<=', $createdate[1]];
+            }
+        }
+        $m_p = new partymodel();
+        $count = $m_p->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_p->getList($where, '*', $page, $size);
+        $data = [
+            'list' => $list,
+            'total' => $count,
+        ];
+        return backarr(1, "查询成功", $data);
+    }
+}

+ 82 - 0
application/admin/model/partymodel.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 16:39:15
+ */
+namespace app\admin\model;
+
+use think\Model;
+
+class partymodel extends Model
+{
+    protected $table = 't_party';
+
+    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;
+    }
+}