wang jun vor 2 Jahren
Ursprung
Commit
bef4e1f871

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

@@ -200,4 +200,21 @@ class Meal
         }
         return backjson2(200, $result['msg'], $result['data']);
     }
+    /**
+     * 获取订餐订单列表
+     *
+     * @return void
+     * @author wj
+     * @date 2023-01-16
+     */
+    public function getorderlist()
+    {
+        $post = request()->post();
+        $l_m = new MealLogic();
+        $result = $l_m->getorderlist($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
 }

+ 44 - 0
application/admin/controller/Visit.php

@@ -0,0 +1,44 @@
+<?php
+namespace app\admin\controller;
+
+use app\admin\logic\visitlogic;
+
+/**
+ * 到访
+ *
+ * @author wj
+ * @date 2023-01-18
+ */
+class Visit
+{
+    public function newinfo()
+    {
+        $post = request()->post();
+        $l_v = new visitlogic();
+        $result = $l_v->newinfo($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    public function getlist()
+    {
+        $post = request()->post();
+        $l_v = new visitlogic();
+        $result = $l_v->getlist($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+    public function getbusinesstyoelist()
+    {
+        $post = request()->post();
+        $l_v = new visitlogic();
+        $result = $l_v->getbusinesstyoelist($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
+}

+ 77 - 0
application/admin/logic/HouseserverLogic.php

@@ -0,0 +1,77 @@
+<?php
+namespace app\admin\logic;
+
+use app\common\model\houseservermodel;
+
+class HouseserverLogic
+{
+    /**
+     * 获取类型列表
+     *
+     * @return void
+     * @author wj
+     * @date 2023-01-18
+     */
+    public function gettypelist()
+    {
+        $userinfo = checkToken();
+        $wherefield = ['servername'];
+        $where = [];
+        foreach ($wherefield as $key => $value) {
+            if (isset($arr[$value]) && !empty($arr[$value])) {
+                $where[] = [$value, 'like', '%' . $arr[$value] . '%'];
+            }
+        }
+        $wherefield2 = ['isactive'];
+        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_hs = new houseservermodel();
+        $count = $m_hs->getList($where, "count", $page, $size);
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $totalpage = ceil($count / $size);
+        $page > $totalpage && $page = $totalpage;
+        $list = $m_hs->getList($where, "*", $page, $size)->toArray();
+        $data = [
+            'page' => $page,
+            'size' => $size,
+            'count' => $count,
+            'list' => $list,
+        ];
+        return backarr(1, "查询成功", $data);
+    }
+    /**
+     * 新建类型
+     *
+     * @return void
+     * @author wj
+     * @date 2023-01-18
+     */
+    public function newtype($arr)
+    {
+        $userinfo = checkToken();
+        $fillfields = ['servername'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $servername = $arr['servername'];
+        $m_hs = new houseservermodel();
+        $hsinfo = $m_hs->getInfo(['servername' => $servername]);
+        if (!empty($hsinfo)) {
+            return backarr(0, "服务已存在");
+        }
+        $hsid = $m_hs->insertData($arr);
+        if (empty($hsid)) {
+            return backarr(0, "添加失败");
+        }
+        return backarr(1, "操作成功", ['hsid' => $hsid]);
+    }
+}

+ 57 - 56
application/admin/logic/MealLogic.php

@@ -6,6 +6,7 @@ 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\MealOrdersModel;
 //use app\common\model\UserAddressModel;
@@ -52,13 +53,6 @@ class MealLogic
             'count' => $count,
             'list' => $list,
         ];
-        //保存日志
-        $s_w = new Webuserserver();
-        $logData = [
-            'node' => '获取配餐中心列表',
-            'type' => 1,
-        ];
-        $s_w->savelog($userinfo['id'], $logData);
         return backarr(1, "查询成功", $data);
     }
     /**
@@ -83,13 +77,6 @@ class MealLogic
         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);
     }
     /**
@@ -216,13 +203,6 @@ class MealLogic
             'count' => $count,
             'list' => $list,
         ];
-        //保存日志
-        $s_w = new Webuserserver();
-        $logData = [
-            'node' => '获取配餐中心列表',
-            'type' => 1,
-        ];
-        $s_w->savelog($userinfo['id'], $logData);
         return backarr(1, "查询成功", $data);
     }
 
@@ -347,13 +327,6 @@ class MealLogic
         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);
     }
     /**
@@ -382,13 +355,6 @@ class MealLogic
         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);
     }
     /**
@@ -482,13 +448,6 @@ class MealLogic
             'count' => $count,
             'list' => $list,
         ];
-        //保存日志
-        $s_w = new Webuserserver();
-        $logData = [
-            'node' => '获取套餐菜谱列表',
-            'type' => 1,
-        ];
-        $s_w->savelog($userinfo['id'], $logData);
         return backarr(1, "查询成功", $data);
     }
     /**
@@ -532,13 +491,6 @@ class MealLogic
             'count' => $count,
             'list' => $list,
         ];
-        //保存日志
-        $s_w = new Webuserserver();
-        $logData = [
-            'node' => '获取套餐菜谱列表',
-            'type' => 1,
-        ];
-        $s_w->savelog($userinfo['id'], $logData);
         return backarr(1, "查询成功", $data);
     }
     /**
@@ -564,13 +516,6 @@ class MealLogic
         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);
     }
     /**
@@ -696,4 +641,60 @@ class MealLogic
         $s_w->savelog($userinfo['id'], $logData);
         return backarr(1, "操作成功", ['mid' => $id]);
     }
+    /**
+     * 获取订单列表
+     *
+     * @return void
+     * @author wj
+     * @date 2023-01-16
+     */
+    public function getorderlist($arr)
+    {
+        $userinfo = checkToken();
+        $wherefield = ['name_center', 'orderno'];
+        $where = [];
+        foreach ($wherefield as $key => $value) {
+            if (isset($arr[$value]) && !empty($arr[$value])) {
+                $where[$value] = $arr[$value];
+            }
+        }
+        if (isset($arr['createtime']) && is_array($arr['createtime']) && !empty($arr['createtime'])) {
+            $createtime = array_filter($arr['createtime']);
+            if (count($arr['createtime']) == count($createtime)) {
+                $where['createtime'] = $createtime;
+            }
+        }
+        if (isset($arr['status']) && is_numeric($arr['status'])) {
+            $where['status'] = $arr['status'];
+        }
+        if (isset($arr['status_delivery']) && is_numeric($arr['status_delivery'])) {
+            $where['status_delivery'] = $arr['status_delivery'];
+        }
+        $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_mo = new MealOrdersModel();
+        $m_cb = new CookbookModel();
+
+        $count = $m_mo->getListjoincenter($where, 'count');
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $totalpage = ceil((int) $count / $size);
+        $page > $totalpage && $page = $totalpage;
+        $field = '*';
+        $list = $m_mo->getListjoincenter($where, $field, $page, $size);
+        foreach ($list as $key => $value) {
+            $cooks = $value['cooks'];
+            $cooks = explode(",", $cooks);
+            $cooklist = $m_cb->getList(['id' => ["in", $cooks], 'is_active' => 1]);
+            $list[$key]['detail'] = $cooklist;
+        }
+        $data = [
+            'page' => $page,
+            'size' => $size,
+            'count' => $count,
+            'list' => $list,
+        ];
+        return backarr(1, "查询成功", $data);
+    }
 }

+ 99 - 0
application/admin/logic/visitlogic.php

@@ -0,0 +1,99 @@
+<?php
+namespace app\admin\logic;
+
+use app\admin\server\Webuserserver;
+use app\common\model\VisitBusinessTypeModel;
+use app\common\model\VisitModel;
+
+class visitlogic
+{
+    public function newinfo($arr)
+    {
+        $userinfo = checkToken();
+        $m_v = new VisitModel();
+        $vid = $m_v->insertData($arr);
+        if (empty($vid)) {
+            return backarr(0, '创建失败');
+        }
+        //保存日志
+        $s_w = new Webuserserver();
+        $logData = [
+            'node' => '到访记录',
+            'type' => 1,
+        ];
+        $s_w->savelog($userinfo['id'], $logData);
+        return backarr(1, '创建成功', ['vid' => $vid]);
+    }
+    public function getlist($arr)
+    {
+        $userinfo = checkToken();
+        $wherefield = ['name', 'telno'];
+        $where = [];
+        foreach ($wherefield as $key => $value) {
+            if (isset($arr[$value]) && !empty($arr[$value])) {
+                $where[] = [$value, 'like', '%' . $arr[$value] . '%'];
+            }
+        }
+        $wherefield2 = ['is_member', 'business_type'];
+        foreach ($wherefield2 as $key => $value) {
+            if (isset($arr[$value]) && is_numeric($arr[$value])) {
+                $where[] = [$value, '=', $arr[$value]];
+            }
+        }
+        if (isset($arr['createtime'])) {
+            if (is_array($arr['createtime'])
+                && !empty(array_filter($arr['createtime']))
+                && $arr['createtime'] = array_filter($arr['createtime'])) {
+                $where[] = ['createtime', 'between', $arr['createtime']];
+            }
+        }
+        $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_v = new VisitModel();
+        $count = $m_v->getList($where, 'count');
+        if ($count <= 0) {
+            return backarr(0, "无数据");
+        }
+        $totalpage = ceil($count / $size);
+        $page > $totalpage && $page = $totalpage;
+        $list = $m_v->getList($where, "*", $page, $size)->toArray();
+        $m_vbt = new VisitBusinessTypeModel();
+        $tylist = $m_vbt->getList([], "*", 1, 0, "id asc");
+        if (!empty($tylist)) {
+            $tylist = $tylist->toArray();
+            $tylist = array_combine(array_column($tylist, "id"), array_column($tylist, "name"));
+        } else {
+            $tylist = [];
+        }
+        foreach ($list as $key => $value) {
+            if (!empty($tylist) && isset($tylist[$value['business_type']])) {
+                $business = $tylist[$value['business_type']];
+            } else {
+                $business = '';
+            }
+            $value['business'] = $business;
+            $list[$key] = $value;
+        }
+        $data = [
+            'page' => $page,
+            'size' => $size,
+            'count' => $count,
+            'list' => $list,
+        ];
+        return backarr(1, "查询成功", $data);
+    }
+    /**
+     * 获取业务类型
+     *
+     * @return void
+     * @author wj
+     * @date 2023-01-18
+     */
+    public function getbusinesstyoelist()
+    {
+        $m_vbt = new VisitBusinessTypeModel();
+        $where = [];
+        $list = $m_vbt->getList($where, "*", 1, 0, "id asc");
+        return backarr(1, 'success', $list);
+    }
+}

+ 17 - 0
application/api/controller/User.php

@@ -111,4 +111,21 @@ class User
         }
         return backjson2(200, $result['msg'], $result['data']);
     }
+    /**
+     * 聘用人员注册
+     *
+     * @return void
+     * @author wj
+     * @date 2022-12-21
+     */
+    public function registerengage()
+    {
+        $post = request()->post();
+        $l_u = new UserLogic();
+        $result = $l_u->registerengage($post);
+        if (empty($result['status'])) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(200, $result['msg'], $result['data']);
+    }
 }

+ 1 - 1
application/api/logic/CourierLogic.php

@@ -97,7 +97,7 @@ class CourierLogic
         }
         if (0 == $moinfo['status_delivery']) {
             $updateData = [
-                'status_delivery' => 2,
+                'status_delivery' => $status_delivery,
                 'deliverytime' => date('Y-m-d H:i:s'),
             ];
             $row = $m_mo->updateinfo(['id' => $orderid], $updateData);

+ 23 - 10
application/api/logic/MealLogic.php

@@ -118,18 +118,28 @@ class MealLogic
                         throw new \Exception("参数缺少");
                     }
                 }
-                $insertData = [
+                $where = [
                     'receiver_address' => $arr['receiver_address'],
-                    'address' => $arr['address'],
-                    'receiver_name' => $arr['receiver_name'],
                     'receiver_telno' => $arr['receiver_telno'],
-                    'gcj_lat' => $arr['gcj_lat'],
-                    'gcj_long' => $arr['gcj_long'],
                     'user_id' => $userid,
                 ];
-                $uaid = $m_ua->insertData($insertData);
-                if (empty($uaid)) {
-                    throw new \Exception("地址保存失败");
+                $uainfo = $m_ua->getInfo($where);
+                if (!empty($uainfo)) {
+                    $uaid = $uainfo['id'];
+                } else {
+                    $insertData = [
+                        'receiver_address' => $arr['receiver_address'],
+                        'address' => $arr['address'],
+                        'receiver_name' => $arr['receiver_name'],
+                        'receiver_telno' => $arr['receiver_telno'],
+                        'gcj_lat' => $arr['gcj_lat'],
+                        'gcj_long' => $arr['gcj_long'],
+                        'user_id' => $userid,
+                    ];
+                    $uaid = $m_ua->insertData($insertData);
+                    if (empty($uaid)) {
+                        throw new \Exception("地址保存失败");
+                    }
                 }
             } else {
                 $uaid = $arr['address_id'];
@@ -141,7 +151,10 @@ class MealLogic
             $many = bcmul($quantity, $minfo['price'], 2);
             //$m_c = new CookbookModel();
             $m_mc = new MealcookModel();
-            $cooks = $m_mc->getcooks($center_id, $meal_id);
+            $cooks = $m_mc->getcooks($center_id, $meal_id)->toArray();
+            if (empty($cooks)) {
+                throw new \Exception("无对应菜谱");
+            }
             $cooksids = implode(',', array_column($cooks, 'id'));
             $orderno = date('ymdhis') . $center_id . $meal_id . $userid;
             $remark = isset($arr['remark']) ? $arr['remark'] : '';
@@ -166,7 +179,7 @@ class MealLogic
                 throw new \Exception("订单添加失败");
             }
             Db::commit();
-            return backarr(1, "订单添加成功", ['moid' => $moid]);
+            return backarr(1, "订单添加成功", ['moid' => $moid, 'orderno' => $orderno]);
         } catch (\Exception $e) {
             Db::rollback();
             $msg = $e->getMessage();

+ 101 - 1
application/api/logic/UserLogic.php

@@ -6,6 +6,7 @@ use app\common\model\EngageUserModel;
 use app\common\model\MealcenterModel;
 use app\common\model\UserAddressModel;
 use app\common\model\UserModel;
+use think\Db;
 
 class UserLogic
 {
@@ -222,7 +223,7 @@ class UserLogic
         $size = isset($arr['size']) && is_numeric($arr['size']) && !empty($arr['size']) && $arr['size'] > 0 ? $arr['size'] : 10;
         $where = [];
         if (!empty($userid)) {
-            $where['userid'] = $userid;
+            $where['user_id'] = $userid;
         }
         if (isset($arr['is_active'])) {
             $where['is_active'] = $arr['is_active'];
@@ -327,4 +328,103 @@ class UserLogic
                 break;
         }
     }
+    /**
+     * 聘用人员注册
+     *
+     * @param  [type] $arr
+     * @return void
+     * @author wj
+     * @date 2022-12-21
+     */
+    public function registerengage($arr)
+    {
+        $fillfields = ['phone', 'passwd', 'name', 'type'];
+        foreach ($fillfields as $key => $value) {
+            if (!isset($arr[$value]) || empty($arr[$value])) {
+                return backarr(0, "参数缺少");
+            }
+        }
+        $m_u = new UserModel();
+        $m_eu = new EngageUserModel();
+        $phone = $arr['phone'];
+        $name = $arr['name'];
+        $type = $arr['type'];
+        $passwd = $phone . $arr['passwd'];
+        $where = ['name' => $name];
+        $uinfo = $m_u->getInfo($where);
+        if (!empty($uinfo)) {
+            return backarr(0, "登陆名已存在");
+        }
+        Db::startTrans();
+        try {
+            //注册
+            $passwd = $this->createpasswd($passwd);
+            $insertData = [
+                'name' => $name,
+                'phone' => $phone,
+                'passwd' => $passwd,
+                'is_engage' => 1,
+            ];
+            $uid = $m_u->insertData($insertData);
+            if (empty($uid)) {
+                throw new \Exception("注册失败");
+            }
+            $euinsertData = [
+                'user_id' => $uid,
+                'et_id' => $type,
+            ];
+            $euid = $m_eu->insertData($euinsertData);
+            if (empty($euid)) {
+                throw new \Exception("聘用人员信息添加失败");
+            }
+            switch ($type) {
+                case 1:
+                    $m_c = new CourierModel();
+                    //username 用户姓名
+                    $fillfields = ['username'];
+                    foreach ($fillfields as $key => $value) {
+                        if (!isset($arr[$value]) || empty($arr[$value])) {
+                            throw new \Exception("参数缺少");
+                        }
+                    }
+                    $username = $arr['username'];
+                    $cinsertData = [
+                        'name' => $username,
+                        'telno' => $phone,
+                        'is_active' => 1,
+                        'user_id' => $uid,
+                    ];
+                    $cid = $m_c->insertData($cinsertData);
+                    if (empty($cid)) {
+                        throw new \Exception("配送员信息添加失败");
+                    }
+                    break;
+
+                default:
+                    throw new \Exception("聘用人员类型错误");
+                    break;
+            }
+            Db::commit();
+            $result = $this->getengageinfo($type, $uid);
+            if (empty($result['status'])) {
+                return backarr(0, $result['msg']);
+            }
+            $engageinfo = $result['data'];
+            $result = $this->changetoken($uid, $phone);
+            if (empty($result['status'])) {
+                throw new \Exception($result['msg']);
+            }
+            $field = ['id', 'phone', 'token'];
+            $where = ['id' => $uid];
+            $uinfo = $m_u->getInfo($where, $field);
+            $uinfo['engageinfo'] = $engageinfo;
+            return backarr($uinfo, "注册成功", $uinfo);
+        } catch (\Exception $e) {
+            Db::rollback();
+            $msg = $e->getMessage();
+            //var_dump($msg, $e->getTraceAsString());
+            return backarr(0, $msg);
+        }
+
+    }
 }

+ 39 - 0
application/common/model/MealOrdersModel.php

@@ -80,4 +80,43 @@ class MealOrdersModel extends Model
         }
         return $data;
     }
+    public function getListjoincenter($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $usewhere = [];
+        if (isset($where['name_center']) && !empty($where['name_center'])) {
+            $usewhere['mc.name_center'] = ['like', "%" . $where['name_center'] . "%"];
+        }
+        if (isset($where['orderno']) && !empty($where['orderno'])) {
+            $usewhere['mo.orderno'] = ['like', "%" . $where['orderno'] . "%"];
+        }
+        if (isset($where['createtime'])) {
+            $usewhere['mo.createtime'] = ['between', $where['createtime']];
+        }
+        if (isset($where['status'])) {
+            $usewhere['mo.status'] = $where['status'];
+        }
+        if (isset($where['status_delivery'])) {
+            $usewhere['mo.status_delivery'] = $where['status_delivery'];
+        }
+
+        if ($field == "*") {
+            $field = ['mc.name_center', 'm.name_meal', 'm.price', 'mo.*'];
+        }
+        $sqlObj = $this->alias('mo')->join("t_mealcenter mc", "mc.id=mo.center_id")->join("t_meal m", "m.id=mo.meal_id")->where($usewhere)->field($field);
+        if ("count" != $field) {
+            if (empty($size)) {
+                $sqlObj = $sqlObj->order($order)->group($group);
+            } else {
+                $sqlObj = $sqlObj->order($order)->group($group)->page($page, $size);
+            }
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj->count();
+        }
+        return $data;
+    }
 }

+ 89 - 0
application/common/model/VisitBusinessTypeModel.php

@@ -0,0 +1,89 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 到访记录
+ *
+ * @author wj
+ * @date 2023-01-18
+ */
+class VisitBusinessTypeModel extends Model
+{
+
+    protected $table = 't_visit_business_type';
+
+    public function insertData($data)
+    {
+        $field = $this->getTableFields();
+        $insertData = [];
+        foreach ($field as $key => $value) {
+            if (in_array($value, array_keys($data))) {
+                $insertData[$value] = $data[$value];
+            }
+        }
+        unset($insertData['id']);
+        $data = $insertData;
+        $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;
+    }
+    /**
+     * 获取业务的类型
+     *
+     * @return void
+     * @author wj
+     * @date 2023-01-18
+     */
+    public function getbusinesstype()
+    {
+        $list = [
+            1 => "文体活动",
+            2 => "健康保健",
+            3 => "现场用餐",
+            4 => "家政服务",
+            5 => "日间照料",
+            6 => "其他",
+        ];
+        return $list;
+    }
+}

+ 73 - 0
application/common/model/VisitModel.php

@@ -0,0 +1,73 @@
+<?php
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 到访记录
+ *
+ * @author wj
+ * @date 2023-01-18
+ */
+class VisitModel extends Model
+{
+
+    protected $table = 't_visit';
+
+    public function insertData($data)
+    {
+        $field = $this->getTableFields();
+        $insertData = [];
+        foreach ($field as $key => $value) {
+            if (in_array($value, array_keys($data))) {
+                $insertData[$value] = $data[$value];
+            }
+        }
+        unset($insertData['id']);
+        if (!isset($insertData['createtime'])) {
+            $insertData['createtime'] = date("Y-m-d H:i:s");
+        }
+        $data = $insertData;
+        $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;
+    }
+}

+ 91 - 0
application/common/server/MyPhpOffacePsr16Implementation.php

@@ -0,0 +1,91 @@
+<?php
+namespace app\common\server;
+
+use Psr\SimpleCache\CacheInterface;
+use Psr\SimpleCache\InvalidArgumentException;
+
+/**
+ * phpoffice 自定义缓存
+ *
+ * 参考 PhpOffice\PhpSpreadsheet\Collection\Memory\SimpleCache3
+ * 使用 PhpOffice\PhpSpreadsheet\Settings::setCache($cache);
+ *
+ * @author wj
+ * @date 2023-01-17
+ */
+class MyPhpOffacePsr16Implementation implements CacheInterface
+{
+    private $redis;
+    public function __construct()
+    {
+        //var_dump(__CLASS__);
+        $this->redis = new \Redis();
+        //docker redis1 6379
+        $this->redis->connect('127.0.0.1', 6379);
+        $this->redis->auth("qwe110110");
+        $this->redis->select("1"); //选择1号数据库 默认0号
+        if (!$this->redis->ping()) {
+            $error = "connect error";
+            throw new InvalidArgumentException($error);
+            //throw new \Exception("链接失败");
+        }
+    }
+    public function get($key, $default = null)
+    {
+        $$this->redis->get($key);
+        throw new InvalidArgumentException($error);
+
+    }
+    public function set($key, $value, $ttl = null)
+    {
+        $this->redis->set($key, $value);
+        //throw new InvalidArgumentException($error);
+        return true;
+    }
+    public function delete($key)
+    {
+        $this->redis->del($key);
+        return true;
+        //throw new InvalidArgumentException($error);
+    }
+    public function clear()
+    {
+        $keys = $this->redis->keys("*");
+        foreach ($keys as $key => $value) {
+            $this->redis->del($value);
+        }
+        return true;
+        //throw new InvalidArgumentException($error);
+    }
+    public function getMultiple($keys, $default = null)
+    {
+        $values = [];
+        foreach ($keys as $key => $value) {
+            $values[$key] = $this->redis->get($value);
+        }
+        return $values;
+        //throw new InvalidArgumentException($error);
+    }
+    public function setMultiple($values, $ttl = null)
+    {
+        foreach ($values as $key => $value) {
+            $this->redis->set($key, $value);
+        }
+        return true;
+        //throw new InvalidArgumentException($error);
+    }
+    public function deleteMultiple($keys)
+    {
+        foreach ($keys as $key => $value) {
+            $this->redis->del($key);
+        }
+        return true;
+        //$error = "";
+        //throw new InvalidArgumentException($error);
+    }
+    public function has($key)
+    {
+        return $this->redis->exists($key);
+        //throw new InvalidArgumentException($error);
+    }
+}

+ 98 - 0
application/common/server/PhpExcel.php

@@ -0,0 +1,98 @@
+<?php
+
+namespace app\common\server;
+
+//use think\Log;
+use app\common\server\MyPhpOffacePsr16Implementation;
+//use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+use PhpOffice\PhpSpreadsheet\IOFactory;
+use PhpOffice\PhpSpreadsheet\Settings;
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+
+/**
+ * excel导出
+ *
+ * @Author wj
+ * @DateTime 2022-10-02
+ * @Describe
+ */
+class PhpExcel
+{
+    private $title;
+    private $body;
+    private $sheetobj;
+    private $spreadsheet;
+    public function __construct()
+    {
+        $this->spreadsheet = new Spreadsheet();
+        $sheet = $this->spreadsheet->getActiveSheet();
+        $this->sheetobj = $sheet;
+    }
+    public function settitle($title)
+    {
+        $this->title = $title;
+    }
+    public function setbody($body)
+    {
+        $this->body = $body;
+    }
+    /**
+     * 自定义缓存
+     *
+     * @return void
+     * @author wj
+     * @date 2023-01-17
+     */
+    public function setmararycache()
+    {
+        $cache = new MyPhpOffacePsr16Implementation();
+        Settings::setCache($cache);
+    }
+    public function getsheetobj($body, $title = [], $style = [], $newsheet = false)
+    {
+        if ($newsheet) {
+            $sheetobj = $this->spreadsheet->createSheet();
+        } else {
+            $sheetobj = $this->sheetobj;
+        }
+        if (!empty($title)) {
+            foreach ($title as $key => $value) {
+                $sheetobj->getCell($value['cell'])->setValue($value['value']);
+            }
+        }
+        foreach ($body as $key => $value) {
+            foreach ($value as $k => $v) {
+                $sheetobj->getCell($v['cell'])->setValue($v['value']);
+            }
+        }
+        if (!empty($style)) {
+            foreach ($style as $key => $value) {
+                $sheetobjstyle = $sheetobj->getColumnDimension($key);
+                foreach ($value as $k => $v) {
+                    switch ($k) {
+                        case 'width':
+                            $sheetobjstyle->setWidth($v);
+                            break;
+                    }
+                }
+            }
+        }
+        $this->sheetobj = $sheetobj;
+    }
+    public function exportsheet($filename, $type = "Xlsx")
+    {
+        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        header('Content-Disposition: attachment;filename=' . $filename);
+        header('Cache-Control: max-age=0');
+        // If you're serving to IE 9, then the following may be needed
+        header('Cache-Control: max-age=1');
+        header('Pragma: public'); // HTTP/1.0
+        $objwriter = IOFactory::createWriter($this->spreadsheet, $type);
+        $objwriter->save('php://output');
+    }
+    public function sevefile($filename, $type = "Xlsx")
+    {
+        $objwriter = IOFactory::createWriter($this->spreadsheet, $type);
+        $objwriter->save($filename);
+    }
+}

+ 2 - 2
application/common/server/WatchPay.php

@@ -1,7 +1,7 @@
 <?php
-namespace app\api\server;
+namespace app\common\server;
 
-use think\Facade\Log;
+use think\facade\Log;
 
 /**
  * 微信支付

+ 30 - 0
application/test/controller/Phpexcel.php

@@ -0,0 +1,30 @@
+<?php
+namespace app\test\controller;
+
+use app\common\server\PhpExcel as PhpExcelServer;
+
+class Phpexcel
+{
+    public function test()
+    {
+        $s_pes = new PhpExcelServer();
+        $title = [
+            ['cell' => 'A1', 'value' => '测试1'],
+            ['cell' => 'B1', 'value' => '测试2'],
+        ];
+        $body = [
+            [
+                'test1' => ['cell' => 'A2', "value" => 2],
+                'test2' => ['cell' => 'B2', "value" => 5],
+            ],
+        ];
+        $exportData = [
+            'title' => $title,
+            'body' => $body,
+        ];
+        $s_pes->setmararycache();
+        $s_pes->getsheetobj($body, $title);
+        $s_pes->sevefile('test.xml');
+    }
+
+}

+ 2 - 1
composer.json

@@ -17,7 +17,8 @@
     ],
     "require": {
         "php": ">=5.6.0",
-        "topthink/framework": "5.1.*"
+        "topthink/framework": "5.1.*",
+        "phpoffice/phpspreadsheet": "^1.25"
     },
     "autoload": {
         "psr-4": {

+ 52 - 51
thinkphp/library/think/db/Query.php

@@ -95,14 +95,14 @@ class Query
      * @var array
      */
     protected $timeRule = [
-        'today'      => ['today', 'tomorrow -1second'],
-        'yesterday'  => ['yesterday', 'today -1second'],
-        'week'       => ['this week 00:00:00', 'next week 00:00:00 -1second'],
-        'last week'  => ['last week 00:00:00', 'this week 00:00:00 -1second'],
-        'month'      => ['first Day of this month 00:00:00', 'first Day of next month 00:00:00 -1second'],
+        'today' => ['today', 'tomorrow -1second'],
+        'yesterday' => ['yesterday', 'today -1second'],
+        'week' => ['this week 00:00:00', 'next week 00:00:00 -1second'],
+        'last week' => ['last week 00:00:00', 'this week 00:00:00 -1second'],
+        'month' => ['first Day of this month 00:00:00', 'first Day of next month 00:00:00 -1second'],
         'last month' => ['first Day of last month 00:00:00', 'first Day of this month 00:00:00 -1second'],
-        'year'       => ['this year 1/1', 'next year 1/1 -1second'],
-        'last year'  => ['last year 1/1', 'this year 1/1 -1second'],
+        'year' => ['this year 1/1', 'next year 1/1 -1second'],
+        'last year' => ['last year 1/1', 'this year 1/1 -1second'],
     ];
 
     /**
@@ -228,7 +228,7 @@ class Query
     public function setConnection(Connection $connection)
     {
         $this->connection = $connection;
-        $this->prefix     = $this->connection->getConfig('prefix');
+        $this->prefix = $this->connection->getConfig('prefix');
 
         return $this;
     }
@@ -557,12 +557,12 @@ class Query
         // 对数据表进行分区
         if ($field && isset($data[$field])) {
             $value = $data[$field];
-            $type  = $rule['type'];
+            $type = $rule['type'];
             switch ($type) {
                 case 'id':
                     // 按照id范围分表
                     $step = $rule['expr'];
-                    $seq  = floor($value / $step) + 1;
+                    $seq = floor($value / $step) + 1;
                     break;
                 case 'year':
                     // 按照年份分表
@@ -662,7 +662,7 @@ class Query
         if (!empty($this->options['group'])) {
             // 支持GROUP
             $options = $this->getOptions();
-            $subSql  = $this->options($options)
+            $subSql = $this->options($options)
                 ->field('count(' . $field . ') AS think_count')
                 ->bind($this->bind)
                 ->buildSql();
@@ -1025,11 +1025,11 @@ class Query
         if (true === $field) {
             // 获取全部字段
             $fields = $this->getTableFields($tableName);
-            $field  = $fields ?: ['*'];
+            $field = $fields ?: ['*'];
         } elseif ($except) {
             // 字段排除
             $fields = $this->getTableFields($tableName);
-            $field  = $fields ? array_diff($fields, $field) : $field;
+            $field = $fields ? array_diff($fields, $field) : $field;
         }
 
         if ($tableName) {
@@ -1164,7 +1164,7 @@ class Query
             }
         } else {
             $fields = [];
-            $table  = $this->getJoinTable($join, $alias);
+            $table = $this->getJoinTable($join, $alias);
 
             if (true === $field) {
                 $fields = $alias . '.*';
@@ -1419,7 +1419,7 @@ class Query
         }
 
         if (is_null($field2)) {
-            $field2   = $operator;
+            $field2 = $operator;
             $operator = '=';
         }
 
@@ -1628,6 +1628,8 @@ class Query
                     $where[] = [$key, 'exp', $val];
                 } elseif (is_null($val)) {
                     $where[] = [$key, 'NULL', ''];
+                } elseif (is_array($val) && isset($val[0])) {
+                    $where[] = [$key, $val[0], $val[1]];
                 } else {
                     $where[] = [$key, is_array($val) ? 'IN' : '=', $val];
                 }
@@ -1636,7 +1638,6 @@ class Query
             // 数组批量查询
             $where = $field;
         }
-
         if (!empty($where)) {
             $this->options['where'][$logic] = isset($this->options['where'][$logic]) ? array_merge($this->options['where'][$logic], $where) : $where;
         }
@@ -1676,7 +1677,7 @@ class Query
     {
         if (true === $option) {
             $this->options = [];
-            $this->bind    = [];
+            $this->bind = [];
         } elseif (is_string($option) && isset($this->options[$option])) {
             unset($this->options[$option]);
         }
@@ -1770,23 +1771,23 @@ class Query
     public function paginate($listRows = null, $simple = false, $config = [])
     {
         if (is_int($simple)) {
-            $total  = $simple;
+            $total = $simple;
             $simple = false;
         }
 
         $paginate = Container::get('config')->pull('paginate');
 
         if (is_array($listRows)) {
-            $config   = array_merge($paginate, $listRows);
+            $config = array_merge($paginate, $listRows);
             $listRows = $config['list_rows'];
         } else {
-            $config   = array_merge($paginate, $config);
+            $config = array_merge($paginate, $config);
             $listRows = $listRows ?: $config['list_rows'];
         }
 
         /** @var Paginator $class */
         $class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']);
-        $page  = isset($config['page']) ? (int) $config['page'] : call_user_func([
+        $page = isset($config['page']) ? (int) $config['page'] : call_user_func([
             $class,
             'getCurrentPage',
         ], $config['var_page']);
@@ -1800,12 +1801,12 @@ class Query
 
             unset($this->options['order'], $this->options['limit'], $this->options['page'], $this->options['field']);
 
-            $bind    = $this->bind;
-            $total   = $this->count();
+            $bind = $this->bind;
+            $total = $this->count();
             $results = $this->options($options)->bind($bind)->page($page, $listRows)->select();
         } elseif ($simple) {
             $results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select();
-            $total   = null;
+            $total = null;
         } else {
             $results = $this->page($page, $listRows)->select();
         }
@@ -1829,7 +1830,7 @@ class Query
                 // 子查询
             } elseif (strpos($table, ',')) {
                 $tables = explode(',', $table);
-                $table  = [];
+                $table = [];
 
                 foreach ($tables as $item) {
                     list($item, $alias) = explode(' ', trim($item));
@@ -1848,7 +1849,7 @@ class Query
             }
         } else {
             $tables = $table;
-            $table  = [];
+            $table = [];
 
             foreach ($tables as $key => $val) {
                 if (is_numeric($key)) {
@@ -1988,7 +1989,7 @@ class Query
         // 增加快捷调用方式 cache(10) 等同于 cache(true, 10)
         if ($key instanceof \DateTime || (is_numeric($key) && is_null($expire))) {
             $expire = $key;
-            $key    = true;
+            $key = true;
         }
 
         if (false !== $key) {
@@ -2030,7 +2031,7 @@ class Query
      */
     public function lock($lock = false)
     {
-        $this->options['lock']   = $lock;
+        $this->options['lock'] = $lock;
         $this->options['master'] = true;
 
         return $this;
@@ -2256,7 +2257,7 @@ class Query
      */
     public function json(array $json = [], $assoc = false)
     {
-        $this->options['json']       = $json;
+        $this->options['json'] = $json;
         $this->options['json_assoc'] = $assoc;
         return $this;
     }
@@ -2347,7 +2348,7 @@ class Query
             } elseif ($this->model) {
                 // 检测搜索器
                 $fieldName = is_numeric($key) ? $field : $key;
-                $method    = 'search' . Loader::parseName($fieldName, 1) . 'Attr';
+                $method = 'search' . Loader::parseName($fieldName, 1) . 'Attr';
 
                 if (method_exists($this->model, $method)) {
                     $this->model->$method($this, isset($data[$field]) ? $data[$field] : null, $data, $prefix);
@@ -2453,7 +2454,7 @@ class Query
     public function whereBetweenTime($field, $startTime, $endTime = null, $logic = 'AND')
     {
         if (is_null($endTime)) {
-            $time    = is_string($startTime) ? strtotime($startTime) : $startTime;
+            $time = is_string($startTime) ? strtotime($startTime) : $startTime;
             $endTime = strtotime('+1 day', $time);
         }
 
@@ -2587,7 +2588,7 @@ class Query
 
             if ($relation instanceof \Closure) {
                 // 支持闭包查询过滤关联条件
-                $closure  = $relation;
+                $closure = $relation;
                 $relation = $key;
             } elseif (is_array($relation)) {
                 $relation = $key;
@@ -2597,7 +2598,7 @@ class Query
 
             /** @var Relation $model */
             $relation = Loader::parseName($relation, 1, false);
-            $model    = $class->$relation();
+            $model = $class->$relation();
 
             if ($model instanceof OneToOne && 0 == $model->getEagerlyType()) {
                 $table = $model->getTable();
@@ -2638,14 +2639,14 @@ class Query
         $class = $this->model;
         foreach ($with as $key => $relation) {
             $closure = null;
-            $field   = true;
+            $field = true;
 
             if ($relation instanceof \Closure) {
                 // 支持闭包查询过滤关联条件
-                $closure  = $relation;
+                $closure = $relation;
                 $relation = $key;
             } elseif (is_array($relation)) {
-                $field    = $relation;
+                $field = $relation;
                 $relation = $key;
             } elseif (is_string($relation) && strpos($relation, '.')) {
                 list($relation, $subRelation) = explode('.', $relation, 2);
@@ -2653,7 +2654,7 @@ class Query
 
             /** @var Relation $model */
             $relation = Loader::parseName($relation, 1, false);
-            $model    = $class->$relation();
+            $model = $class->$relation();
 
             if ($model instanceof OneToOne) {
                 $model->eagerly($this, $relation, $field, $joinType, $closure, $first);
@@ -2695,11 +2696,11 @@ class Query
                 $closure = $aggregateField = null;
 
                 if ($relation instanceof \Closure) {
-                    $closure  = $relation;
+                    $closure = $relation;
                     $relation = $key;
                 } elseif (!is_int($key)) {
                     $aggregateField = $relation;
-                    $relation       = $key;
+                    $relation = $key;
                 }
 
                 $relation = Loader::parseName($relation, 1, false);
@@ -3205,7 +3206,7 @@ class Query
 
         if (true === $with || is_int($with)) {
             $cache = $with;
-            $with  = [];
+            $with = [];
         }
 
         return $this->parseQuery($data, $with, $cache)
@@ -3240,7 +3241,7 @@ class Query
     {
         if (true === $with || is_int($with)) {
             $cache = $with;
-            $with  = [];
+            $with = [];
         }
 
         return $this->parseQuery($data, $with, $cache)->select($data);
@@ -3260,13 +3261,13 @@ class Query
 
         if ((is_array($data) && key($data) !== 0) || $data instanceof Where) {
             $result = $result->where($data);
-            $data   = null;
+            $data = null;
         } elseif ($data instanceof \Closure) {
             $data($result);
             $data = null;
         } elseif ($data instanceof Query) {
             $result = $data->with($with)->cache($cache);
-            $data   = null;
+            $data = null;
         }
 
         return $result;
@@ -3331,7 +3332,7 @@ class Query
 
                 if (isset($withRelationAttr[$name])) {
                     foreach ($withRelationAttr[$name] as $key => $closure) {
-                        $data                = get_object_vars($result[$name]);
+                        $data = get_object_vars($result[$name]);
                         $result[$name]->$key = $closure(isset($result[$name]->$key) ? $result[$name]->$key : null, $data);
                     }
                 }
@@ -3490,7 +3491,7 @@ class Query
     public function chunk($count, $callback, $column = null, $order = 'asc')
     {
         $options = $this->getOptions();
-        $column  = $column ?: $this->getPk($options);
+        $column = $column ?: $this->getPk($options);
 
         if (isset($options['order'])) {
             if (Container::get('app')->isDebug()) {
@@ -3529,7 +3530,7 @@ class Query
                 $times++;
                 $query = $this->options($options)->page($times, $count);
             } else {
-                $end    = end($resultSet);
+                $end = end($resultSet);
                 $lastId = is_array($end) ? $end[$key] : $end->getData($key);
 
                 $query = $this->options($options)
@@ -3650,7 +3651,7 @@ class Query
             // 根据复合主键查询
             foreach ($pk as $key) {
                 if (isset($data[$key])) {
-                    $attr        = isset($alias) ? $alias . '.' . $key : $key;
+                    $attr = isset($alias) ? $alias . '.' . $key : $key;
                     $where[$key] = [$attr, '=', $data[$key]];
                 } else {
                     throw new Exception('miss complex primary data');
@@ -3723,10 +3724,10 @@ class Query
         if (isset($options['page'])) {
             // 根据页数计算limit
             list($page, $listRows) = $options['page'];
-            $page                  = $page > 0 ? $page : 1;
-            $listRows              = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20);
-            $offset                = $listRows * ($page - 1);
-            $options['limit']      = $offset . ',' . $listRows;
+            $page = $page > 0 ? $page : 1;
+            $listRows = $listRows > 0 ? $listRows : (is_numeric($options['limit']) ? $options['limit'] : 20);
+            $offset = $listRows * ($page - 1);
+            $options['limit'] = $offset . ',' . $listRows;
         }
 
         $this->options = $options;