wang jun 2 years ago
parent
commit
063d15644d

+ 203 - 0
application/admin/controller/Meal.php

@@ -0,0 +1,203 @@
+<?php
+namespace app\admin\controller;
+
+use app\admin\logic\MealLogic;
+
+/**
+ * 套餐配送
+ *
+ * @author wj
+ * @date 2022-12-03
+ */
+class Meal
+{
+
+    /**
+     * 获取套餐中心列表
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-03
+     */
+    public function getcenterlist()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->getcenterlist($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 获取套餐列表
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-07
+     */
+    public function getmeallist()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->getmeallist($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 改套餐可用
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-07
+     */
+    public function updatemealisactive()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->updatemealisactive($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 编辑菜单
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-07
+     */
+    public function editmeal()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->editmeal($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 根据id获取菜单详细
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-07
+     */
+    public function getmealinfo()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->getmealinfo($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 根据配餐中心id获取菜品列表
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-07
+     */
+    public function getcooks()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->getcooks($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 保存套餐菜单
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function savemealcooks()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->savemealcooks($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+
+    /**
+     * 获取菜单全部信息
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function getmealcooklist()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->getmealcooklist($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 获取菜品列表
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function getcookslist()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->getcookslist($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 编辑菜品信息
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function editcookinfo()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->editcookinfo($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    /**
+     * 修改菜品可用
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function updatecookisactive()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->updatecookisactive($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+}

+ 85 - 0
application/admin/controller/Weblogin.php

@@ -0,0 +1,85 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: sicilon_IT
+ * Date: 2020/1/22
+ * Time: 22:16
+ */
+namespace app\admin\controller;
+
+use app\admin\logic\webmanger;
+use app\admin\logic\webuserloglogic;
+use think\Controller;
+
+class Weblogin extends Controller
+{
+    /**
+     * 后台登录
+     * 20211116
+     * wj
+     **/
+    public function login()
+    {
+        $userinfo = request()->param();
+        $wm = new webmanger();
+        $l_wul = new webuserloglogic();
+        $result = $wm->userlogin($userinfo['userName'], $userinfo['password']);
+        $logData = ['type' => 1, 'tablename' => 'webuser'];
+        if (1 == $result['status']) {
+            $logData['wuid'] = $result['data']['id'];
+            $logData['node'] = "登录成功";
+            $result1 = $l_wul->addlog($logData);
+            //log::info($result1);
+            return backjson2(200, '登录成功', $result['data']);
+        } else {
+            $logData['node'] = "登录失败:" . $result['msg'];
+            $result1 = $l_wul->addlog($logData);
+            //log::info($result1);
+            return backjson2(0, $result['msg']);
+        }
+    }
+
+    /***
+     * 后台退出
+     * 20211116
+     * wj
+     */
+    public function loginout()
+    {
+        checkToken();
+        $param = request()->param();
+        $logData = [
+            'type' => 1,
+            'tablename' => 'webuser',
+            'token' => $param['token'],
+            'node' => '退出',
+        ];
+        $m_w = new webmanger();
+        $l_wul = new webuserloglogic();
+        $result = $l_wul->addlog($logData);
+        if (1 === $result['status']) {
+            $result = $m_w->updateToken();
+            if (1 != $result['status']) {
+                return backjson2(0, $result['msg']);
+            }
+            return backjson2(200, '操作成功');
+        } else {
+            return backjson2(0, '操作失败');
+        }
+    }
+
+    /***
+     * 根据token获取用户信息
+     */
+    public function queryinfobytoken()
+    {
+        $param = request()->param();
+        $wm = new webmanger();
+        $result = $wm->queryinfobytoken($param);
+        if (1 == $result['status']) {
+            return backjson2(200, '登录成功', $result['data']);
+        } else {
+            return backjson2(0, $result['msg']);
+        }
+    }
+}

+ 153 - 0
application/admin/controller/Webuser.php

@@ -0,0 +1,153 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2021-10-30 16:54:46
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2021-11-10 16:47:23
+ */
+namespace app\admin\controller;
+
+use app\admin\logic\webmanger;
+use app\admin\logic\webuserloglogic;
+use think\Controller;
+
+class Webuser extends Controller
+{
+    /**
+     * 创建web用户
+     */
+    public function newinfo()
+    {
+        $param = request()->param();
+        $t_wu = new webmanger();
+        $result = $t_wu->newwebuser($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, "操作成功", $result['data']);
+        }
+    }
+    /**
+     * 改用户状态
+     * 20211103
+     * wj
+     */
+    public function updateisactive()
+    {
+        checkToken();
+        $param = request()->param();
+        $t_wu = new webmanger();
+        $result = $t_wu->updateisactive($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, "操作成功", $result['data']);
+        }
+    }
+    /**
+     * 获取列表
+     * 20211103
+     * wj
+     */
+    public function getalllist()
+    {
+        checkToken();
+        $param = request()->param();
+        $t_wu = new webmanger();
+        $result = $t_wu->getalllist($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, "操作成功", $result['data']);
+        }
+    }
+
+    /**
+     * 编辑用户信息
+     * 20211103
+     * wj
+     */
+    public function editwebuser()
+    {
+        checkToken();
+        $param = request()->param();
+        $t_wu = new webmanger();
+        $result = $t_wu->editwebuser($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, "操作成功", $result['data']);
+        }
+    }
+
+    /**
+     * 修改用户密码
+     * 20211108
+     * wj
+     */
+    public function updatepasswd()
+    {
+        checkToken();
+        $param = request()->param();
+        $t_wu = new webmanger();
+        $result = $t_wu->updatepasswd($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, "操作成功", $result['data']);
+        }
+    }
+
+    /**
+     * 获取用户信息
+     * 20211110
+     * wj
+     */
+    public function searchUserInfo()
+    {
+        checkToken();
+        $param = request()->param();
+        $t_wu = new webmanger();
+        $result = $t_wu->searchUserInfo($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, "查询成功", $result['data']);
+        }
+    }
+
+    /**
+     * 保存用户设置
+     * 20211110
+     * wj
+     */
+    public function saveuserrole()
+    {
+        checkToken();
+        $param = request()->param();
+        $t_wu = new webmanger();
+        $result = $t_wu->saveuserrole($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, "操作成功", $result['data']);
+        }
+    }
+    /**
+     * 获取用户日志
+     * 20211223
+     * wj
+     */
+    public function getlogs()
+    {
+        checkToken();
+        $param = request()->param();
+        $l_wl = new webuserloglogic();
+        $result = $l_wl->getlistbywhere($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, "操作成功", $result['data']);
+        }
+    }
+}

+ 699 - 0
application/admin/logic/MealLogic.php

@@ -0,0 +1,699 @@
+<?php
+namespace app\admin\logic;
+
+use app\admin\server\Webuserserver;
+use app\common\model\CookbookModel;
+use app\common\model\MealcenterModel;
+use app\common\model\MealcookModel;
+use app\common\model\MealModel;
+
+//use app\common\model\MealOrdersModel;
+//use app\common\model\UserAddressModel;
+use think\Db;
+
+class MealLogic
+{
+    /**
+     * 获取套餐配送中心列表
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-01
+     */
+    public function getcenterlist($arr)
+    {
+        $userinfo = checkToken();
+        $wherefield = ['name_center', 'address'];
+        $where = [];
+        foreach ($wherefield as $key => $value) {
+            if (isset($arr[$value]) && !empty($arr[$value])) {
+                $where[] = [$value, 'like', '%' . $arr[$value] . '%'];
+            }
+        }
+        $wherefield2 = ['is_active'];
+        foreach ($wherefield2 as $key => $value) {
+            if (isset($arr[$value]) && is_numeric($arr[$value])) {
+                $where[] = [$value, '=', $arr[$value]];
+            }
+        }
+        $page = isset($arr['page']) && is_numeric($arr['page']) && !empty($arr['page']) && $arr['page'] > 0 ? $arr['page'] : 1;
+        $size = isset($arr['size']) && is_numeric($arr['size']) && !empty($arr['size']) && $arr['size'] > 0 ? $arr['size'] : 10;
+        $m_m = new MealcenterModel();
+        $count = $m_m->getList($where, 'count');
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $totalpage = ceil($count / $size);
+        $page > $totalpage && $page = $totalpage;
+        $list = $m_m->getList($where, "*", $page, $size);
+        $data = [
+            'page' => $page,
+            'size' => $size,
+            'count' => $count,
+            'list' => $list,
+        ];
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '获取配餐中心列表',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "查询成功", $data);
+    }
+    /**
+     * 通过配送中心获取详细信息
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-05
+     */
+    public function getmealcenterinfobyid($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['cmid'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $cmid = $arr['cmid'];
+        $m_m = new MealcenterModel();
+        $minfo = $m_m->getInfo(['id' => $cmid]);
+        if (empty($minfo)) {
+            return backarr(0, "无数据");
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '获取配送中心[' . $cmid . ']信息',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "查询成功", $minfo);
+    }
+    /**
+     * 创建配餐中心
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-05
+     */
+    public function newcenter($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['name_center', 'gcj_lat', 'gcj_long', 'show_img', 'address'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $name_center = $arr['name_center'];
+        $m_m = new MealcenterModel();
+        $where = ['name_center' => $name_center];
+        $minfo = $m_m->getInfo($where);
+        if (!empty($minfo)) {
+            return backarr(0, "配送中心已存在");
+        }
+        $insertData = $arr;
+        $mcid = $m_m->insertData($insertData);
+        if (empty($mcid)) {
+            return backarr(0, "配送中心添加失败");
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '配餐中心创建:' . $mcid . ":" . $name_center,
+            'type' => 1,
+            'tablename' => 'mealcenter',
+            'refid' => $mcid,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "配送中心添加成功", ['mcid' => $mcid]);
+    }
+    /**
+     * 修改配餐中心
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-05
+     */
+    public function editcenter($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['id'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $id = $arr['id'];
+        $m_m = new MealcenterModel();
+        $where = ['id' => $id];
+        $minfo = $m_m->getInfo($where);
+        if (empty($minfo)) {
+            return backarr(0, "配送中心不存在");
+        }
+        unset($arr['id']);
+        $updateData = [];
+        foreach ($minfo as $key => $value) {
+            if (isset($arr[$key]) && $arr[$key] != $value) {
+                $updateData[$key] = $arr[$key];
+            }
+        }
+        $row = $m_m->updateinfo($where, $updateData);
+        if (empty($row)) {
+            return backarr(0, "配送中心修改失败");
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '配餐中心修改:' . $id . ":" . $minfo['name_center'],
+            'type' => 1,
+            'tablename' => 'mealcenter',
+            'refid' => $id,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "配送中心修改成功", ['mcid' => $id]);
+    }
+    /**
+     * 获取套餐配送中心
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-07
+     */
+    public function getmeallist($arr)
+    {
+        $userinfo = checkToken();
+        $wherefield = ['name_center' => 'mc.name_center', 'name_meal' => 'm.name_meal'];
+        $where = [];
+        foreach ($wherefield as $key => $value) {
+            if (isset($arr[$key]) && !empty($arr[$key])) {
+                $where[] = [$value, 'like', '%' . $arr[$key] . '%'];
+            }
+        }
+        $wherefield2 = ['is_active' => 'm.is_active'];
+        foreach ($wherefield2 as $key => $value) {
+            if (isset($arr[$key]) && is_numeric($arr[$key])) {
+                $where[] = [$value, '=', $arr[$key]];
+            }
+        }
+        $page = isset($arr['page']) && is_numeric($arr['page']) && !empty($arr['page']) && $arr['page'] > 0 ? $arr['page'] : 1;
+        $size = isset($arr['size']) && is_numeric($arr['size']) && !empty($arr['size']) && $arr['size'] > 0 ? $arr['size'] : 10;
+        $m_m = new MealModel();
+        $count = $m_m->getListJoinCenter($where, 'count');
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $totalpage = ceil($count / $size);
+        $page > $totalpage && $page = $totalpage;
+        $field = ['m.*', 'mc.name_center'];
+        $list = $m_m->getListJoinCenter($where, $field, $page, $size);
+        $data = [
+            'page' => $page,
+            'size' => $size,
+            'count' => $count,
+            'list' => $list,
+        ];
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '获取配餐中心列表',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "查询成功", $data);
+    }
+
+    public function updatemealisactive($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['id'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $id = $arr['id'];
+        $m_m = new MealModel();
+        $where = ['id' => $id];
+        $minfo = $m_m->getInfo($where);
+        if (empty($minfo)) {
+            return backarr(0, "无对应数据");
+        }
+        $update = [];
+        if (1 == $minfo['is_active'] && 0 === $arr['is_active']) {
+            $update['is_active'] = $arr['is_active'];
+        }
+        if (0 === $minfo['is_active'] && 1 === $arr['is_active']) {
+            $update['is_active'] = $arr['is_active'];
+        }
+        if (empty($update)) {
+            $update['updatetime'] = date('y-m-d H:i:s');
+        }
+        $row = $m_m->updateinfo($where, $update);
+        if (empty($row)) {
+            return backarr(0, "修改失败");
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '修改套餐可用[id:' . $id . '][is_active:' . $arr['is_active'] . ']',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "操作成功", ['mid' => $id]);
+    }
+    /**
+     * 编辑套餐
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-07
+     */
+    public function editmeal($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['center_id', 'name_meal', 'price'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $m_m = new MealModel();
+        if (isset($arr['id'])) {
+            //修改
+            $mid = $arr['id'];
+            $where = ['id' => $mid];
+            $minfo = $m_m->getInfo($where);
+            $updateData = [];
+            foreach ($arr as $key => $value) {
+                if (isset($minfo[$key]) && $minfo[$key] != $value) {
+                    $updateData[$key] = $value;
+                }
+            }
+            if (!empty($updateData)) {
+                $updateData['updatetime'] = date('Y-m-d');
+                $row = $m_m->updateinfo($where, $updateData);
+                if (empty($row)) {
+                    return backarr(0, "修改失败");
+                }
+            }
+        } else {
+            //添加
+            $insertData = [
+                'center_id' => $arr['center_id'],
+                'name_meal' => $arr['name_meal'],
+                'price' => $arr['price'],
+                'is_active' => 1,
+                'createtime' => date('Y-m-d H:i:s'),
+            ];
+            $mid = $m_m->insertData($insertData);
+            if (empty($mid)) {
+                return backarr(0, "添加失败");
+            }
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '套餐编辑[id:' . $mid . ']',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "操作成功", ['mid' => $mid]);
+    }
+    /**
+     * 根据id获取套餐详情
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2022-12-07
+     */
+    public function getmealinfo($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['id'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $id = $arr['id'];
+        $m_m = new MealModel();
+        $where = ['id' => $id];
+        $minfo = $m_m->getInfo($where);
+        if (empty($minfo)) {
+            return backarr(0, "无对应数据");
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '获取套餐[' . $id . ']详情',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "查询成功", $minfo);
+    }
+    /**
+     * 根据中心id获取菜品列表
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-07
+     */
+    public function getcooks($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['center_id'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $centerid = $arr['center_id'];
+        $where = [
+            'center_id' => $centerid,
+            'is_active' => 1,
+        ];
+        $m_cb = new CookbookModel();
+        $list = $m_cb->getList($where, "*", 1, 0);
+        if (empty($list)) {
+            return backarr(0, "无对应数据");
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '获取配送中心[' . $centerid . ']菜品列表',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "查询成功", $list);
+    }
+    /**
+     * 保存套餐菜谱
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function savemealcooks($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['center_id', 'week', 'items', 'meal_id'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $centerid = $arr['center_id'];
+        $week = $arr['week'];
+        $mealid = $arr['meal_id'];
+        $items = $arr['items'];
+        $where = [
+            'center_id' => $centerid,
+            'meal_id' => $mealid,
+            'week' => $week,
+        ];
+        Db::startTrans();
+        try {
+            $m_mc = new MealcookModel();
+            $m_mc->deletecooks($where);
+            foreach ($items as $key => $value) {
+                $insertData = [
+                    'center_id' => $centerid,
+                    'meal_id' => $mealid,
+                    'cook_id' => $value['cook_id'],
+                    'week' => $week,
+                ];
+                $mcid = $m_mc->insertData($insertData);
+                if (empty($mcid)) {
+                    throw new \Exception("添加失败");
+                }
+            }
+            //保存日志
+            $s_w = new Webuserserver();
+            $logData = [
+                'node' => '更新套餐[' . $mealid . ']菜谱',
+                'type' => 1,
+            ];
+            $s_w->savelog($userinfo['id'], $logData);
+            Db::commit();
+            return backarr(1, "添加成功");
+        } catch (\Exception $e) {
+            Db::rollback();
+            $msg = $e->getMessage();
+            return backarr(0, $msg);
+        }
+    }
+
+    /**
+     * 获取套餐菜谱全部信息
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function getmealcooklist($arr)
+    {
+        $userinfo = checkToken();
+        $wherefield = ['name_center' => 'mc1.name_center', 'name_meal' => 'm.name_meal', 'name_cook' => 'cb.name_meal', 'week', 'mc.week'];
+        $where = [];
+        foreach ($wherefield as $key => $value) {
+            if (isset($arr[$key]) && !empty($arr[$key])) {
+                $where[] = [$value, 'like', '%' . $arr[$key] . '%'];
+            }
+        }
+        $page = isset($arr['page']) && is_numeric($arr['page']) && !empty($arr['page']) && $arr['page'] > 0 ? $arr['page'] : 1;
+        $size = isset($arr['size']) && is_numeric($arr['size']) && !empty($arr['size']) && $arr['size'] > 0 ? $arr['size'] : 10;
+        $m_mc = new MealcookModel();
+        $count = $m_mc->getListJoinInfo($where, 'count');
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $totalpage = ceil($count / $size);
+        $page > $totalpage && $page = $totalpage;
+        $list = $m_mc->getListJoinInfo($where, '*', $page, $size);
+        $data = [
+            'page' => $page,
+            'size' => $size,
+            'count' => $count,
+            'list' => $list,
+        ];
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '获取套餐菜谱列表',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "查询成功", $data);
+    }
+    /**
+     * 获取菜单列表
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function getcookslist($arr)
+    {
+        $userinfo = checkToken();
+        $wherefield = ['name_cook' => 'cb.name_cook', 'name_center' => 'mc.name_center'];
+        $where = [];
+        foreach ($wherefield as $key => $value) {
+            if (isset($arr[$key]) && !empty($arr[$key])) {
+                $where[] = [$value, 'like', '%' . $arr[$key] . '%'];
+            }
+        }
+        $wherefield2 = ['is_active' => 'cb.is_active'];
+        foreach ($wherefield2 as $key => $value) {
+            if (isset($arr[$key]) && is_numeric($arr[$key])) {
+                $where[] = [$value, '=', $arr[$key]];
+            }
+        }
+        $page = isset($arr['page']) && is_numeric($arr['page']) && !empty($arr['page']) && $arr['page'] > 0 ? $arr['page'] : 1;
+        $size = isset($arr['size']) && is_numeric($arr['size']) && !empty($arr['size']) && $arr['size'] > 0 ? $arr['size'] : 10;
+        $m_cb = new CookbookModel();
+        $count = $m_cb->getListjoinMC($where, 'count');
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $totalpage = ceil($count / $size);
+        $page > $totalpage && $page = $totalpage;
+        $field = ['cb.*', 'mc.name_center'];
+        $list = $m_cb->getListjoinMC($where, $field, $page, $size);
+        $data = [
+            'page' => $page,
+            'size' => $size,
+            'count' => $count,
+            'list' => $list,
+        ];
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '获取套餐菜谱列表',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "查询成功", $data);
+    }
+    /**
+     * 获取菜谱信息根据id
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function getcookinfobyid($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['cmid'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $mbid = $arr['cmid'];
+        $m_cb = new CookbookModel();
+        $minfo = $m_cb->getInfo(['id' => $mbid]);
+        if (empty($minfo)) {
+            return backarr(0, "无数据");
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '获取配送中心[' . $mbid . ']信息',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "查询成功", $minfo);
+    }
+    /**
+     * 改菜品信息
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function editcookinfo($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['name_center', 'name_cook', 'show_img'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $namecenter = trim($arr['name_center']);
+        $namecook = trim($arr['name_cook']);
+        $showimg = $arr['show_img'];
+        $mcwhere = ['name_center' => $namecenter, 'is_active' => 1];
+        $time = date('Y-m-d H:i:s');
+        $m_mc = new MealcenterModel();
+        $m_cb = new CookbookModel();
+        $mcinfo = $m_mc->getInfo($mcwhere);
+        if (empty($mcinfo)) {
+            return backarr(0, "配送中心不存在");
+        }
+        if (!isset($arr['id']) || empty($arr['id'])) {
+            $cbwhere = ['name_cook' => $namecook, 'is_active' => 1];
+            $cbinfo = $m_cb->getInfo($cbwhere);
+            if (!empty($cbinfo)) {
+                return backarr(0, "菜品已存在");
+            }
+            $insertData = [
+                'name_cook' => $namecook,
+                'show_img' => $showimg,
+                'center_id' => $mcinfo['id'],
+                'craetetime' => $time,
+            ];
+            $id = $m_cb->insertData($insertData);
+            if (empty($id)) {
+                return backarr(0, "菜品添加失败");
+            }
+            $cbinfo = $insertData;
+            $cbinfo['id'] = $id;
+        }
+        if (isset($arr['id']) && !empty($arr['id'])) {
+            $id = $arr['id'];
+            $where = ['id' => $id];
+            $cbinfo = $m_cb->getInfo($where);
+            if (empty($minfo)) {
+                return backarr(0, "菜品不存在");
+            }
+            unset($arr['id']);
+            $updateData = [];
+            foreach ($cbinfo as $key => $value) {
+                if (isset($arr[$key]) && $arr[$key] != $value) {
+                    $updateData[$key] = $arr[$key];
+                }
+            }
+            $row = $m_cb->updateinfo($where, $updateData);
+            if (empty($row)) {
+                return backarr(0, "菜品修改失败");
+            }
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '菜品编辑:' . $id . ":" . $cbinfo['name_cook'],
+            'type' => 1,
+            'tablename' => 'cookbook',
+            'refid' => $id,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "菜品编辑成功", ['cbid' => $id]);
+    }
+    /**
+     * 修改菜品可用
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function updatecookisactive($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['id'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $id = $arr['id'];
+        $m_cb = new CookbookModel();
+        $where = ['id' => $id];
+        $cbnfo = $m_cb->getInfo($where);
+        if (empty($cbnfo)) {
+            return backarr(0, "无对应数据");
+        }
+        $update = [];
+        if (1 == $cbnfo['is_active'] && 0 === $arr['is_active']) {
+            $update['is_active'] = $arr['is_active'];
+        }
+        if (0 === $cbnfo['is_active'] && 1 === $arr['is_active']) {
+            $update['is_active'] = $arr['is_active'];
+        }
+        if (empty($update)) {
+            $update['updatetime'] = date('y-m-d H:i:s');
+        }
+        $row = $m_cb->updateinfo($where, $update);
+        if (empty($row)) {
+            return backarr(0, "修改失败");
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '修改菜品可用[id:' . $id . '][is_active:' . $arr['is_active'] . ']',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, "操作成功", ['mid' => $id]);
+    }
+}

+ 450 - 0
application/admin/logic/webmanger.php

@@ -0,0 +1,450 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: sicilon_IT
+ * Date: 2020/1/22
+ * Time: 21:19
+ */
+namespace app\admin\logic;
+
+use app\common\model\rolesmodel;
+use app\common\model\roleusermodel;
+use app\common\model\webusermodel;
+use think\Log;
+
+class webmanger
+{
+    public function getlogininfo($lname, $lpwd)
+    {
+
+        $webusertable = new webusermodel();
+        $userinfo = $webusertable->getlogininfo($lname, $lpwd);
+        //var_dump($userinfo);
+        return $userinfo;
+    }
+    /**
+     * 校验登录 并修改token
+     */
+    public function userlogin($lname, $lpwd, $updateToken = true)
+    {
+        $m_wu = new webusermodel();
+        $userinfo = $m_wu->getlogininfomd5($lname, $lpwd);
+        if (empty($userinfo)) {
+            return backarr(0, '无用户信息');
+        }
+        $token = $userinfo['token'];
+        if ($updateToken) {
+            $result = $this->updateToken($userinfo['id']);
+            if (1 != $result['status']) {
+                return $result;
+            }
+        }
+        $token = $result['data']['token'];
+        return backarr(1, '登录成功', ['token' => $token, 'id' => $userinfo['id']]);
+    }
+    /**
+     * 用户登出
+     * 改用户token
+     * 20211204
+     * wj
+     */
+    public function updateToken($uid = 0)
+    {
+        $m_wu = new webusermodel();
+        $m_r = new rolesmodel();
+        $m_ru = new roleusermodel();
+        $rwhere = ['name' => '普通用户', 'is_active' => 1];
+        $rid = 0; //不改token组id
+        $userinfo = [];
+        $rinfo = $m_r->getInfo($rwhere);
+        if (!empty($rinfo)) {
+            $rid = $rinfo['id'];
+        }
+        if (empty($uid)) {
+            $token = request()->server('HTTP_TOKEN');
+            if (empty($token)) {
+                return backarr(0, "无token数据");
+            }
+            $where = ['token' => $token];
+            $field = ['id', 'user_name', 'token'];
+            $userinfo = $m_wu->getInfo($where, $field);
+        } else {
+            $where = ['id' => $uid];
+            $field = ['id', 'user_name', 'token'];
+            $userinfo = $m_wu->getInfo($where);
+        }
+        if (empty($userinfo)) {
+            return backarr(0, "无用户信息");
+        }
+        $ruwhere = ['uid' => $userinfo['id']];
+        $ruinfo = $m_ru->getInfo($ruwhere);
+        $changeToken = true;
+        if (!empty($ruinfo) && !empty($rid)) {
+            if ($ruinfo['rid'] == $rid) {
+                $changeToken = false;
+            }
+        }
+        if ($changeToken) {
+            $token = $this->getToken($userinfo['user_name']);
+            $updateData = [
+                'token' => $token,
+            ];
+            $where = ['id' => $userinfo['id']];
+            $row = $m_wu->updateinfo($where, $updateData);
+            if (empty($row)) {
+                log::info($userinfo['user_name'] . " token 修改失败");
+                return backarr(0, "token 修改失败");
+            }
+        } else {
+            $token = $userinfo['token'];
+        }
+        return backarr(1, "操作成功", ['uid' => $userinfo['id'], 'token' => $token]);
+    }
+    /***
+     * 获取用户token
+     */
+    private function getToken($username)
+    {
+        $str = md5(uniqid(md5(microtime(true)), true));
+        $token = sha1($str . $username);
+        return $token;
+    }
+    /**
+     * 获取用户信息 权限组名 和头像 待改
+     * 20211101
+     * wj
+     */
+    public function queryinfobytoken($arr)
+    {
+        if (!isset($arr['token']) || empty($arr['token'])) {
+            return backarr(0, "请求错误");
+        }
+        $defaultData = [
+            //'access' => 'admin',
+            'avatar' => 'https://file.iviewui.com/dist/a0e88e83800f138b94d2414621bd9704.png',
+        ];
+        $token = $arr['token'];
+        $m_wu = new webusermodel();
+        $where = ['token' => $token];
+        $field = ['id', 'user_name'];
+        $userinfo = $m_wu->getInfo($where, $field);
+        if (empty($userinfo)) {
+            return backarr(0, "无用户数据");
+        }
+        //获取权限组名
+        $m_ru = new roleusermodel();
+        $ruwhere = [
+            'uid' => $userinfo['id'],
+        ];
+        $ruinfo = $m_ru->getInfo($ruwhere);
+        if (!empty($ruinfo)) {
+            $rwhere = [
+                'id' => $ruinfo['rid'],
+                'is_active' => 1,
+            ];
+            $m_r = new rolesmodel();
+            $rinfo = $m_r->getInfo($rwhere);
+            if ($rinfo) {
+                $userinfo['access'] = $rinfo['flag_bit'];
+            }
+        }
+        if (!isset($userinfo['access'])) {
+            $userinfo['access'] = "";
+        }
+        if (empty($userinfo)) {
+            return backarr(0, "无数据");
+        } else {
+            $userinfo = array_merge($defaultData, $userinfo->toArray());
+            return backarr(1, "查询成功", $userinfo);
+        }
+    }
+
+    /***
+     * 获取用户信息 通过id
+     * 20211103
+     * wj
+     */
+    public function queryinfobyid($arr)
+    {
+        $id = $arr['id'];
+        $m_wu = new webusermodel();
+        $where = ['id' => $id];
+        $fields = ['id', 'user_name', 'email', 'create_date', 'isactive', 'create_id', 'token'];
+        $userinfo = $m_wu->getInfo($where, $fields);
+        if (empty($userinfo)) {
+            return backarr(0, "无数据");
+        }
+        if (!empty($userinfo['create_id'])) {
+            $where = ['id' => $userinfo['create_id']];
+            $createinfo = $m_wu->getInfo($where, ['user_name']);
+            $userinfo['create_user_name'] = $createinfo['user_name'];
+        }
+        return backarr(1, "查询成功", $userinfo);
+    }
+
+    public function queryinfowitchsetting($id)
+    {
+        $m_wu = new webusermodel();
+        $m_ru = new roleusermodel();
+        $where = ['id' => $id];
+        $fields = ['id', 'user_name', 'email', 'create_date', 'isactive', 'create_id'];
+        $userinfo = $m_wu->getInfo($where, $fields);
+        if (empty($userinfo)) {
+            return backarr(0, "无数据");
+        }
+        if (!empty($userinfo['create_id'])) {
+            $where = ['id' => $userinfo['create_id']];
+            $createinfo = $m_wu->getInfo($where, ['user_name']);
+            $userinfo['create_user_name'] = $createinfo['user_name'];
+        }
+        $userinfo['setting'] = ['access' => '', 'access_name' => ''];
+        $roleinfo = $m_ru->getinfoforuser($id);
+        if ($roleinfo) {
+            $roleinfo = $roleinfo[0];
+            $setting = [
+                'access' => $roleinfo['flag_bit'],
+                'access_name' => $roleinfo['name'],
+            ];
+            $userinfo['setting'] = $setting;
+        }
+
+        return backarr(1, "查询成功", $userinfo);
+    }
+
+    public function editwebuser($arr)
+    {
+        if (isset($arr['id']) && !empty($arr['id'])) {
+            $result = $this->updatewebuserinfo($arr);
+        } else {
+            $result = $this->newwebuser($arr);
+        }
+        return $result;
+    }
+    /**
+     * 新建web用户
+     * 登录名不可重复
+     */
+    public function newwebuser($arr)
+    {
+        $name = $arr['name'];
+        $m_wu = new webusermodel();
+        $where = ['user_name' => $name];
+        $userinfo = $m_wu->getInfo($where);
+        if ($userinfo) {
+            return backarr(0, "用户已存在");
+        }
+        $insertData = [];
+        $insertData['user_name'] = $name;
+        $insertData['user_password'] = md5($name . $arr['password']);
+        $insertData['token'] = $this->getToken($name);
+        $insertData['create_date'] = date('Y-m-d H:i:s');
+        $insertData['create_id'] = $arr['userid'];
+        if (isset($arr['email']) && !empty($arr['email'])) {
+            $insertData['email'] = $arr['email'];
+        }
+        $id = $m_wu->insertData($insertData);
+        if (empty($id)) {
+            return backarr(0, "操作失败");
+        }
+        return backarr(1, "操作成功", ['id' => $id]);
+    }
+    /***
+     * 改用户信息
+     * 20211103
+     * wj
+     * 仅改用户邮箱
+     */
+    public function updatewebuserinfo($arr)
+    {
+        $id = $arr['id'];
+        $m_wu = new webusermodel();
+        $where = ['id' => $id];
+        $userinfo = $m_wu->getInfo($where);
+        if (empty($userinfo)) {
+            return backarr(0, "用户不存在");
+        }
+        $updateData = [];
+        if (isset($arr['email']) && !empty($arr['email'])) {
+            $updateData['email'] = $arr['email'];
+        }
+        if (!empty($updateData)) {
+            $row = $m_wu->updateinfo($where, $updateData);
+            if (empty($row)) {
+                return backarr(0, "操作失败");
+            }
+            return backarr(1, "操作成功", ['id' => $id]);
+        }
+        return backarr(0, "无修改数据");
+    }
+    /***
+     * 改用户密码
+     * 20211103
+     * wj
+     */
+    public function updatepasswd($arr)
+    {
+        $fillfields = [
+            'name', 'password',
+        ];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "请求错误");
+            }
+        }
+        $m_wu = new webusermodel();
+        $name = trim($arr['name']);
+        $password = trim($arr['password']);
+        $where = ['user_name' => $name];
+        $userinfo = $m_wu->getInfo($where);
+        if (empty($userinfo)) {
+            return backarr(0, "用户不存在");
+        }
+        $updateData = [
+            'user_password' => md5($name . $password),
+            'token' => $this->getToken($name),
+        ];
+        $id = $userinfo['id'];
+        $where = ['id' => $id];
+        $row = $m_wu->updateinfo($where, $updateData);
+        if (empty($row)) {
+            return backarr(0, "操作失败");
+        }
+        return backarr(1, "操作成功", ['id' => $id]);
+    }
+
+    /***
+     * 改用户状态
+     * 20211103
+     * wj
+     */
+    public function updateisactive($arr)
+    {
+        $id = $arr['id'];
+        $isactive = $arr['isactive'];
+        $m_wu = new webusermodel();
+        $where = ['id' => $id];
+        $userinfo = $m_wu->getInfo($where);
+        if (empty($userinfo)) {
+            return backarr(0, "用户不存在");
+        }
+        //默认 isactive 0
+        $isactive = in_array($isactive, [0, 1]) ? $isactive : 0;
+        $updateData = ['isactive' => $isactive];
+        $row = $m_wu->updateinfo($where, $updateData);
+        if (empty($row)) {
+            return backarr(0, "操作失败");
+        }
+        return backarr(1, "操作成功", ['id' => $id]);
+    }
+
+    /***
+     * 获取用户列表
+     * 20211103
+     * wj
+     */
+    public function getalllist($arr)
+    {
+        $searchData = [];
+        if (isset($arr['userName']) && !empty($arr['userName'])) {
+            $searchData['user_name'] = ['like', '%' . $arr['userName'] . '%'];
+        }
+        if (isset($arr['isactive']) && in_array($arr['isactive'], [0, 1]) && is_numeric($arr['isactive'])) {
+            $searchData['isactive'] = $arr['isactive'];
+        }
+        $m_wu = new webusermodel();
+        $count = $m_wu->getList($searchData, 'count');
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $page = !isset($arr['page']) || empty($arr['page']) ? 1 : $arr['page'];
+        $size = !isset($arr['size']) || empty($arr['size']) ? 10 : $arr['size'];
+        $fields = ['id'];
+        $list = $m_wu->getList($searchData, $fields, $page, $size);
+        foreach ($list as $key => &$value) {
+            $result = $this->queryinfowitchsetting($value['id']);
+            if (1 != $result['status']) {
+                return backarr(0, $result['msg']);
+            }
+            $list[$key] = $result['data'];
+        }
+        $data = [
+            'count' => $count,
+            'list' => $list->toArray(),
+        ];
+        return backarr(1, "查询成功", $data);
+    }
+
+    /**
+     * 按照id查用户信息
+     * 20211110
+     * wj
+     */
+    public function searchUserInfo($arr)
+    {
+        $id = 0;
+        if (isset($arr['id']) && !empty($arr['id'])) {
+            $id = $arr['id'];
+        }
+        if (empty($id)) {
+            return backarr(0, "无数据");
+        }
+        $result = $this->queryinfowitchsetting($id);
+        return $result;
+    }
+
+    /**
+     * 保存用户和用户组关系
+     * 20211110
+     * wj
+     */
+    public function saveuserrole($arr)
+    {
+        $fillfields = ['access', 'uid'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || !isset($arr[$value])) {
+                return backarr(0, "请求错误");
+            }
+        }
+
+        $m_r = new rolesmodel();
+        $m_wu = new webusermodel();
+        $m_ru = new roleusermodel();
+
+        $userid = $arr['uid'];
+        $access = $arr['access'];
+
+        $mrinfo = $m_r->getInfo(['flag_bit' => $access, 'is_active' => 1]);
+        if (empty($mrinfo)) {
+            return backarr(0, "无权限组");
+        }
+
+        $wuinfo = $m_wu->getInfo(['id' => $userid]);
+        if (empty($wuinfo)) {
+            return backarr(0, "用户不存在");
+        }
+        $ruinfo = $m_ru->getInfo(['uid' => $userid]);
+        if (empty($ruinfo)) {
+            $insertData = [
+                'uid' => $userid,
+                'rid' => $mrinfo['id'],
+            ];
+            $id = $m_ru->insertData($insertData);
+        } else {
+            $ruwhere = ['id' => $ruinfo['id']];
+            $updateData = [
+                'rid' => $mrinfo['id'],
+            ];
+            $row = $m_ru->updateinfo($ruwhere, $updateData);
+            if ($row <= 0) {
+                $id = 0;
+            } else {
+                $id = $ruinfo['id'];
+            }
+        }
+
+        if (empty($id)) {
+            return backarr(0, "操作失败");
+        }
+        return backarr(1, "操作成功", ['id' => $id]);
+    }
+}

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

@@ -0,0 +1,101 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2021-11-16 11:27:46
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2021-11-18 17:56:34
+ */
+namespace app\admin\logic;
+
+use app\common\model\webuserlogmodel;
+use app\common\model\webusermodel;
+use think\facade\Request;
+
+class webuserloglogic
+{
+    //加日志信息
+    public function addlog($arr)
+    {
+        $insertData = [];
+        $m_wu = new webusermodel();
+        $ip = Request::instance()->ip();
+        $insertData = [
+            'ip' => $ip,
+            'createtime' => date('Y-m-d H:i:s'),
+        ];
+        $where = [];
+        if (isset($arr['token']) && !empty($arr['token'])) {
+            $token = $arr['token'];
+            $where['token'] = $token;
+        }
+
+        if (isset($arr['wuid']) && !empty($arr['wuid']) && !isset($insertData['wuid'])) {
+            $id = $arr['wuid'];
+            $where['id'] = $id;
+        }
+        $info = $m_wu->getInfo($where, ['id']);
+        if (empty($info)) {
+            return backarr(0, "无用户数据");
+        }
+        $insertData['wuid'] = $info['id'];
+        if (isset($arr['node']) && !empty($arr['node'])) {
+            $insertData['node'] = $arr['node'];
+        }
+        if (isset($arr['type']) && !empty($arr['type'])) {
+            $insertData['type'] = $arr['type'];
+        }
+        if (isset($arr['tablename']) && !empty($arr['tablename'])) {
+            $insertData['tablename'] = $arr['tablename'];
+        }
+        if (isset($arr['refid']) && !empty($arr['refid'])) {
+            $insertData['refid'] = $arr['refid'];
+        }
+        $m_wul = new webuserlogmodel();
+        $id = $m_wul->insertData($insertData);
+        if ($id <= 0) {
+            return backarr(0, "操作失败");
+        }
+        return backarr(1, "操作成功");
+    }
+    /***
+     * 获取列表
+     * 20211221
+     * wj
+     */
+    public function getlistbywhere($arr)
+    {
+        $m_wl = new webuserlogmodel();
+        $m_wu = new webusermodel();
+        $userlist = [];
+        $where = [];
+        if (isset($arr['type']) && !empty($arr['type'])) {
+            $type = explode(',', $arr['type']);
+            $where['type'] = ['in', $type];
+        }
+        if (isset($arr['refid']) && !empty($arr['refid']) && is_numeric($arr['refid'])) {
+            $where['refid'] = $arr['refid'];
+        }
+        $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
+        $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
+        $count = $m_wl->getList($where, 'count');
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $field = ['id', 'wuid', 'ip', 'node', 'createtime', 'type', 'refid'];
+        $list = $m_wl->getList($where, $field, $page, $size);
+        foreach ($list as $key => &$value) {
+            if (isset($userlist[$value['wuid']])) {
+                $wuinfo = $userlist[$value['wuid']];
+            } else {
+                $wuinfo = $m_wu->getInfo(['id' => $value['wuid']], 'user_name');
+                $userlist[$value['wuid']] = $wuinfo;
+            }
+            $list[$key]['username'] = $wuinfo['user_name'];
+        }
+        $data = [
+            'count' => $count,
+            'list' => $list,
+        ];
+        return backarr(1, "查询成功", $data);
+    }
+}

+ 46 - 0
application/admin/server/Webuserserver.php

@@ -0,0 +1,46 @@
+<?php
+namespace app\admin\server;
+
+use app\common\model\webuserlogmodel;
+use app\common\model\webusermodel;
+use think\facade\Request;
+
+class Webuserserver
+{
+    /**
+     * 保存管理员日志
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-05
+     */
+    public function savelog($wuid, $arr)
+    {
+        $m_wl = new webuserlogmodel();
+        $m_w = new webusermodel();
+        $ip = Request::instance()->ip();
+        $insertData = [
+            'ip' => $ip,
+            'createtime' => date('Y-m-d H:i:s'),
+        ];
+        $insertData['wuid'] = $wuid;
+        if (isset($arr['node']) && !empty($arr['node'])) {
+            $insertData['node'] = $arr['node'];
+        }
+        if (isset($arr['type']) && !empty($arr['type'])) {
+            $insertData['type'] = $arr['type'];
+        }
+        if (isset($arr['tablename']) && !empty($arr['tablename'])) {
+            $insertData['tablename'] = $arr['tablename'];
+        }
+        if (isset($arr['refid']) && !empty($arr['refid'])) {
+            $insertData['refid'] = $arr['refid'];
+        }
+        $m_wul = new webuserlogmodel();
+        $id = $m_wul->insertData($insertData);
+        if ($id <= 0) {
+            return backarr(0, "操作失败");
+        }
+        return backarr(1, "操作成功");
+    }
+}

+ 89 - 0
application/api/controller/Fileoper.php

@@ -0,0 +1,89 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: sicilon_IT
+ * Date: 2020/1/5
+ * Time: 9:49
+ */
+
+namespace app\api\controller;
+
+use think\Controller;
+use think\Log;
+use think\Request;
+
+class Fileoper extends Controller
+{
+    private function filterfiletype($usefile = "file")
+    {
+        $filetype = $_FILES[$usefile]['type'];
+        $types = [
+            'image',
+            'excel',
+        ];
+        $filetypeuse = "*" . $filetype;
+        $iscanupload = false;
+        foreach ($types as $key => $value) {
+            if (strpos($filetypeuse, $value)) {
+                $iscanupload = true;
+            }
+        }
+        if (!$iscanupload) {
+            log::info($_FILES);
+            $msg = "file type error: " . $filetype;
+            log::info($msg);
+            $this->error($msg);
+        }
+    }
+
+    /**
+     * 指定文件位置上传
+     *
+     * @return void
+     */
+    public function uploadfilebydir()
+    {
+        //log::info($_FILES);
+        $this->filterfiletype();
+        // 获取表单上传文件
+        $file = request()->file('file');
+        if (empty($file)) {
+            $this->error('请选择上传文件');
+        }
+        $defaultdir = 'Uploads' . '/';
+        $dir = request()->param('dir') ? request()->param('dir') : request()->post('dir');
+        $filename = request()->param('filename') ? request()->param('filename') : request()->post('filename');
+        if ($dir) {
+            if (!preg_match("/^[a-z0-9]{1,20}$/", $dir)) {
+                $this->error('请求错误');
+            }
+            $dir = $defaultdir . $dir;
+        } else {
+            $dir = $defaultdir;
+        }
+        $domainpath = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $dir . '/';
+        // 移动到框架应用根目录/public/uploads/ 目录下
+        if ($filename) {
+            $info = $file->move(ROOT_PATH . 'public' . '/' . $dir, $filename);
+        } else {
+            $info = $file->move(ROOT_PATH . 'public' . '/' . $dir);
+        }
+        //如果不清楚文件上传的具体键名,可以直接打印$info来查看
+        //获取文件(文件名),$info->getFilename()  ***********不同之处,笔记笔记哦
+        //获取文件(日期/文件名),$info->getSaveName()  **********不同之处,笔记笔记哦
+        $filename = $info->getSaveName(); //在测试的时候也可以直接打印文件名称来查看
+        $filename = str_replace(DS, "/", $filename);
+        if ($filename) {
+            //$this->success('文件上传成功!');
+            $imageUrl = $domainpath . $filename;
+            $r_upload['code'] = '200';
+            $r_upload['resultData'] = $imageUrl;
+            //不转义反斜杠
+            return json_encode($r_upload, 320);
+        } else {
+            // 上传失败获取错误信息
+            $this->error($file->getError());
+        }
+    }
+}

+ 33 - 0
application/common/model/CookbookModel.php

@@ -80,4 +80,37 @@ class CookbookModel extends Model
         }
         return $data;
     }
+    /**
+     * 获取列表 join 配送中心
+     *
+     * @param  array   $where
+     * @param  string  $field
+     * @param  integer $page
+     * @param  integer $size
+     * @param  string  $order
+     * @param  string  $group
+     * @param  boolean $row
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function getListjoinMC($where = [], $field = "*", $page = 1, $size = 10, $order = "cb.id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->alias('cb')->join("t_mealcenter mc", "cb.center_id=mc.id")->where($where);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
 }

+ 52 - 3
application/common/model/MealcookModel.php

@@ -15,9 +15,6 @@ class MealcookModel extends Model
 
     public function insertData($data)
     {
-        if (!isset($data['createtime']) || empty($data['createtime']) || !is_string($data['createtime'])) {
-            $data['createtime'] = date("Y-m-d H:i:s");
-        }
         if (isset($data['id'])) {
             unset($data['id']);
         }
@@ -141,4 +138,56 @@ class MealcookModel extends Model
         $list = $this->getListJoinCB($where, $field, 1, 0);
         return empty($list) ? [] : $list->toArray();
     }
+
+    /**
+     * 删除cooks
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function deletecooks($where)
+    {
+        $row = $this->where($where)->delete();
+    }
+    /**
+     * 获取列表 获取全部信息
+     *
+     * @param  array   $where
+     * @param  string  $field
+     * @param  integer $page
+     * @param  integer $size
+     * @param  string  $order
+     * @param  string  $group
+     * @param  boolean $row
+     * @return void
+     * @author wj
+     * @date 2022-12-08
+     */
+    public function getListJoinInfo($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->alias('mc')
+            ->join("t_cookbook cb", "mc.cook_id=cb.id")
+            ->join("t_mealcenter mc1", "mc.center_id=mc1.id")
+            ->join("t_meal m", "mc.meal_id=m.id")
+            ->where($where);
+        if ("count" != $field) {
+            if ('*' == $field) {
+                $field = ['mc.*', 'cb.name_cook', 'cb.show_img', 'mc1.name_center', 'm.name_meal'];
+            }
+            if (empty($size)) {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
 }

+ 41 - 0
application/common/server/GaodeMapApi.php

@@ -0,0 +1,41 @@
+<?php
+namespace app\common\server;
+
+//use think\Facade\Log;
+/**
+ * 高德地图api
+ *
+ * @author wj
+ * @date 2022-12-05
+ */
+class GaodeMapApi
+{
+    private $config = [
+        'key' => "b7e81de97ba4810541998fc029436f4c",
+    ];
+    /**
+     * 地址解析
+     *
+     * @param  [type] $address
+     * @return void
+     * @author wj
+     * @date 2022-12-05
+     */
+    public function geo($address)
+    {
+        $url = "https://restapi.amap.com/v3/geocode/regeo";
+        $param = [
+            'key' => $this->config['key'],
+            'address' => $address,
+        ];
+        $params = [];
+        foreach ($param as $key => $value) {
+            $params[] = $key . '=' . $value;
+        }
+        $paramstr = implode('&', $params);
+        $url .= '?' . $paramstr;
+        $result = curl_request($url);
+        var_dump($result);
+        return $result;
+    }
+}

+ 21 - 17
thinkphp/base.php

@@ -10,6 +10,10 @@
 // +----------------------------------------------------------------------
 namespace think;
 
+define('DS', DIRECTORY_SEPARATOR);
+defined('APP_PATH') or define('APP_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS);
+defined('ROOT_PATH') or define('ROOT_PATH', dirname(realpath(APP_PATH)) . DS);
+
 // 载入Loader类
 require __DIR__ . '/library/think/Loader.php';
 
@@ -30,23 +34,23 @@ if (interface_exists('Psr\Log\LoggerInterface')) {
 
 // 注册类库别名
 Loader::addClassAlias([
-    'App'      => facade\App::class,
-    'Build'    => facade\Build::class,
-    'Cache'    => facade\Cache::class,
-    'Config'   => facade\Config::class,
-    'Cookie'   => facade\Cookie::class,
-    'Db'       => Db::class,
-    'Debug'    => facade\Debug::class,
-    'Env'      => facade\Env::class,
-    'Facade'   => Facade::class,
-    'Hook'     => facade\Hook::class,
-    'Lang'     => facade\Lang::class,
-    'Log'      => facade\Log::class,
-    'Request'  => facade\Request::class,
+    'App' => facade\App::class,
+    'Build' => facade\Build::class,
+    'Cache' => facade\Cache::class,
+    'Config' => facade\Config::class,
+    'Cookie' => facade\Cookie::class,
+    'Db' => Db::class,
+    'Debug' => facade\Debug::class,
+    'Env' => facade\Env::class,
+    'Facade' => Facade::class,
+    'Hook' => facade\Hook::class,
+    'Lang' => facade\Lang::class,
+    'Log' => facade\Log::class,
+    'Request' => facade\Request::class,
     'Response' => facade\Response::class,
-    'Route'    => facade\Route::class,
-    'Session'  => facade\Session::class,
-    'Url'      => facade\Url::class,
+    'Route' => facade\Route::class,
+    'Session' => facade\Session::class,
+    'Url' => facade\Url::class,
     'Validate' => facade\Validate::class,
-    'View'     => facade\View::class,
+    'View' => facade\View::class,
 ]);