Browse Source

替换tp5

master
453530270@qq.com 2 years ago
parent
commit
74f45124c0
  1. 1
      .example.env
  2. 9
      .gitignore
  3. 42
      .travis.yml
  4. 32
      LICENSE.txt
  5. 56
      README.md
  6. 22
      app/AppService.php
  7. 204
      app/BaseController.php
  8. 58
      app/ExceptionHandle.php
  9. 8
      app/Request.php
  10. 91
      app/command/passengerFlow.php
  11. 92
      app/command/passengerFlowAll.php
  12. 65
      app/command/passengerFlowReal.php
  13. 237
      app/common.php
  14. 235
      app/controller/Index.php
  15. 24
      app/controller/Passport.php
  16. 17
      app/event.php
  17. 10
      app/middleware.php
  18. 9
      app/provider.php
  19. 9
      app/service.php
  20. 49
      composer.json
  21. 1085
      composer.lock
  22. 37
      config/app.php
  23. 29
      config/cache.php
  24. 12
      config/console.php
  25. 20
      config/cookie.php
  26. 63
      config/database.php
  27. 24
      config/filesystem.php
  28. 27
      config/lang.php
  29. 45
      config/log.php
  30. 8
      config/middleware.php
  31. 45
      config/route.php
  32. 19
      config/session.php
  33. 10
      config/trace.php
  34. 29
      config/view.php
  35. BIN
      doc/HIK接口.docx
  36. BIN
      icon.jpg
  37. 8
      public/.htaccess
  38. BIN
      public/favicon.ico
  39. 24
      public/index.php
  40. 2
      public/robots.txt
  41. 19
      public/router.php
  42. 23
      route/app.php
  43. 0
      source/application/admin/config.php
  44. 0
      source/application/admin/controller/Controller.php
  45. 0
      source/application/admin/controller/Index.php
  46. 0
      source/application/admin/controller/Passport.php
  47. 0
      source/application/admin/controller/Store.php
  48. 0
      source/application/admin/controller/admin/User.php
  49. 0
      source/application/admin/controller/setting/Cache.php
  50. 0
      source/application/admin/controller/setting/Science.php
  51. 0
      source/application/admin/controller/store/Access.php
  52. 0
      source/application/admin/extra/menus.php
  53. 0
      source/application/admin/model/Setting.php
  54. 0
      source/application/admin/model/Wxapp.php
  55. 0
      source/application/admin/model/WxappCategory.php
  56. 0
      source/application/admin/model/WxappHelp.php
  57. 0
      source/application/admin/model/WxappPage.php
  58. 0
      source/application/admin/model/admin/User.php
  59. 0
      source/application/admin/model/store/Access.php
  60. 0
      source/application/admin/model/store/User.php
  61. 0
      source/application/admin/view/admin/user/renew.php
  62. 0
      source/application/admin/view/index/index.php
  63. 0
      source/application/admin/view/layouts/layout.php
  64. 0
      source/application/admin/view/passport/login.php
  65. 0
      source/application/admin/view/setting/cache/clear.php
  66. 0
      source/application/admin/view/setting/science/index.php
  67. 0
      source/application/admin/view/store/access/add.php
  68. 0
      source/application/admin/view/store/access/edit.php
  69. 0
      source/application/admin/view/store/access/index.php
  70. 0
      source/application/admin/view/store/add.php
  71. 0
      source/application/admin/view/store/index.php
  72. 0
      source/application/admin/view/store/recycle.php
  73. 117
      source/application/api/behavior/order/PaySuccess.php
  74. 8
      source/application/api/config.php
  75. 111
      source/application/api/controller/Address.php
  76. 53
      source/application/api/controller/Article.php
  77. 84
      source/application/api/controller/Cart.php
  78. 29
      source/application/api/controller/Category.php
  79. 29
      source/application/api/controller/Comment.php
  80. 139
      source/application/api/controller/Controller.php
  81. 29
      source/application/api/controller/Coupon.php
  82. 74
      source/application/api/controller/Goods.php
  83. 135
      source/application/api/controller/Order.php
  84. 61
      source/application/api/controller/Page.php
  85. 65
      source/application/api/controller/Recharge.php
  86. 41
      source/application/api/controller/Shop.php
  87. 86
      source/application/api/controller/Upload.php
  88. 43
      source/application/api/controller/User.php
  89. 39
      source/application/api/controller/Wxapp.php
  90. 28
      source/application/api/controller/balance/Log.php
  91. 26
      source/application/api/controller/live/Room.php
  92. 28
      source/application/api/controller/recharge/Order.php
  93. 39
      source/application/api/controller/sharing/Active.php
  94. 68
      source/application/api/controller/sharing/Comment.php
  95. 68
      source/application/api/controller/sharing/Goods.php
  96. 26
      source/application/api/controller/sharing/Index.php
  97. 235
      source/application/api/controller/sharing/Order.php
  98. 109
      source/application/api/controller/sharing/Refund.php
  99. 26
      source/application/api/controller/sharing/Setting.php
  100. 72
      source/application/api/controller/shop/Order.php

1
.example.env

@ -1 +0,0 @@
APP_DEBUG = true [APP] DEFAULT_TIMEZONE = Asia/Shanghai [DATABASE] TYPE = mysql HOSTNAME = 127.0.0.1 DATABASE = test USERNAME = username PASSWORD = password HOSTPORT = 3306 CHARSET = utf8 DEBUG = true [LANG] default_lang = zh-cn

9
.gitignore

@ -1,5 +1,6 @@
/.idea
/.vscode
/vendor
.idea
composer.lock
*.log
.env
*.css.map
.sass-cache

42
.travis.yml

@ -1,42 +0,0 @@
sudo: false
language: php
branches:
only:
- stable
cache:
directories:
- $HOME/.composer/cache
before_install:
- composer self-update
install:
- composer install --no-dev --no-interaction --ignore-platform-reqs
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
script:
- php think unit
deploy:
provider: releases
api_key:
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
file:
- ThinkPHP_Core.zip
- ThinkPHP_Full.zip
skip_cleanup: true
on:
tags: true

32
LICENSE.txt

@ -1,32 +0,0 @@
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
Apache Licence是著名的非盈利开源组织Apache采用的协议。
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
允许代码修改,再作为开源或商业软件发布。需要满足
的条件:
1. 需要给代码的用户一份Apache Licence ;
2. 如果你修改了代码,需要在被修改的文件中说明;
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
带有原来代码中的协议,商标,专利声明和其他原来作者规
定需要包含的说明;
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
件中需要带有本协议内容。你可以在Notice中增加自己的
许可,但不可以表现为对Apache Licence构成更改。
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

56
README.md

@ -1,56 +0,0 @@
ThinkPHP 6.0
===============
> 运行环境要求PHP7.1+,兼容PHP8.0。
[官方应用服务市场](https://market.topthink.com) | [`ThinkAPI`——官方统一API服务](https://docs.topthink.com/think-api)
ThinkPHPV6.0版本由[亿速云](https://www.yisu.com/)独家赞助发布。
## 主要新特性
* 采用`PHP7`强类型(严格模式)
* 支持更多的`PSR`规范
* 原生多应用支持
* 更强大和易用的查询
* 全新的事件系统
* 模型事件和数据库事件统一纳入事件系统
* 模板引擎分离出核心
* 内部功能中间件化
* SESSION/Cookie机制改进
* 对Swoole以及协程支持改进
* 对IDE更加友好
* 统一和精简大量用法
## 安装
~~~
composer create-project topthink/think tp 6.0.*
~~~
如果需要更新框架使用
~~~
composer update topthink/framework
~~~
## 文档
[完全开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content)
## 参与开发
请参阅 [ThinkPHP 核心框架包](https://github.com/top-think/framework)。
## 版权信息
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
本项目包含的第三方源码和二进制文件之版权信息另行标注。
版权所有Copyright © 2006-2020 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
更多细节参阅 [LICENSE.txt](LICENSE.txt)

22
app/AppService.php

@ -1,22 +0,0 @@
<?php
declare (strict_types = 1);
namespace app;
use think\Service;
/**
* 应用服务类
*/
class AppService extends Service
{
public function register()
{
// 服务注册
}
public function boot()
{
// 服务启动
}
}

204
app/BaseController.php

@ -1,204 +0,0 @@
<?php
declare (strict_types = 1);
namespace app;
use think\App;
use think\exception\ValidateException;
use think\Validate;
use think\facade\View;
use think\facade\Config;
use think\facade\Request;
/**
* 控制器基础类
*/
abstract class BaseController
{
/**
* Request实例
* @var \think\Request
*/
protected $request;
/**
* 应用实例
* @var \think\App
*/
protected $app;
/**
* 是否批量验证
* @var bool
*/
protected $batchValidate = false;
/**
* 控制器中间件
* @var array
*/
protected $middleware = [];
/* @var array $admin 商家登录信息 */
protected $admin;
/* @var string $route 当前控制器名称 */
protected $controller = '';
/* @var string $route 当前方法名称 */
protected $action = '';
/* @var string $route 当前路由uri */
protected $routeUri = '';
/* @var string $route 当前路由:分组名称 */
protected $group = '';
/* @var array $allowAllAction 登录验证白名单 */
protected $allowAllAction = [
// 登录页面
'passport/login',
];
/* @var array $notLayoutAction 无需全局layout */
protected $notLayoutAction = [
// 登录页面
'passport/login',
];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();
// 全局layout
$this->layout();
}
/**
* 全局layout模板输出
* @throws \Exception
*/
private function layout()
{
// 验证当前请求是否在白名单
if (!in_array($this->routeUri, $this->notLayoutAction)) {
// 输出到view
View::assign([
'base_url' => base_url(), // 当前域名
'admin_url' => url('/admin'), // 后台模块url
'group' => $this->group,
'menus' => $this->menus(), // 后台菜单
'admin' => $this->admin, // 商家登录信息
'request' => Request::instance() // Request对象
]);
}
}
// 初始化
protected function initialize()
{}
/**
* 验证数据
* @access protected
* @param array $data 数据
* @param string|array $validate 验证器名或者验证规则数组
* @param array $message 提示信息
* @param bool $batch 是否批量验证
* @return array|string|true
* @throws ValidateException
*/
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
{
if (is_array($validate)) {
$v = new Validate();
$v->rule($validate);
} else {
if (strpos($validate, '.')) {
// 支持场景
[$validate, $scene] = explode('.', $validate);
}
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
$v = new $class();
if (!empty($scene)) {
$v->scene($scene);
}
}
$v->message($message);
// 是否批量验证
if ($batch || $this->batchValidate) {
$v->batch(true);
}
return $v->failException(true)->check($data);
}
/**
* 解析当前路由参数 (分组名称、控制器名称、方法名)
*/
protected function getRouteinfo()
{
// 控制器名称
$this->controller = toUnderScore($this->request->controller());
// 方法名称
$this->action = $this->request->action();
// 控制器分组 (用于定义所属模块)
$groupstr = strstr($this->controller, '.', true);
$this->group = $groupstr !== false ? $groupstr : $this->controller;
// 当前uri
$this->routeUri = $this->controller . '/' . $this->action;
}
/**
* 后台菜单配置
* @return array
*/
private function menus()
{
foreach ($data = Config::get('menus') as $group => $first) {
$data[$group]['active'] = $group === $this->group;
// 遍历:二级菜单
if (isset($first['submenu'])) {
foreach ($first['submenu'] as $secondKey => $second) {
// 二级菜单所有uri
$secondUris = isset($second['uris']) ? $second['uris'] : [$second['index']];
// 二级菜单:active
!isset($data[$group]['submenu'][$secondKey]['active'])
&& $data[$group]['submenu'][$secondKey]['active'] = in_array($this->routeUri, $secondUris);
}
}
}
return $data;
}
/**
* 验证登录状态
* @return bool
*/
private function checkLogin()
{
// 验证当前请求是否在白名单
if (in_array($this->routeUri, $this->allowAllAction)) {
return true;
}
// 验证登录状态
if (empty($this->admin)
|| (int)$this->admin['is_login'] !== 1
) {
$this->redirect('passport/login');
return false;
}
return true;
}
}

58
app/ExceptionHandle.php

@ -1,58 +0,0 @@
<?php
namespace app;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\Response;
use Throwable;
/**
* 应用异常处理类
*/
class ExceptionHandle extends Handle
{
/**
* 不需要记录信息(日志)的异常类列表
* @var array
*/
protected $ignoreReport = [
HttpException::class,
HttpResponseException::class,
ModelNotFoundException::class,
DataNotFoundException::class,
ValidateException::class,
];
/**
* 记录异常信息(包括日志或者其它方式记录)
*
* @access public
* @param Throwable $exception
* @return void
*/
public function report(Throwable $exception): void
{
// 使用内置的方式记录异常日志
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @access public
* @param \think\Request $request
* @param Throwable $e
* @return Response
*/
public function render($request, Throwable $e): Response
{
// 添加自定义异常处理机制
// 其他错误交给系统处理
return parent::render($request, $e);
}
}

8
app/Request.php

@ -1,8 +0,0 @@
<?php
namespace app;
// 应用请求对象类
class Request extends \think\Request
{
}

91
app/command/passengerFlow.php

@ -1,91 +0,0 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;
class passengerFlow extends Command
{
protected function configure()
{
$this->setName('passengerFlow')
->addArgument('name', Argument::OPTIONAL, "your name")
->addOption('city', null, Option::VALUE_REQUIRED, 'city name')
->setDescription('Say Hello');
}
protected function execute(Input $input, Output $output)
{
$config = config('app');
$dateData = getTargetDate();
$token = getAccessToken();
$arr = [
'hourly' => [
'startTime' => $dateData['day']['c_start_time'],
'endTime' => $dateData['day']['c_end_time'],
],
'daily' => [
'startTime' => $dateData['month']['c_start_time'],
'endTime' => $dateData['month']['c_end_time'],
],
'monthly' => [
'startTime' => $dateData['year']['c_start_time'],
'endTime' => date('c'),
]
];
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups";
$delete = Db::table('tp_passenger_flow')->where('id','>',1)->delete();
try {
foreach ($arr as $granularity => $value) {
$dataArr = [
'granularity' => $granularity,
'startTime' => $value['startTime'],
'endTime' => $value['endTime'],
'ids' => '01' // --- <replace> --- //
];
$json_data = json_encode($dataArr);
$result = postToken($url,$json_data,false,[],$token);
$res_data = json_decode($result,true);
if ($res_data['code'] != 0) throw new \Exception('请求失败');
$list = (array)$res_data['data']['list'];
foreach ($list as $val) {
$insert_arr = [
'groupId' => $val['groupId'],
'groupName' => $val['groupName'],
'flowInNum' => $val['flowInNum'],
'flowOutNum' => $val['flowOutNum'],
'noRepeatInNum' => $val['noRepeatInNum'],
'noRepeatOutNum' => $val['noRepeatOutNum'],
'holdValue' => $val['holdValue'],
'createTime' => $val['createTime'],
'updateTime' => $val['updateTime'],
'netValue' => $val['netValue'],
'statTime' => $val['statTime'],
'granularity' => $granularity,
];
Db::table('tp_passenger_flow')->insert($insert_arr);
}
}
$output->writeln('完成');
} catch (\Exception $e) {
$output->writeln($e->getMessage());
}
}
}
//return $res_data['data']['list'];

92
app/command/passengerFlowAll.php

@ -1,92 +0,0 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;
class passengerFlowAll extends Command
{
protected function configure()
{
$this->setName('passengerFlow')
->addArgument('name', Argument::OPTIONAL, "your name")
->addOption('city', null, Option::VALUE_REQUIRED, 'city name')
->setDescription('Say Hello');
}
protected function execute(Input $input, Output $output)
{
$config = config('app');
$dateData = getTargetDate();
$token = getAccessToken();
$dateArr = [
'day' => [
'startTime' => $dateData['day']['c_start_time'],// 当天开始时间
'endTime' => date("c"),// 当天结束时间
'granularity' => 'daily'
],
'week' => [
'startTime' => $dateData['week']['c_start_time'],
'endTime' => date("c"),
'granularity' => 'daily'
],
'month' =>[
'startTime' => $dateData['month']['c_start_time'],
'endTime' => date("c"),
'granularity' => 'monthly'
]
];
$delete = Db::table('tp_passenger_flow_all')->where('id','>',1)->delete();
try {
foreach ($dateArr as $date => $value) {
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups";
$granularity = $value['granularity'];
$dataArr = [
'granularity' => $granularity,
'startTime' => $value['startTime'],
'endTime' => $value['endTime'],
'ids' => '01' // --- <replace> --- //
];
$json_data = json_encode($dataArr);
$result = postToken($url,$json_data,false,[],$token);
$res_data = json_decode($result,true);
if ($res_data['code'] != 0) throw new \Exception('请求失败');
$list = (array)$res_data['data']['list'];
foreach ($list as $val) {
$insert_arr = [
'groupId' => $val['groupId'],
'groupName' => $val['groupName'],
'flowInNum' => $val['flowInNum'],
'flowOutNum' => $val['flowOutNum'],
'noRepeatInNum' => $val['noRepeatInNum'],
'noRepeatOutNum' => $val['noRepeatOutNum'],
'holdValue' => $val['holdValue'],
'createTime' => $val['createTime'],
'updateTime' => $val['updateTime'],
'netValue' => $val['netValue'],
'statTime' => $val['statTime'],
'granularity' => $granularity,
'date' => $date,
];
Db::table('tp_passenger_flow_all')->insert($insert_arr);
}
}
$output->writeln('完成');
} catch (\Exception $e) {
$output->writeln($e->getMessage());
}
}
}

65
app/command/passengerFlowReal.php

@ -1,65 +0,0 @@
<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;
class passengerFlowReal extends Command
{
protected function configure()
{
$this->setName('passengerFlow')
->addArgument('name', Argument::OPTIONAL, "your name")
->addOption('city', null, Option::VALUE_REQUIRED, 'city name')
->setDescription('Say Hello');
}
protected function execute(Input $input, Output $output)
{
$config = config('app');
$delete = Db::table('tp_passenger_flow_real')->where('id','>',1)->delete();
try{
$url = $config['host_url'] . "/api/cfas/v3/passenger/realTime";
$dataArr = [
'01' // --- <replace> --- //
];
$token = getAccessToken();
$json_data = json_encode($dataArr);
$result = postToken($url,$json_data,false,[],$token);
$res_data = json_decode($result,true);
$list = (array) $res_data['data'];
foreach ($list as $value) {
$insert_arr = [
'groupId' => $value['groupId'],
'regionId' => $value['regionId'],
'statisticsTime' => $value['statisticsTime'],
'enter' => $value['enter'],
'exit' => $value['exit'],
'pass' => $value['pass'],
'holdValue' => $value['holdValue'],
'allEnter' => $value['allEnter'],
'allExit' => $value['allExit']
];
Db::table('tp_passenger_flow_real')->insert($insert_arr);
}
$output->writeln('完成');
} catch (\Exception $e) {
$output->writeln($e->getMessage());
}
}
}

237
app/common.php

@ -1,237 +0,0 @@
<?php
// 应用公共文件
use think\facade\Request;
use think\facade\Session;
/**
* 模拟GET请求 HTTPS的页面
* @param string $url 请求地址
* @param array $data
* @return string $result
*/
function get(string $url, array $data = [])
{
// 处理query参数
if (!empty($data)) {
$url = $url . '?' . http_build_query($data);
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
$result = curl_exec($curl);
if ($result === false) {
curl_error($curl);
}
curl_close($curl);
return $result;
}
/**
* 模拟POST请求
* @param string $url 请求地址
* @param mixed $data 请求数据
* @param false $useCert 是否引入微信支付证书
* @param array $sslCert 证书路径
* @return mixed|bool|string
*/
function post(string $url, $data = [], bool $useCert = false, array $sslCert = [])
{
$header = [
'Content-type: application/json;'
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
if ($useCert == true) {
// 设置证书:cert 与 key 分别属于两个.pem文件
curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLCERT, $sslCert['certPem']);
curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLKEY, $sslCert['keyPem']);
}
$result = curl_exec($curl);
if ($result === false) {
curl_error($curl);
}
curl_close($curl);
return $result;
}
/**
* 模拟POST请求
* @param string $url 请求地址
* @param mixed $data 请求数据
* @param false $useCert 是否引入微信支付证书
* @param array $sslCert 证书路径
* @return mixed|bool|string
*/
function postToken(string $url, $data = [], bool $useCert = false, array $sslCert = [],string $token)
{
$header = [
'Content-type: application/json;',
"access_token: {$token}"
];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
if ($useCert == true) {
// 设置证书:cert 与 key 分别属于两个.pem文件
curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLCERT, $sslCert['certPem']);
curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($curl, CURLOPT_SSLKEY, $sslCert['keyPem']);
}
$result = curl_exec($curl);
if ($result === false) {
curl_error($curl);
}
curl_close($curl);
return $result;
}
/**
* 模拟POST请求 [第二种方式,]
* @param $url
* @param array $data
* @return mixed
*/
function post2($url, array $data = [])
{
$header = [
'Content-Type: application/x-www-form-urlencoded'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
$result = curl_exec($ch);
if ($result === false) {
curl_error($ch);
}
curl_close($ch);
return $result;
}
/**
* 获取当前域名及根路径
* @return string
*/
function base_url()
{
static $baseUrl = '';
if (empty($baseUrl)) {
$request = Request::instance();
$subDir = str_replace('\\', '/', dirname($request->server('PHP_SELF')));
$baseUrl = $request->scheme() . '://' . $request->host() . $subDir . ($subDir === '/' ? '' : '/');
}
return $baseUrl;
}
/**
* 获取 接口 accessToken
* @return mixed
*/
function getAccessToken(){
$token = Session::get('apiAccessToken');
if (empty($token)) {
$config = config('app');
//
$url = $config['host_url']."/oauth/token?client_id=".$config['cid']."&client_secret=".$config['cskey'];
// do post
$ret = post($url);
$res = json_decode($ret,true);
if ($res['access_token']) {
Session::set('apiAccessToken',$res['access_token']);
$token = $res['access_token'];
}
}
return $token;
}
/**
* 获取 天,周,月,年 开始时间~结束时间
* @param $granularity
* @return array
*/
function getTargetDate($granularity = 'all') {
$data = [];
if ($granularity === 'day' || $granularity === 'all') {
$date = $granularity !== 'all' ? $granularity : 'day';
$data[$date] = [
'start_time' => strtotime('today'),
'end_time' => strtotime('tomorrow - 1 second'),
];
}
if ($granularity === 'week' || $granularity === 'all') {
$date = $granularity !== 'all' ? $granularity : 'week';
$data[$date] = [
'start_time' => strtotime('this week midnight'),
'end_time' => strtotime('next week midnight - 1 second'),
];
}
if ($granularity === 'month' || $granularity === 'all') {
$date = $granularity !== 'all' ? $granularity : 'month';
$data[$date] = [
'start_time' => strtotime(date('Y-m-01 00:00:00')),
'end_time' => strtotime(date('Y-m-t 23:59:59')),
];
}
if ($granularity === 'year' || $granularity === 'all') {
$date = $granularity !== 'all' ? $granularity : 'year';
$data[$date] = [
'start_time' => strtotime('first day of January this year'),
'end_time' => strtotime('first day of January next year - 1 second'),
];
}
foreach ($data as &$val) {
$val['c_start_time'] = date("c",$val['start_time']);
$val['c_end_time'] = date("c",$val['end_time']);
$val['start_time'] = date("Y-m-d H:i:s",$val['start_time']);
$val['end_time'] = date("Y-m-d H:i:s",$val['end_time']);
}
return $data;
}
/**
* 特殊处理数字
* @param $number
* @return string
*/
function formatNumber($number)
{
if ($number < 10000) {
return number_format($number);
} else if ($number < 100000000) {
if ($number % 10000 == 0) {
return number_format($number / 10000) . '万';
} else {
return number_format($number);
}
} else {
if ($number % 100000000 == 0) {
return number_format($number / 100000000) . '亿';
} else {
return number_format($number);
}
}
}

235
app/controller/Index.php

@ -1,235 +0,0 @@
<?php
namespace app\controller;
use app\BaseController;
use think\facade\Db;
use think\facade\View;
class Index extends BaseController
{
public function index()
{
return view("index");
//return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V' . \think\facade\App::version() . '<br/><span style="font-size:30px;">14载初心不改 - 你值得信赖的PHP框架</span></p><span style="font-size:25px;">[ V6.0 版本由 <a href="https://www.yisu.com/" target="yisu">亿速云</a> 独家赞助发布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ee9b1aa918103c4fc"></think>';
}
public function hello($name = 'ThinkPHP6')
{
return 'hello,' . $name;
}
public function getAccessToken(){
$config = config('app');
//
$url = $config['host_url']."/oauth/token?client_id=".$config['cid']."&client_secret=".$config['cskey'];
// do post
$ret = post($url);
return $ret;
}
protected $token = 'y871T5okLEegC6WrcKN259Mhy4AGDcjm';
/**
* 分时时间段接口 <首页-客流趋势>
* @return false|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function allGroupTimeNum() {
$request = $this->request;
$granularity = $request['granularity'];
if (empty($granularity)) return json_encode(['code' => 403, 'date参数不能为空'],JSON_UNESCAPED_UNICODE);
$dateData = getTargetDate();
$allTimeData = [];
$groupsData = [];
if ($granularity == 'daily') {
$list = Db::table('tp_passenger_flow')->where(['granularity' => 'hourly'])->select()->toArray();
$data = $this->handleGroupData($list);
$allTimeData = $data['allTimeData'];
$groupsData = $data['groupsData'];
} elseif ($granularity == 'monthly') {
$list = Db::table('tp_passenger_flow')->where(['granularity' => 'daily'])->select()->toArray();
$data = $this->handleGroupData($list,'d');
$allTimeData = $data['allTimeData'];
$groupsData = $data['groupsData'];
} elseif ($granularity == 'yearly') {
$list = Db::table('tp_passenger_flow')->where(['granularity' => 'monthly'])->select()->toArray();
$data = $this->handleGroupData($list,'m');
$allTimeData = $data['allTimeData'];
$groupsData = $data['groupsData'];
}
return json_encode(['code' => 0, 'msg' => '成功', 'data' => [
'allTimeData' => $allTimeData,
'groupsData' => $groupsData
]],JSON_UNESCAPED_UNICODE);
}
/**
* 查询时间范围内的多个统计组的客流统计数据
* @param $granularity // 可选 hourly | daily | monthly | yearly,分别为按小时、按天、按月和按年统计
* @param $s_time // 开始时间
* @param $e_time // 结束时间
* @return false|mixed|string
*/
protected function getGroupData($granularity,$s_time,$e_time) {
$config = config('app');
$token = getAccessToken();
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups";
$dataArr = [
'granularity' => $granularity,
'startTime' => $s_time,
'endTime' => $e_time,
'ids' => '01' // --- <replace> --- //
];
$json_data = json_encode($dataArr);
$result = postToken($url,$json_data,false,[],$token);
$res_data = json_decode($result,true);
if ($res_data['code'] != 0) return json_encode(['code' => 403, 'msg' => $res_data['msg']],JSON_UNESCAPED_UNICODE);
return json_encode(['code' => 403, 'msg' => $res_data['msg'],'data' => $res_data['data']['list']],JSON_UNESCAPED_UNICODE);
}
/**
* 特殊处理
* @param $list
* @param $date_str
* @return array
*/
protected function handleGroupData($list,$date_str = 'H:00') {
$allTimeData = [];
$groupsData = [];
if ($date_str == 'H:00') {
for ($i = 9; $i < 23; $i++) {
$str = strlen($i) == 1 ? '0'.$i.':00' : $i.':00';
$allTimeData[$str]['num'] = 0;
$allTimeData[$str]['title'] = $str;
}
} elseif ($date_str == 'd') {
$d = date('d') * 1;
$date = $d - 12 > 0 ? $d - 12 : 1;
for ($i = $date; $i <= $d; $i++) {
$str = strlen($i) == 1 ? '0'.$i : $i;
$allTimeData[$str]['num'] = 0;
$allTimeData[$str]['title'] = $str;
}
} elseif ($date_str == 'm') {
$m = date('m') * 1;
$date = $m - 12 > 0 ? $m - 12 : 1;
for ($i = $date; $i <= $m; $i++) {
$str = strlen($i) == 1 ? '0'.$i : $i;
$allTimeData[$str]['num'] = 0;
$allTimeData[$str]['title'] = $str;
}
}
$sumNoRepeatInNum = 0;
foreach ($list as $value) {
$sumNoRepeatInNum += $value['noRepeatInNum']; // 进馆总人数
if (!isset($groupsData[$value['groupName']]['noRepeatInNum'])) $groupsData[$value['groupName']]['noRepeatInNum'] = 0;
$groupsData[$value['groupName']]['noRepeatInNum'] += $value['noRepeatInNum']; // 分租进馆人数
$date = date($date_str,ceil($value['createTime'] / 1000) + (8*3600)); // 各时间端进馆人数
if (!isset($allTimeData[$date])) continue;
$allTimeData[$date]['num'] += $value['noRepeatInNum'];
}
ksort($allTimeData);
// 计算各组占比
foreach ($groupsData as &$val) {
$val['proportion'] = (round($val['noRepeatInNum']/$sumNoRepeatInNum,2) * 100) ."%";
}
return [
'allTimeData' => $allTimeData, // 总客流趋势时间段
'groupsData' => $groupsData // 各组总数及占比
];
}
/**
* 总览总数据接口 <首页-中间部分总览>
* @return false|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function allGroupNum() {
$dateArr = ['day' => 'daily', 'week' => 'daily', 'month' => 'monthly'];
$returnData = [];
foreach ($dateArr as $date => $granularity) {
$list = Db::table('tp_passenger_flow_all')
->where(['granularity' => $granularity, 'date' => $date])->select()->toArray();
$returnData[$date]['noRepeatInNum'] = 0;
foreach ($list as $value) {
$returnData[$date]['noRepeatInNum'] += $value['noRepeatInNum'];
}
}
foreach ($returnData as &$val) {
$val['noRepeatInNum'] = formatNumber($val['noRepeatInNum']);
}
$returnArr = [
'code' => 0,
'msg' => '成功',
'data' => $returnData
];
return json_encode($returnArr,JSON_UNESCAPED_UNICODE);
}
/**
* 查询最新客流统计组实时数据 <各场管实施实时进馆人数>
* @return void
*/
public function realTimeData() {
$list = Db::table('tp_passenger_flow_real')->select()->toArray();
$returnData = [];
$sumAllEnter = 0;
foreach ($list as $value) {
if (!isset($returnData[$value['groupId']]['allEnter'])) $returnData[$value['groupId']]['allEnter'] = 0;
$returnData[$value['groupId']]['allEnter'] += $value['allEnter'];
$sumAllEnter += $value['allEnter'];
}
foreach ($returnData as &$val) {
$val['proportion'] = (round($val['allEnter']/$sumAllEnter,2) * 100) ."%";
}
return json_encode(['code' => 0, 'msg' => '成功', 'data' => $returnData],JSON_UNESCAPED_UNICODE);
}
/**
* 今日各场馆人数趋势
* @return false|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function toDayGroupsEnterNum()
{
$list = Db::table('tp_passenger_flow')->where(['granularity' => 'hourly'])->select()->toArray();
$allTimeData = [];
for ($i = 9; $i < 23; $i++) {
$str = strlen($i) == 1 ? '0'.$i.':00' : $i.':00';
$allTimeData[$str] = 0;
}
$returnData = [];
foreach ($list as $value) {
$date = date('H:00',ceil($value['createTime'] / 1000)); // 各时间端进馆人数
if (!isset($allTimeData[$date])) continue;
if (!isset($returnData[$value['groupName']][$allTimeData[$date]])) $returnData[$value['groupName']][$date] = 0;
$returnData[$value['groupName']][$date] += $value['flowInNum'];
}
return json_encode(['code' => 0, 'msg' => '成功', 'data' => $returnData],JSON_UNESCAPED_UNICODE);
}
}

24
app/controller/Passport.php

@ -1,24 +0,0 @@
<?php
namespace app\controller;
use app\BaseController;
use think\facade\View;
use think\facade\Session;
class Passport extends BaseController
{
public function login(){
return View::fetch("login");
}
/**
* 退出登录
*/
public function logout()
{
Session::clear('btgym_manager');
$url =url('passport/login');
return redirect($url);
}
}

17
app/event.php

@ -1,17 +0,0 @@
<?php
// 事件定义文件
return [
'bind' => [
],
'listen' => [
'AppInit' => [],
'HttpRun' => [],
'HttpEnd' => [],
'LogLevel' => [],
'LogWrite' => [],
],
'subscribe' => [
],
];

10
app/middleware.php

@ -1,10 +0,0 @@
<?php
// 全局中间件定义文件
return [
// 全局请求缓存
// \think\middleware\CheckRequestCache::class,
// 多语言加载
// \think\middleware\LoadLangPack::class,
// Session初始化
// \think\middleware\SessionInit::class
];

9
app/provider.php

@ -1,9 +0,0 @@
<?php
use app\ExceptionHandle;
use app\Request;
// 容器Provider定义文件
return [
'think\Request' => Request::class,
'think\exception\Handle' => ExceptionHandle::class,
];

9
app/service.php

@ -1,9 +0,0 @@
<?php
use app\AppService;
// 系统服务定义文件
// 服务在完成全局初始化之后执行
return [
AppService::class,
];

49
composer.json

@ -1,49 +0,0 @@
{
"name": "topthink/think",
"description": "the new thinkphp framework",
"type": "project",
"keywords": [
"framework",
"thinkphp",
"ORM"
],
"homepage": "http://thinkphp.cn/",
"license": "Apache-2.0",
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
},
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"require": {
"php": ">=7.1.0",
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0",
"topthink/think-view": "^1.0"
},
"require-dev": {
"symfony/var-dumper": "^4.2",
"topthink/think-trace":"^1.0"
},
"autoload": {
"psr-4": {
"app\\": "app"
},
"psr-0": {
"": "extend/"
}
},
"config": {
"preferred-install": "dist"
},
"scripts": {
"post-autoload-dump": [
"@php think service:discover",
"@php think vendor:publish"
]
}
}

1085
composer.lock

File diff suppressed because it is too large

37
config/app.php

@ -1,37 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
return [
// 应用地址
'app_host' => env('app.host', ''),
// 应用的命名空间
'app_namespace' => '',
// 是否启用路由
'with_route' => true,
// 默认应用
'default_app' => 'index',
// 默认时区
'default_timezone' => 'Asia/Shanghai',
// 应用映射(自动多应用模式有效)
'app_map' => [],
// 域名绑定(自动多应用模式有效)
'domain_bind' => [],
// 禁止URL访问的应用列表(自动多应用模式有效)
'deny_app_list' => [],
// 异常页面的模板文件
'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
// 调用网址地址
'host_url' => 'https://192.168.66.13:443/artemis',
'port' => '443',
'cid' => '29940726',
'cskey' => 'SkTCnQdFbNW4Z2suNj8P',
];

29
config/cache.php

@ -1,29 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
return [
// 默认缓存驱动
'default' => env('cache.driver', 'file'),
// 缓存连接方式配置
'stores' => [
'file' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => '',
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
// 缓存标签前缀
'tag_prefix' => 'tag:',
// 序列化机制 例如 ['serialize', 'unserialize']
'serialize' => [],
],
// 更多的缓存连接
],
];

12
config/console.php

@ -1,12 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | 控制台配置
// +----------------------------------------------------------------------
return [
// 指令定义
'commands' => [
'passengerFlow' => 'app\command\passengerFlow',
'passengerFlowAll' => 'app\command\passengerFlowAll',
'passengerFlowReal' => 'app\command\passengerFlowReal',
],
];

20
config/cookie.php

@ -1,20 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | Cookie设置
// +----------------------------------------------------------------------
return [
// cookie 保存时间
'expire' => 0,
// cookie 保存路径
'path' => '/',
// cookie 有效域名
'domain' => '',
// cookie 启用安全传输
'secure' => false,
// httponly设置
'httponly' => false,
// 是否使用 setcookie
'setcookie' => true,
// samesite 设置,支持 'strict' 'lax'
'samesite' => '',
];

63
config/database.php

@ -1,63 +0,0 @@
<?php
return [
// 默认使用的数据库连接配置
'default' => env('database.driver', 'mysql'),
// 自定义时间查询规则
'time_query_rule' => [],
// 自动写入时间戳字段
// true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp' => true,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 时间字段配置 配置格式:create_time,update_time
'datetime_field' => '',
// 数据库连接配置信息
'connections' => [
'mysql' => [
// 数据库类型
'type' => env('database.type', 'mysql'),
// 服务器地址
'hostname' => env('database.hostname', '127.0.0.1'),
// 数据库名
'database' => env('database.database', ''),
// 用户名
'username' => env('database.username', 'root'),
// 密码
'password' => env('database.password', 'root'),
// 端口
'hostport' => env('database.hostport', '3306'),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => env('database.charset', 'utf8'),
// 数据库表前缀
'prefix' => env('database.prefix', ''),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => env('app_debug', true),
// 开启字段缓存
'fields_cache' => false,
],
// 更多的数据库配置信息
],
];

24
config/filesystem.php

@ -1,24 +0,0 @@
<?php
return [
// 默认磁盘
'default' => env('filesystem.driver', 'local'),
// 磁盘列表
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
// 磁盘类型
'type' => 'local',
// 磁盘路径
'root' => app()->getRootPath() . 'public/storage',
// 磁盘路径对应的外部URL路径
'url' => '/storage',
// 可见性
'visibility' => 'public',
],
// 更多的磁盘配置信息
],
];

27
config/lang.php

@ -1,27 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | 多语言设置
// +----------------------------------------------------------------------
return [
// 默认语言
'default_lang' => env('lang.default_lang', 'zh-cn'),
// 允许的语言列表
'allow_lang_list' => [],
// 多语言自动侦测变量名
'detect_var' => 'lang',
// 是否使用Cookie记录
'use_cookie' => true,
// 多语言cookie变量
'cookie_var' => 'think_lang',
// 多语言header变量
'header_var' => 'think-lang',
// 扩展语言包
'extend_list' => [],
// Accept-Language转义为对应语言包名称
'accept_language' => [
'zh-hans-cn' => 'zh-cn',
],
// 是否支持语言分组
'allow_group' => false,
];

45
config/log.php

@ -1,45 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | 日志设置
// +----------------------------------------------------------------------
return [
// 默认日志记录通道
'default' => env('log.channel', 'file'),
// 日志记录级别
'level' => [],
// 日志类型记录的通道 ['error'=>'email',...]
'type_channel' => [],
// 关闭全局日志写入
'close' => false,
// 全局日志处理 支持闭包
'processor' => null,
// 日志通道列表
'channels' => [
'file' => [
// 日志记录方式
'type' => 'File',
// 日志保存目录
'path' => '',
// 单文件日志写入
'single' => false,
// 独立日志级别
'apart_level' => [],
// 最大日志文件数量
'max_files' => 0,
// 使用JSON格式记录
'json' => false,
// 日志处理
'processor' => null,
// 关闭通道日志写入
'close' => false,
// 日志输出格式化
'format' => '[%s][%s] %s',
// 是否实时写入
'realtime_write' => false,
],
// 其它日志通道配置
],
];

8
config/middleware.php

@ -1,8 +0,0 @@
<?php
// 中间件配置
return [
// 别名或分组
'alias' => [],
// 优先级设置,此数组中的中间件会按照数组中的顺序优先执行
'priority' => [],
];

45
config/route.php

@ -1,45 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | 路由设置
// +----------------------------------------------------------------------
return [
// pathinfo分隔符
'pathinfo_depr' => '/',
// URL伪静态后缀
'url_html_suffix' => 'html',
// URL普通方式参数 用于自动生成
'url_common_param' => true,
// 是否开启路由延迟解析
'url_lazy_route' => false,
// 是否强制使用路由
'url_route_must' => false,
// 合并路由规则
'route_rule_merge' => false,
// 路由是否完全匹配
'route_complete_match' => false,
// 访问控制器层名称
'controller_layer' => 'controller',
// 空控制器名
'empty_controller' => 'Error',
// 是否使用控制器后缀
'controller_suffix' => false,
// 默认的路由变量规则
'default_route_pattern' => '[\w\.]+',
// 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
'request_cache_key' => false,
// 请求缓存有效期
'request_cache_expire' => null,
// 全局请求缓存排除规则
'request_cache_except' => [],
// 默认控制器名
'default_controller' => 'Index',
// 默认操作名
'default_action' => 'index',
// 操作方法后缀
'action_suffix' => '',
// 默认JSONP格式返回的处理方法
'default_jsonp_handler' => 'jsonpReturn',
// 默认JSONP处理方法
'var_jsonp_handler' => 'callback',
];

19
config/session.php

@ -1,19 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | 会话设置
// +----------------------------------------------------------------------
return [
// session name
'name' => 'PHPSESSID',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
// 驱动方式 支持file cache
'type' => 'file',
// 存储连接标识 当type使用cache的时候有效
'store' => null,
// 过期时间
'expire' => 1440,
// 前缀
'prefix' => '',
];

10
config/trace.php

@ -1,10 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | Trace设置 开启调试模式后有效
// +----------------------------------------------------------------------
return [
// 内置Html和Console两种方式 支持扩展
'type' => 'Html',
// 读取的日志通道名
'channel' => '',
];

29
config/view.php

@ -1,29 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
return [
// 模板引擎类型使用Think
'type' => 'Think',
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
'auto_rule' => 1,
// 模板目录名
'view_dir_name' => 'view',
// 模板后缀
'view_suffix' => 'php',
// 模板文件名分隔符
'view_depr' => DIRECTORY_SEPARATOR,
// 模板引擎普通标签开始标记
'tpl_begin' => '{',
// 模板引擎普通标签结束标记
'tpl_end' => '}',
// 标签库标签开始标记
'taglib_begin' => '{',
// 标签库标签结束标记
'taglib_end' => '}',
// layout 设置
'layout_on' => true,
'layout_name' => 'layouts/layout',
'layout_item' => '{__CONTENT__}'
];

BIN
doc/HIK接口.docx

Binary file not shown.

BIN
icon.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

8
public/.htaccess

@ -1,8 +0,0 @@
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

BIN
public/favicon.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

24
public/index.php

@ -1,24 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// [ 应用入口文件 ]
namespace think;
require __DIR__ . '/../vendor/autoload.php';
// 执行HTTP应用并响应
$http = (new App())->http;
$response = $http->run();
$response->send();
$http->end($response);

2
public/robots.txt

@ -1,2 +0,0 @@
User-agent: *
Disallow:

19
public/router.php

@ -1,19 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$
if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) {
return false;
} else {
$_SERVER["SCRIPT_FILENAME"] = __DIR__ . '/index.php';
require __DIR__ . "/index.php";
}

23
route/app.php

@ -1,23 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;
Route::get('think', function () {
return 'hello,ThinkPHP6!';
});
Route::get('hello/:name', 'index/hello');
Route::get('getAccessToken', 'index/getAccessToken');
Route::get('allGroupTimeNum', 'index/allGroupTimeNum');
Route::get('allGroupNum', 'index/allGroupNum');
Route::get('realTimeData', 'index/realTimeData');
Route::get('toDayGroupsEnterNum', 'index/toDayGroupsEnterNum');
Route::rule('admin', 'admin/Index/index');

0
app/admin/config.php → source/application/admin/config.php

0
app/admin/controller/Controller.php → source/application/admin/controller/Controller.php

0
app/admin/controller/Index.php → source/application/admin/controller/Index.php

0
app/admin/controller/Passport.php → source/application/admin/controller/Passport.php

0
app/admin/controller/Store.php → source/application/admin/controller/Store.php

0
app/admin/controller/admin/User.php → source/application/admin/controller/admin/User.php

0
app/admin/controller/setting/Cache.php → source/application/admin/controller/setting/Cache.php

0
app/admin/controller/setting/Science.php → source/application/admin/controller/setting/Science.php

0
app/admin/controller/store/Access.php → source/application/admin/controller/store/Access.php

0
app/admin/extra/menus.php → source/application/admin/extra/menus.php

0
app/admin/model/Setting.php → source/application/admin/model/Setting.php

0
app/admin/model/Wxapp.php → source/application/admin/model/Wxapp.php

0
app/admin/model/WxappCategory.php → source/application/admin/model/WxappCategory.php

0
app/admin/model/WxappHelp.php → source/application/admin/model/WxappHelp.php

0
app/admin/model/WxappPage.php → source/application/admin/model/WxappPage.php

0
app/admin/model/admin/User.php → source/application/admin/model/admin/User.php

0
app/admin/model/store/Access.php → source/application/admin/model/store/Access.php

0
app/admin/model/store/User.php → source/application/admin/model/store/User.php

0
app/admin/view/admin/user/renew.php → source/application/admin/view/admin/user/renew.php

0
app/admin/view/index/index.php → source/application/admin/view/index/index.php

0
app/admin/view/layouts/layout.php → source/application/admin/view/layouts/layout.php

0
app/admin/view/passport/login.php → source/application/admin/view/passport/login.php

0
app/admin/view/setting/cache/clear.php → source/application/admin/view/setting/cache/clear.php

0
app/admin/view/setting/science/index.php → source/application/admin/view/setting/science/index.php

0
app/admin/view/store/access/add.php → source/application/admin/view/store/access/add.php

0
app/admin/view/store/access/edit.php → source/application/admin/view/store/access/edit.php

0
app/admin/view/store/access/index.php → source/application/admin/view/store/access/index.php

0
app/admin/view/store/add.php → source/application/admin/view/store/add.php

0
app/admin/view/store/index.php → source/application/admin/view/store/index.php

0
app/admin/view/store/recycle.php → source/application/admin/view/store/recycle.php

117
source/application/api/behavior/order/PaySuccess.php

@ -0,0 +1,117 @@
<?php
namespace app\api\behavior\order;
use app\common\service\Message as MessageService;
use app\common\service\order\Printer as PrinterService;
use app\common\service\wechat\wow\Order as WowOrder;
use app\common\enum\OrderType as OrderTypeEnum;
use app\common\enum\OrderStatus as OrderStatusEnum;
use app\common\enum\order\OrderSource as OrderSourceEnum;
/**
* 订单支付成功后扩展类
* Class PaySuccess
* @package app\api\behavior\order
*/
class PaySuccess
{
// 订单信息
private $order;
// 订单类型
private $orderType;
private $wxappId;
/**
* 订单来源回调业务映射类
* @var array
*/
protected $sourceCallbackClass = [
OrderSourceEnum::MASTER => 'app\api\service\master\order\PaySuccess',
OrderSourceEnum::BARGAIN => 'app\api\service\bargain\order\PaySuccess',
OrderSourceEnum::SHARP => 'app\api\service\sharp\order\PaySuccess',
];
/**
* 执行入口
* @param $order
* @param int $orderType
* @return bool
* @throws \app\common\exception\BaseException
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function run($order, $orderType = OrderTypeEnum::MASTER)
{
// 设置当前类的属性
$this->setAttribute($order, $orderType);
// 订单公共业务
$this->onCommonEvent();
// 普通订单业务
if ($orderType == OrderTypeEnum::MASTER) {
$this->onMasterEvent();
}
// 订单来源回调业务
$this->onSourceCallback();
return true;
}
/**
* 设置当前类的属性
* @param $order
* @param int $orderType
*/
private function setAttribute($order, $orderType = OrderTypeEnum::MASTER)
{
$this->order = $order;
$this->wxappId = $this->order['wxapp_id'];
$this->orderType = $orderType;
}
/**
* 订单公共业务
* @throws \app\common\exception\BaseException
* @throws \think\Exception
* @throws \think\exception\DbException
*/
private function onCommonEvent()
{
// 发送消息通知
MessageService::send('order.payment', [
'order' => $this->order,
'order_type' => $this->orderType,
]);
// 小票打印
(new PrinterService)->printTicket($this->order, OrderStatusEnum::ORDER_PAYMENT);
}
/**
* 普通订单业务
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
private function onMasterEvent()
{
// 同步好物圈
(new WowOrder($this->wxappId))->import([$this->order], true);
}
/**
* 订单来源回调业务
* @return bool
*/
private function onSourceCallback()
{
if (!isset($this->order['order_source'])) {
return false;
}
if (!isset($this->sourceCallbackClass[$this->order['order_source']])) {
return false;
}
$class = $this->sourceCallbackClass[$this->order['order_source']];
return !is_null($class) ? (new $class)->onPaySuccess($this->order) : false;
}
}

8
source/application/api/config.php

@ -0,0 +1,8 @@
<?php
return [
// 默认输出类型
'default_return_type' => 'json',
// 默认全局过滤方法 用逗号分隔多个
'default_filter' => 'trim,htmlspecialchars',
];

111
source/application/api/controller/Address.php

@ -0,0 +1,111 @@
<?php
namespace app\api\controller;
use app\api\model\UserAddress;
/**
* 收货地址管理
* Class Address
* @package app\api\controller
*/
class Address extends Controller
{
/**
* 收货地址列表
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function lists()
{
$user = $this->getUser();
$model = new UserAddress;
$list = $model->getList($user['user_id']);
return $this->renderSuccess([
'list' => $list,
'default_id' => $user['address_id'],
]);
}
/**
* 添加收货地址
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function add()
{
$model = new UserAddress;
if ($model->add($this->getUser(), $this->request->post())) {
return $this->renderSuccess([], '添加成功');
}
return $this->renderError('添加失败');
}
/**
* 收货地址详情
* @param $address_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function detail($address_id)
{
$user = $this->getUser();
$detail = UserAddress::detail($user['user_id'],$address_id);
$region = array_values($detail['region']);
return $this->renderSuccess(compact('detail', 'region'));
}
/**
* 编辑收货地址
* @param $address_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function edit($address_id)
{
$user = $this->getUser();
$model = UserAddress::detail($user['user_id'], $address_id);
if ($model->edit($this->request->post())) {
return $this->renderSuccess([], '更新成功');
}
return $this->renderError('更新失败');
}
/**
* 设为默认地址
* @param $address_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function setDefault($address_id) {
$user = $this->getUser();
$model = UserAddress::detail($user['user_id'], $address_id);
if ($model->setDefault($user)) {
return $this->renderSuccess([], '设置成功');
}
return $this->renderError('设置失败');
}
/**
* 删除收货地址
* @param $address_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function delete($address_id)
{
$user = $this->getUser();
$model = UserAddress::detail($user['user_id'], $address_id);
if ($model->remove($user)) {
return $this->renderSuccess([], '删除成功');
}
return $this->renderError('删除失败');
}
}

53
source/application/api/controller/Article.php

@ -0,0 +1,53 @@
<?php
namespace app\api\controller;
use app\api\model\Article as ArticleModel;
use app\api\model\article\Category as CategoryModel;
/**
* 文章控制器
* Class Article
* @package app\api\controller
*/
class Article extends Controller
{
/**
* 文章首页
* @return array
*/
public function index()
{
// 文章分类列表
$categoryList = CategoryModel::getAll();
return $this->renderSuccess(compact('categoryList'));
}
/**
* 文章列表
* @param int $category_id
* @return array
* @throws \think\exception\DbException
*/
public function lists($category_id = 0)
{
$model = new ArticleModel;
$list = $model->getList($category_id);
return $this->renderSuccess(compact('list'));
}
/**
* 文章详情
* @param $article_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function detail($article_id)
{
$detail = ArticleModel::detail($article_id);
return $this->renderSuccess(compact('detail'));
}
}

84
source/application/api/controller/Cart.php

@ -0,0 +1,84 @@
<?php
namespace app\api\controller;
use app\api\model\Cart as CartModel;
/**
* 购物车管理
* Class Cart
* @package app\api\controller
*/
class Cart extends Controller
{
/* @var \app\api\model\User $user */
private $user;
/* @var \app\api\model\Cart $model */
private $model;
/**
* 构造方法
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function _initialize()
{
parent::_initialize();
$this->user = $this->getUser();
$this->model = new CartModel($this->user);
}
/**
* 购物车列表
* @return array
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function lists()
{
return $this->renderSuccess($this->model->getList());
}
/**
* 加入购物车
* @param $goods_id
* @param $goods_num
* @param $goods_sku_id
* @return array
*/
public function add($goods_id, $goods_num, $goods_sku_id)
{
if (!$this->model->add($goods_id, $goods_num, $goods_sku_id)) {
return $this->renderError($this->model->getError() ?: '加入购物车失败');
}
$total_num = $this->model->getTotalNum();
return $this->renderSuccess(['cart_total_num' => $total_num], '加入购物车成功');
}
/**
* 减少购物车商品数量
* @param $goods_id
* @param $goods_sku_id
* @return array
*/
public function sub($goods_id, $goods_sku_id)
{
$this->model->sub($goods_id, $goods_sku_id);
return $this->renderSuccess();
}
/**
* 删除购物车中指定商品
* @param $goods_sku_id (支持字符串ID集)
* @return array
*/
public function delete($goods_sku_id)
{
$this->model->delete($goods_sku_id);
return $this->renderSuccess();
}
}

29
source/application/api/controller/Category.php

@ -0,0 +1,29 @@
<?php
namespace app\api\controller;
use app\api\model\Category as CategoryModel;
use app\api\model\WxappCategory as WxappCategoryModel;
/**
* 商品分类控制器
* Class Goods
* @package app\api\controller
*/
class Category extends Controller
{
/**
* 分类页面
* @return array
* @throws \think\exception\DbException
*/
public function index()
{
// 分类模板
$templet = WxappCategoryModel::detail();
// 商品分类列表
$list = array_values(CategoryModel::getCacheTree());
return $this->renderSuccess(compact('templet', 'list'));
}
}

29
source/application/api/controller/Comment.php

@ -0,0 +1,29 @@
<?php
namespace app\api\controller;
use app\api\model\Comment as CommentModel;
/**
* 商品评价控制器
* Class Comment
* @package app\api\controller
*/
class Comment extends Controller
{
/**
* 商品评价列表
* @param $goods_id
* @param int $scoreType
* @return array
* @throws \think\exception\DbException
*/
public function lists($goods_id, $scoreType = -1)
{
$model = new CommentModel;
$list = $model->getGoodsCommentList($goods_id, $scoreType);
$total = $model->getTotal($goods_id);
return $this->renderSuccess(compact('list', 'total'));
}
}

139
source/application/api/controller/Controller.php

@ -0,0 +1,139 @@
<?php
namespace app\api\controller;
use app\api\model\User as UserModel;
use app\api\model\Wxapp as WxappModel;
use app\common\exception\BaseException;
/**
* API控制器基类
* Class BaseController
* @package app\store\controller
*/
class Controller extends \think\Controller
{
const JSON_SUCCESS_STATUS = 1;
const JSON_ERROR_STATUS = 0;
/* @ver $wxapp_id 小程序id */
protected $wxapp_id;
/**
* API基类初始化
* @throws BaseException
* @throws \think\exception\DbException
*/
public function _initialize()
{
// 当前小程序id
$this->wxapp_id = $this->getWxappId();
// 验证当前小程序状态
$this->checkWxapp();
}
/**
* 获取当前小程序ID
* @return mixed
* @throws BaseException
*/
private function getWxappId()
{
if (!$wxapp_id = $this->request->param('wxapp_id')) {
throw new BaseException(['msg' => '缺少必要的参数:wxapp_id']);
}
return $wxapp_id;
}
/**
* 验证当前小程序状态
* @throws BaseException
* @throws \think\exception\DbException
*/
private function checkWxapp()
{
$wxapp = WxappModel::detail($this->wxapp_id);
if (empty($wxapp)) {
throw new BaseException(['msg' => '当前小程序信息不存在']);
}
if ($wxapp['is_recycle'] || $wxapp['is_delete']) {
throw new BaseException(['msg' => '当前小程序已删除']);
}
}
/**
* 获取当前用户信息
* @param bool $is_force
* @return UserModel|bool|null
* @throws BaseException
* @throws \think\exception\DbException
*/
protected function getUser($is_force = true)
{
if (!$token = $this->request->param('token')) {
$is_force && $this->throwError('缺少必要的参数:token', -1);
return false;
}
if (!$user = UserModel::getUser($token)) {
$is_force && $this->throwError('没有找到用户信息', -1);
return false;
}
return $user;
}
/**
* 输出错误信息
* @param int $code
* @param $msg
* @throws BaseException
*/
protected function throwError($msg, $code = 0)
{
throw new BaseException(['code' => $code, 'msg' => $msg]);
}
/**
* 返回封装后的 API 数据到客户端
* @param int $code
* @param string $msg
* @param array $data
* @return array
*/
protected function renderJson($code = self::JSON_SUCCESS_STATUS, $msg = '', $data = [])
{
return compact('code', 'msg', 'data');
}
/**
* 返回操作成功json
* @param string $msg
* @param array $data
* @return array
*/
protected function renderSuccess($data = [], $msg = 'success')
{
return $this->renderJson(self::JSON_SUCCESS_STATUS, $msg, $data);
}
/**
* 返回操作失败json
* @param string $msg
* @param array $data
* @return array
*/
protected function renderError($msg = 'error', $data = [])
{
return $this->renderJson(self::JSON_ERROR_STATUS, $msg, $data);
}
/**
* 获取post数据 (数组)
* @param $key
* @return mixed
*/
protected function postData($key = null)
{
return $this->request->post(is_null($key) ? '' : $key . '/a');
}
}

29
source/application/api/controller/Coupon.php

@ -0,0 +1,29 @@
<?php
namespace app\api\controller;
use app\api\model\Coupon as CouponModel;
/**
* 优惠券中心
* Class Coupon
* @package app\api\controller
*/
class Coupon extends Controller
{
/**
* 优惠券列表
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function lists()
{
$model = new CouponModel;
$list = $model->getList($this->getUser(false));
return $this->renderSuccess(compact('list'));
}
}

74
source/application/api/controller/Goods.php

@ -0,0 +1,74 @@
<?php
namespace app\api\controller;
use app\api\model\Goods as GoodsModel;
use app\api\model\Cart as CartModel;
use app\common\service\qrcode\Goods as GoodsPoster;
/**
* 商品控制器
* Class Goods
* @package app\api\controller
*/
class Goods extends Controller
{
/**
* 商品列表
* @param $category_id
* @param $search
* @param $sortType
* @param $sortPrice
* @return array
* @throws \think\exception\DbException
*/
public function lists($category_id, $search, $sortType, $sortPrice)
{
$model = new GoodsModel;
$list = $model->getList(10, $category_id, $search, $sortType, $sortPrice);
return $this->renderSuccess(compact('list'));
}
/**
* 获取商品详情
* @param $goods_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function detail($goods_id)
{
// 商品详情
$detail = GoodsModel::detail($goods_id);
if (!$detail || $detail['is_delete'] || $detail['goods_status']['value'] != 10) {
return $this->renderError('很抱歉,商品信息不存在或已下架');
}
// 多规格商品sku信息
$specData = $detail['spec_type'] == 20 ? $detail->getManySpecData($detail['spec_rel'], $detail['sku']) : null;
// 购物车商品总数量
$cart_total_num = 0;
if ($user = $this->getUser(false)) {
$cart_total_num = (new CartModel($user))->getGoodsNum();
}
return $this->renderSuccess(compact('detail', 'cart_total_num', 'specData'));
}
/**
* 获取推广二维码
* @param $goods_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
* @throws \Exception
*/
public function poster($goods_id)
{
// 商品详情
$detail = GoodsModel::detail($goods_id);
$Qrcode = new GoodsPoster($detail, $this->getUser(false));
return $this->renderSuccess([
'qrcode' => $Qrcode->getImage(),
]);
}
}

135
source/application/api/controller/Order.php

@ -0,0 +1,135 @@
<?php
namespace app\api\controller;
use app\api\model\Order as OrderModel;
use app\api\model\Cart as CartModel;
use app\common\enum\DeliveryType as DeliveryTypeEnum;
use app\common\enum\order\PayType as PayTypeEnum;
/**
* 订单控制器
* Class Order
* @package app\api\controller
*/
class Order extends Controller
{
/* @var \app\api\model\User $user */
private $user;
/**
* 构造方法
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function _initialize()
{
parent::_initialize();
$this->user = $this->getUser(); // 用户信息
}
/**
* 订单确认-立即购买
* @param int $goods_id 商品id
* @param int $goods_num 购买数量
* @param int $goods_sku_id 商品sku_id
* @param int $delivery 配送方式
* @param int $pay_type 支付方式
* @param int $coupon_id 优惠券id
* @param int $shop_id 自提门店id
* @param string $remark 买家留言
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
* @throws \Exception
*/
public function buyNow(
$goods_id,
$goods_num,
$goods_sku_id,
$delivery = DeliveryTypeEnum::EXPRESS,
$pay_type = PayTypeEnum::WECHAT,
$shop_id = 0,
$coupon_id = null,
$remark = ''
)
{
// 商品结算信息
$model = new OrderModel;
$order = $model->getBuyNow(
$this->user,
$goods_id,
$goods_num,
$goods_sku_id,
$delivery,
$pay_type,
$shop_id
);
if (!$this->request->isPost()) {
return $this->renderSuccess($order);
}
if ($model->hasError()) {
return $this->renderError($model->getError());
}
// 创建订单
if (!$model->createOrder($this->user, $order, $coupon_id, $remark)) {
return $this->renderError($model->getError() ?: '订单创建失败');
}
// 构建微信支付请求
$payment = ($pay_type == PayTypeEnum::WECHAT) ? $model->paymentByWechat($this->user) : [];
return $this->renderSuccess([
'order_id' => $model['order_id'], // 订单id
'pay_type' => $pay_type, // 支付方式
'payment' => $payment // 微信支付参数
]);
}
/**
* 订单确认-购物车结算
* @param string $cart_ids (支持字符串ID集)
* @param int $delivery 配送方式
* @param int $pay_type 支付方式
* @param int $shop_id 自提门店id
* @param int $coupon_id 优惠券id
* @param string $remark 买家留言
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \Exception
*/
public function cart(
$cart_ids,
$delivery = DeliveryTypeEnum::EXPRESS,
$pay_type = PayTypeEnum::WECHAT,
$shop_id = 0,
$coupon_id = null,
$remark = ''
)
{
// 商品结算信息
$Cart = new CartModel($this->user);
$order = $Cart->getList($cart_ids, $delivery, $pay_type, $shop_id);
if (!$this->request->isPost()) {
return $this->renderSuccess($order);
}
// 创建订单
$model = new OrderModel;
if (!$model->createOrder($this->user, $order, $coupon_id, $remark)) {
return $this->renderError($model->getError() ?: '订单创建失败');
}
// 移出购物车中已下单的商品
$Cart->clearAll($cart_ids);
// 构建微信支付请求
$payment = ($pay_type == PayTypeEnum::WECHAT) ? $model->paymentByWechat($this->user) : [];
// 返回状态
return $this->renderSuccess([
'order_id' => $model['order_id'], // 订单id
'pay_type' => $pay_type, // 支付方式
'payment' => $payment // 微信支付参数
]);
}
}

61
source/application/api/controller/Page.php

@ -0,0 +1,61 @@
<?php
namespace app\api\controller;
use app\api\model\WxappPage;
/**
* 页面控制器
* Class Index
* @package app\api\controller
*/
class Page extends Controller
{
/**
* 页面数据
* @param null $page_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index($page_id = null)
{
// 页面元素
$data = WxappPage::getPageData($this->getUser(false), $page_id);
return $this->renderSuccess($data);
}
/**
* 首页diy数据 (即将废弃)
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function home()
{
// 页面元素
$data = WxappPage::getPageData($this->getUser(false));
return $this->renderSuccess($data);
}
/**
* 自定义页数据 (即将废弃)
* @param $page_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function custom($page_id)
{
// 页面元素
$data = WxappPage::getPageData($this->getUser(false), $page_id);
return $this->renderSuccess($data);
}
}

65
source/application/api/controller/Recharge.php

@ -0,0 +1,65 @@
<?php
namespace app\api\controller;
use app\api\model\Setting as SettingModel;
use app\api\model\recharge\Plan as PlanModel;
use app\api\model\recharge\Order as OrderModel;
use app\api\service\Payment as PaymentService;
use app\common\enum\OrderType as OrderTypeEnum;
/**
* 用户充值管理
* Class Recharge
* @package app\api\controller
*/
class Recharge extends Controller
{
/**
* 充值中心
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index()
{
// 用户信息
$userInfo = $this->getUser();
// 充值套餐列表
$planList = (new PlanModel)->getList();
// 充值设置
$setting = SettingModel::getItem('recharge');
return $this->renderSuccess(compact('userInfo', 'planList', 'setting'));
}
/**
* 确认充值
* @param null $planId
* @param int $customMoney
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function submit($planId = null, $customMoney = 0)
{
// 用户信息
$userInfo = $this->getUser();
// 生成充值订单
$model = new OrderModel;
if (!$model->createOrder($userInfo, $planId, $customMoney)) {
return $this->renderError($model->getError() ?: '充值失败');
}
// 构建微信支付
$payment = PaymentService::wechat(
$userInfo,
$model['order_id'],
$model['order_no'],
$model['pay_price'],
OrderTypeEnum::RECHARGE
);
return $this->renderSuccess(compact('payment'));
}
}

41
source/application/api/controller/Shop.php

@ -0,0 +1,41 @@
<?php
namespace app\api\controller;
use app\api\model\store\Shop as ShopModel;
/**
* 门店列表
* Class Shop
* @package app\api\controller
*/
class Shop extends Controller
{
/**
* 门店列表
* @param string $longitude
* @param string $latitude
* @return array
* @throws \think\exception\DbException
*/
public function lists($longitude = '', $latitude = '')
{
$model = new ShopModel;
$list = $model->getList(true, $longitude, $latitude);
return $this->renderSuccess(compact('list'));
}
/**
* 门店详情
* @param $shop_id
* @return array
* @throws \think\exception\DbException
*/
public function detail($shop_id)
{
$detail = ShopModel::detail($shop_id);
return $this->renderSuccess(compact('detail'));
}
}

86
source/application/api/controller/Upload.php

@ -0,0 +1,86 @@
<?php
namespace app\api\controller;
use app\api\model\UploadFile;
use app\api\model\Setting as SettingModel;
use app\common\library\storage\Driver as StorageDriver;
/**
* 文件库管理
* Class Upload
* @package app\api\controller
*/
class Upload extends Controller
{
private $config;
private $user;
/**
* 构造方法
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function _initialize()
{
parent::_initialize();
// 存储配置信息
$this->config = SettingModel::getItem('storage');
// 验证用户
$this->user = $this->getUser();
}
/**
* 图片上传接口
* @return array
* @throws \think\Exception
*/
public function image()
{
// 实例化存储驱动
$StorageDriver = new StorageDriver($this->config);
// 设置上传文件的信息
$StorageDriver->setUploadFile('iFile');
// 上传图片
if (!$StorageDriver->upload()) {
return json(['code' => 0, 'msg' => '图片上传失败' . $StorageDriver->getError()]);
}
// 图片上传路径
$fileName = $StorageDriver->getFileName();
// 图片信息
$fileInfo = $StorageDriver->getFileInfo();
// 添加文件库记录
$uploadFile = $this->addUploadFile($fileName, $fileInfo, 'image');
// 图片上传成功
return json(['code' => 1, 'msg' => '图片上传成功', 'data' => $uploadFile->visible(['file_id'])]);
}
/**
* 添加文件库上传记录
* @param $fileName
* @param $fileInfo
* @param $fileType
* @return UploadFile
*/
private function addUploadFile($fileName, $fileInfo, $fileType)
{
// 存储引擎
$storage = $this->config['default'];
// 存储域名
$fileUrl = isset($this->config['engine'][$storage]['domain'])
? $this->config['engine'][$storage]['domain'] : '';
// 添加文件库记录
$model = new UploadFile;
$model->add([
'storage' => $storage,
'file_url' => $fileUrl,
'file_name' => $fileName,
'file_size' => $fileInfo['size'],
'file_type' => $fileType,
'extension' => pathinfo($fileInfo['name'], PATHINFO_EXTENSION),
'is_user' => 1
]);
return $model;
}
}

43
source/application/api/controller/User.php

@ -0,0 +1,43 @@
<?php
namespace app\api\controller;
use app\api\model\User as UserModel;
/**
* 用户管理
* Class User
* @package app\api
*/
class User extends Controller
{
/**
* 用户自动登录
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function login()
{
$model = new UserModel;
return $this->renderSuccess([
'user_id' => $model->login($this->request->post()),
'token' => $model->getToken()
]);
}
/**
* 当前用户详情
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function detail()
{
// 当前用户信息
$userInfo = $this->getUser();
return $this->renderSuccess(compact('userInfo'));
}
}

39
source/application/api/controller/Wxapp.php

@ -0,0 +1,39 @@
<?php
namespace app\api\controller;
use app\api\model\Wxapp as WxappModel;
use app\api\model\WxappHelp;
/**
* 微信小程序
* Class Wxapp
* @package app\api\controller
*/
class Wxapp extends Controller
{
/**
* 小程序基础信息
* @return array
*/
public function base()
{
// $wxapp = WxappModel::getWxappCache();
return $this->renderSuccess([]);
}
/**
* 帮助中心
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function help()
{
$model = new WxappHelp;
$list = $model->getList();
return $this->renderSuccess(compact('list'));
}
}

28
source/application/api/controller/balance/Log.php

@ -0,0 +1,28 @@
<?php
namespace app\api\controller\balance;
use app\api\controller\Controller;
use app\api\model\user\BalanceLog as BalanceLogModel;
/**
* 余额账单明细
* Class Log
* @package app\api\controller\balance
*/
class Log extends Controller
{
/**
* 余额账单明细列表
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function lists()
{
$user = $this->getUser();
$list = (new BalanceLogModel)->getList($user['user_id']);
return $this->renderSuccess(compact('list'));
}
}

26
source/application/api/controller/live/Room.php

@ -0,0 +1,26 @@
<?php
namespace app\api\controller\live;
use app\api\controller\Controller;
use app\api\model\wxapp\LiveRoom as LiveRoomModel;
/**
* 微信小程序直播列表
* Class Room
* @package app\api\controller\live
*/
class Room extends Controller
{
/**
* 获取直播间列表
* @return mixed
* @throws \think\exception\DbException
*/
public function lists()
{
$model = new LiveRoomModel;
$list = $model->getList();
return $this->renderSuccess(compact('list'));
}
}

28
source/application/api/controller/recharge/Order.php

@ -0,0 +1,28 @@
<?php
namespace app\api\controller\recharge;
use app\api\controller\Controller;
use app\api\model\recharge\Order as OrderModel;
/**
* 充值记录
* Class Order
* @package app\api\controller\user\balance
*/
class Order extends Controller
{
/**
* 我的充值记录列表
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function lists()
{
$user = $this->getUser();
$list = (new OrderModel)->getList($user['user_id']);
return $this->renderSuccess(compact('list'));
}
}

39
source/application/api/controller/sharing/Active.php

@ -0,0 +1,39 @@
<?php
namespace app\api\controller\sharing;
use app\api\controller\Controller;
use app\api\model\sharing\Active as ActiveModel;
use app\api\model\sharing\Goods as GoodsModel;
/**
* 拼团拼单控制器
* Class Active
* @package app\api\controller\sharing
*/
class Active extends Controller
{
/**
* 拼单详情
* @param $active_id
* @return array
* @throws \think\exception\DbException
*/
public function detail($active_id)
{
// 拼单详情
$detail = ActiveModel::detail($active_id);
if (!$detail) {
return $this->renderError('很抱歉,拼单不存在');
}
// 拼团商品详情
$goods = GoodsModel::detail($detail['goods_id']);
// 多规格商品sku信息
$specData = $goods['spec_type'] == 20 ? $goods->getManySpecData($goods['spec_rel'], $goods['sku']) : null;
// 更多拼团商品
$model = new GoodsModel;
$goodsList = $model->getList(10, 0, '', 'all', false, 5);
return $this->renderSuccess(compact('detail', 'goods', 'goodsList', 'specData'));
}
}

68
source/application/api/controller/sharing/Comment.php

@ -0,0 +1,68 @@
<?php
namespace app\api\controller\sharing;
use app\api\controller\Controller;
use app\api\model\sharing\Order as OrderModel;
use app\api\model\sharing\OrderGoods as OrderGoodsModel;
use app\api\model\sharing\Comment as CommentModel;
/**
* 拼团订单评价管理
* Class Comment
* @package app\api\controller\sharing
*/
class Comment extends Controller
{
/**
* 待评价订单商品列表
* @param $order_id
* @return array
* @throws \Exception
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function order($order_id)
{
// 用户信息
$user = $this->getUser();
// 订单信息
$order = OrderModel::getUserOrderDetail($order_id, $user['user_id']);
// 验证订单是否已完成
$model = new CommentModel;
if (!$model->checkOrderAllowComment($order)) {
return $this->renderError($model->getError());
}
// 待评价商品列表
/* @var \think\Collection $goodsList */
$goodsList = OrderGoodsModel::getNotCommentGoodsList($order_id);
if ($goodsList->isEmpty()) {
return $this->renderError('该订单没有可评价的商品');
}
// 提交商品评价
if ($this->request->isPost()) {
$formData = $this->request->post('formData', '', null);
if ($model->addForOrder($order, $goodsList, $formData)) {
return $this->renderSuccess([], '评价发表成功');
}
return $this->renderError($model->getError() ?: '评价发表失败');
}
return $this->renderSuccess(compact('goodsList'));
}
/**
* 商品评价列表
* @param $goods_id
* @param int $scoreType
* @return array
* @throws \think\exception\DbException
*/
public function lists($goods_id, $scoreType = -1)
{
$model = new CommentModel;
$list = $model->getGoodsCommentList($goods_id, $scoreType);
$total = $model->getTotal($goods_id);
return $this->renderSuccess(compact('list', 'total'));
}
}

68
source/application/api/controller/sharing/Goods.php

@ -0,0 +1,68 @@
<?php
namespace app\api\controller\sharing;
use app\api\controller\Controller;
use app\api\model\sharing\Goods as GoodsModel;
use app\common\service\qrcode\Goods as GoodsPoster;
use app\api\model\sharing\Active as ActiveModel;
/**
* 商品控制器
* Class Goods
* @package app\api\controller
*/
class Goods extends Controller
{
/**
* 商品列表
* @param int $category_id
* @return array
* @throws \think\exception\DbException
*/
public function lists($category_id = 0)
{
$model = new GoodsModel;
$list = $model->getList(10, $category_id);
return $this->renderSuccess(compact('list'));
}
/**
* 获取商品详情
* @param $goods_id
* @return array
*/
public function detail($goods_id)
{
// 商品详情
$detail = GoodsModel::detail($goods_id);
if (!$detail || $detail['is_delete'] || $detail['goods_status']['value'] != 10) {
return $this->renderError('很抱歉,商品信息不存在或已下架');
}
// 多规格商品sku信息
$specData = $detail['spec_type'] == 20 ? $detail->getManySpecData($detail['spec_rel'], $detail['sku']) : null;
// 当前进行中的拼单
$activeList = ActiveModel::getActivityListByGoods($goods_id, 2);
return $this->renderSuccess(compact('detail', 'specData', 'activeList'));
}
/**
* 获取推广二维码
* @param $goods_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
* @throws \Exception
*/
public function poster($goods_id)
{
// 商品详情
$detail = GoodsModel::detail($goods_id);
// 生成推广二维码
$Qrcode = new GoodsPoster($detail, $this->getUser(false), 20);
return $this->renderSuccess([
'qrcode' => $Qrcode->getImage(),
]);
}
}

26
source/application/api/controller/sharing/Index.php

@ -0,0 +1,26 @@
<?php
namespace app\api\controller\sharing;
use app\api\controller\Controller;
use app\api\model\sharing\Category as CategoryModel;
/**
* 拼团首页控制器
* Class Active
* @package app\api\controller\sharing
*/
class Index extends Controller
{
/**
* 拼团首页
* @return array
*/
public function index()
{
// 拼团分类列表
$categoryList = CategoryModel::getCacheAll();
return $this->renderSuccess(compact('categoryList'));
}
}

235
source/application/api/controller/sharing/Order.php

@ -0,0 +1,235 @@
<?php
namespace app\api\controller\sharing;
use app\api\controller\Controller;
use app\api\model\sharing\Order as OrderModel;
use app\common\enum\OrderType as OrderTypeEnum;
use app\common\enum\DeliveryType as DeliveryTypeEnum;
use app\common\enum\order\PayType as PayTypeEnum;
use app\common\service\qrcode\Extract as ExtractQRcode;
/**
* 拼团订单控制器
* Class Order
* @package app\api\controller
*/
class Order extends Controller
{
/* @var \app\api\model\User $user */
private $user;
/**
* 构造方法
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function _initialize()
{
parent::_initialize();
$this->user = $this->getUser(); // 用户信息
}
/**
* 订单确认
* @param int $order_type 订单类型 (10单独购买 20拼团)
* @param int $goods_id 商品id
* @param int $goods_num
* @param int $goods_sku_id
* @param int $delivery 配送方式
* @param int $pay_type 支付方式
* @param int $shop_id 自提门店id
* @param int $active_id 拼团活动id
* @param int $coupon_id 优惠券id
* @param string $remark
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function checkout(
$order_type,
$goods_id,
$goods_num,
$goods_sku_id,
$delivery = DeliveryTypeEnum::EXPRESS,
$pay_type = PayTypeEnum::WECHAT,
$shop_id = 0,
$active_id = null,
$coupon_id = null,
$remark = ''
)
{
// 商品结算信息
$model = new OrderModel;
$order = $model->getBuyNow(
$this->user,
$order_type,
$goods_id,
$goods_num,
$goods_sku_id,
$delivery,
$pay_type,
$shop_id
);
if (!$this->request->isPost()) {
return $this->renderSuccess($order);
}
if ($model->hasError()) {
return $this->renderError($model->getError());
}
// 创建订单
if (!$model->createOrder($this->user, $order, $active_id, $coupon_id, $remark)) {
return $this->renderError($model->getError() ?: '订单创建失败');
}
// 构建微信支付请求
$payment = ($pay_type == PayTypeEnum::WECHAT) ? $model->paymentByWechat($this->user) : [];
return $this->renderSuccess([
'order_id' => $model['order_id'], // 订单id
'pay_type' => $pay_type, // 支付方式
'payment' => $payment // 微信支付参数
]);
}
/**
* 我的拼团订单列表
* @param $dataType
* @return array
* @throws \think\exception\DbException
*/
public function lists($dataType)
{
$model = new OrderModel;
$list = $model->getList($this->user['user_id'], $dataType);
return $this->renderSuccess(compact('list'));
}
/**
* 拼团订单详情信息
* @param $order_id
* @return array
* @throws \app\common\exception\BaseException
*/
public function detail($order_id)
{
// 订单详情
$order = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
// 该订单是否允许申请售后
$order['isAllowRefund'] = $order->isAllowRefund();
return $this->renderSuccess(compact('order'));
}
/**
* 获取物流信息
* @param $order_id
* @return array
* @throws \app\common\exception\BaseException
*/
public function express($order_id)
{
// 订单信息
$order = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
if (!$order['express_no']) {
return $this->renderError('没有物流信息');
}
// 获取物流信息
/* @var \app\store\model\Express $model */
$model = $order['express'];
$express = $model->dynamic($model['express_name'], $model['express_code'], $order['express_no']);
if ($express === false) {
return $this->renderError($model->getError());
}
return $this->renderSuccess(compact('express'));
}
/**
* 取消订单
* @param $order_id
* @return array
* @throws \app\common\exception\BaseException
*/
public function cancel($order_id)
{
$model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
if ($model->cancel()) {
return $this->renderSuccess($model->getError() ?: '订单取消成功');
}
return $this->renderError($model->getError() ?: '订单取消失败');
}
/**
* 确认收货
* @param $order_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function receipt($order_id)
{
$model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
if ($model->receipt()) {
return $this->renderSuccess();
}
return $this->renderError($model->getError());
}
/**
* 立即支付
* @param int $order_id 订单id
* @param int $payType 支付方式
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\Exception
* @throws \think\exception\DbException
*/
public function pay($order_id, $payType = PayTypeEnum::WECHAT)
{
// 订单详情
$model = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
// 判断商品状态、库存
if (!$model->checkGoodsStatusFromOrder($model['goods'])) {
return $this->renderError($model->getError());
}
$render = [
'order_id' => $model['order_id'], // 订单id
'pay_type' => $payType, // 支付方式
];
if ($payType == PayTypeEnum::WECHAT) {
$render['payment'] = $model->paymentByWechat($this->user);
} elseif ($payType == PayTypeEnum::BALANCE) {
if ($model->paymentByBalance($model['order_no'])) {
return $this->renderSuccess($render, '支付成功');
}
return $this->renderError($model->getError() ?: '支付失败', $render);
}
return $this->renderSuccess($render);
}
/**
* 获取订单核销二维码
* @param $order_id
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function extractQrcode($order_id)
{
// 订单详情
$order = OrderModel::getUserOrderDetail($order_id, $this->user['user_id']);
// 判断是否为待核销订单
if (!$order->checkExtractOrder($order)) {
return $this->renderError($order->getError());
}
$Qrcode = new ExtractQRcode(
$this->wxapp_id,
$this->user,
$order_id,
OrderTypeEnum::SHARING
);
return $this->renderSuccess([
'qrcode' => $Qrcode->getImage(),
]);
}
}

109
source/application/api/controller/sharing/Refund.php

@ -0,0 +1,109 @@
<?php
namespace app\api\controller\sharing;
use app\api\controller\Controller;
use app\api\model\Express as ExpressModel;
use app\api\model\sharing\OrderGoods as OrderGoodsModel;
use app\api\model\sharing\OrderRefund as OrderRefundModel;
/**
* 拼团订单售后服务
* Class Refund
* @package app\api\controller\user\order
*/
class Refund extends Controller
{
/* @var \app\api\model\User $user */
private $user;
/**
* 构造方法
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function _initialize()
{
parent::_initialize();
$this->user = $this->getUser(); // 用户信息
}
/**
* 用户售后单列表
* @param int $state
* @return array
* @throws \think\exception\DbException
*/
public function lists($state = -1)
{
$model = new OrderRefundModel;
$list = $model->getList($this->user['user_id'], (int)$state);
return $this->renderSuccess(compact('list'));
}
/**
* 申请售后
* @param $order_goods_id
* @return array
* @throws \think\exception\DbException
* @throws \Exception
*/
public function apply($order_goods_id)
{
// 订单商品详情
$goods = OrderGoodsModel::detail($order_goods_id);
if (isset($goods['refund']) && !empty($goods['refund'])) {
return $this->renderError('当前商品已申请售后');
}
if (!$this->request->isPost()) {
return $this->renderSuccess(['detail' => $goods]);
}
// 新增售后单记录
$model = new OrderRefundModel;
if ($model->apply($this->user, $goods, $this->request->post())) {
return $this->renderSuccess([], '提交成功');
}
return $this->renderError($model->getError() ?: '提交失败');
}
/**
* 售后单详情
* @param $order_refund_id
* @return array
* @throws \think\exception\DbException
*/
public function detail($order_refund_id)
{
// 售后单详情
$detail = OrderRefundModel::detail([
'user_id' => $this->user['user_id'],
'order_refund_id' => $order_refund_id
]);
if (empty($detail)) {
return $this->renderError('售后单不存在');
}
// 物流公司列表
$expressList = ExpressModel::getAll();
return $this->renderSuccess(compact('detail', 'expressList'));
}
/**
* 用户发货
* @param $order_refund_id
* @return array
* @throws \think\exception\DbException
*/
public function delivery($order_refund_id)
{
// 售后单详情
$model = OrderRefundModel::detail([
'user_id' => $this->user['user_id'],
'order_refund_id' => $order_refund_id
]);
if ($model->delivery($this->postData())) {
return $this->renderSuccess([], '操作成功');
}
return $this->renderError($model->getError() ?: '提交失败');
}
}

26
source/application/api/controller/sharing/Setting.php

@ -0,0 +1,26 @@
<?php
namespace app\api\controller\sharing;
use app\api\controller\Controller;
use app\api\model\sharing\Setting as SettingModel;
/**
* 拼团设置控制器
* Class Setting
* @package app\api\controller\sharing
*/
class Setting extends Controller
{
/**
* 获取拼团设置
* @return array
*/
public function getAll()
{
// 获取拼团设置
$setting = SettingModel::getSetting();
return $this->renderSuccess(compact('setting'));
}
}

72
source/application/api/controller/shop/Order.php

@ -0,0 +1,72 @@
<?php
namespace app\api\controller\shop;
use app\api\controller\Controller;
use app\common\service\Order as OrderService;
use app\common\enum\OrderType as OrderTypeEnum;
use app\api\model\store\shop\Clerk as ClerkModel;
/**
* 自提订单管理
* Class Order
* @package app\api\controller\shop
*/
class Order extends Controller
{
/* @var \app\api\model\User $user */
private $user;
/**
* 构造方法
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function _initialize()
{
parent::_initialize();
$this->user = $this->getUser(); // 用户信息
}
/**
* 核销订单详情
* @param $order_id
* @param int $order_type
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function detail($order_id, $order_type = OrderTypeEnum::MASTER)
{
// 订单详情
$order = OrderService::getOrderDetail($order_id, $order_type);
// 验证是否为该门店的核销员
$clerkModel = ClerkModel::detail(['user_id' => $this->user['user_id']]);
return $this->renderSuccess(compact('order', 'clerkModel'));
}
/**
* 确认核销
* @param $order_id
* @param int $order_type
* @return array
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function extract($order_id, $order_type = OrderTypeEnum::MASTER)
{
// 订单详情
$order = OrderService::getOrderDetail($order_id, $order_type);
// 验证是否为该门店的核销员
$ClerkModel = ClerkModel::detail(['user_id' => $this->user['user_id']]);
if (!$ClerkModel->checkUser($order['extract_shop_id'])) {
return $this->renderError($ClerkModel->getError());
}
// 确认核销
if ($order->extract($ClerkModel['clerk_id'])) {
return $this->renderSuccess([], '订单核销成功');
}
return $this->renderError($order->getError() ?: '核销失败');
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save