From 7f305fb6d2c3fbbd6ba84f99b24005df2c80316a Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Thu, 31 Aug 2023 11:21:56 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0app=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../controller/AppUpdateController.php        | 108 ++++++++++++++++
 app/adminapi/lists/AppUpdateLists.php         |  77 ++++++++++++
 app/adminapi/logic/AppUpdateLogic.php         | 118 ++++++++++++++++++
 app/adminapi/validate/AppUpdateValidate.php   | 104 +++++++++++++++
 app/api/lists/AccountLogLists.php             |   3 +-
 app/api/logic/IndexLogic.php                  |  17 ++-
 app/api/service/UserTokenService.php          |  13 +-
 app/common/model/AppUpdate.php                |  34 +++++
 8 files changed, 464 insertions(+), 10 deletions(-)
 create mode 100644 app/adminapi/controller/AppUpdateController.php
 create mode 100644 app/adminapi/lists/AppUpdateLists.php
 create mode 100644 app/adminapi/logic/AppUpdateLogic.php
 create mode 100644 app/adminapi/validate/AppUpdateValidate.php
 create mode 100644 app/common/model/AppUpdate.php

diff --git a/app/adminapi/controller/AppUpdateController.php b/app/adminapi/controller/AppUpdateController.php
new file mode 100644
index 000000000..e2b85299f
--- /dev/null
+++ b/app/adminapi/controller/AppUpdateController.php
@@ -0,0 +1,108 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+
+namespace app\adminapi\controller;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\AppUpdateLists;
+use app\adminapi\logic\AppUpdateLogic;
+use app\adminapi\validate\AppUpdateValidate;
+
+
+/**
+ * app更新控制器
+ * Class AppUpdateController
+ * @package app\adminapi\controller
+ */
+class AppUpdateController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取app更新列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function lists()
+    {
+        return $this->dataLists(new AppUpdateLists());
+    }
+
+
+    /**
+     * @notes 添加app更新
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function add()
+    {
+        $params = (new AppUpdateValidate())->post()->goCheck('add');
+        $result = AppUpdateLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(AppUpdateLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑app更新
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function edit()
+    {
+        $params = (new AppUpdateValidate())->post()->goCheck('edit');
+        $result = AppUpdateLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(AppUpdateLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除app更新
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function delete()
+    {
+        $params = (new AppUpdateValidate())->post()->goCheck('delete');
+        AppUpdateLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取app更新详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function detail()
+    {
+        $params = (new AppUpdateValidate())->goCheck('detail');
+        $result = AppUpdateLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}
\ No newline at end of file
diff --git a/app/adminapi/lists/AppUpdateLists.php b/app/adminapi/lists/AppUpdateLists.php
new file mode 100644
index 000000000..07dfc96b5
--- /dev/null
+++ b/app/adminapi/lists/AppUpdateLists.php
@@ -0,0 +1,77 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\AppUpdate;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * app更新列表
+ * Class AppUpdateLists
+ * @package app\adminapi\lists
+ */
+class AppUpdateLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['title', 'content', 'type', 'version', 'dow_url', 'force', 'quiet'],
+        ];
+    }
+
+
+    /**
+     * @notes 获取app更新列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function lists(): array
+    {
+        return AppUpdate::where($this->searchWhere)
+            ->field(['id', 'title', 'content', 'type', 'version', 'dow_url', 'force', 'quiet'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取app更新数量
+     * @return int
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function count(): int
+    {
+        return AppUpdate::where($this->searchWhere)->count();
+    }
+
+}
\ No newline at end of file
diff --git a/app/adminapi/logic/AppUpdateLogic.php b/app/adminapi/logic/AppUpdateLogic.php
new file mode 100644
index 000000000..a35cc5eda
--- /dev/null
+++ b/app/adminapi/logic/AppUpdateLogic.php
@@ -0,0 +1,118 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\logic;
+
+
+use app\common\model\AppUpdate;
+use app\common\logic\BaseLogic;
+use think\facade\Db;
+
+
+/**
+ * app更新逻辑
+ * Class AppUpdateLogic
+ * @package app\adminapi\logic
+ */
+class AppUpdateLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加app更新
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            AppUpdate::create([
+                'title' => $params['title'],
+                'content' => $params['content'],
+                'type' => $params['type'],
+                'version' => $params['version'],
+                'dow_url' => $params['dow_url'],
+                'force' => $params['force'],
+                'quiet' => $params['quiet']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑app更新
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            AppUpdate::where('id', $params['id'])->update([
+                'title' => $params['title'],
+                'content' => $params['content'],
+                'type' => $params['type'],
+                'version' => $params['version'],
+                'dow_url' => $params['dow_url'],
+                'force' => $params['force'],
+                'quiet' => $params['quiet']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 删除app更新
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public static function delete(array $params): bool
+    {
+        return AppUpdate::destroy($params['id']);
+    }
+
+
+    /**
+     * @notes 获取app更新详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public static function detail($params): array
+    {
+        return AppUpdate::findOrEmpty($params['id'])->toArray();
+    }
+}
\ No newline at end of file
diff --git a/app/adminapi/validate/AppUpdateValidate.php b/app/adminapi/validate/AppUpdateValidate.php
new file mode 100644
index 000000000..f7be5b2ba
--- /dev/null
+++ b/app/adminapi/validate/AppUpdateValidate.php
@@ -0,0 +1,104 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\validate;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * app更新验证器
+ * Class AppUpdateValidate
+ * @package app\adminapi\validate
+ */
+class AppUpdateValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+        'title' => 'require',
+        'content' => 'require',
+        'type' => 'require',
+        'version' => 'require',
+        'dow_url' => 'require',
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+        'title' => '标题',
+        'content' => '内容',
+        'type' => '1ios 2安卓',
+        'version' => '版本',
+        'dow_url' => 'app链接',
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return AppUpdateValidate
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function sceneAdd()
+    {
+        return $this->only(['title','content','type','version','dow_url']);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return AppUpdateValidate
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id','title','content','type','version','dow_url']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return AppUpdateValidate
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return AppUpdateValidate
+     * @author likeadmin
+     * @date 2023/08/31 11:08
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}
\ No newline at end of file
diff --git a/app/api/lists/AccountLogLists.php b/app/api/lists/AccountLogLists.php
index cb4154e84..79d38df8c 100755
--- a/app/api/lists/AccountLogLists.php
+++ b/app/api/lists/AccountLogLists.php
@@ -115,8 +115,9 @@ class AccountLogLists extends BaseApiDataLists
             $endTime = $date + 86399; // 获取该日期24小时后的时间戳
             $where[] = ['create_time', 'between', [$startTime, $endTime]];
         }else{
-            $where[] = ['create_time', 'between', [strtotime(date('Y-m-d')), strtotime(date('Y-m-d'))+86366]];
+            // $where[] = ['create_time', 'between', [strtotime(date('Y-m-d')), strtotime(date('Y-m-d'))+86366]];
         }
+
         $lists = UserAccountLog::field($field)
             ->where($where)
             ->with(['userInfo'])
diff --git a/app/api/logic/IndexLogic.php b/app/api/logic/IndexLogic.php
index d3794a4e4..b80b81fb8 100755
--- a/app/api/logic/IndexLogic.php
+++ b/app/api/logic/IndexLogic.php
@@ -154,9 +154,7 @@ class IndexLogic extends BaseLogic
             'shop_name' => ConfigService::get('website', 'shop_name'),
             'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
         ];
-        // H5配置
-
-
+        $versionInfo=[];
         return [
             'domain' => FileService::getFileUrl(),
             'style' => $style,
@@ -164,8 +162,19 @@ class IndexLogic extends BaseLogic
             'menu' => $menu,
             'login' => $loginConfig,
             'website' => $website,
-            'version'=> config('project.version')
+            'version'=> config('project.version'),
+            'version_info'=>$versionInfo,
         ];
     }
 
+    function isAndroid() {
+   $userAgent = $_SERVER['HTTP_USER_AGENT'];
+   return strpos($userAgent, 'Android') !== false;
+}
+
+function isIOS() {
+   $userAgent = $_SERVER['HTTP_USER_AGENT'];
+   return strpos($userAgent, 'iPhone') !== false || strpos($userAgent, 'iPad') !== false;
+}
+
 }
\ No newline at end of file
diff --git a/app/api/service/UserTokenService.php b/app/api/service/UserTokenService.php
index f86bfa6d9..755c688c4 100755
--- a/app/api/service/UserTokenService.php
+++ b/app/api/service/UserTokenService.php
@@ -78,13 +78,16 @@ class UserTokenService
     public static function overtimeToken($token)
     {
         $time = time();
-        $adminSession = UserSession::where('token', '=', $token)->find();
+        $userSession = UserSession::where('token', '=', $token)->find();
+        if ($userSession->isEmpty()) {
+            return false;
+        }
         //延长token过期时间
-        $adminSession->expire_time = $time + Config::get('project.user_token.expire_duration');
-        $adminSession->update_time = $time;
-        $adminSession->save();
+        $userSession->expire_time = $time + Config::get('project.user_token.expire_duration');
+        $userSession->update_time = $time;
+        $userSession->save();
 
-        return (new UserTokenCache())->setUserInfo($adminSession->token);
+        return (new UserTokenCache())->setUserInfo($userSession->token);
     }
 
 
diff --git a/app/common/model/AppUpdate.php b/app/common/model/AppUpdate.php
new file mode 100644
index 000000000..07d31e886
--- /dev/null
+++ b/app/common/model/AppUpdate.php
@@ -0,0 +1,34 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model;
+
+
+use app\common\model\BaseModel;
+use think\model\concern\SoftDelete;
+
+
+/**
+ * app更新模型
+ * Class AppUpdate
+ * @package app\common\model
+ */
+class AppUpdate extends BaseModel
+{
+    use SoftDelete;
+    protected $name = 'app_update';
+    protected $deleteTime = 'delete_time';
+
+    
+}
\ No newline at end of file