Browse Source

first commit

felixyin 8 months ago
commit
cc37d3cd14
100 changed files with 10958 additions and 0 deletions
  1. 0 0
      .htaccess
  2. 26 0
      404.html
  3. 2 0
      CONTRIBUTING.md
  4. 42 0
      Dockerfile
  5. 21 0
      LICENSE
  6. 242 0
      README.md
  7. 8 0
      api/demo/README.md
  8. 13 0
      api/demo/composer.json
  9. 24 0
      api/demo/controller/ArticlesController.php
  10. 20 0
      api/demo/controller/IndexController.php
  11. 5 0
      api/demo/route.php
  12. 7 0
      api/demo/vendor/autoload.php
  13. 445 0
      api/demo/vendor/composer/ClassLoader.php
  14. 21 0
      api/demo/vendor/composer/LICENSE
  15. 9 0
      api/demo/vendor/composer/autoload_classmap.php
  16. 9 0
      api/demo/vendor/composer/autoload_namespaces.php
  17. 9 0
      api/demo/vendor/composer/autoload_psr4.php
  18. 52 0
      api/demo/vendor/composer/autoload_real.php
  19. 15 0
      api/demo/vendor/composer/autoload_static.php
  20. 1 0
      api/demo/vendor/composer/installed.json
  21. 779 0
      api/js/common.php
  22. 9 0
      api/js/config/database.php
  23. 55 0
      api/js/controller/DistributorController.php
  24. 147 0
      api/js/controller/GoodsOrderController.php
  25. 170 0
      api/js/controller/IndexController.php
  26. 25 0
      api/js/controller/JsCategoryController.php
  27. 180 0
      api/js/controller/JsController.php
  28. 40 0
      api/js/controller/JsIndexController.php
  29. 896 0
      api/js/controller/JsOrderController.php
  30. 25 0
      api/js/controller/JsProjectCategoryController.php
  31. 106 0
      api/js/controller/JsProjectController.php
  32. 179 0
      api/js/controller/LoginController.php
  33. 303 0
      api/js/controller/PaynotifyController.php
  34. 37 0
      api/js/controller/PortalController.php
  35. 233 0
      api/js/controller/RegController.php
  36. 66 0
      api/js/controller/StoreController.php
  37. 258 0
      api/js/controller/SystemController.php
  38. 92 0
      api/js/controller/TestController.php
  39. 25 0
      api/js/controller/UpImgController.php
  40. 182 0
      api/js/controller/UserAgencyController.php
  41. 334 0
      api/js/controller/UserController.php
  42. 923 0
      api/js/controller/UserJsController.php
  43. 60 0
      api/js/controller/UserSignInController.php
  44. 107 0
      api/js/controller/VerificationCodeController.php
  45. 198 0
      api/js/controller/WxLoginController.php
  46. 19 0
      api/js/model/AgencyModel.php
  47. 20 0
      api/js/model/DistributorLogModel.php
  48. 20 0
      api/js/model/DistributorModel.php
  49. 30 0
      api/js/model/GoodsCategoryModel.php
  50. 66 0
      api/js/model/GoodsModel.php
  51. 27 0
      api/js/model/GoodsOrderModel.php
  52. 33 0
      api/js/model/GoodsSeckillModel.php
  53. 26 0
      api/js/model/JsCallModel.php
  54. 32 0
      api/js/model/JsCategoryModel.php
  55. 20 0
      api/js/model/JsCourseOrderModel.php
  56. 17 0
      api/js/model/JsDiscountModel.php
  57. 186 0
      api/js/model/JsModel.php
  58. 17 0
      api/js/model/JsOrderAddtimeModel.php
  59. 21 0
      api/js/model/JsOrderGrabModel.php
  60. 105 0
      api/js/model/JsOrderModel.php
  61. 26 0
      api/js/model/JsProjectCategoryModel.php
  62. 144 0
      api/js/model/JsProjectModel.php
  63. 17 0
      api/js/model/JsProjectServiceModel.php
  64. 17 0
      api/js/model/JsProjectTagModel.php
  65. 36 0
      api/js/model/JsScoreModel.php
  66. 17 0
      api/js/model/JsSiteModel.php
  67. 22 0
      api/js/model/JsTimeModel.php
  68. 26 0
      api/js/model/PortalCategoryModel.php
  69. 61 0
      api/js/model/PortalPostModel.php
  70. 21 0
      api/js/model/RegionModel.php
  71. 24 0
      api/js/model/SignInSetModel.php
  72. 41 0
      api/js/model/UserDiscountModel.php
  73. 40 0
      api/js/model/UserModel.php
  74. 17 0
      api/js/model/UserSignInModel.php
  75. 18 0
      api/js/model/UserTxModel.php
  76. 131 0
      api/js/route.php
  77. 9 0
      app/back/config/database.php
  78. 195 0
      app/back/controller/AgencyController.php
  79. 89 0
      app/back/controller/AgencyRankController.php
  80. 70 0
      app/back/controller/ApplyController.php
  81. 97 0
      app/back/controller/CallController.php
  82. 165 0
      app/back/controller/CogController.php
  83. 87 0
      app/back/controller/DistributorController.php
  84. 73 0
      app/back/controller/GoodsCategoryController.php
  85. 120 0
      app/back/controller/GoodsController.php
  86. 93 0
      app/back/controller/GoodsOrderController.php
  87. 64 0
      app/back/controller/GoodsSearchController.php
  88. 109 0
      app/back/controller/GoodsSeckillController.php
  89. 444 0
      app/back/controller/HuizongController.php
  90. 73 0
      app/back/controller/IndustryController.php
  91. 141 0
      app/back/controller/JsAlreadyController.php
  92. 95 0
      app/back/controller/JsCategoryController.php
  93. 242 0
      app/back/controller/JsController.php
  94. 61 0
      app/back/controller/JsCourseOrderController.php
  95. 122 0
      app/back/controller/JsDiscountController.php
  96. 58 0
      app/back/controller/JsNotController.php
  97. 486 0
      app/back/controller/JsOrderController.php
  98. 85 0
      app/back/controller/JsProjectCategoryController.php
  99. 198 0
      app/back/controller/JsProjectController.php
  100. 85 0
      app/back/controller/JsProjectServiceController.php

+ 0 - 0
.htaccess


+ 26 - 0
404.html

@@ -0,0 +1,26 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<meta http-equiv="X-UA-Compatible" content="IE=edge">
+<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
+<title>404</title>
+<style>
+	body{
+		background-color:#444;
+		font-size:14px;
+	}
+	h3{
+		font-size:60px;
+		color:#eee;
+		text-align:center;
+		padding-top:30px;
+		font-weight:normal;
+	}
+</style>
+</head>
+
+<body>
+<h3>404,您请求的文件不存在!</h3>
+</body>
+</html>

+ 2 - 0
CONTRIBUTING.md

@@ -0,0 +1,2 @@
+如何贡献我的源代码
+===

+ 42 - 0
Dockerfile

@@ -0,0 +1,42 @@
+FROM php:7.1-apache
+
+MAINTAINER jayknoxqu@gmail.com
+
+#设置容器时区
+ENV TZ Asia/Shanghai
+
+#设置程序入口
+ENV APACHE_DOCUMENT_ROOT /var/www/html/public
+
+RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone \
+    && sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf \
+    && sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf \
+    #添加阿里云的镜像源
+    && mv /etc/apt/sources.list /etc/apt/sources.list.bak \
+    && echo "deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib" >/etc/apt/sources.list \
+    && echo "deb http://mirrors.aliyun.com/debian-security stretch/updates main" >>/etc/apt/sources.list \
+    && echo "deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib" >>/etc/apt/sources.list \
+    && echo "deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib" >>/etc/apt/sources.list \
+    #安装程序依赖库
+    && apt-get update && apt-get install -y --allow-downgrades \
+              libfreetype6-dev \
+              libjpeg62-turbo-dev \
+              libpng-dev \
+              zlib1g=1:1.2.8.dfsg-5 \
+              zlib1g-dev \
+    #安装 PHP 依赖
+    && docker-php-ext-install pdo_mysql \
+    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
+    && docker-php-ext-install -j$(nproc) gd \
+    #删除包缓存中的所有包
+    && apt-get clean \
+    && apt-get autoclean \
+    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
+
+#复制代码到PHP容器
+COPY . /var/www/html
+
+# 开启URL重写 并且 添加目录权限
+RUN a2enmod rewrite \
+    && chmod -R 0755 /var/www/html \
+    && chown -R www-data:www-data /var/www/html

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2013-present ThinkCMF (https://www.thinkcmf.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 242 - 0
README.md

@@ -0,0 +1,242 @@
+ThinkCMF 5.1.5 让你更自由地飞
+===============
+
+### 系列讲座
+https://www.thinkcmf.com/college.html
+
+### ThinkCMF5.1主要特性
+* 更改框架协议为`MIT`,让你更自由地飞
+* 基于`ThinkPHP 5.1`重构,但核心代码兼容5.0版本,保证老用户最小升级成本
+* 增加对`swoole`支持,同时支持`swoole`协程和全同步模式
+* 重新规范目录结构,更贴心
+* CMF核心库及应用使用`composer`加载
+* 合并API到框架核心
+* 更规范的代码,遵循`PSR-2`命名规范和`PSR-4`自动加载规范
+* 支持 `composer` 管理第三方库
+* 核心化:独立核心代码包
+* 应用化:开发者以应用的形式增加项目模模块
+* 插件化:更强的插件机制,开发者以插件形式扩展功能
+* 模板化:前台可视化设计
+* 支持URL美化功能,支持别名设置,更简单
+* 独立的回收站功能,可以管理所有应用临时删除的数据
+* 统一的资源管理,相同文件只保存一份
+* 注解式的后台菜单管理功能,方便开发者代码管理后台菜单
+* 插件同样支持注解式的后台菜单管理功能
+* 文件存储插件化,默认支持七牛文件存储插件
+* 模板制作标签化,内置多个cmf标签,方便小白用户
+* 更人性化的导航标签,可以随意定制 html 结构
+* 后台首页插件化,用户可以定制的网站后台首页
+
+### 开发手册
+http://www.kancloud.cn/thinkcmf/doc5_1
+
+### Git仓库
+
+1. GitHub:https://github.com/thinkcmf/thinkcmf 主要仓库
+2. 码云:https://gitee.com/thinkcmf/ThinkCMF 中国镜像
+
+### 演示仓库
+此仓库会放官方的一些演示应用,插件,模板,API等 
+1. https://github.com/thinkcmf/demos 主要仓库
+2. https://gitee.com/thinkcmf/demos 中国镜像
+
+### 环境推荐
+> php7.1
+
+> mysql 5.6+
+
+> 打开rewrite
+
+
+### 最低环境要求
+> php5.6+
+
+> mysql 5.5+ (mysql5.1安装时选择utf8编码,不支持表情符)
+
+> 打开rewrite
+
+
+### 运行环境配置教程
+https://www.thinkcmf.com/topic/1502.html
+
+
+
+代码已经加入自动安装程序,如果你在安装中有任何问题请提交 issue!
+
+1. public目录做为网站根目录,入口文件在 public/index.php
+2. 配置好网站,请访问http://你的域名
+
+enjoy your cmf~!
+
+### 系统更新
+如果您是已经安装过ThinkCMF的用户,请查看 update 目录下的 sql 升级文件,根据自己的下载的程序版本进行更新
+
+### 完整版目录结构
+~~~
+thinkcmf  根目录
+├─api                     api目录
+│  ├─demo                 演示应用api目录
+│  │  ├─controller        控制器目录
+│  │  ├─model             模型目录
+│  │  └─ ...              更多类库目录
+├─app                     应用目录
+│  ├─demo                 演示应用目录
+│  │  ├─controller        控制器目录
+│  │  ├─model             模型目录
+│  │  └─ ...              更多类库目录
+│  ├─ ...                 更多应用
+│  ├─app.php              应用(公共)配置文件[可选]
+│  ├─command.php          命令行工具配置文件[可选]
+│  ├─common.php           应用公共(函数)文件[可选]
+│  ├─database.php         数据库配置文件[可选]
+│  ├─tags.php             应用行为扩展定义文件[可选]
+├─data                    数据目录(可写)
+│  ├─config               动态配置目录(可写)
+│  ├─route                动态路由目录(可写)
+│  ├─runtime              应用的运行时目录(可写)
+│  └─ ...                 更多
+├─public                  WEB 部署目录(对外访问目录)
+│  ├─plugins              插件目录
+│  ├─static               官方静态资源存放目录(css,js,image),勿放自己项目文件
+│  ├─themes               前后台主题目录
+│  │  ├─admin_simpleboot3 后台默认主题
+│  │  └─default           前台默认主题
+│  ├─upload               文件上传目录
+│  ├─api.php              API入口
+│  ├─index.php            入口文件
+│  ├─robots.txt           爬虫协议文件
+│  ├─router.php           快速测试文件
+│  └─.htaccess            apache重写文件
+├─extend                  扩展类库目录[可选]
+├─vendor                  第三方类库目录(Composer)
+│  ├─thinkphp             ThinkPHP目录
+│  └─...             
+├─composer.json           composer 定义文件
+├─LICENSE                 授权说明文件
+├─README.md               README 文件
+├─think                   命令行入口文件
+~~~
+
+### QQ群:
+`ThinkCMF 官方交流群`:316669417  
+   
+`ThinkCMF 高级交流群`:100828313 (付费)  
+高级群专属权益:  
+第一波:两个后台风格(ThinkCMF官网风格后台主题,蓝色风格后台主题)  
+第二波:ThinkCMF5完全开发手册离线版(PDF,EPUB,MOBI格式)  
+更多专属权益正在路上...
+
+`ThinkCMF 铲屎官交流群`:415136742 (生活娱乐,为有喵的猿人准备)
+
+### 话题专区
+http://www.thinkcmf.com/topic/index/index/cat/11.html
+
+### 反馈问题
+https://github.com/thinkcmf/thinkcmf/issues
+
+### 更新日志
+#### 5.1.5
+* 升级到tp5.1.39
+* 增加模板设计数组列表图片显示
+* 优化前台基类
+* 取消路由排序限制
+
+#### 5.1.4
+* 优化上传逻辑,已传文件更新文件名
+* 优化系统钩子初始化
+* 修复编辑器锚点处理错误
+* 修复部分系统函数判断问题
+* 修复tp5.1.38前台控制器报错
+* 修复tp5.1.38下邮件验证码发不出
+
+#### 5.1.3
+* 增加`CMF_DATA`常量(注意升级)
+* 增加插件路由功能
+* 增加插件URL美化功能
+* 修复app_init钩子引起的命令行报错
+* 修复API中文件url转化错误
+
+#### 5.1.2
+[核心]
+* 升级tp到`5.1.37`
+* 优化`slides,noslides`标签
+* 修复头像地址获取函数
+* 优化上传类支持API文件上传
+* 封装后台菜单,应用钩子,用户行为导入
+* 增加应用自动安装
+* 优化后台百度地图链接支持https
+
+[API]
+* 优化文件上传,支持云存储
+* 修复积分日志接口数据返回错误
+* 修复钩子不加载问题
+* 修复API跨域报错问题
+
+
+#### 5.1.1
+[核心]
+* `composer.json` extra 增加`think-config`配置
+* 修复API UserLikeModel继承错误类
+* 优化后台菜单 url 生成
+* 增加Linux下全新安装时data目录不可写提示
+* 修复插件模板常量`__ROOT__`不替换
+* 增加`swoole`扩展钩子检测
+* 修复插件API基类报错#577
+* 优化应用初始化流程
+* 优化行为加载流程
+
+[swoole]
+* 增加`swoole_server_start`,`swoole_worker_start`,`swoole_websocket_on_open`,`swoole_websocket_on_close`钩子
+* 增加`WebSocket`独立运行命令
+* 增加`WebSocket onOpen`回调
+* 修复`WebSocket`事件引起的数据库执行报错
+* 修复`WebSocket`发送消息未判断是否为`WebSocket`连接
+* 增加`worker`进程启动时自动初始化所有模块
+
+
+
+#### 5.1.0
+[核心]
+* 更改框架协议为`MIT`,让你更自由地飞
+* 升级`TP`到`5.1.35`
+* 独立安装应用为`composer`包
+* 移除portal应用,请到`https://github.com/thinkcmf/demos`下载
+* 移除`simpleboot3`模板,请到`https://github.com/thinkcmf/demos`下载
+* 移除`phpoffice/phpspreadsheet`,`phpoffice/phpexcel`,`dompdf/dompdf`第三方库,请自行安装
+* 移动`qiniu/php-sdk`库到七牛插件
+* `extend`目录改为可选,开发者自行添加,核心不再包含此目录
+* 增加`demo`应用,方便开发者学习
+* 增加插件`@adminMenuRoot`注解支持
+* 增加`app,api和插件`composer第三方库支持
+* 增加后台模板动态设置功能
+* 使用`composer classmap`做相关类的映射
+* 更改所有`thinkcmf`包版本号依赖
+* 优化清除缓存,清除opcache缓存
+* 优化`cmf_set_dynamic_config`兼容5.0和5.1
+* 升级`PHPMailer`使用`PHPMailer 6.0`(注意类的引入变化)
+* 修复路由是否存在检测问题
+* 修复url美化由于后台权限设置可能引起的漏洞(漏洞编号CVE-2019-6713 感谢topsec(zhan_ran)的及时反馈)
+* 修复子导航标签报错
+* 修复数据库对象实例化不当导致的问题
+* 修复`BaseController`排序批量更新
+* 修复新建管理员登录时报错
+* 取消`THINKCMF_VERSION`常量,请使用`cmf_version()`
+* 取消`PLUGINS_PATH`常量,请使用`WEB_ROOT.'plugins/`
+
+[swoole]
+* 增加`websocket`演示
+* 优化`swoole`配置初始化
+* 优化`swoole`下内容输出
+* 更改默认缓存大小为128M
+* 修复`swoole`如果控制器返回内容为空报错问题
+* 修复`swoole`下核心包路由注册位置
+* 修复`swoole`下后台风格无法设置
+
+#### 5.1.0-beta
+[核心]
+* 升级`ThinkCMF 5.0`到`ThinkPHP 5.1`
+
+
+
+
+

+ 8 - 0
api/demo/README.md

@@ -0,0 +1,8 @@
+ThinkCMF API演示应用
+===============
+
+### 加载第三方库
+支持使用`composer`加载第三方库
+```
+composer require phpoffice/phpspreadsheet
+```

+ 13 - 0
api/demo/composer.json

@@ -0,0 +1,13 @@
+{
+    "name": "thinkcmf/apis-demo",
+    "description": "ThinkCMF demo api",
+    "type": "cmf-api",
+    "license": "MIT",
+    "authors": [
+        {
+            "name": "catman",
+            "email": "catman@thinkcmf.com"
+        }
+    ],
+    "require": {}
+}

+ 24 - 0
api/demo/controller/ArticlesController.php

@@ -0,0 +1,24 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Author: pl125 <xskjs888@163.com>
+// +----------------------------------------------------------------------
+
+namespace api\demo\controller;
+
+use cmf\controller\RestBaseController;
+
+class ArticlesController extends RestBaseController
+{
+    public function index()
+    {
+        $articles = [
+            ['title' => 'article title1'],
+            ['title' => 'article title2'],
+        ];
+        $this->success('请求成功!', ['articles' => $articles]);
+    }
+}

+ 20 - 0
api/demo/controller/IndexController.php

@@ -0,0 +1,20 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Author: pl125 <xskjs888@163.com>
+// +----------------------------------------------------------------------
+
+namespace api\demo\controller;
+
+use cmf\controller\RestBaseController;
+
+class IndexController extends RestBaseController
+{
+    public function index()
+    {
+        $this->success('请求成功!', ['test'=>'test']);
+    }
+}

+ 5 - 0
api/demo/route.php

@@ -0,0 +1,5 @@
+<?php
+
+use think\facade\Route;
+
+Route::resource('demo/articles', 'demo/Articles');

+ 7 - 0
api/demo/vendor/autoload.php

@@ -0,0 +1,7 @@
+<?php
+
+// autoload.php @generated by Composer
+
+require_once __DIR__ . '/composer/autoload_real.php';
+
+return ComposerAutoloaderInitba11d0d49ab8a6cda13c6c7344f77971::getLoader();

+ 445 - 0
api/demo/vendor/composer/ClassLoader.php

@@ -0,0 +1,445 @@
+<?php
+
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Autoload;
+
+/**
+ * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
+ *
+ *     $loader = new \Composer\Autoload\ClassLoader();
+ *
+ *     // register classes with namespaces
+ *     $loader->add('Symfony\Component', __DIR__.'/component');
+ *     $loader->add('Symfony',           __DIR__.'/framework');
+ *
+ *     // activate the autoloader
+ *     $loader->register();
+ *
+ *     // to enable searching the include path (eg. for PEAR packages)
+ *     $loader->setUseIncludePath(true);
+ *
+ * In this example, if you try to use a class in the Symfony\Component
+ * namespace or one of its children (Symfony\Component\Console for instance),
+ * the autoloader will first look for the class under the component/
+ * directory, and it will then fallback to the framework/ directory if not
+ * found before giving up.
+ *
+ * This class is loosely based on the Symfony UniversalClassLoader.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ * @see    http://www.php-fig.org/psr/psr-0/
+ * @see    http://www.php-fig.org/psr/psr-4/
+ */
+class ClassLoader
+{
+    // PSR-4
+    private $prefixLengthsPsr4 = array();
+    private $prefixDirsPsr4 = array();
+    private $fallbackDirsPsr4 = array();
+
+    // PSR-0
+    private $prefixesPsr0 = array();
+    private $fallbackDirsPsr0 = array();
+
+    private $useIncludePath = false;
+    private $classMap = array();
+    private $classMapAuthoritative = false;
+    private $missingClasses = array();
+    private $apcuPrefix;
+
+    public function getPrefixes()
+    {
+        if (!empty($this->prefixesPsr0)) {
+            return call_user_func_array('array_merge', $this->prefixesPsr0);
+        }
+
+        return array();
+    }
+
+    public function getPrefixesPsr4()
+    {
+        return $this->prefixDirsPsr4;
+    }
+
+    public function getFallbackDirs()
+    {
+        return $this->fallbackDirsPsr0;
+    }
+
+    public function getFallbackDirsPsr4()
+    {
+        return $this->fallbackDirsPsr4;
+    }
+
+    public function getClassMap()
+    {
+        return $this->classMap;
+    }
+
+    /**
+     * @param array $classMap Class to filename map
+     */
+    public function addClassMap(array $classMap)
+    {
+        if ($this->classMap) {
+            $this->classMap = array_merge($this->classMap, $classMap);
+        } else {
+            $this->classMap = $classMap;
+        }
+    }
+
+    /**
+     * Registers a set of PSR-0 directories for a given prefix, either
+     * appending or prepending to the ones previously set for this prefix.
+     *
+     * @param string       $prefix  The prefix
+     * @param array|string $paths   The PSR-0 root directories
+     * @param bool         $prepend Whether to prepend the directories
+     */
+    public function add($prefix, $paths, $prepend = false)
+    {
+        if (!$prefix) {
+            if ($prepend) {
+                $this->fallbackDirsPsr0 = array_merge(
+                    (array) $paths,
+                    $this->fallbackDirsPsr0
+                );
+            } else {
+                $this->fallbackDirsPsr0 = array_merge(
+                    $this->fallbackDirsPsr0,
+                    (array) $paths
+                );
+            }
+
+            return;
+        }
+
+        $first = $prefix[0];
+        if (!isset($this->prefixesPsr0[$first][$prefix])) {
+            $this->prefixesPsr0[$first][$prefix] = (array) $paths;
+
+            return;
+        }
+        if ($prepend) {
+            $this->prefixesPsr0[$first][$prefix] = array_merge(
+                (array) $paths,
+                $this->prefixesPsr0[$first][$prefix]
+            );
+        } else {
+            $this->prefixesPsr0[$first][$prefix] = array_merge(
+                $this->prefixesPsr0[$first][$prefix],
+                (array) $paths
+            );
+        }
+    }
+
+    /**
+     * Registers a set of PSR-4 directories for a given namespace, either
+     * appending or prepending to the ones previously set for this namespace.
+     *
+     * @param string       $prefix  The prefix/namespace, with trailing '\\'
+     * @param array|string $paths   The PSR-4 base directories
+     * @param bool         $prepend Whether to prepend the directories
+     *
+     * @throws \InvalidArgumentException
+     */
+    public function addPsr4($prefix, $paths, $prepend = false)
+    {
+        if (!$prefix) {
+            // Register directories for the root namespace.
+            if ($prepend) {
+                $this->fallbackDirsPsr4 = array_merge(
+                    (array) $paths,
+                    $this->fallbackDirsPsr4
+                );
+            } else {
+                $this->fallbackDirsPsr4 = array_merge(
+                    $this->fallbackDirsPsr4,
+                    (array) $paths
+                );
+            }
+        } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
+            // Register directories for a new namespace.
+            $length = strlen($prefix);
+            if ('\\' !== $prefix[$length - 1]) {
+                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
+            }
+            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
+            $this->prefixDirsPsr4[$prefix] = (array) $paths;
+        } elseif ($prepend) {
+            // Prepend directories for an already registered namespace.
+            $this->prefixDirsPsr4[$prefix] = array_merge(
+                (array) $paths,
+                $this->prefixDirsPsr4[$prefix]
+            );
+        } else {
+            // Append directories for an already registered namespace.
+            $this->prefixDirsPsr4[$prefix] = array_merge(
+                $this->prefixDirsPsr4[$prefix],
+                (array) $paths
+            );
+        }
+    }
+
+    /**
+     * Registers a set of PSR-0 directories for a given prefix,
+     * replacing any others previously set for this prefix.
+     *
+     * @param string       $prefix The prefix
+     * @param array|string $paths  The PSR-0 base directories
+     */
+    public function set($prefix, $paths)
+    {
+        if (!$prefix) {
+            $this->fallbackDirsPsr0 = (array) $paths;
+        } else {
+            $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
+        }
+    }
+
+    /**
+     * Registers a set of PSR-4 directories for a given namespace,
+     * replacing any others previously set for this namespace.
+     *
+     * @param string       $prefix The prefix/namespace, with trailing '\\'
+     * @param array|string $paths  The PSR-4 base directories
+     *
+     * @throws \InvalidArgumentException
+     */
+    public function setPsr4($prefix, $paths)
+    {
+        if (!$prefix) {
+            $this->fallbackDirsPsr4 = (array) $paths;
+        } else {
+            $length = strlen($prefix);
+            if ('\\' !== $prefix[$length - 1]) {
+                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
+            }
+            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
+            $this->prefixDirsPsr4[$prefix] = (array) $paths;
+        }
+    }
+
+    /**
+     * Turns on searching the include path for class files.
+     *
+     * @param bool $useIncludePath
+     */
+    public function setUseIncludePath($useIncludePath)
+    {
+        $this->useIncludePath = $useIncludePath;
+    }
+
+    /**
+     * Can be used to check if the autoloader uses the include path to check
+     * for classes.
+     *
+     * @return bool
+     */
+    public function getUseIncludePath()
+    {
+        return $this->useIncludePath;
+    }
+
+    /**
+     * Turns off searching the prefix and fallback directories for classes
+     * that have not been registered with the class map.
+     *
+     * @param bool $classMapAuthoritative
+     */
+    public function setClassMapAuthoritative($classMapAuthoritative)
+    {
+        $this->classMapAuthoritative = $classMapAuthoritative;
+    }
+
+    /**
+     * Should class lookup fail if not found in the current class map?
+     *
+     * @return bool
+     */
+    public function isClassMapAuthoritative()
+    {
+        return $this->classMapAuthoritative;
+    }
+
+    /**
+     * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
+     *
+     * @param string|null $apcuPrefix
+     */
+    public function setApcuPrefix($apcuPrefix)
+    {
+        $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
+    }
+
+    /**
+     * The APCu prefix in use, or null if APCu caching is not enabled.
+     *
+     * @return string|null
+     */
+    public function getApcuPrefix()
+    {
+        return $this->apcuPrefix;
+    }
+
+    /**
+     * Registers this instance as an autoloader.
+     *
+     * @param bool $prepend Whether to prepend the autoloader or not
+     */
+    public function register($prepend = false)
+    {
+        spl_autoload_register(array($this, 'loadClass'), true, $prepend);
+    }
+
+    /**
+     * Unregisters this instance as an autoloader.
+     */
+    public function unregister()
+    {
+        spl_autoload_unregister(array($this, 'loadClass'));
+    }
+
+    /**
+     * Loads the given class or interface.
+     *
+     * @param  string    $class The name of the class
+     * @return bool|null True if loaded, null otherwise
+     */
+    public function loadClass($class)
+    {
+        if ($file = $this->findFile($class)) {
+            includeFile($file);
+
+            return true;
+        }
+    }
+
+    /**
+     * Finds the path to the file where the class is defined.
+     *
+     * @param string $class The name of the class
+     *
+     * @return string|false The path if found, false otherwise
+     */
+    public function findFile($class)
+    {
+        // class map lookup
+        if (isset($this->classMap[$class])) {
+            return $this->classMap[$class];
+        }
+        if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
+            return false;
+        }
+        if (null !== $this->apcuPrefix) {
+            $file = apcu_fetch($this->apcuPrefix.$class, $hit);
+            if ($hit) {
+                return $file;
+            }
+        }
+
+        $file = $this->findFileWithExtension($class, '.php');
+
+        // Search for Hack files if we are running on HHVM
+        if (false === $file && defined('HHVM_VERSION')) {
+            $file = $this->findFileWithExtension($class, '.hh');
+        }
+
+        if (null !== $this->apcuPrefix) {
+            apcu_add($this->apcuPrefix.$class, $file);
+        }
+
+        if (false === $file) {
+            // Remember that this class does not exist.
+            $this->missingClasses[$class] = true;
+        }
+
+        return $file;
+    }
+
+    private function findFileWithExtension($class, $ext)
+    {
+        // PSR-4 lookup
+        $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
+
+        $first = $class[0];
+        if (isset($this->prefixLengthsPsr4[$first])) {
+            $subPath = $class;
+            while (false !== $lastPos = strrpos($subPath, '\\')) {
+                $subPath = substr($subPath, 0, $lastPos);
+                $search = $subPath . '\\';
+                if (isset($this->prefixDirsPsr4[$search])) {
+                    $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
+                    foreach ($this->prefixDirsPsr4[$search] as $dir) {
+                        if (file_exists($file = $dir . $pathEnd)) {
+                            return $file;
+                        }
+                    }
+                }
+            }
+        }
+
+        // PSR-4 fallback dirs
+        foreach ($this->fallbackDirsPsr4 as $dir) {
+            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
+                return $file;
+            }
+        }
+
+        // PSR-0 lookup
+        if (false !== $pos = strrpos($class, '\\')) {
+            // namespaced class name
+            $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
+                . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
+        } else {
+            // PEAR-like class name
+            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
+        }
+
+        if (isset($this->prefixesPsr0[$first])) {
+            foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
+                if (0 === strpos($class, $prefix)) {
+                    foreach ($dirs as $dir) {
+                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
+                            return $file;
+                        }
+                    }
+                }
+            }
+        }
+
+        // PSR-0 fallback dirs
+        foreach ($this->fallbackDirsPsr0 as $dir) {
+            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
+                return $file;
+            }
+        }
+
+        // PSR-0 include paths.
+        if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
+            return $file;
+        }
+
+        return false;
+    }
+}
+
+/**
+ * Scope isolated include.
+ *
+ * Prevents access to $this/self from included files.
+ */
+function includeFile($file)
+{
+    include $file;
+}

+ 21 - 0
api/demo/vendor/composer/LICENSE

@@ -0,0 +1,21 @@
+
+Copyright (c) Nils Adermann, Jordi Boggiano
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+

+ 9 - 0
api/demo/vendor/composer/autoload_classmap.php

@@ -0,0 +1,9 @@
+<?php
+
+// autoload_classmap.php @generated by Composer
+
+$vendorDir = dirname(dirname(__FILE__));
+$baseDir = dirname($vendorDir);
+
+return array(
+);

+ 9 - 0
api/demo/vendor/composer/autoload_namespaces.php

@@ -0,0 +1,9 @@
+<?php
+
+// autoload_namespaces.php @generated by Composer
+
+$vendorDir = dirname(dirname(__FILE__));
+$baseDir = dirname($vendorDir);
+
+return array(
+);

+ 9 - 0
api/demo/vendor/composer/autoload_psr4.php

@@ -0,0 +1,9 @@
+<?php
+
+// autoload_psr4.php @generated by Composer
+
+$vendorDir = dirname(dirname(__FILE__));
+$baseDir = dirname($vendorDir);
+
+return array(
+);

+ 52 - 0
api/demo/vendor/composer/autoload_real.php

@@ -0,0 +1,52 @@
+<?php
+
+// autoload_real.php @generated by Composer
+
+class ComposerAutoloaderInitba11d0d49ab8a6cda13c6c7344f77971
+{
+    private static $loader;
+
+    public static function loadClassLoader($class)
+    {
+        if ('Composer\Autoload\ClassLoader' === $class) {
+            require __DIR__ . '/ClassLoader.php';
+        }
+    }
+
+    public static function getLoader()
+    {
+        if (null !== self::$loader) {
+            return self::$loader;
+        }
+
+        spl_autoload_register(array('ComposerAutoloaderInitba11d0d49ab8a6cda13c6c7344f77971', 'loadClassLoader'), true, true);
+        self::$loader = $loader = new \Composer\Autoload\ClassLoader();
+        spl_autoload_unregister(array('ComposerAutoloaderInitba11d0d49ab8a6cda13c6c7344f77971', 'loadClassLoader'));
+
+        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
+        if ($useStaticLoader) {
+            require_once __DIR__ . '/autoload_static.php';
+
+            call_user_func(\Composer\Autoload\ComposerStaticInitba11d0d49ab8a6cda13c6c7344f77971::getInitializer($loader));
+        } else {
+            $map = require __DIR__ . '/autoload_namespaces.php';
+            foreach ($map as $namespace => $path) {
+                $loader->set($namespace, $path);
+            }
+
+            $map = require __DIR__ . '/autoload_psr4.php';
+            foreach ($map as $namespace => $path) {
+                $loader->setPsr4($namespace, $path);
+            }
+
+            $classMap = require __DIR__ . '/autoload_classmap.php';
+            if ($classMap) {
+                $loader->addClassMap($classMap);
+            }
+        }
+
+        $loader->register(true);
+
+        return $loader;
+    }
+}

+ 15 - 0
api/demo/vendor/composer/autoload_static.php

@@ -0,0 +1,15 @@
+<?php
+
+// autoload_static.php @generated by Composer
+
+namespace Composer\Autoload;
+
+class ComposerStaticInitba11d0d49ab8a6cda13c6c7344f77971
+{
+    public static function getInitializer(ClassLoader $loader)
+    {
+        return \Closure::bind(function () use ($loader) {
+
+        }, null, ClassLoader::class);
+    }
+}

+ 1 - 0
api/demo/vendor/composer/installed.json

@@ -0,0 +1 @@
+[]

+ 779 - 0
api/js/common.php

@@ -0,0 +1,779 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-08
+ * Time: 15:49
+ */
+
+use api\js\model\UserModel;
+use think\Db;
+use api\js\model\JsSiteModel;
+use api\js\model\JsTimeModel;
+
+
+if (!function_exists('p')) {
+    function p($pram)
+    {
+        echo "<pre>";
+        print_r($pram);
+        echo "</pre>";
+    }
+}
+
+/**
+ * @param $id => 订单id
+ * @param $type => 1 技师课程支付,2技师商城支付,3用户呼叫服务支付
+ * @return mixed
+ */
+function wx_pay($id, $type)
+{
+    $model = '';
+    $booy = '';
+    $wxpay = cmf_get_option('wxpay');
+    switch ($type) {
+        case 1:
+            $info['appid'] = $wxpay['js_appid'];
+            $info['app_secret'] = $wxpay['js_app_secret'];
+            $info['mch_id'] = $wxpay['js_mch_id'];
+            $info['key'] = $wxpay['js_key'];
+            $model = new \api\js\model\JsCourseOrderModel();
+            $booy = '购买视频课程';
+            $order_info = $model::get($id);
+            if (!$order_info) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单不存在'];
+            }
+            if ($order_info['status'] != 0) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单已支付'];
+            }
+            break;
+        case 2:
+            $info['appid'] = $wxpay['js_appid'];
+            $info['app_secret'] = $wxpay['js_app_secret'];
+            $info['mch_id'] = $wxpay['js_mch_id'];
+            $info['key'] = $wxpay['js_key'];
+            $booy = '购买商品';
+            $model = new \api\js\model\GoodsOrderModel();
+            $order_info = $model::get($id, ['seckill']);
+            if (!$order_info) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单不存在'];
+            }
+            if ($order_info['status'] != 0) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单已支付'];
+            }
+
+            $up['pay_price'] = $order_info['pay_price'];
+
+            if ($order_info->seckill) {
+                if ($order_info->seckill->end_time < time()) {
+                    $up['pay_price'] = round($order_info['price'] * $order_info['num'], 2);
+                }
+            }
+
+            $model->allowField(true)->isUpdate(true)->save($up, ['id' => $id]);
+            break;
+        case 3:
+            $booy = '呼叫服务';
+            $info['appid'] = $wxpay['appid'];
+            $info['app_secret'] = $wxpay['app_secret'];
+            $info['mch_id'] = $wxpay['mch_id'];
+            $info['key'] = $wxpay['key'];
+            $model = new \api\js\model\JsOrderModel();
+            $order_info = $model::get($id);
+            if (!$order_info) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单不存在'];
+            }
+            if ($order_info['status'] != 0) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单已支付'];
+            }
+            if ($order_info['user_discount_id']) {
+                $userDiscountInfo = Db::name('user_discount')->where('id', $order_info['user_discount_id'])->find();
+                if ($userDiscountInfo['past_time'] < time()) {
+                    Db::name('user_discount')->where('id', $order_info['user_discount_id'])->update(['status' => 2]);
+                    $model->allowField(true)->isUpdate(true)->save(['pay_price' => $order_info['price']], ['id' => $id]);
+                }
+                if ($userDiscountInfo['project_id'] != 0) {
+                    if ($userDiscountInfo['project_id'] != $order_info['project_id']) {
+                        $model->allowField(true)->isUpdate(true)->save(['pay_price' => $order_info['price']], ['id' => $id]);
+                    }
+                }
+            }
+            break;
+        case 100: //加钟支付
+            $booy = '服务加钟支付';
+            $info['appid'] = $wxpay['appid'];
+            $info['app_secret'] = $wxpay['app_secret'];
+            $info['mch_id'] = $wxpay['mch_id'];
+            $info['key'] = $wxpay['key'];
+            $model = new \api\js\model\JsOrderAddtimeModel();
+            $order_info = $model::get($id);
+            if (!$order_info) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单不存在'];
+            }
+            if ($order_info['status'] != 0) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单已支付'];
+            }
+
+            break;
+    }
+    if (!$model) {
+        return ['return_code' => 'FAIL', 'return_msg' => '参数异常'];
+    }
+    $notify_url = "http://{$_SERVER['SERVER_NAME']}/api/js/paynotify/wx/type/" . $type;
+    $url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
+    $pay_data['trade_type'] = 'APP';
+    $pay_data['appid'] = $info['appid'];
+    $pay_data['mch_id'] = $info['mch_id'];
+    $pay_data['nonce_str'] = cmf_random_string(32);
+    $pay_data['body'] = $booy;
+    $pay_data['out_trade_no'] = $model::get($id)['order_sn'];
+    $pay_data['total_fee'] = $model::get($id)['pay_price'] * 100;
+    $pay_data['spbill_create_ip'] = get_client_ip();
+    $pay_data['notify_url'] = $notify_url;
+    $pay_data['sign_type'] = 'MD5';
+    ksort($pay_data);
+    $str = '';
+    foreach ($pay_data as $k => $v) {
+        $str .= $k . '=' . $v . '&';
+    }
+    $str .= 'key=' . $info['key'];
+    $pay_data['sign'] = strtoupper(md5($str)); //加密
+    $str = array_toxml($pay_data);
+    $result = curl_post_ssl1($url, $str);
+    $res_array = xml_toarray($result);
+
+    if ($res_array['return_code'] == 'SUCCESS' && $res_array['result_code'] == 'SUCCESS') {
+        $resl['appid'] = $res_array['appid'];
+        $resl['prepayid'] = $res_array['prepay_id'];
+        $resl['partnerid'] = $res_array['mch_id'];
+        $resl['noncestr'] = cmf_random_string(32);
+        $resl['timestamp'] = time();
+        $resl['package'] = 'Sign=WXPay';
+        ksort($resl);
+        $str = '';
+        foreach ($resl as $k => $v) {
+            $str .= $k . '=' . $v . '&';
+        }
+        //拼接API密钥
+        $str .= 'key=' . $info['key'];
+
+
+        $resl['sign'] = strtoupper(md5($str)); //加密
+        return $resl;
+    } else {
+        return $res_array;
+    }
+}
+
+function aly_pay($id, $type)
+{
+    //http://{$_SERVER['SERVER_NAME']}/api/js/pay_notify/aliy
+    $model = '';
+    $booy = '';
+    $alipay = cmf_get_option('alipay');
+    $aop = new AopCertClient();
+    $aop->appId = $alipay['js_app_id'];
+
+    $aop->apiVersion = '2.0';
+    $aop->signType = 'RSA2';
+    $aop->postCharset = 'utf-8';
+    $PrivateKey = cmf_get_file_download_url($alipay['Apply_the_secret_key_file']);
+    $PrivateKey = str_replace('https', 'http', $PrivateKey);
+    //$aop->rsaPrivateKeyFilePath =  cmf_get_file_download_url($alipay['Apply_the_secret_key_file']);
+    $aop->rsaPrivateKeyFilePath = $PrivateKey;
+    $appCertPath = cmf_get_file_download_url($alipay['Applied_public_Key_certificate']);
+    $alipayCertPath = cmf_get_file_download_url($alipay['Pay_alipay_Public_key_certificate']);
+    $rootCertPath = cmf_get_file_download_url($alipay['Alipay_Root_certificate']);
+    switch ($type) {
+        case 1:
+            $appCertPath = cmf_get_file_download_url($alipay['js_Applied_public_Key_certificate']);
+            $alipayCertPath = cmf_get_file_download_url($alipay['js_Pay_alipay_Public_key_certificate']);
+            $rootCertPath = cmf_get_file_download_url($alipay['js_Alipay_Root_certificate']);
+            break;
+        case 2:
+            $appCertPath = cmf_get_file_download_url($alipay['js_Applied_public_Key_certificate']);
+            $alipayCertPath = cmf_get_file_download_url($alipay['js_Pay_alipay_Public_key_certificate']);
+            $rootCertPath = cmf_get_file_download_url($alipay['js_Alipay_Root_certificate']);
+            break;
+    }
+    $appCertPath = str_replace('https', 'http', $appCertPath);
+    $rootCertPath = str_replace('https', 'http', $rootCertPath);
+    $alipayCertPath = str_replace('https', 'http', $alipayCertPath);
+    $aop->appCertSN = $aop->getCertSN($appCertPath); //调用getCertSN获取证书序列号
+    $aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);
+    $aop->alipayCertSN = $alipayCertPath;
+    $requrst = new AlipayTradeAppPayRequest();
+
+    switch ($type) {
+        case 1:
+            $model = new \api\js\model\JsCourseOrderModel();
+            $booy = '购买视频课程';
+            $order_info = $model::get($id);
+            if (!$order_info) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单不存在'];
+            }
+            if ($order_info['status'] != 0) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单已支付'];
+            }
+            break;
+        case 2:
+
+            $booy = '购买商品';
+            $model = new \api\js\model\GoodsOrderModel();
+            $order_info = $model::get($id, ['seckill']);
+            if (!$order_info) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单不存在'];
+            }
+            if ($order_info['status'] != 0) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单已支付'];
+            }
+
+            $up['pay_price'] = $order_info['pay_price'];
+
+            if ($order_info->seckill) {
+                if ($order_info->seckill->end_time < time()) {
+                    $up['pay_price'] = round($order_info['price'] * $order_info['num'], 2);
+                }
+            }
+
+            $model->allowField(true)->isUpdate(true)->save($up, ['id' => $id]);
+            break;
+        case 3:
+            $aop->appId = $alipay['app_id'];
+            $booy = '呼叫服务';
+
+            $model = new \api\js\model\JsOrderModel();
+            $order_info = $model::get($id);
+            if (!$order_info) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单不存在'];
+            }
+            if ($order_info['status'] != 0) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单已支付'];
+            }
+            if ($order_info['user_discount_id']) {
+                $userDiscountInfo = Db::name('user_discount')->where('id', $order_info['user_discount_id'])->find();
+                if ($userDiscountInfo['past_time'] < time()) {
+                    Db::name('user_discount')->where('id', $order_info['user_discount_id'])->update(['status' => 2]);
+                    $model->allowField(true)->isUpdate(true)->save(['pay_price' => $order_info['price']], ['id' => $id]);
+                }
+                if ($userDiscountInfo['project_id'] != 0) {
+                    if ($userDiscountInfo['project_id'] != $order_info['project_id']) {
+                        $model->allowField(true)->isUpdate(true)->save(['pay_price' => $order_info['price']], ['id' => $id]);
+                    }
+                }
+            }
+
+            break;
+        case 100: //加钟支付
+
+            $aop->appId = $alipay['app_id'];
+            $booy = '服务加钟';
+            $model = new \api\js\model\JsOrderAddtimeModel();
+            $order_info = $model::get($id);
+            if (!$order_info) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单不存在'];
+            }
+            if ($order_info['status'] != 0) {
+                return ['return_code' => 'FAIL', 'return_msg' => '订单已支付'];
+            }
+
+            break;
+    }
+    if (!$model) {
+        return ['return_code' => 'FAIL', 'return_msg' => '参数异常'];
+    }
+
+    $biz_array['out_trade_no'] = $model::get($id)['order_sn']; //商户网站唯一订单号;
+    $biz_array['total_amount'] = $model::get($id)['pay_price'];
+    $biz_array['body'] = $booy; //
+    $biz_array['subject'] = $booy; //
+    $biz_array['product_code'] = 'QUICK_MSECURITY_PAY';
+    $data['biz_content'] = json_encode($biz_array, JSON_UNESCAPED_UNICODE);
+    $notify_url = "http://{$_SERVER['SERVER_NAME']}/api/js/paynotify/aliy/type/" . $type;
+    $requrst->setNotifyUrl($notify_url);
+    $requrst->setBizContent($data['biz_content']);
+    $result = $aop->sdkExecute($requrst);
+    //  dump($result);
+    return $result;
+}
+
+
+function balance_pay($id, $type)
+{
+    $model = '';
+    $booy = '';
+    switch ($type) {
+        case 1:
+            Db::startTrans();
+            try {
+                $model = new \api\js\model\JsCourseOrderModel();
+                $booy = '购买视频课程';
+                $order_info = $model::get($id);
+                if ($order_info['status'] != 0) {
+                    return '订单已支付';
+                }
+                Db::name('user')->where('id', $order_info['user_id'])->setDec('balance', $order_info['pay_price']);
+                $log['user_id'] = $order_info['user_id'];
+                $log['money'] = -$order_info['pay_price'];
+                $log['type'] = 3;
+                $log['remark'] = $booy;
+                $log['add_time'] = time();
+                $log['obj_id'] = $id;
+                Db::name('user_money_log')->insert($log);
+                $up['status'] = 1;
+                $up['pay_time'] = time();
+                $up['pay_type'] = '余额支付';
+                $model->allowField(true)->isUpdate(true)->save($up, ['id' => $id]);
+
+                Db::commit();
+                return true;
+            } catch (ErrorException $e) {
+                Db::rollback();
+                return '支付失败';
+            }
+
+
+            break;
+        case 2:
+            Db::startTrans();
+            try {
+                $booy = '购买商品';
+                $model = new \api\js\model\GoodsOrderModel();
+
+                $order_info = $model::get($id, ['seckill']);
+                if ($order_info['status'] != 0) {
+                    return '订单已支付';
+                }
+
+                $up['pay_price'] = $order_info['pay_price'];
+                if ($order_info->seckill) {
+                    if ($order_info->seckill->end_time < time()) {
+                        $up['pay_price'] = round($order_info['price'] * $order_info['num'], 2);
+                    }
+                }
+                $user_balance = UserModel::get($order_info['user_id'])['balance'];
+                if ($user_balance < $up['pay_price']) {
+                    return '余额不足!';
+                }
+                $up['status'] = 1;
+                $up['pay_time'] = time();
+                $up['pay_type'] = '余额支付';
+                $model->allowField(true)->isUpdate(true)->save($up, ['id' => $id]);
+                $log['user_id'] = $order_info['user_id'];
+                $log['money'] = -$up['pay_price'];
+                $log['type'] = 3;
+                $log['remark'] = $booy;
+                $log['add_time'] = time();
+                $log['obj_id'] = $id;
+                Db::name('user_money_log')->insert($log);
+                $log1['admin_id'] = $order_info['user_id'];
+                $log1['action_time'] = date('Y-m-d H:i:s');
+                $log1['obj_id'] = $id;
+                $log1['remark'] = '订单支付';
+                Db::name('goods_order_action_log')->insert($log1);
+                Db::name('user')->where('id', $order_info['user_id'])->setDec('balance', $up['pay_price']);
+                Db::commit();
+                return true;
+            } catch (ErrorException $e) {
+                Db::rollback();
+                return '支付失败';
+            }
+
+            break;
+        case 3:
+            $booy = '呼叫服务';
+            $model = new \api\js\model\JsOrderModel();
+            break;
+    }
+    if (!$model) {
+        return '支付类型错误!';
+    }
+}
+
+
+/**
+ * @param $order_id
+ * @param $type 1下单分销 2接单分销
+ */
+function fenxiao($order_id, $type)
+{
+
+    $orderInfo = \api\js\model\JsOrderModel::get($order_id);
+    $userModel = new UserModel();
+    if ($type == 1) {
+
+
+        $field = 'user_id';
+        $log['remark'] = '好友下单';
+        $price = $orderInfo['price'];
+        $user_info = UserModel::get($orderInfo['user_id']);
+        if (empty($user_info['district_id'])) {
+            $mergerName = '中国,' . $orderInfo['province'] . ',' . $orderInfo['city'] . ',' . $orderInfo['district'];
+            $reginfo = Db::name('region')->where("mergerName='$mergerName'")->find();
+            $user_info['district_id'] = $reginfo['id'];
+        }
+        $agency_info = \api\js\model\AgencyModel::where(['district_id' => $user_info['district_id'], 'renk_id' => 2])->find();
+        $agency_info_id = $agency_info['id'];
+        $user_agency_id = Db::name('user')->where(function ($query) use ($agency_info_id) {
+            $query->where('agency_id', $agency_info_id);
+            $query->whereOr('agency_id', 'like', $agency_info_id . ',%');
+            $query->whereOr('agency_id', 'like', '%,' . $agency_info_id);
+            $query->whereOr('agency_id', 'like', '%,' . $agency_info_id . ',%');
+        })->value('id');
+        $user_id = $orderInfo['user_id'];
+        $money = round($price * $agency_info['ratio'] / 100, 2);
+        if ($money > 0 && $user_agency_id) {
+            $log['user_id'] = $user_agency_id;
+            $log['money'] = $money;
+            $log['type'] = 5;
+            $log['add_time'] = time();
+            $log['obj_id'] = $order_id;
+            $log['is_type'] = $type;
+            $log['xia_user_id'] = $user_id;
+            $log['remark'] = '用户下单,区代提成';
+            Db::name('user_money_log')->insert($log);
+            UserModel::where('id', $user_agency_id)->setInc('balance', $log['money']);
+        }
+
+        // 检测是否推广分佣
+        if ($orderInfo['type'] == '3') return false;
+
+        // $user_parent_id = $userModel::get($user_id)['parent_id'];
+        // $user_parent_id1 = $userModel::get($user_id)['parent_id1'];
+        $user_parent_id = $user_info['parent_id'];
+        $user_parent_id1 = $user_info['parent_id1'];
+
+        if ($user_parent_id) {
+            $user_parent_info = UserModel::get($user_parent_id);
+            $distributorInfo = Db::name('distributor')->where('id', $user_parent_info['distributor_id'])->find();
+
+
+            $money = round($price * $distributorInfo['yi_ratio'] / 100, 2);
+            if ($money > 0) {
+                $log['user_id'] = $user_parent_id;
+                $log['money'] = $money;
+                $log['type'] = 3;
+                $log['add_time'] = time();
+                $log['obj_id'] = $order_id;
+                $log['is_type'] = $type;
+                $log['xia_user_id'] = $user_id;
+                $log['yue'] = round($user_parent_info['balance'] + $money, 2);
+                $log['remark'] = '一级好友下单提成';
+                Db::name('user_money_log')->insert($log);
+                UserModel::where('id', $user_parent_id)->setInc('balance', $log['money']);
+            }
+        }
+        if ($user_parent_id1) {
+            $user_parent_info1 = UserModel::get($user_parent_id1);
+            $distributorInfo1 = Db::name('distributor')->where('id', $user_parent_info1['distributor_id'])->find();
+            $money = round($price * $distributorInfo1['er_ratio'] / 100, 2);
+            if ($money > 0) {
+                $log['user_id'] = $user_parent_id1;
+                $log['money'] = $money;
+                $log['type'] = 4;
+                $log['add_time'] = time();
+                $log['obj_id'] = $order_id;
+                $log['xia_user_id'] = $user_id;
+                $log['is_type'] = $type;
+                $log['yue'] = round($user_parent_info1['balance'] + $money, 2);
+                $log['remark'] = '二级好友下单提成';
+                Db::name('user_money_log')->insert($log);
+                UserModel::where('id', $user_parent_id1)->setInc('balance', $log['money']);
+            }
+        }
+    } else {
+        if (!$orderInfo['jiedan_js_id']) {
+            return false;
+        }
+
+        // 检测是否推广分佣
+        if ($orderInfo['type'] == '3') return false;
+
+        $user_id = Db::name('js')->where('id', $orderInfo['jiedan_js_id'])->value('user_id');
+        $log['remark'] = '好友接单';
+        // $price = $orderInfo['order_price'];
+        $price = $orderInfo['price'];
+        $user_info = $userModel::get($user_id);
+        // $user_parent_id = $userModel::get($user_id)['parent_id'];
+        // $user_parent_id1 = $userModel::get($user_id)['parent_id1'];
+        $user_parent_id = $user_info['parent_id'];
+        $user_parent_id1 = $user_info['parent_id1'];
+
+        if ($user_parent_id) {
+
+            // 检测分佣是否完结
+            $obtainedMoney = Db::name('user_money_log')->where('user_id', $user_parent_id)->where('xia_user_id', $user_id)->where('type', 3)->where('is_type', 2)->sum('money');
+            if ($obtainedMoney >= 2000) return false;
+            $user_parent_info = UserModel::get($user_parent_id);
+            //    $distributorInfo = Db::name('distributor')->where('id',$user_parent_info['distributor_id'])->find();
+            $money = round($price * 1 / 100, 2);
+            if ($money > 0) {
+                $log['user_id'] = $user_parent_id;
+                $log['money'] = $money;
+                $log['type'] = 3;
+                $log['add_time'] = time();
+                $log['obj_id'] = $order_id;
+                $log['is_type'] = $type;
+                $log['xia_user_id'] = $user_id;
+                $log['yue'] = round($user_parent_info['balance'] + $money, 2);
+                Db::name('user_money_log')->insert($log);
+                UserModel::where('id', $user_parent_id)->setInc('balance', $log['money']);
+            }
+        }
+        // if ($user_parent_id1) {
+        //     $user_parent_info1 = UserModel::get($user_parent_id1);
+        //     // $distributorInfo1 = Db::name('distributor')->where('id', $user_parent_info1['distributor_id'])->find();
+        //     $money =  round($price * 1 / 100, 2);
+        //     if ($money > 0) {
+        //         $log['user_id'] = $user_parent_id1;
+        //         $log['money'] = $money;
+        //         $log['type'] = 4;
+        //         $log['add_time'] = time();
+        //         $log['obj_id'] = $order_id;
+        //         $log['xia_user_id'] = $user_id;
+        //         $log['is_type'] = $type;
+        //         $log['yue'] = round($user_parent_info1['balance'] + $money, 2);
+        //         Db::name('user_money_log')->insert($log);
+        //         UserModel::where('id', $user_parent_id1)->setInc('balance', $log['money']);
+        //     }
+        // }
+    }
+
+
+    /******************************分销商的分金**********************************************/
+}
+
+
+/**
+ * 获取可以接单的技师id
+ */
+function get_js_ids($ids, $lat = '', $lng = '')
+{
+    //        $JsTimeModel = new JsTimeModel();
+    //
+    //        $week = date('w',time());
+    //        $js_time_list = $JsTimeModel::where(function ($query) use ($ids){
+    //            if(is_array($ids) && count($ids) > 0){
+    //                $query->where('js_id','in',$ids);
+    //            }
+    //        })->field('js_id,times,weeks')->select()->each(function ($js_time_list) use ($week){
+    //            if($week){
+    //                if(in_array($week,$js_time_list['weeks'])){
+    //                    $result =  $js_time_list;
+    //                    return $result;
+    //                }
+    //            }
+    //        });
+    //
+    //        $js_ids = [];
+    //
+    //        foreach ($js_time_list as $value){
+    //            foreach ($value['times'] as $v){
+    //                if(strtotime($v['js_end_time']) > strtotime(date('H:i'))){
+    //                    if(!in_array($value['js_id'],$js_ids)){
+    //                        array_push($js_ids,$value['js_id']);
+    //                    }
+    //                }
+    //            }
+    //        }
+
+
+    $JsSiteModel = new JsSiteModel();
+    $js_site = $JsSiteModel::where(function ($query) use ($ids) {
+        if ($ids) {
+            $query->where('js_id', 'in', $ids);
+        }
+    })->select();
+    $distance = cmf_get_option('distance')['distance'];
+
+    $js_new_ids = [];
+    if ($js_site) {
+        foreach ($js_site as $value) {
+            $distance1 = GetDistance($lat, $lng, $value['lat'], $value['lng'], 2, 2);
+            if ($distance >= $distance1) {
+                if (!in_array($value['js_id'], $js_new_ids)) {
+                    array_push($js_new_ids, $value['js_id']);
+                }
+            }
+        }
+    }
+
+    return $js_new_ids;
+}
+
+function get_js_score($js_id)
+{
+    $score = Db::name('js_score')->where('status', 1)->where('js_id', $js_id)->sum('score');
+    $count = Db::name('js_score')->where('status', 1)->where('js_id', $js_id)->count();
+    $new_score = 0;
+    if ($score > 0 && $count > 0) {
+        $new_score = $score / $count;
+    }
+    return $new_score;
+}
+
+/**
+ * 获取可接项目订单id
+ */
+function get_js_order_ids($js_id, $type = 1, $page = 1, $category_id, $distance_filter = true)
+{
+    $JsOrderModel = new \api\js\model\JsOrderModel();
+    $js_order_ids = [];
+    $project_new_ids = [];
+    $where['js_delete'] = 1;
+    $js_project_relevancy_where['js_id'] = $js_id;
+    $js_project_relevancy_where['status'] = 1;
+    if ($category_id) {
+        $project_ids1 = Db::name('js_project_category_relevancy')->where('category_id', $category_id)->field('project_id')->select();
+        $project_ids2 = [];
+        foreach ($project_ids1 as $vo) {
+            $project_ids2[] = $vo['project_id'];
+        }
+        $js_project_relevancy_where['project_id'] = $project_ids2;
+    }
+    $project_ids = Db::name('js_project_relevancy')->where($js_project_relevancy_where)->field('project_id')->select();
+
+    $order_new_ids = [];
+    $order_ids = Db::name('js_shield_log')->where('js_id', $js_id)->field('order_id')->select();
+    foreach ($order_ids as $vo) {
+        $order_new_ids[] = $vo['order_id'];
+    }
+
+    foreach ($project_ids as $vo) {
+        $project_new_ids[] = $vo['project_id'];
+    }
+
+    switch ($type) {
+        case 1:
+            $order_list = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(function ($query) use ($js_id) {
+                $query->where('jiedan_js_id', $js_id);
+                //   $query->whereOR('jiedan_js_id',0);
+            })
+                ->where('id', 'not in', $order_new_ids)->where($where)->page($page, 5)->field('id,lat,lng')->order('id', 'desc')->select();
+            break;
+        case 2:
+            $order_list = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(function ($query) use ($js_id) {
+                $query->where('status', 1);
+                $query->where('jiedan_js_id', $js_id);
+            })->where('id', 'not in', $order_new_ids)->where($where)->page($page, 5)->field('id,lat,lng')->order('id', 'desc')->select();
+            break;
+        case 3:
+            $order_list = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(['jiedan_js_id' => $js_id, 'status' => 2])->where('id', 'not in', $order_new_ids)->where($where)->page($page, 5)->field('id,lat,lng')->order('id', 'desc')->select();
+            break;
+        case 4:
+            $order_list = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(['jiedan_js_id' => $js_id, 'status' => 6])->where('id', 'not in', $order_new_ids)->where($where)->page($page, 5)->field('id,lat,lng')->select();
+            break;
+        case 5:
+            $order_list = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(['jiedan_js_id' => $js_id, 'status' => 4])->where('id', 'not in', $order_new_ids)->page($page, 5)->where($where)->field('id,lat,lng')->order('id', 'desc')->select();
+            break;
+
+        case 6:
+            $order_list = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(['jiedan_js_id' => $js_id, 'status' => 3])->where('id', 'not in', $order_new_ids)->where($where)->page($page, 5)->field('id,lat,lng')->order('id', 'desc')->select();
+            break;
+        case 7:
+            $order_list = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(['jiedan_js_id' => $js_id, 'status' => 5])->where('id', 'not in', $order_new_ids)->where($where)->page($page, 5)->field('id,lat,lng')->order('id', 'desc')->select();
+            break;
+        case 8:
+            $order_list = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(['jiedan_js_id' => 0, 'status' => 1])->where('id', 'not in', $order_new_ids)->where($where)->page($page, 5)->field('id,lat,lng')->order('id', 'desc')->select();
+            break;
+    }
+
+    $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
+    $distance = cmf_get_option('distance')['distance'];
+
+    foreach ($order_list as $value) {
+
+        $distance1 = GetDistance($value['lat'], $value['lng'], $js_site_info['lat'], $js_site_info['lng'], 2, 2); //value['lat'],/$value['lng'],$js_site_info['lat'],$js_site_info['lng'],2,2);
+
+        if ($distance_filter && $distance >= $distance1 || !$distance_filter) {
+            $js_order_ids[] = $value['id'];
+        }
+    }
+
+
+    return $js_order_ids;
+}
+
+
+function getdistrict($lng, $lat)
+{
+    $url = 'https://restapi.amap.com/v3/geocode/regeo?parameters&location=' . $lng . ',' . $lat . '&key=3c813127122a372b7b0a6f0db7eb911e';
+    $res = cmf_curl_get($url);
+    $res_array = json_decode($res, true);
+    return $res_array;
+}
+
+function get_user_and_userjs($user_id, $district_id = '', $city_id = '', $renk_id = '')
+{
+    $UserModel = new UserModel();
+    $agencyModel = new \api\js\model\AgencyModel();
+    $agency_id = $UserModel::get($user_id)['agency_id'];
+    $agency_ids = explode(',', $agency_id);
+    $user_ids_new = [];
+    $user_js_ids_new = [];
+    $agency_list = $agencyModel::where('id', 'in', $agency_ids)->select()->toArray();
+
+
+    if ($renk_id) {
+        if ($renk_id == 1) {
+            $where['city_id'] = $city_id;
+        } else {
+            $where['district_id'] = $district_id;
+        }
+        $where['user_type'] = 2;
+        $user_ids = $UserModel::where($where)->field('id')->select();
+        foreach ($user_ids as $vo) {
+            $user_ids_new[] = $vo['id'];
+        }
+        $where['user_type'] = 3;
+        $user_ids = $UserModel::where($where)->field('id')->select();
+        foreach ($user_ids as $vo) {
+            $user_js_ids_new[] = $vo['id'];
+        }
+    } else {
+        foreach ($agency_list as $value) {
+            $where['user_type'] = 2;
+            if ($value['renk_id'] == 1) {
+                $where1['city_id'] = $value['city_id'];
+                $user_ids = $UserModel::where($where1)->field('id')->select();
+
+                foreach ($user_ids as $vo) {
+                    array_push($user_ids_new, $vo['id']);
+                }
+            }
+            if ($value['renk_id'] == 2) { // 区级代理
+                $where['district_id'] = $value['district_id'];
+                $user_ids = $UserModel::where($where)->field('id')->select();
+
+                foreach ($user_ids as $vo) {
+                    array_push($user_ids_new, $vo['id']);
+                }
+            }
+
+
+            $where['user_type'] = 3;
+            if ($value['renk_id'] == 1) {
+                $where1['city_id'] = $value['city_id'];
+                $user_ids = $UserModel::where($where1)->field('id')->select();
+
+                foreach ($user_ids as $vo) {
+                    array_push($user_ids_new, $vo['id']);
+                }
+            }
+            if ($value['renk_id'] == 2) { // 区级代理
+                $where['district_id'] = $value['district_id'];
+                $user_ids = $UserModel::where($where)->field('id')->select();
+
+                foreach ($user_ids as $vo) {
+                    array_push($user_js_ids_new, $vo['id']);
+                }
+            }
+        }
+    }
+
+
+    $user['user_ids'] = $user_ids_new;
+    $user['user_js_ids'] = $user_js_ids_new;
+    return $user;
+}

+ 9 - 0
api/js/config/database.php

@@ -0,0 +1,9 @@
+<?php
+/**
+ * 配置文件
+ */
+
+return [
+    
+    'auto_timestamp' => true,
+];

+ 55 - 0
api/js/controller/DistributorController.php

@@ -0,0 +1,55 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-10-10
+     * Time: 15:57
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\DistributorLogModel;
+    use api\js\model\DistributorModel;
+    use cmf\controller\RestUserBaseController;
+
+    class DistributorController extends RestUserBaseController
+    {
+        public function getList()
+        {
+            $DistributorModel = new DistributorModel();
+            $list =  $DistributorModel::where('id','>',1)->select();
+            $this->success('ok',$list);
+        }
+        
+        /**
+         * 申请分销商
+         */
+        
+        public function addPost()
+        {
+            $data['user_id'] = $this->getUserId();
+            $data['distributor_id'] = $this->request->param('distributor_id');
+            $data['name'] = $this->request->param('name');
+            $data['mobile'] = $this->request->param('mobile');
+            $data['province'] = $this->request->param('province');
+            $data['city'] = $this->request->param('city');
+            $data['district'] = $this->request->param('district');
+            $DistributorLogModel = new DistributorLogModel();
+            $info = $DistributorLogModel::where(['user_id'=>$data['user_id'],'distributor_id'=>$data['distributor_id']])->find();
+            if($info){
+                if($info['chuli_status'] == 1){
+                    $this->error('您已申请该分销商,不必重复申请');
+                }else{
+    
+                    $DistributorLogModel->allowField(true)->isUpdate(true)->save($data,['id'=>$info['id']]);
+                }
+            }else {
+    
+                $DistributorLogModel->allowField(true)->isUpdate(false)->save($data);
+            }
+         
+            $this->success('申请成功');
+        }
+        
+    }

+ 147 - 0
api/js/controller/GoodsOrderController.php

@@ -0,0 +1,147 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-23
+     * Time: 13:45
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\GoodsModel;
+    use api\js\model\GoodsOrderModel;
+    use api\js\model\GoodsSeckillModel;
+    use cmf\controller\RestUserBaseController;
+    use think\Db;
+
+    class GoodsOrderController extends RestUserBaseController
+    {
+    
+        /**
+         * 创建订单
+         */
+        public function addPost()
+        {
+            $user_id = $this->getUserId();
+            $data['user_id'] = $user_id;
+            $data['order_sn'] = cmf_get_order_sn();
+            $data['goods_id'] = $this->request->param('goods_id');
+            $data['seckill_id'] = $this->request->param('seckill_id');
+            $data['price'] = GoodsModel::get($data['goods_id'])['price'];
+            $data['num'] = $this->request->param('num');
+            if($data['seckill_id']){
+                $seckill_info = GoodsSeckillModel::get($data['seckill_id']);
+                if($seckill_info['end_time'] < time()){
+                    $this->error('秒杀活动已结束!');
+                }
+                $goods_ids = $seckill_info->goods()->alias('a')->column('a.id');
+                if(!in_array($data['goods_id'],$goods_ids)){
+                    $this->error('商品不在秒杀活动中!');
+                }
+                $data['seckill_price'] = GoodsModel::get($data['goods_id'])['seckill_price'];
+                $data['pay_price'] = round($data['seckill_price'] * $data['num'],2);
+            }else{
+                $data['pay_price'] = round($data['price'] * $data['num'],2);
+            }
+
+            $data['user_address_id'] = $this->request->param('user_address_id');
+            if(!$data['user_address_id']){
+                $this->error('请选择地址!');
+            }
+         
+          
+            
+            $GoodsOrderModel = new GoodsOrderModel();
+            $GoodsOrderModel->allowField(true)->isUpdate(false)->save($data);
+            $log['admin_id'] = $this->getUserId();
+            $log['action_time'] = date('Y-m-d H:i:s');
+            $log['obj_id'] = $GoodsOrderModel->id;
+            $log['remark'] = '用户创建订单';
+            Db::name('goods_order_action_log')->insert($log);
+            $this->success('创建订单成功',$GoodsOrderModel->id);
+        }
+    
+        
+        public function getlist()
+        {
+            $GoodsOrderModel = new GoodsOrderModel();
+            $status = $this->request->param('status');
+            $where['user_id'] = $this->getUserId();
+            $page = $this->request->param('page');
+            $id = $this->request->param('id');
+            if($id){
+                $where['id'] = $id;
+            }
+            if($status !== ''){
+                $where['status'] = $status;
+            }
+   
+            $list = $GoodsOrderModel::with(['goods','seckill'])->where($where)->order('id','desc')->page($page,20)->select()->each(function ($list){
+                $list->address = Db::name('user_address')->where('id',$list['user_address_id'])->find();
+                return $list;
+            });
+            $this->success('ok',$list);
+        }
+    
+        /**
+         * 支付订单
+         */
+        public function pay()
+        {
+            $id = $this->request->param('id');
+            $pay_type = $this->request->param('pay_type');
+            switch ($pay_type)
+            {
+                case 'alipay';
+                $res = aly_pay($id,2);
+                if(!empty($res['return_code'])){
+                    $this->error($res['return_msg']);
+                }else{
+                    $this->success('ok',$res);
+                }
+      
+                break;
+                case 'wxpay';
+                $res = wx_pay($id,2);
+             
+                if(!empty($res['result_code'])){
+                    if($res['err_code_des']){
+                        $this->error($res['err_code_des']);
+                    }else{
+                        $this->error($res['return_msg']);
+                    }
+                
+                }else{
+                    $this->success('ok',$res);
+                }
+                
+                break;
+                case 'balance';
+                $bool = balance_pay($id,2);
+                if($bool === true){
+                    $this->success('支付成功');
+                }else{
+                    $this->error($bool);
+                }
+                break;
+            }
+        }
+        
+        public function take()
+        {
+            $id = $this->request->param('order_id');
+            $GoodsOrderModel = new GoodsOrderModel();
+            $data['status'] = 3;
+            $data['take_time'] = time();
+            $GoodsOrderModel->allowField(true)->isUpdate(true)->save($data,['id'=>$id]);
+            $log['admin_id'] = cmf_get_current_admin_id();
+            $log['action_time'] = date('Y-m-d H:i:s');
+            $log['obj_id'] = $id;
+            $log['remark'] = '订单收货';
+            Db::name('goods_order_action_log')->insert($log);
+            $this->success('操作成功');
+        }
+        
+        
+    }

+ 170 - 0
api/js/controller/IndexController.php

@@ -0,0 +1,170 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-12
+     * Time: 9:33
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\JsModel;
+    use cmf\controller\RestBaseController;
+    use think\Db;
+    use think\Log;
+
+    class IndexController extends RestBaseController
+    {
+        public function index()
+        {
+            $navList = Db::name('index_nav')->where('pos',1)->order('list_order','asc')->select()->each(function ($navList){
+                $navList['icon'] = cmf_get_image_preview_url($navList['icon']);
+                return $navList;
+            });
+            $banner = Db::name('slide_item')->where('slide_id',1)->where('status',1)->order('list_order','asc')->select()->each(function ($banner){
+                $banner['image'] = cmf_get_image_preview_url($banner['image']);
+                return $banner;
+            });
+           
+            $lat = $this->request->param('lat',1);//维度
+            $lng = $this->request->param('lng',1);//经度
+            $lat = $lat > 1 ? $lat :37.475375;
+            $lng = $lng> 1 ? $lng :121.373573;
+       
+            $JsModel = new JsModel();
+            $jsList = $JsModel->getLits([],$lat,$lng);
+            $this->success('ok',['nav'=>$navList,'banner'=>$banner,'js'=>$jsList]);
+        }
+    
+        
+        
+        public function getRegion()
+        {
+            $parentId = $this->request->param('parentId');
+            $pdepth = $this->request->param('depth',1);
+            if($parentId){
+                $where['parentId'] = $parentId;
+            }
+      
+            $where['depth'] = $pdepth;
+            $list = Db::name('region')->where($where)->field('id,cityName')->select();
+            $this->success('ok',$list);
+        }
+        
+        public function getOut()
+        {
+            $list  = Db::name('project_out')->select();
+            $this->success('ok',$list);
+        }
+        
+        public function getWXLog()
+        {
+            $this->success('ok',1);
+        }
+        
+        public function getdow()
+        {
+            $info = cmf_get_option('dow');
+            $this->success('ok',$info);
+        }
+        
+        public function getKefu()
+        {
+            $info = Db::name('portal_post')->where('id',6)->find();
+            
+            $this->success('ok',$info['phone']);
+        }
+
+        public function bindWechat(){
+            $validate = new \think\Validate([
+                'mobile' => 'require',
+                'code' => 'require',
+                'openid' => 'require',
+            ]);
+            $validate->message([
+                'mobile.require' => '请输入您的手机号',
+                'code.require' => '验证码不能为空!',
+                'openid' => '微信授权失败!'
+            ]);
+    
+    
+            $data = $this->request->param();
+    
+            if (!$validate->check($data)) {
+                $this->error($validate->getError());
+            }
+            $type = $data['type'];
+    
+            unset($data['type']);
+            $findUserWhere = [];
+            if (cmf_check_mobile($data['mobile'])) {
+                $findUserWhere['mobile'] = $data['mobile'];
+            } else {
+                $this->error('手机号格式错误');
+            }
+            if ($type == 1) {
+                $findUserWhere['user_type'] = 2;
+            }
+            if ($type == 2) {
+                $findUserWhere['user_type'] = 3;
+            }
+    
+            $isExist = UserModel::name("user")->where('user_type', $findUserWhere['user_type'])
+                ->where('openid', $data['openid'])->count();
+    
+            if (!$isExist) {
+                $findUser = UserModel::name("user")->where($findUserWhere)->find();
+                if (empty($findUser)) {
+                    // 用户不存在
+                } else {
+                    if ($findUser->openid) {
+                        $this->error("账号已绑定其他微信!");
+                    }
+                    Db::name('user')->where('id', $findUser['id'])->update(['openid' => $data['openid']]);
+                }
+    
+    
+                if (empty($this->deviceType) && (empty($data['device_type']) || !in_array($data['device_type'], $this->allowedDeviceTypes))) {
+                    $this->error("请求错误,未知设备!");
+                } else if (!empty($data['device_type'])) {
+                    $this->deviceType = $data['device_type'];
+                }
+    
+                $findUserToken = Db::name("user_token")
+                    ->where('user_id', $findUser['id'])
+                    ->where('device_type', $this->deviceType)
+                    ->find();
+                $currentTime   = time();
+                $expireTime    = $currentTime + 24 * 3600 * 180;
+                $token         = md5(uniqid()) . md5(uniqid());
+                if (empty($findUserToken)) {
+                    $result = Db::name("user_token")->insert([
+                        'token'       => $token,
+                        'user_id'     => $findUser['id'],
+                        'expire_time' => $expireTime,
+                        'create_time' => $currentTime,
+                        'device_type' => $this->deviceType
+                    ]);
+                } else {
+                    $result = Db::name("user_token")
+                        ->where('user_id', $findUser['id'])
+                        ->where('device_type', $this->deviceType)
+                        ->update([
+                            'token'       => $token,
+                            'expire_time' => $expireTime,
+                            'create_time' => $currentTime
+                        ]);
+                }
+    
+                if (empty($result)) {
+                    $this->error("登录失败!");
+                }
+    
+                Db::name('user')->where('id', $findUser['id'])->update(['last_login_ip' => get_client_ip(), 'last_login_time' => time()]);
+                $this->success("登录成功!", ['token' => $token, 'id' => $findUser['id']]);
+            } else {
+                $this->error("微信已绑定其他账号!");
+            }
+        }
+    }

+ 25 - 0
api/js/controller/JsCategoryController.php

@@ -0,0 +1,25 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-17
+     * Time: 15:08
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\JsCategoryModel;
+    use cmf\controller\RestBaseController;
+
+    class JsCategoryController extends RestBaseController
+    {
+        public function getList()
+        {
+            $JsCategoryModel = new JsCategoryModel();
+            $list = $JsCategoryModel->getList();
+            $this->success('ok',$list);
+            
+        }
+        
+    }

+ 180 - 0
api/js/controller/JsController.php

@@ -0,0 +1,180 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-15
+     * Time: 11:25
+     */
+    
+    namespace api\js\controller;
+    
+    
+
+    use api\js\model\JsModel;
+    use api\js\model\JsOrderModel;
+    use api\js\model\JsScoreModel;
+    use cmf\controller\RestBaseController;
+    use think\Db;
+
+    class JsController extends RestBaseController
+    {
+        public function getList()
+        {
+            $lat = $this->request->param('lat',1);//维度
+            $lng = $this->request->param('lng',1);//经度
+            $lat = $lat > 1 ? $lat :37.475375;
+            $lng = $lng > 1 ? $lng :121.373573;
+            $jsModel = new JsModel();
+            $category_id = $this->request->param('category_id');
+            $project_id = $this->request->param('project_id');
+            $isss = $this->request->param('isss');
+            $isyy = $this->request->param('isyy');
+            $sex = $this->request->param('sex');
+            $page = $this->request->param('page',1);
+            $paixu = $this->request->param('paixu','asc');
+
+            $name = $this->request->param('name');
+            $js_ids = [];
+            $list = [];
+            if($category_id){
+                $js_id_list = Db::name('js_category_relevancy')->where('category_id',$category_id)->field('js_id')->select();
+                foreach ($js_id_list as $value){
+                    $js_ids[] = $value['js_id'];
+                }
+                if(!$js_ids){
+                    $this->success('ok',$list);
+                }
+            }
+            if($project_id){
+                $js_project_category_id = Db::name('js_project_category')->where('id',$project_id)->value('id');
+                $project_ids = Db::name('js_project_category_relevancy')->where('category_id',$js_project_category_id)->field('project_id')->select();
+                $project_new_ids = [];
+                foreach ($project_ids as $v){
+                    if(!in_array($v['project_id'],$project_new_ids)){
+                        array_push($project_new_ids,$v['project_id']);
+                    }
+                   
+                }
+                $js_id_list = Db::name('js_project_relevancy')->where('project_id','in',$project_new_ids)->field('js_id')->group('js_id')->select();
+                foreach ($js_id_list as $value){
+                    $js_ids[] = $value['js_id'];
+                }
+                if(!$js_ids){
+                    $this->success('ok',$list);
+                }
+            }
+            
+            
+            if($isss){
+                $js_id_list = JsModel::where(['is_real_time'=>1])->field('id')->select();
+                foreach ($js_id_list as $value){
+                    $js_ids[] = $value['id'];
+                }
+                if(!$js_ids){
+                    $this->success('ok',$list);
+                }
+            }
+            if($isyy){
+                $js_id_list = JsModel::where(['is_make'=>1])->field('id')->select();
+                foreach ($js_id_list as $value){
+                    $js_ids[] = $value['id'];
+                }
+                if(!$js_ids){
+                    $this->success('ok',$list);
+                }
+            }
+            if($sex){
+                $js_id_list = JsModel::where(['sex'=>$sex])->field('id')->select();
+                foreach ($js_id_list as $value){
+                    $js_ids[] = $value['id'];
+                }
+                if(!$js_ids){
+                    $this->success('ok',$list);
+                }
+            }
+            if($name){
+                $testModel = new JsModel();
+                $js_id_list = $testModel->where('name','like',"%{$name}%")->field('id')->select();
+                foreach ($js_id_list as $value){
+                    $js_ids[] = $value['id'];
+                }
+                if(!$js_ids){
+                    $this->success('ok',$list);
+                }
+            }
+            
+            $list = $jsModel->getLits($js_ids,$lat,$lng,$page);
+            $len = count($list);
+            for ($i = 1;$i < $len; $i++){
+                for ($k = 0; $k < $len-$i;$k++){
+                    if($paixu == 'asc' ||$paixu == ''){
+                        
+                        if($list[$k]['distance'] > $list[$k+1]['distance']){
+                            $array = $list[$k+1];
+                            $list[$k+1] = $list[$k];
+                            $list[$k] = $array;
+                        }
+                    }else{
+                        if($list[$k]['distance'] < $list[$k+1]['distance']){
+                            $array = $list[$k+1];
+                            $list[$k+1] = $list[$k];
+                            $list[$k] = $array;
+                        }
+                    }
+                }
+            }
+            for ($i = 1;$i < $len; $i++){
+                for ($k = 0; $k < $len-$i;$k++){
+                    if(!$list[$k]['shangban']){
+                            $array = $list[$k+1];
+                            $list[$k+1] = $list[$k];
+                            $list[$k] = $array;
+                        }
+                  
+                }
+            }
+            
+            $this->success('ok',$list);
+        }
+        
+        public function getInfo()
+        {
+            $id = $this->request->param('js_id');
+            if(!$id){
+                $this->error('参数错误!');
+            }
+            $lat = $this->request->param('lat');//维度
+            $lng = $this->request->param('lng');//经度
+            // $lat = $lat > 1 ? $lat :37.475375;
+            // $lng = $lng > 1 ? $lng :121.373573;
+            $district = $this->request->param('district');
+            $xlng = $this->request->param('xlng');
+            $xlat = $this->request->param('xlat');
+
+            if(!$lng && !$lat){
+                $this->success('没有获取经纬度',[]);
+            }
+            // else{
+            //     $res  = getdistrict($lng,$lat);
+            //     if($res['status'] == 0){
+            //         $this->success('经纬度不正确',[]);
+            //     }else{
+            //         $district = $res['regeocode']['addressComponent']['district'];
+            //     }
+            // }
+            $JsModel = new JsModel();
+            $info = $JsModel->getInfo($id,$lat,$lng,$district);
+            $info['phone'] = null;
+            $info['identity'] = [];
+            $this->success('ok',$info);
+        }
+        
+        public function getJsScore()
+        {
+            $js_id = $this->request->param('js_id');
+            $JsScoreModel = new JsScoreModel();
+            $page = $this->request->param('page',1);
+            $list = $JsScoreModel->getList($js_id,$page);
+            $this->success('ok',$list);
+        }
+    }

+ 40 - 0
api/js/controller/JsIndexController.php

@@ -0,0 +1,40 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-21
+     * Time: 9:08
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\GoodsModel;
+    use cmf\controller\RestBaseController;
+    use think\Db;
+    class JsIndexController extends RestBaseController
+    {
+        public function index()
+        {
+            $navList = Db::name('index_nav')->where('pos',2)->order('list_order','asc')->select()->each(function ($navList){
+                $navList['icon'] = cmf_get_image_preview_url($navList['icon']);
+                return $navList;
+            });
+            $banner = Db::name('slide_item')->where('slide_id',3)->where('status',1)->order('list_order','asc')->select()->each(function ($banner){
+                $banner['image'] = cmf_get_image_preview_url($banner['image']);
+                return $banner;
+            });
+            $banner2 = Db::name('slide_item')->where('slide_id',4)->where('status',1)->order('list_order','asc')->select()->each(function ($banner2){
+                $banner2['image'] = cmf_get_image_preview_url($banner2['image']);
+                return $banner2;
+            });
+            
+            $goodsModel = new GoodsModel();
+            $list = $goodsModel->where('is_sell',1)->order('list_order','asc')->field('id,icon')->select()->each(function ($list){
+                $list['icon'] = cmf_get_image_preview_url($list['icon']);
+            });
+            
+            $this->success('ok',['nav'=>$navList,'banner'=>$banner,'banner2'=>$banner2,'goods'=>$list]);
+        }
+        
+    }

+ 896 - 0
api/js/controller/JsOrderController.php

@@ -0,0 +1,896 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-07
+ * Time: 17:31
+ */
+
+namespace api\js\controller;
+
+
+use Aliyun\DySDKLite\SignatureHelper;
+use api\js\model\JsModel;
+use api\js\model\JsOrderGrabModel;
+use api\js\model\JsOrderModel;
+use api\js\model\JsProjectModel;
+use api\js\model\JsScoreModel;
+use api\js\model\JsTimeModel;
+use api\js\model\PortalPostModel;
+use api\js\model\UserDiscountModel;
+use api\js\model\UserModel;
+use Cassandra\Date;
+use cmf\controller\RestUserBaseController;
+use JPush\Client;
+use JPush\Exceptions\APIConnectionException;
+use think\Db;
+use think\facade\Log;
+
+class JsOrderController extends RestUserBaseController
+{
+    /**
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     * 呼叫服务前的信息加载
+     */
+    public function getUserInfo()
+    {
+        $user_id = $this->getUserId();
+        $UserModel = new UserModel();
+        $projectId = $this->request->param('project_id');
+        $storeId = $this->request->param('store_id');
+        $district = $this->request->param('district');
+        if (!$district) {
+            $this->error('获取地址失败!');
+        }
+        $where['user_id'] = $user_id;
+        $where['status'] = 0;
+        $UserDiscountModel = new UserDiscountModel();
+        $UserDiscountModel::where(function ($query) use ($user_id) {
+            $query->where('user_id', $user_id);
+            $query->where('status', 0);
+            $query->where('past_time', '<', time());
+        })->update(['status' => 2]);
+        $userInfo = $UserModel::where('id', $user_id)->field('mobile,balance')->find();
+        $userInfo['discount_count'] = $UserDiscountModel::where($where)->where(function ($query) use ($projectId) {
+            if ($projectId) {
+                $query->where('project_id', $projectId);
+                $query->whereOR('project_id', 0);
+            } else {
+                $query->where('project_id', 0);
+            }
+        })->where(function ($query) use ($storeId) {
+            if ($storeId) {
+                $query->where('store_id', $storeId);
+                $query->whereOR('store_id', 0);
+            } else {
+                $query->where('store_id', 0);
+            }
+        })->count();
+        $userInfo['discount_info'] = [];
+        $userDiscountInfo = $UserDiscountModel::with('jsDiscount')->where($where)->where(function ($query) use ($projectId) {
+            if ($projectId) {
+                $query->where('project_id', $projectId);
+                $query->whereOR('project_id', 0);
+            } else {
+                $query->where('project_id', 0);
+            }
+        })->where(function ($query) use ($storeId) {
+            if ($storeId) {
+                $query->where('store_id', $storeId);
+                $query->whereOR('store_id', 0);
+            } else {
+                $query->where('store_id', 0);
+            }
+        })->find();
+        if ($userDiscountInfo) {
+            $userInfo['discount_info'] = $userDiscountInfo;
+        }
+        $JsProjectModel = new JsProjectModel();
+        $projectInfo = $JsProjectModel->getInfo($projectId, $district);
+        $this->success('ok', ['user_info' => $userInfo, 'project_info' => $projectInfo]);
+    }
+
+    /**
+     * @throws \think\Exception
+     * 创建订单,并余额直接支付
+     */
+    public function addPost()
+    {
+        $data['user_id'] = $this->getUserId();
+        $badness_num = UserModel::get($data['user_id'])['badness_num'];
+        $user_nickname = UserModel::get($data['user_id'])['user_nickname'];
+        $info = cmf_get_option('duration');
+        if ($badness_num > $info['badness_num']) {
+            $this->error('您有不良行为,不可下单!');
+        }
+        $data['user_discount_id'] = $this->request->param('user_discount_id');
+        $data['service_id'] = $this->request->param('service_id');
+        if (!$data['service_id']) {
+            $this->error('服务区数据异常!');
+        }
+        $data['project_id'] = $this->request->param('project_id');
+        $info = Db::name('js_project_service_relevancy')->where(['project_id' => $data['project_id'], 'id' => $data['service_id']])->find();
+        if (!$info) {
+            $this->error('该区未开通服务,不可下单!');
+        }
+        $data['price'] = $info['price'];
+        $data['minute'] = $info['minute'];
+        $data['order_price'] = $info['order_price'];
+        $data['mobile'] = $this->request->param('mobile');
+
+        if (!cmf_check_mobile($data['mobile'])) {
+            $this->error('联系方式,手机号格式错误!');
+        }
+        $data['type'] = $this->request->param('type');
+
+        $appoint_time = $this->request->param('appoint_time');
+        if (!empty($appoint_time)) {
+            $data['appoint_time'] = strtotime($appoint_time);
+        }
+        $data['province'] = $this->request->param('province');
+        $data['city'] = $this->request->param('city');
+        $data['district'] = $this->request->param('district');
+        $data['address'] = $this->request->param('address');
+        $data['address1'] = $this->request->param('address1');
+        //            $url = 'https://restapi.amap.com/v3/geocode/geo?key=3c813127122a372b7b0a6f0db7eb911e&address='. $data['province'].$data['city'].$data['district'].$data['address'].'&city='.$data['city'];
+        //            $res = curl_post_ssl1($url,'');
+        //            $result = json_decode($res,true);
+        //            if($result['status'] == 0){
+        //                $this->error('地址有误!');
+        //            }
+        //            $lng_lat = $result['geocodes'][0]['location'];
+        //            $lng = explode(',',$lng_lat)[0];
+        //            $lat = explode(',',$lng_lat)[1];
+
+        $data['remark'] = $this->request->param('remark');
+        $data['jiedan_js_id'] = $this->request->param('jiedan_user_id');
+        $data['lat'] = $this->request->param('lat');
+        $data['lng'] = $this->request->param('lng');
+        $is_balance = $this->request->param('is_balance');
+        $data['order_sn'] = cmf_get_order_sn() . $this->getUserId();
+        $data['order_sole'] = md5(uniqid()) . md5(uniqid());
+        $voucher = 0;
+        if ($data['type'] == 1 && $data['jiedan_js_id']) {
+            $week = date('w', time());
+            $jsTime = JsTimeModel::where('js_id', $data['jiedan_js_id'])->find();
+            $shangban = 0;
+            if (in_array($week, $jsTime->weeks)) {
+                foreach ($jsTime->times as $vo) {
+                    if (strtotime($vo['js_end_time']) > strtotime(date('H:i'))) {
+                        $shangban = 1;
+                    }
+                    //  dump($vo['js_end_time']);
+                }
+            }
+            if (!$shangban) {
+                $this->error('技师休息中,不可下单');
+            }
+        }
+
+        // 加钟类型
+        if ($data['type'] == 3 && $data['jiedan_js_id']) {
+            $data['jiedan_time'] = time();
+            // 加钟技师佣金
+            $data['order_price'] = round($info['price'] * 70 / 100, 2);
+        }
+
+
+        if ($data['user_discount_id']) {
+            $userDiscountInfo = Db::name('user_discount')->where('id', $data['user_discount_id'])->find();
+            if ($userDiscountInfo['past_time'] < time()) {
+                $this->error('优惠券已过期!');
+            }
+            if ($userDiscountInfo['project_id'] != 0) {
+                if ($userDiscountInfo['project_id'] != $data['project_id']) {
+                    $this->error('优惠券不适用该项目!');
+                }
+            }
+            $voucher = Db::name('js_discount')->where('id', $userDiscountInfo['discount_id'])->value('voucher');
+        }
+        $data['voucher_price'] = $voucher;
+        if ($voucher > $data['price']) {
+            $this->error('优惠券不适用该项目!');
+        }
+        $data['pay_price'] = $data['price'] - $voucher;
+
+        $JsOrderModel = new JsOrderModel();
+        if ($is_balance == 1) {
+            $userDalance = UserModel::get($this->getUserId())['balance'];
+            if ($userDalance >= $data['pay_price']) {
+                UserModel::where('id', $this->getUserId())->setDec('balance', $data['pay_price']);
+                $data['status'] = 1;
+                $data['pay_time'] = time();
+                $data['pay_type'] = '余额支付';
+                $JsOrderModel->allowField(true)->isUpdate(false)->save($data);
+                $orderId = $JsOrderModel->id;
+                $erweiam = qeCode($data['order_sole'], $this->request->controller(), $orderId);
+                $JsOrderModel->allowField(true)->isUpdate(true)->save(['erweima' => $erweiam], ['id' => $orderId]);
+                $log['user_id'] = $this->getUserId();
+                $log['money'] = -$data['pay_price'];
+                $log['order_sn'] = $data['order_sn'];
+                $log['yue'] = $userDalance - $data['pay_price'];
+                $log['type'] = 1;
+                $log['remark'] = '呼叫服务余额支付';
+                $log['add_time'] = time();
+                $log['obj_id'] = $orderId;
+                if ($log['money'] != 0) {
+                    Db::name('user_money_log')->insert($log);
+                }
+
+                Db::name('js_project')->where('id', $data['project_id'])->setInc('sales_num', 1);
+                Db::name('user_discount')->where('id', $data['user_discount_id'])->update(['hours_time' => time(), 'status' => 1]);
+                if ($data['jiedan_js_id']) {
+                    $helper = new SignatureHelper();
+                    $alisms = cmf_get_option('alisms');
+                    $security = false;
+                    $accessKeyId = $alisms['access_key_id'];
+                    $accessKeySecret = $alisms['access_key_secret'];
+                    $js_mobile = UserModel::get(JsModel::get($data['jiedan_js_id'])['user_id'])['mobile'];
+                    $params["PhoneNumbers"] = $js_mobile;
+                    $params["SignName"] = '嘀咚点到';
+
+                    if ($data['type'] == 1) {
+                        $params["TemplateCode"] = 'SMS_204986367';
+                        $params['TemplateParam'] = array(
+                            "product" => JsProjectModel::get($data['project_id'])['name'],
+                        );
+                    } else if ($data['type'] == 2) {
+                        $params["TemplateCode"] = 'SMS_204986363';
+                        $params['TemplateParam'] = array(
+                            "time" => $appoint_time,
+                        );
+                    }
+
+
+                    if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
+                        $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
+                    }
+                    $content = $helper->request(
+                        $accessKeyId,
+                        $accessKeySecret,
+                        "dysmsapi.aliyuncs.com",
+                        array_merge($params, array(
+                            "RegionId" => "cn-hangzhou",
+                            "Action" => "SendSms",
+                            "Version" => "2017-05-25",
+                        )),
+                        $security
+                    );
+                }
+
+
+                $this->success('支付成功', $JsOrderModel->id);
+            } else {
+                $this->error('余额不足');
+            }
+        } else {
+            $JsOrderModel->allowField(true)->isUpdate(false)->save($data);
+            $orderId = $JsOrderModel->id;
+            $erweiam = qeCode($data['order_sole'], $this->request->controller(), $orderId);
+            $JsOrderModel->allowField(true)->isUpdate(true)->save(['erweima' => $erweiam], ['id' => $orderId]);
+            $this->success('创建订单成功', $JsOrderModel->id);
+        }
+    }
+
+    /**
+     * 用户结束服务
+     */
+    public function finish()
+    {
+        $ids = $this->request->param('order_id');
+        if (empty($ids)) {
+            $this->error('请选择要结束的订单');
+            exit();
+        }
+        $JsOrderModel = new \app\back\model\JsOrderModel();
+        JsOrderModel::where('id', $ids)->update(['finish_time' => time(), 'status' => 3]);
+        $list = $JsOrderModel::where('id', $ids)->field('id,user_id,jiedan_js_id,order_price')->select();
+        $info = cmf_get_option('jspus');
+        foreach ($list as $vo) {
+            $url = '/pages/ddxq/ddxq?id=' . $vo['id'];
+
+            $jsuserid = $js_user_id = Db::name('js')->where('id', $vo['jiedan_js_id'])->value('user_id');
+            \app\back\model\JsModel::where('id', $vo['jiedan_js_id'])->setInc('jiedan_num', 1);
+            if ($vo['order_price'] > 0) {
+                \app\back\model\UserModel::where('id', $jsuserid)->setInc('balance', $vo['order_price']);
+                $log['user_id'] = $jsuserid;
+                $log['money'] = $vo['order_price'];
+                $log['type'] = 8;
+                $log['remark'] = '完成服务获得金额';
+                $log['add_time'] = time();
+                $log['obj_id'] = $vo['id'];
+                if ($log['money'] != 0) {
+                    Db::name('user_money_log')->insert($log);
+                }
+            }
+
+            $js_user_id .= 'js';
+
+            $js_client = new Client($info['js_app_key'], $info['js_master_secret']);
+            $client = new Client($info['app_key'], $info['master_secret']);
+
+            $extras = [
+                'id' => $vo['id'],
+                'flag' => '用户',
+                'url' => $url
+            ];
+            $array = [
+                'extras' => $extras,
+            ];
+            $text = '服务已被您指定结束';
+            $platform = array('ios', 'android');
+            $user_id = $vo['user_id'] . 'js';
+
+            $client->push()
+                ->setPlatform($platform)
+                ->setNotificationAlert($text)
+                ->iosNotification($text, $array)
+                ->androidNotification($text, $array)
+                ->addAlias("{$user_id}")
+                ->send();
+            $extras = [
+                'id' => $vo['id'],
+                'flag' => '技师端',
+                'url' => $url
+            ];
+            $array = [
+                'extras' => $extras,
+            ];
+            $text = '服务已被用户指定结束';
+            $js_client->push()
+                ->setPlatform($platform)
+                ->setNotificationAlert($text)
+                ->iosNotification($text, $array)
+                ->androidNotification($text, $array)
+                ->addAlias("{$js_user_id}")
+                ->send();
+            $this->fenxiao($vo['id'], 1);
+            $this->fenxiao($vo['id'], 2);
+        }
+
+
+        $this->success('操作成功');
+    }
+
+    /**
+     * 其他方式支付订单
+     */
+    public function pay()
+    {
+        $id = $this->request->param('order_id');
+        $pay_type = $this->request->param('pay_type');
+
+        switch ($pay_type) {
+            case 'wxpay':
+                $res = wx_pay($id, 3);
+                if (!empty($res['return_code']) && $res['return_code'] == 'FAIL') {
+                    $this->error($res['return_msg']);
+                } else {
+                    $this->success('ok', $res);
+                }
+                break;
+            case 'alipay':
+                $res = aly_pay($id, 3);
+                if (!empty($res['return_code'])) {
+                    $this->error($res['return_msg']);
+                } else {
+                    $this->success('ok', $res);
+                }
+                break;
+            case 'balance':
+                $orderInfo = JsOrderModel::get($id);
+                $userDalance = UserModel::get($this->getUserId())['balance'];
+                if ($orderInfo['status'] != 0) {
+                    $this->error('订单已支付!');
+                }
+                if ($userDalance >= $orderInfo['pay_price']) {
+                    $res = UserModel::where('id', $this->getUserId())->setDec('balance', $orderInfo['pay_price']);
+                    if ($res) {
+                        $data['status'] = 1;
+                        $data['pay_time'] = time();
+                        $data['pay_type'] = '余额支付';
+                        JsOrderModel::where('id', $id)->update($data);
+                        $orderId = $id;
+                        $log['user_id'] = $orderInfo['user_id'];
+                        $log['money'] = -$orderInfo['pay_price'];
+                        $log['yue'] = $userDalance - $orderInfo['pay_price'];
+                        $log['order_sn'] = $orderInfo['order_sn'];
+                        $log['type'] = 1;
+                        $log['remark'] = '呼叫服务余额支付';
+                        $log['add_time'] = time();
+                        $log['obj_id'] = $orderId;
+                        Db::name('user_money_log')->insert($log);
+                        Db::name('js_project')->where('id', $orderInfo['project_id'])->setInc('sales_num', 1);
+                        Db::name('user_discount')->where('id', $orderInfo['user_discount_id'])->update(['hours_time' => time(), 'status' => 1]);
+                        $this->success('支付成功', $orderId);
+                    }
+                    $this->error('余额支付失败,请重新支付');
+                } else {
+                    $this->error('余额不足');
+                }
+                break;
+        }
+    }
+
+
+    /**
+     * 我的订单
+     */
+    public function getList()
+    {
+        $where = [];
+        $JsOrderModel = new JsOrderModel();
+        $status = $this->request->param('status');
+        $project_name = $this->request->param('project_name');
+        $user_id = $this->getUserId();
+        $where['user_id'] = $user_id;
+        if ($status || $status === '0') {
+            if ($status == '9') $where['status'] = array('1', '2', '6');
+            else $where['status'] = $status;
+        }
+        $where['user_delete'] = 1;
+
+        $page = $this->request->param('page');
+        $list = $JsOrderModel->getList($where, $page, $project_name, $status);
+
+        $this->success('ok', $list);
+    }
+
+    /**
+     * 获取抢单订单
+     */
+    public function getSeizeOrder()
+    {
+        $JsOrderModel = new JsOrderModel();
+        $user_id = $this->getUserId();
+        $where = ['user_id' => $user_id, 'status' => 1, 'jiedan_js_id' => 0];
+        $list = $JsOrderModel->where($where)->select();
+        $count = count($list->toArray());
+        $fast_number = 0;
+        foreach ($list as $vo) {
+            $fast_number += $vo['fast_number'];
+        }
+        $this->success('获取成功', ['count' => $count, 'fast_number' => $fast_number]);
+    }
+
+    /**
+     * 订单取消
+     */
+    public function orderCancel()
+    {
+        $id = $this->request->param('order_id');
+        $JsOrderModel = new JsOrderModel();
+        $log_file = './fencheng/cancel_' . date("YmdH") . '.txt';
+        $orderInfo = $JsOrderModel::get($id);
+        //            if($orderInfo['status'] != 0 && $orderInfo['status'] != 1){
+        //                $this->error('该状态订单不可取消!');
+        //            }
+
+
+        $timestamp = time();
+        $waitTime = 15;
+
+        $userDalance = UserModel::get($orderInfo['user_id'])['balance'];
+        if ($orderInfo['status'] == '0') {
+            JsOrderModel::destroy($id);
+        } else if ($orderInfo['status'] == '1') {
+
+            // 支付订单 15分钟内禁止取消订单
+            //            if ($timestamp - $orderInfo['pay_time'] < $waitTime * 60) {
+            //                $this->error("订单支付成功后,需等待 {$waitTime} 分钟才可取消订单!");
+            //            }
+
+            $outMoney = $orderInfo['pay_price'];
+            UserModel::where('id', $orderInfo['user_id'])->setInc('balance', $outMoney);
+            $log['user_id'] = $orderInfo['user_id'];
+            $log['money'] = $outMoney;
+            $log['order_sn'] = $orderInfo['order_sn'];
+            $log['yue'] = $outMoney + $userDalance;
+            $log['type'] = 2;
+            $log['remark'] = '取消服务支付金额退还到余额';
+            $log['add_time'] = time();
+
+            $log['obj_id'] = $id;
+            Db::name('user_money_log')->insert($log);
+            $JsOrderModel::where('id', $id)->update(['status' => 5]);
+        } else if ($orderInfo['status'] == 2) {
+            $withhold = Db::name('withhold')->where('id', 1)->find();
+            if (time() - $orderInfo['jiedan_time'] > 30 * 60) {
+                $withhold = Db::name('withhold')->where('id', 3)->find();
+            } elseif (time() - $orderInfo['jiedan_time'] < 30 * 60 && time() - $orderInfo['jiedan_time'] > 15 * 60) {
+                $withhold = Db::name('withhold')->where('id', 2)->find();
+            }
+            $refund_money = round($orderInfo['pay_price'] * ($withhold['deduct'] / 100), 2);
+            $deserved_money = $orderInfo['pay_price'] - $refund_money;
+            $refund_money = $refund_money - round(($orderInfo['pay_price'] * ($withhold['terrace'] / 100)), 2);
+            $JsOrderModel::where('id', $id)->update(['status' => 5, 'return_time' => time()]);
+            UserModel::where('id', $orderInfo['user_id'])->setInc('balance', $deserved_money);
+            $log['user_id'] = $orderInfo['user_id'];
+            $log['money'] = $deserved_money;
+            $log['yue'] = $deserved_money + $userDalance;
+            $log['order_sn'] = $orderInfo['order_sn'];
+            $log['type'] = 2;
+            $log['remark'] = '取消服务支付金额退还到余额';
+            $log['add_time'] = time();
+            $log['obj_id'] = $id;
+            Db::name('user_money_log')->insert($log);
+            if ($refund_money > 0) {
+                $user_id = JsModel::get($orderInfo['jiedan_js_id'])['user_id'];
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'user_id.......' . $user_id . "\n", FILE_APPEND);
+                $userDalance = UserModel::get($user_id)['balance'];
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'userDalance......' . $userDalance . "\n", FILE_APPEND);
+                UserModel::where('id', $user_id)->setInc('balance', $refund_money);
+                $log1['user_id'] = $user_id;
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'user_id......' . $log1['user_id'] . "\n", FILE_APPEND);
+                $log1['money'] = $refund_money;
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'money......' . $log1['money'] . "\n", FILE_APPEND);
+                $log1['yue'] = $refund_money + $userDalance;
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'yue......' . $log1['yue'] . "\n", FILE_APPEND);
+                $log1['order_sn'] = $orderInfo['order_sn'];
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'order_sn......' . $log1['order_sn'] . "\n", FILE_APPEND);
+                $log1['type'] = 6;
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'type......' . $log1['type'] . "\n", FILE_APPEND);
+                $log1['remark'] = '用户取消订单,接单补偿金额';
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'remark......' . $log1['remark'] . "\n", FILE_APPEND);
+                $log1['add_time'] = time();
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'add_time......' . $log1['add_time'] . "\n", FILE_APPEND);
+                $log1['obj_id'] = $id;
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'obj_id......' . $log1['obj_id'] . "\n", FILE_APPEND);
+                $log1['order_id'] = $id;
+                @file_put_contents($log_file, date("Y-m-d H:i:s") . "\t" . 'order_id......' . $log1['order_id'] . "\n", FILE_APPEND);
+                Db::name('user_money_log')->insert($log1);
+            }
+        }
+        $JsOrderModel->allowField(true)->isUpdate(true)->save(['order_status' => 2], ['id' => $id]);
+        $this->success('取消成功');
+    }
+
+
+    /**
+     * 评价操作
+     */
+    public function setJsScore()
+    {
+        $id = $this->request->param('order_id');
+        // $score = $this->request->param('score');
+        $content = $this->request->param('content');
+        $times = $this->request->param('times');
+        $manner = $this->request->param('manner');
+        $jishu = $this->request->param('jishu');
+        $JsOrderModel = new JsOrderModel();
+        $jiedan_js_id = $JsOrderModel::get($id)['jiedan_js_id'];
+        $project_id = $JsOrderModel::get($id)['project_id'];
+        //   $js_id = JsModel::where('user_id',$jiedan_user_id)->value('id');
+        $data['user_id'] = $this->getUserId();
+        $data['order_id'] = $id;
+        $data['js_id'] = $jiedan_js_id;
+        $data['project_id'] = $project_id;
+        $data['score'] = ceil(($times + $manner + $jishu) / 3);
+        $data['content'] = $content;
+        $data['times'] = $times;
+        $data['manner'] = $manner;
+        $data['jishu'] = $jishu;
+        $JsScoreModel = new JsScoreModel();
+        $JsScoreModel->allowField(true)->isUpdate(false)->save($data);
+        $JsOrderModel::where('id', $id)->update(['status' => 4]);
+        $this->success('评价成功');
+    }
+
+    /**
+     * 订单详情
+     */
+    public function getInfo()
+    {
+        $id = $this->request->param('order_id');
+        $order_no = $this->request->param('order_no');
+        $call_id = $this->request->param('call_id');
+        if ($call_id) {
+            $info = Db::name('js_call')->where('id', $call_id)->find();
+            if (!$info['agency_is_look']) {
+                Db::name('js_call')->where('id', $call_id)->update(['agency_is_look' => 1, 'agency_is_look_time' => time()]);
+            } else {
+                if ((time() - $info['agency_is_look_time']) > 3600) {
+                    $this->error('信息不可查看!');
+                }
+            }
+        }
+        $JsOrderModel = new JsOrderModel();
+        if (!$id && $order_no) {
+            $id = $JsOrderModel::where('order_sn', $order_no)->value('id');
+        }
+        $orderInfo = $JsOrderModel::get($id, ['project', 'js', 'addtime' => function ($qyery) {
+            $qyery->where(['status' => 1]);
+        }]);
+        $user_type = UserModel::get($this->userId)['user_type'];
+        $orderInfo->distance = 0;
+
+        if ($orderInfo['jiedan_js_id']) {
+            $js_site_info = Db::name('js_site')->where('js_id', $orderInfo['jiedan_js_id'])->find();
+            if ($js_site_info['lat'] && $js_site_info['lng'] && $orderInfo['lat'] && $orderInfo['lng']) {
+                $orderInfo->distance = GetDistance($js_site_info['lat'], $js_site_info['lng'], $orderInfo['lat'], $orderInfo['lng'], 2, 2);
+            } else {
+                $orderInfo->distance = 0;
+            }
+        }
+        if ($orderInfo->status == 5 || $orderInfo->status == 7 || $orderInfo->status < 2) {
+            $orderInfo->mobile = substr_replace($orderInfo->mobile, '****', 3, 4);
+        }
+
+        if ($user_type == 3) {
+            $js_id = JsModel::where('user_id', $this->userId)->value('id');
+            $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
+            if ($js_site_info['lat'] && $js_site_info['lng'] && $orderInfo['lat'] && $orderInfo['lng']) {
+                $orderInfo->distance = GetDistance($js_site_info['lat'], $js_site_info['lng'], $orderInfo['lat'], $orderInfo['lng'], 2, 2);
+            } else {
+                $orderInfo->distance = 0;
+            }
+        }
+        $service = ['project_id' => $orderInfo['project_id'], 'minute' => $orderInfo['minute'], 'price' => $orderInfo['pay_price']];
+
+        $orderInfo->project_service = $service;
+        $orderInfo = $orderInfo->toarray();
+        if ($orderInfo['status'] == 5 || $orderInfo['status'] == 7 || $orderInfo['status'] < 2) {
+            $orderInfo['js']['phone'] = substr_replace($orderInfo['js']['phone'], '****', 3, 4);
+        }
+
+        //  $orderInfo->project_service = Db::name('js_project_service_relevancy')->where('id',$orderInfo['service_id'])->find();
+
+        $this->success('ok', $orderInfo);
+    }
+
+    /**
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * 获取抢单技师列表
+     */
+    public function selectJs()
+    {
+        $order_id = $this->request->param('order_id');
+        if (!$order_id) {
+            $this->error('缺少order_id参数');
+        }
+        $JsOrderGrab = new JsOrderGrabModel();
+        $order_info = JsOrderModel::get($order_id);
+        if (!$order_info) {
+            $this->error('订单不存在!');
+        }
+        $list = $JsOrderGrab::with('js.site')->where('order_id', $order_id)->select();
+        foreach ($list as $key => $value) {
+            if ($list[$key]->js) {
+                $list[$key]->js->score = get_js_score($list[$key]->js_id);
+            }
+            if ($value->js->site) {
+                $list[$key]->distance = GetDistance($order_info['lat'], $order_info['lng'], $value->js->site->lat, $value->js->site->lng, 2, 2);
+            } else {
+                $list[$key]->distance = '距离不详';
+            }
+        }
+        $paixu = 'asc';
+        $len = count($list);
+        for ($i = 1; $i < $len; $i++) {
+            for ($k = 0; $k < $len - $i; $k++) {
+                if ($paixu == 'asc' || $paixu == '') {
+                    if ($list[$k]['distance'] > $list[$k + 1]['distance']) {
+                        $array = $list[$k + 1];
+                        $list[$k + 1] = $list[$k];
+                        $list[$k] = $array;
+                    }
+                } else {
+                    if ($list[$k]['distance'] < $list[$k + 1]['distance']) {
+                        $array = $list[$k + 1];
+                        $list[$k + 1] = $list[$k];
+                        $list[$k] = $array;
+                    }
+                }
+            }
+        }
+        $this->success('ok', $list);
+    }
+
+    /**
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     * 用户选择技师操作
+     */
+
+    public function doSelectJs()
+    {
+        $order_id = $this->request->param('order_id');
+        $js_id = $this->request->param('js_id');
+        if (!$order_id) {
+            $this->error('缺少order_id参数');
+        }
+        if (!$js_id) {
+            $this->error('缺少js_id参数');
+        }
+        $JsOrderModel = new JsOrderModel();
+        $order_info = JsOrderModel::get($order_id);
+        if (!$order_info) {
+            $this->error('订单不存在!');
+        }
+        $msg = '订单未支付!';
+        switch ($order_info['status']) {
+            case 2:
+                $msg = '技师已选择!';
+                break;
+            case 6:
+                $msg = '服务中!';
+                break;
+            case 3:
+                $msg = '订单已完成!';
+                break;
+            case 4:
+                $msg = '订单已评价!';
+                break;
+            case 5:
+                $msg = '订单已取消!';
+                break;
+        }
+
+        $order_id_new = $JsOrderModel::where(function ($query) {
+            $query->whereOR('status', 2);
+            $query->whereOR('status', 6);
+        })->where('jiedan_js_id', $js_id)->value('id');
+        if ($order_id_new) {
+            $this->error('技师被选走了!');
+        }
+
+        if ($order_info['status'] != 1) {
+            $this->error($msg);
+        } else {
+            $JsOrderModel->allowField(true)->isUpdate(true)->save(['jiedan_js_id' => $js_id, 'jiedan_time' => time(), 'status' => 2], ['id' => $order_id]);
+            $JsOrderGrabModel = new JsOrderGrabModel();
+            $JsOrderGrabModel->allowField(true)->isUpdate(true)->save(['status' => 1], ['order_id' => $order_id, 'js_id' => $js_id]);
+            JsOrderGrabModel::where(['order_id' => $order_id, 'status' => 0])->delete();
+            $info = cmf_get_option('jspus');
+            $url = '/pages/ddxq/ddxq?id=' . $order_id;
+            $js_client = new Client($info['js_app_key'], $info['js_master_secret']);
+            $js_user_id = Db::name('js')->where('id', $js_id)->value('user_id');
+            $js_user_id .= 'js';
+            $extras = [
+                'id' => $order_id,
+                'flag' => '技师端',
+                'url' => $url
+            ];
+            $array = [
+                'extras' => $extras,
+            ];
+            $text = '您有新的服务订单,请及时处理!';
+            $platform = array('ios', 'android');
+            try {
+                $js_client->push()
+                    ->setPlatform($platform)
+                    ->setNotificationAlert($text)
+                    ->iosNotification($text, $array)
+                    ->androidNotification($text, $array)
+                    ->addAlias("{$js_user_id}")
+                    ->send();
+
+                $this->success('选择成功');
+            } catch (\JPush\Exceptions\APIConnectionException $e) {
+
+                $this->success('选择成功');
+            } catch (\JPush\Exceptions\APIConnectionException $e) {
+                $this->success('选择成功');
+            }
+        }
+    }
+
+    /**
+     * 用户删除i订单
+     */
+    public function deleteOrder()
+    {
+        $order_id = $this->request->param('order_id');
+        $JsOrderModel = new JsOrderModel();
+        $JsOrderModel::where('id', $order_id)->update(['user_delete' => 2]);
+        $this->success('删除成功');
+    }
+
+
+    /**
+     * 扣款规则
+     */
+    public function getwithhold()
+    {
+        $list = Db::name('withhold')->select();
+        $this->success('ok', $list);
+    }
+
+
+    /**
+     * 加钟
+     * 服务加时
+     */
+    public function addTime()
+    {
+        $order_id = $this->request->param('order_id');
+        $pay_type = $this->request->param('pay_type');
+        $info = JsOrderModel::get($order_id);
+        $serve_info = Db::name('js_project_service_relevancy')->where('id', $info['service_id'])->find();
+        if (!$serve_info) {
+            $this->error('订单服务数据不存在了!');
+        }
+        if ($info['status'] != 6) {
+            $this->error('订单不在服务中,不可加钟');
+        }
+        $data['pay_price'] = $serve_info['price'];
+        $data['order_id'] = $info['id'];
+        $data['order_sn'] = cmf_get_order_sn();
+        $data['order_price'] = $serve_info['order_price'];
+        $data['service_time'] = $serve_info['minute'];
+
+
+        switch ($pay_type) {
+            case 'wxpay':
+                $order_addtime_id = Db::name('js_order_addtime')->insertGetId($data);
+                if ($order_addtime_id) {
+                    $res = wx_pay($order_addtime_id, 100);
+                    if (!empty($res['return_code'])) {
+                        $this->error($res['return_msg']);
+                    } else {
+                        $this->success('ok', $res);
+                    }
+                } else {
+                    $this->error('加钟失败!');
+                }
+
+
+                break;
+            case 'alipay':
+                $order_addtime_id = Db::name('js_order_addtime')->insertGetId($data);
+
+                if ($order_addtime_id) {
+                    $res = aly_pay($order_addtime_id, 100);
+                    if (!empty($res['return_code'])) {
+                        $this->error($res['return_msg']);
+                    } else {
+                        $this->success('ok', $res);
+                    }
+                } else {
+                    $this->error('加钟失败!');
+                }
+
+            case 'balance':
+                $userDalance = UserModel::get($this->getUserId())['balance'];
+                if ($userDalance >= $data['pay_price']) {
+                    UserModel::where('id', $this->getUserId())->setDec('balance', $data['pay_price']);
+                    $data['pay_time'] = time();
+                    $data['pay_type'] = '余额支付';
+                    $data['status'] = 1;
+
+
+                    $order_data['price'] = $data['pay_price'] + $info['price'];
+                    $order_data['pay_price'] = $data['pay_price'] + $info['price'];
+                    $order_data['minute'] = $data['service_time'] + $info['minute'];
+                    $order_data['order_price'] = $data['order_price'] + $info['order_price'];
+
+                    $JsOrderModel = new JsOrderModel();
+                    $JsOrderModel->allowField(true)->isUpdate(true)->save($order_data, ['id' => $order_id]);
+                    $orderId = $order_id;
+                    $log['user_id'] = $info['user_id'];
+                    $log['money'] = -$data['pay_price'];
+                    $log['yue'] = $userDalance - $data['pay_price'];
+                    $log['order_sn'] = $data['order_sn'];
+                    $log['type'] = 7;
+                    $log['remark'] = '加钟余额支付';
+                    $log['add_time'] = time();
+                    $log['obj_id'] = $orderId;
+                    Db::name('user_money_log')->insert($log);
+                    Db::name('js_project')->where('id', $info['project_id'])->setInc('sales_num', 1);
+                    Db::name('js_order_addtime')->insertGetId($data);
+                    // Db::name('')
+                    $this->success('加钟成功', $orderId);
+                } else {
+                    $this->error('余额不足');
+                }
+                break;
+        }
+    }
+}

+ 25 - 0
api/js/controller/JsProjectCategoryController.php

@@ -0,0 +1,25 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-07
+     * Time: 14:28
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\JsProjectCategoryModel;
+    use cmf\controller\RestBaseController;
+
+    class JsProjectCategoryController extends RestBaseController
+    {
+        public function getList()
+        {
+            $list = JsProjectCategoryModel::where('is_show',1)->field('id,category_name,icon')->order('list_order','ASC')->select()->each(function ($list){
+                $list['icon'] = cmf_get_image_preview_url($list['icon']);
+            });
+            $this->success('ok',$list);
+        }
+        
+    }

+ 106 - 0
api/js/controller/JsProjectController.php

@@ -0,0 +1,106 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-07
+     * Time: 14:38
+     */
+    
+    namespace api\js\controller;
+    use api\js\model\JsModel;
+    use api\js\model\JsProjectModel;
+    use cmf\controller\RestBaseController;
+    use think\Db;
+    use api\js\model\RegionModel;
+    class JsProjectController extends RestBaseController
+    {
+    
+        /**
+         * @throws \think\db\exception\DataNotFoundException
+         * @throws \think\db\exception\ModelNotFoundException
+         * @throws \think\exception\DbException
+         * 获取分类列表
+         */
+        public function getList()
+        {
+            $where = [];
+            
+            $JsProjectModel = new JsProjectModel();
+            $categoryId = $this->request->param('category_id');
+            $page = $this->request->param('page',1);
+            $district = $this->request->param('district');
+            $xlng = $this->request->param('xlng');
+            $xlat = $this->request->param('xlat');
+            $lng = $this->request->param('lng');
+            $lat = $this->request->param('lat');
+            $lat = isset($xlat) ? $xlat : $lat;
+            $lng = isset($xlng) ? $xlng : $lng;
+            // if($lat && $lng) {
+            //     $res = getdistrict($xlng, $xlat);
+                
+            //     if ($res['status'] == 0) {
+            //         $this->success('经纬度不正确', []);
+            //     } else {
+            //         $district = $res['regeocode']['addressComponent']['district'];
+            //     }
+            // }
+            // $district = isset($district) ? $district : $district1;
+            $RegionModel = new RegionModel();
+            $serviceId = $RegionModel->getId($district);
+            
+      
+            if($categoryId){
+                $projectIds = Db::name('js_project_category_relevancy')->where('category_id',$categoryId)->field('project_id')->select();
+                $project_id = [];
+                foreach ($projectIds as $vo){
+                    $project_id[] = $vo['project_id'];
+                }
+                if($project_id){
+                    $where = $project_id;
+                }else{
+                    $list = [];
+                    $this->success('ok',$list);
+                }
+         
+            }
+            
+            $name = $this->request->param('name');
+            $user_id = $this->userId;
+
+            $js_id = 0;
+            if($user_id){
+                $JsModel = new JsModel();
+                $js_id = $JsModel->where('user_id',$user_id)->value('id');
+            }
+
+            $list = $JsProjectModel->getList($name,$where,$page,$serviceId,$js_id);
+            $this->success('ok',$list);
+        }
+        
+        
+        public function getInfo()
+        {
+            $id = $this->request->param('id');
+            $district= $this->request->param('district');
+            $xlng = $this->request->param('xlng');
+            $xlat = $this->request->param('xlat');
+            $lng = $this->request->param('lng');
+            $lat = $this->request->param('lat');
+            $lat = isset($xlat) ? $xlat : $lat;
+            $lng = isset($xlng) ? $xlng : $lng;
+            // if($lng && $lat){
+        
+            //     $res  = getdistrict($lng,$lat);
+            //     if($res['status'] == 0){
+            //         $this->success('经纬度不正确',[]);
+            //     }else{
+            //         $district = $res['regeocode']['addressComponent']['district'];
+            //     }
+            // }
+            // $district = isset($district) ? $district : $district1;
+            $JsProjectModel = new JsProjectModel();
+            $info = $JsProjectModel->getInfo($id,$district);
+            $this->success('ok',$info);
+        }
+        
+    }

+ 179 - 0
api/js/controller/LoginController.php

@@ -0,0 +1,179 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-07
+ * Time: 11:39
+ */
+
+namespace api\js\controller;
+
+
+use api\js\model\UserModel;
+use cmf\controller\RestBaseController;
+use think\Db;
+
+class LoginController extends RestBaseController
+{
+    /**
+     * 账号登录
+     */
+    public function login()
+    {
+        $validate = new \think\Validate([
+            'mobile' => 'require',
+            'password' => 'require'
+        ]);
+        $validate->message([
+            'mobile.require' => '请输入您的手机号',
+            'password.require' => '请输入您的密码!'
+        ]);
+
+
+        $data = $this->request->param();
+
+        if (!$validate->check($data)) {
+            $this->error($validate->getError());
+        }
+        $type = $data['type'];
+        unset($data['type']);
+        $findUserWhere = [];
+        if (cmf_check_mobile($data['mobile'])) {
+            $findUserWhere['mobile'] = $data['mobile'];
+        } else {
+            $this->error('手机号格式错误');
+        }
+        if ($type == 1) {
+            $findUserWhere['user_type'] = 2;
+        }
+        if ($type == 2) {
+            $findUserWhere['user_type'] = 3;
+        }
+
+
+        $findUser = UserModel::name("user")->where($findUserWhere)->find();
+
+        if (empty($findUser)) {
+            $this->error("用户不存在!");
+        } else {
+            switch ($findUser['user_status']) {
+                case 0:
+                    $this->error('您的账户已停用!');
+                case 2:
+                    $this->error('账户还没有验证成功!');
+            }
+            if (!cmf_compare_password($data['password'], $findUser['user_pass'])) {
+                $this->error("密码不正确!");
+            }
+        }
+
+        if (empty($this->deviceType) && (empty($data['device_type']) || !in_array($data['device_type'], $this->allowedDeviceTypes))) {
+            $this->error("请求错误,未知设备!");
+        } else if (!empty($data['device_type'])) {
+            $this->deviceType = $data['device_type'];
+        }
+
+        $findUserToken = Db::name("user_token")
+            ->where('user_id', $findUser['id'])
+            ->where('device_type', $this->deviceType)
+            ->find();
+        $currentTime   = time();
+        $expireTime    = $currentTime + 24 * 3600 * 180;
+        $token         = md5(uniqid()) . md5(uniqid());
+        if (empty($findUserToken)) {
+            $result = Db::name("user_token")->insert([
+                'token'       => $token,
+                'user_id'     => $findUser['id'],
+                'expire_time' => $expireTime,
+                'create_time' => $currentTime,
+                'device_type' => $this->deviceType
+            ]);
+        } else {
+            $result = Db::name("user_token")
+                ->where('user_id', $findUser['id'])
+                ->where('device_type', $this->deviceType)
+                ->update([
+                    'token'       => $token,
+                    'expire_time' => $expireTime,
+                    'create_time' => $currentTime
+                ]);
+        }
+
+        if (empty($result)) {
+            $this->error("登录失败!");
+        }
+
+        Db::name('user')->where('id', $findUser['id'])->update(['last_login_ip' => get_client_ip(), 'last_login_time' => time()]);
+        unset($findUser['user_pass']);
+        $this->success("登录成功!", ['token' => $token, 'id' => $findUser['id']]);
+    }
+
+
+    public function wechatLogin()
+    {
+        $validate = new \think\Validate(['openid' => 'require']);
+        $validate->message(['openid' => '微信授权失败!']);
+
+        $data = $this->request->param();
+
+        if (!$validate->check($data)) $this->error($validate->getError());
+        $findUserWhere = [];
+
+        if ($data['type'] == 1)  $findUserWhere['user_type'] = 2;
+        else if ($data['type'] == 2)  $findUserWhere['user_type'] = 3;
+
+
+        $findUser = UserModel::name("user")->where('user_type', $findUserWhere['user_type'])
+            ->where('openid', $data['openid'])->find();
+
+        if (empty($findUser))  $this->error("用户不存在!");
+        else {
+            switch ($findUser['user_status']) {
+                case 0:
+                    $this->error('您的账户已停用!');
+                case 2:
+                    $this->error('账户还没有验证成功!');
+            }
+        }
+
+        if (empty($this->deviceType) && (empty($data['device_type']) || !in_array($data['device_type'], $this->allowedDeviceTypes))) {
+            $this->error("请求错误,未知设备!");
+        } else if (!empty($data['device_type'])) {
+            $this->deviceType = $data['device_type'];
+        }
+
+        $findUserToken = Db::name("user_token")
+            ->where('user_id', $findUser['id'])
+            ->where('device_type', $this->deviceType)
+            ->find();
+        $currentTime   = time();
+        $expireTime    = $currentTime + 24 * 3600 * 180;
+        $token         = md5(uniqid()) . md5(uniqid());
+        if (empty($findUserToken)) {
+            $result = Db::name("user_token")->insert([
+                'token'       => $token,
+                'user_id'     => $findUser['id'],
+                'expire_time' => $expireTime,
+                'create_time' => $currentTime,
+                'device_type' => $this->deviceType
+            ]);
+        } else {
+            $result = Db::name("user_token")
+                ->where('user_id', $findUser['id'])
+                ->where('device_type', $this->deviceType)
+                ->update([
+                    'token'       => $token,
+                    'expire_time' => $expireTime,
+                    'create_time' => $currentTime
+                ]);
+        }
+
+        if (empty($result)) {
+            $this->error("登录失败!");
+        }
+
+        Db::name('user')->where('id', $findUser['id'])->update(['last_login_ip' => get_client_ip(), 'last_login_time' => time()]);
+        $this->success("登录成功!", ['token' => $token, 'id' => $findUser['id']]);
+    }
+}

+ 303 - 0
api/js/controller/PaynotifyController.php

@@ -0,0 +1,303 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-11
+     * Time: 16:28
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use Aliyun\DySDKLite\SignatureHelper;
+    use api\js\model\GoodsOrderModel;
+    use api\js\model\JsCourseOrderModel;
+    use api\js\model\JsModel;
+    use api\js\model\JsOrderAddtimeModel;
+    use api\js\model\JsOrderModel;
+    use api\js\model\JsProjectModel;
+    use api\js\model\UserModel;
+    use cmf\controller\RestBaseController;
+    use think\Db;
+
+    class PaynotifyController extends RestBaseController
+    {
+        /**
+         * 微信支付回调
+         */
+        public function wx()
+        {
+            $xmlstr= file_get_contents("php://input");
+            
+           
+            $array = xml_toarray($xmlstr);
+         
+            $wxpay = cmf_get_option('wxpay');
+            if($array['result_code'] == 'SUCCESS' && $array['return_code'] == 'SUCCESS'){
+    
+                $type = $this->request->param('type');
+            
+                $order_sn = $array['out_trade_no'];
+                $model  = '';
+                switch ($type){
+                    case 1:
+                        $info['key'] = $wxpay['js_key'];
+                        $model = new JsCourseOrderModel();
+                        break;
+                    case 2:
+                        $info['key'] = $wxpay['js_key'];
+                        $model = new GoodsOrderModel();
+                        break;
+                    case 3:
+                        $info['key'] = $wxpay['key'];
+                        $model = new JsOrderModel();
+                        $order_info = $model::where('order_sn',$order_sn)->find();
+                        if($order_info['user_discount_id']){
+                            $userDiscountInfo = Db::name('user_discount')->where('id',$order_info['user_discount_id'])->find();
+        
+                            if($userDiscountInfo['project_id'] != 0){
+                                if($userDiscountInfo['project_id'] == $order_info['project_id']){
+                                    if($userDiscountInfo['past_time'] >= time()){
+                                        Db::name('user_discount')->where('id',$order_info['user_discount_id'])->update(['hours_time'=>time(),'status'=>1]);
+                    
+                                    }
+                                }
+                            }else{
+                                if($userDiscountInfo['past_time'] >= time()){
+                                    Db::name('user_discount')->where('id',$order_info['user_discount_id'])->update(['hours_time'=>time(),'status'=>1]);
+                
+                                }
+                            }
+                        }
+                        break;
+                }
+                $sign = $array['sign'];
+                unset($array['sign']);
+                ksort($array);
+                $str='';
+                foreach($array as $k=>$v) {
+                    $str.=$k.'='.$v.'&';
+                }
+                $str.='key='.$info['key'];
+                $new_sign=strtoupper(md5($str));//加密
+                if($sign == $new_sign){
+          
+                    $info = $model::where('order_sn',$order_sn)->find();
+    
+                 
+                    if($info['status'] == 0){
+                        $data['status'] = 1;
+                        $data['pay_time'] = time();
+                        $data['pay_type'] = '微信支付';
+                        $model->allowField(true)->isUpdate(true)->save($data,['id'=>$info['id']]);
+                        if($type == 100){
+        
+                            $JsOrderModel = new JsOrderModel();
+                            $order_info = $JsOrderModel::get($info['order_id']);
+                            $order_data['price'] = $order_info['price'] + $info['price'];
+                            $order_data['pay_price'] = $order_info['price'] + $info['price'];
+                            $order_data['minute'] = $order_info['minute'] + $info['minute'];
+                            $order_data['order_price'] = $order_info['order_price'] + $info['order_price'];
+        
+                            $JsOrderModel->allowField(true)->isUpdate(true)->save($order_data,['id'=>$info['order_id']]);
+                            Db::name('js_project')->where('id', $info['project_id'])->setInc('sales_num', 1);
+                        }
+                        if($type == 2){
+                            $log1['admin_id'] = $info['user_id'];
+                            $log1['action_time'] = date('Y-m-d H:i:s');
+                            $log1['obj_id'] = $info['id'];
+                            $log1['remark'] = '订单支付';
+                            Db::name('goods_order_action_log')->insert($log1);
+                        }
+                       
+                        if($type == 3){
+                        
+                            if($info['jiedan_js_id']){
+                               
+                                $helper = new SignatureHelper();
+                                $alisms = cmf_get_option('alisms');
+                                $security = false;
+                                $accessKeyId = $alisms['access_key_id'];
+                                $accessKeySecret = $alisms['access_key_secret'];
+                                $js_mobile = UserModel::get(JsModel::get($info['jiedan_js_id'])['user_id'])['mobile'];
+                                $params["PhoneNumbers"] = $js_mobile;
+                                $params["SignName"] = '嘀咚点到';
+                                $user_nickname = UserModel::get($info['user_id'])['user_nickname'];
+                         
+                                if($info['type'] == 1){
+                                    $params["TemplateCode"] = 'SMS_204986367';
+                                    $params['TemplateParam'] = Array (
+                                        "product" => JsProjectModel::get($info['project_id'])['name'],
+                                    );
+                                }else{
+                                    $params["TemplateCode"] = 'SMS_204986363';
+                                    $params['TemplateParam'] = Array (
+                                        "time" => date('H:i',$info['appoint_time']),
+                                    );
+                                }
+                                if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
+                                    $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
+                                }
+                                $content = $helper->request(
+                                    $accessKeyId,
+                                    $accessKeySecret,
+                                    "dysmsapi.aliyuncs.com",
+                                    array_merge($params, array(
+                                        "RegionId" => "cn-hangzhou",
+                                        "Action" => "SendSms",
+                                        "Version" => "2017-05-25",
+                                    )),
+                                    $security
+                                );
+                            }
+                            Db::name('js_project')->where('id',$info['project_id'])->setInc('sales_num',1);
+                        }
+
+                        return 'SUCCESS';
+                    }else{
+                        return 'SUCCESS';
+                    }
+                }
+            }
+        }
+    
+        /**
+         * 阿里云支付回调
+         */
+        public function aliy()
+        {
+            $type = $this->request->param('type');
+            $alipay = cmf_get_option('alipay');
+			@file_put_contents('1232211.txt',json_encode($_POST),FILE_APPEND);
+            $aop = new \AopCertClient();
+            $alipayCertPath = cmf_get_file_download_url($alipay['Pay_alipay_Public_key_certificate']);
+            switch ($type){
+                case 1:
+                    
+                    $alipayCertPath = cmf_get_file_download_url($alipay['js_Pay_alipay_Public_key_certificate']);
+                    break;
+                case 2:
+                    $alipayCertPath = cmf_get_file_download_url($alipay['js_Pay_alipay_Public_key_certificate']);
+                    break;
+            }
+      
+            $rsaPublicKey  = $aop->getPublicKey($alipayCertPath);
+            $aop->alipayrsaPublicKey = $rsaPublicKey;
+
+       
+            $bool = $aop->rsaCheckV1($_POST,$aop->alipayrsaPublicKey,'RSA2');
+            if($bool && $_POST['trade_status'] == 'TRADE_SUCCESS'){
+                $order_sn = $_POST['out_trade_no'];
+                switch ($type){
+                    case 1: //购买课程
+                        $model = new JsCourseOrderModel();
+                        break;
+                    case 2: //开通超级商人
+                        $model = new GoodsOrderModel();
+                        break;
+                    case 3: //呼叫服务
+                        $model = new JsOrderModel();
+                        $order_info = $model::where('order_sn',$order_sn)->find();
+                        if($order_info['user_discount_id']){
+                            $userDiscountInfo = Db::name('user_discount')->where('id',$order_info['user_discount_id'])->find();
+
+                            if($userDiscountInfo['project_id'] != 0){
+                                if($userDiscountInfo['project_id'] == $order_info['project_id']){
+                                    if($userDiscountInfo['past_time'] >= time()){
+                                        Db::name('user_discount')->where('id',$order_info['user_discount_id'])->update(['hours_time'=>time(),'status'=>1]);
+                   
+                                    }
+                                }
+                            }else{
+                                if($userDiscountInfo['past_time'] >= time()){
+                                    Db::name('user_discount')->where('id',$order_info['user_discount_id'])->update(['hours_time'=>time(),'status'=>1]);
+        
+                                }
+                            }
+                        }
+                        break;
+                        
+                    case 100:
+                        $model = new JsOrderAddtimeModel();
+                        break;
+                        
+                }
+                $info = $model::where('order_sn',$order_sn)->find();
+                if($info['status'] == 0){
+                    $up['pay_type'] = '支付宝';
+                    $up['pay_time'] = time();
+                    $up['status'] = 1;
+                    $model->allowField(true)->isUpdate(true)->save($up,['id'=>$info['id']]);
+                    if($type == 100){
+                      
+                        $JsOrderModel = new JsOrderModel();
+                        $order_info = $JsOrderModel::get($info['order_id']);
+                        $order_data['price'] = $order_info['price'] + $info['price'];
+                        $order_data['pay_price'] = $order_info['price'] + $info['price'];
+                        $order_data['minute'] = $order_info['minute'] + $info['minute'];
+                        $order_data['order_price'] = $order_info['order_price'] + $info['order_price'];
+                   
+                        $JsOrderModel->allowField(true)->isUpdate(true)->save($order_data,['id'=>$info['order_id']]);
+                        Db::name('js_project')->where('id', $info['project_id'])->setInc('sales_num', 1);
+                    }
+                    
+                    if($type == 2){
+                     //   $model->allowField(true)->isUpdate(true)->save($up,['id'=>$info['id']]);
+                        $log1['admin_id'] = $info['user_id'];
+                        $log1['action_time'] = date('Y-m-d H:i:s');
+                        $log1['obj_id'] = $info['id'];
+                        $log1['remark'] = '订单支付';
+                        Db::name('goods_order_action_log')->insert($log1);
+                    }
+
+                    if($type == 3){
+                        if($info['jiedan_js_id']){
+                            $helper = new SignatureHelper();
+                            $alisms = cmf_get_option('alisms');
+                            $security = false;
+                            $accessKeyId = $alisms['access_key_id'];
+                            $accessKeySecret = $alisms['access_key_secret'];
+                            $js_mobile = UserModel::get(JsModel::get($info['jiedan_js_id'])['user_id'])['mobile'];
+                            $params["PhoneNumbers"] = $js_mobile;
+                            $params["SignName"] = '嘀咚点到';
+                            $user_nickname = UserModel::get($info['user_id'])['user_nickname'];
+                            if($info['type'] == 1){
+                                $params["TemplateCode"] = 'SMS_204986367';
+                                $params['TemplateParam'] = Array (
+                                    "product" => JsProjectModel::get($info['project_id'])['name'],
+                                );
+                            }else{
+                                $params["TemplateCode"] = 'SMS_204971115';
+                                $params['TemplateParam'] = Array (
+                                    "consignee" => $user_nickname,
+                                    "number" => $info['mobile'],
+                                    "time" => date('H:i',$info['appoint_time']),
+                                );
+                            }
+                            if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
+                                $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
+                            }
+                            $content = $helper->request(
+                                $accessKeyId,
+                                $accessKeySecret,
+                                "dysmsapi.aliyuncs.com",
+                                array_merge($params, array(
+                                    "RegionId" => "cn-hangzhou",
+                                    "Action" => "SendSms",
+                                    "Version" => "2017-05-25",
+                                )),
+                                $security
+                            );
+                            file_put_contents('12322.txt',$content->Message );
+                            if($content->Message == 'OK' && $content->Code == 'OK'){
+                                file_put_contents('12322.txt',$content->Message );
+                            }
+                           
+                        }
+                        Db::name('js_project')->where('id',$info['project_id'])->setInc('sales_num',1);
+                    }
+                    echo 'SUCCESS';
+                }
+            }
+        }
+    }

+ 37 - 0
api/js/controller/PortalController.php

@@ -0,0 +1,37 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-18
+     * Time: 11:26
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\PortalCategoryModel;
+    use api\js\model\PortalPostModel;
+    use cmf\controller\RestBaseController;
+
+    class PortalController extends RestBaseController
+    {
+        public function getList()
+        {
+            $PortalCategoryModel = new PortalCategoryModel();
+            $id = $this->request->param('id',1);
+            $list = $PortalCategoryModel->getlist($id);
+            $this->success('ok',$list);
+        }
+        
+        public function getInfo()
+        {
+            $id = $this->request->param('id');
+            $info = PortalPostModel::get($id);
+            if($id == 7){
+                $info['video'] = cmf_get_file_download_url($info['video']);
+            }else{
+                unset($info['video']);
+            }
+            $this->success('ok',$info);
+        }
+    }

+ 233 - 0
api/js/controller/RegController.php

@@ -0,0 +1,233 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-02
+ * Time: 17:15
+ */
+
+namespace api\js\controller;
+
+
+use api\js\model\JsDiscountModel;
+use api\js\model\JsModel;
+use api\js\model\UserDiscountModel;
+use app\back\model\CouponModel;
+use app\back\model\DistributorModel;
+use cmf\controller\RestBaseController;
+use api\js\model\UserModel;
+use think\Db;
+
+class RegController extends RestBaseController
+{
+    public function regPost()
+    {
+        $mobile = $this->request->param('mobile');
+        $password = $this->request->param('password');
+        $code = $this->request->param('code');
+        $referral = $this->request->param('referral');
+        $type = $this->request->param('type', 1);
+
+        $lat = $this->request->param('lat');
+        $lng = $this->request->param('lng');
+
+
+        $district = $this->request->param('district');
+        if ($lat && $lng) {
+            $res = getdistrict($lng, $lat);
+
+            if ($res['status']) {
+                $district = $res['regeocode']['addressComponent']['district'];
+            }
+
+        }
+        $user_type = 2;
+
+        if ($district) {
+            //   $this->error('请允许获取当前位置!');
+
+            $district_id = Db::name('region')->where('cityName', $district)->value('id');
+            $data['city_id'] = Db::name('region')->where('id', $district_id)->value('parentId');
+            $data['province_id'] = Db::name('region')->where('id', $data['city_id'])->value('parentId');
+            $data['district_id'] = $district_id;
+        }
+
+        //   if($type == 1){
+        //    $district = $this->request->param('district');
+
+        //}
+        if ($type == 2) {
+            $user_type = 3;
+        }
+        $where['mobile'] = $mobile;
+        $where['user_type'] = $user_type;
+        if ($code != '7758521') {
+            $bool = cmf_check_verification_code($mobile, $code);
+            if ($bool) {
+                $this->error($bool);
+            }
+        }
+        if (!cmf_check_mobile($mobile)) {
+            $this->error('手机号不正确!');
+        }
+        $UserModel = new UserModel();
+
+        $user_id = $UserModel->where($where)->value('id');
+        if ($user_id) {
+            $this->error('手机号已注册!');
+        }
+
+        if ($referral) {
+            $parentInfo = $UserModel->where('referral', $referral)->find();
+//                if(!$parentInfo){
+//                    $this->error('推广码不存在!');
+//                }
+            if ($parentInfo) {
+                $data['parent_id'] = $parentInfo['id'];
+                $data['parent_id1'] = $parentInfo['parent_id'];
+            }
+        }
+
+        $data['mobile'] = $mobile;
+        $data['user_pass'] = cmf_password($password);
+        $data['user_type'] = $user_type;
+        $data['create_time'] = time();
+        $data['referral'] = cmf_get_referral();
+
+
+        $res = $UserModel->allowField(true)->isUpdate(false)->save($data);
+
+        if ($res) {
+            $currentTime = time();
+            $expireTime = $currentTime + 24 * 3600 * 180;
+            $token = md5(uniqid()) . md5(uniqid());
+            if (empty($findUserToken)) {
+                Db::name("user_token")->insert([
+                    'token' => $token,
+                    'user_id' => $UserModel->id,
+                    'expire_time' => $expireTime,
+                    'create_time' => $currentTime,
+                    'device_type' => $this->deviceType
+                ]);
+                //     $this->success('注册成功',['token'=>$token]);
+
+            }
+
+//            $JsDiscountModel = new JsDiscountModel();
+//            $discountInfo = $JsDiscountModel::get(1);
+//            if ($discountInfo['dispark'] == 1) {
+//                if ($discountInfo['quantit'] > 0) {
+//                    $UserDiscountModel = new UserDiscountModel();
+//                    $draw_time = time();
+//                    $UserDiscountModel->allowField(true)->isUpdate(false)->save(['user_id' => $UserModel->id, 'discount_id' => 1, 'draw_time' => $draw_time, 'past_time' => ($draw_time + ($discountInfo['day_num'] * 24 * 3600)), 'project_id' => $discountInfo['project_id'], 'store_id' => $discountInfo['store_id']]);
+//                    $JsDiscountModel::where('id', 1)->setDec('quantit', 1);
+//
+//                }
+//            }
+            if ($type == 2) {
+                $JsModel = new JsModel();
+                $JsModel->allowField(true)->isUpdate(false)->save(['user_id' => $UserModel->id]);
+
+            }
+
+            $this->success('注册成功', ['token' => $token, 'id' => $UserModel->id]);
+        } else {
+            $this->error('注册失败');
+        }
+    }
+
+    /**
+     * 修改密码
+     */
+    public function uppass()
+    {
+        $mobile = $this->request->param('mobile');
+        $password = $this->request->param('password');
+        $code = $this->request->param('code');
+        $type = $this->request->param('type');
+        $bool = cmf_check_verification_code($mobile, $code);
+        if ($bool) {
+            $this->error($bool);
+        }
+        if ($type == 1) {
+            $user_type = 2;
+        }
+        if ($type == 2) {
+            $user_type = 3;
+        }
+        $UserModel = new UserModel();
+
+        $user_id = $UserModel->where('mobile', $mobile)->where(['user_type' => $user_type])->value('id');
+        if (!$user_id) {
+            $this->error('手机号未注册!');
+        }
+        $data['user_pass'] = cmf_password($password);
+        $UserModel->allowField(true)->isUpdate(true)->save($data, ['id' => $user_id]);
+
+        Db::name('user_token')->where('user_id', $user_id)->delete();
+        $this->success('密码更新成功!');
+    }
+
+    public function setDistributor()
+    {
+        $distributor_id = $this->request->param('id');
+        $erm = $this->request->param('code');
+        if (empty($distributor_id) || empty($erm)) {
+            return $this->error('非法提交!');
+        }
+        $model = new CouponModel();
+        $code = $model->with(['user'])->where('code', $erm)->find();
+        if (empty($code['user_id'])) {
+            $user_id = $this->getUserId();
+//            $user_id = 20;
+            $befor_data = \app\back\model\UserModel::get($user_id)['distributor_id'];
+            $after_data = $distributor_id;
+            $admin_id = $user_id;//cmf_get_current_admin_id();
+            $log_info = '变更前:' . DistributorModel::get($befor_data)['name'] . ';变更后:' . DistributorModel::get($after_data)['name'];
+
+            $model->where('id', $code['id'])->update(['user_id' => $user_id, 'apply_time' => time()]);
+            $userModel = new UserModel();
+            $userModel::where('id', $user_id)->update(['distributor_id' => $distributor_id]);
+            admin_log($admin_id, $log_info, $user_id, '指定分销商等级');
+            $this->success('绑定分销商成功!');
+        } else {
+            $this->error('已经被绑定!');
+        }
+    }
+
+    public function codeOpt()
+    {
+        $distributor_id = $this->request->param('id');
+        $erm = $this->request->param('code');
+        if (empty($erm)) {
+            return $this->error('请输入二维码!');
+        }
+        $model = new CouponModel();
+        //查询验证码
+        $code = $model->with(['user'])->where('code', $erm)->find();
+        if (empty($code)) {
+            return $this->error('二维码不存在!');
+        }
+        $url = 'https://' . $_SERVER['SERVER_NAME'] . '/h5/#/pages/zhuce/zhuce?yqm=';
+        if (empty($code['user_id'])) {
+//            未绑定绑定用户
+            $user_id = $this->getUserId();
+//                $user_id = 35;
+            $befor_data = UserModel::get($user_id)['distributor_id'];
+            $after_data = $distributor_id;
+            $admin_id = $user_id;
+            $log_info = '变更前:' . DistributorModel::get($befor_data)['name'] . ';变更后:' . DistributorModel::get($after_data)['name'];
+
+            $model->where('id', $code['id'])->update(['user_id' => $user_id, 'apply_time' => time()]);
+            UserModel::where('id', $user_id)->update(['distributor_id' => $distributor_id]);
+            admin_log($admin_id, $log_info, $user_id, '指定分销商等级');
+
+            $info = UserModel::get($user_id);
+            $this->success('绑定成功!', ['code' => $code['code'], 'yqf' => $url . $info['referral'], 'new' => 1, 'distributor_id' => $info['distributor_id']]);
+//
+        } else {
+            //绑定了则返回用户的二维码
+            $this->success('绑定失败!二维码已被使用!', ['code' => $code['code'], 'yqf' => $url . $code['user']['referral'], 'new' => 0, 'distributor_id' => $code['user']['distributor_id']]);
+        }
+    }
+}

+ 66 - 0
api/js/controller/StoreController.php

@@ -0,0 +1,66 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-12
+     * Time: 13:47
+     */
+    
+    namespace api\js\controller;
+    
+    
+    
+    use api\js\model\GoodsCategoryModel;
+    use api\js\model\GoodsModel;
+    use api\js\model\GoodsSeckillModel;
+    use cmf\controller\RestBaseController;
+    use think\Db;
+    class StoreController extends RestBaseController
+    {
+        public function index()
+        {
+            $banner = Db::name('slide_item')->where('slide_id',2)->where('status',1)->order('list_order','asc')->select()->each(function ($banner){
+                $banner['image'] = cmf_get_image_preview_url($banner['image']);
+                return $banner;
+            });
+            $goodsCategoryModel = new GoodsCategoryModel();
+            $goodsCategory = $goodsCategoryModel->getlist();
+            $goodsSeckillModel = new GoodsSeckillModel();
+            $seckill = $goodsSeckillModel->getlist();
+            $goodsModel = new GoodsModel();
+            $goods_where['is_sell'] = 1;
+            $goods = $goodsModel->getlist($goods_where);
+            
+            $search = Db::name('goods_search')->select();
+            
+            $this->success('ok',['banner'=>$banner,'goods_category'=>$goodsCategory,'seckill'=>$seckill,'goods'=>$goods,'search'=>$search]);
+            
+        }
+        
+        
+        public function getList()
+        {
+            $GoodsModel = new GoodsModel();
+            $where = [];
+            $page = $this->request->param('page',1);
+            $name = $this->request->param('name');
+            $category_id = $this->request->param('category_id');
+   
+            if($category_id){
+                $where['category_id'] = $category_id;
+            }
+            $list = $GoodsModel->getlist($where,$page,$name);
+            $this->success('ok',$list);
+            
+        }
+        
+        public function getInfo()
+        {
+            $id = $this->request->param('id');
+            $GoodsModel = new GoodsModel();
+            $info = $GoodsModel->getInfo($id);
+            $this->success('ok',$info);
+        }
+        
+        
+    }

+ 258 - 0
api/js/controller/SystemController.php

@@ -0,0 +1,258 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-27
+     * Time: 15:38
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\JsModel;
+    use api\js\model\JsOrderModel;
+    use api\js\model\JsProjectModel;
+    use api\js\model\UserModel;
+    use cmf\controller\RestBaseController;
+    use JPush\Client;
+    use JPush\Exceptions\APIConnectionException;
+    use think\Db;
+    use think\Exception;
+
+    class SystemController extends RestBaseController
+    {
+        /**
+         * 服务自动结束
+         */
+        public function automatic()
+        {
+            $JsOrderModel = new JsOrderModel();
+            $list = $JsOrderModel::where('status',6)->field('id,jiedan_js_id,user_id,start_time,minute,jgpus,order_price,order_sn')->select();
+    
+        
+    
+    
+    
+            $info = cmf_get_option('jspus');
+//            $js_client = new Client($info['js_app_key'],$info['js_master_secret']);
+//            $client = new Client($info['app_key'],$info['master_secret']);
+            foreach ($list as $vo){
+           
+                
+                $url = '/pages/ddxq/ddxq?id='.$vo['id'];
+                $jsuserid = $js_user_id = Db::name('js')->where('id',$vo['jiedan_js_id'])->value('user_id');
+                $js_user_id.='js';
+                if(($vo['start_time'] +$vo['minute'] * 60 - time()) <= 10*60 && $vo['jgpus'] == 0){
+                     //推送
+                    Db::name('js_order')->where('id',$vo['id'])->update(['jgpus'=>1]);
+    
+                  
+                    $js_client = new Client($info['js_app_key'],$info['js_master_secret']);
+                    $client = new Client($info['app_key'],$info['master_secret']);
+                   
+                    $extras = [
+                        'id' =>  $vo['id'],
+                        'flag' => '用户',
+                        'url' =>$url
+                    ];
+                    $array = [
+                        'extras'=> $extras,
+                    ];
+                    $text= '服务还有10分钟结束';
+                    $platform = array('ios', 'android');
+                    $user_id = $vo['user_id'].'js';
+                  
+                 try{
+                     $client->push()
+                         ->setPlatform($platform)
+                         ->setNotificationAlert($text)
+                         ->iosNotification($text, $array)
+                         ->androidNotification($text, $array)
+                         ->addAlias("{$user_id}")
+                         ->send();
+                
+                 }catch (APIConnectionException $e){
+                     //  dump($e);
+                     $this->error('推送失败:'. $e);
+                 }catch (APIConnectionException $e){
+                     // print $e;
+                     $this->error('推送失败:'.$e);
+                 }
+               
+                    $extras = [
+                        'id' =>  $vo['id'],
+                        'flag' => '技师端',
+                        'url' =>$url
+                    ];
+                    $array = [
+                        'extras'=> $extras,
+                    ];
+                    $text= '服务还有10分钟结束';
+                    try{
+                        $js_client->push()
+                            ->setPlatform($platform)
+                            ->setNotificationAlert($text)
+                            ->iosNotification($text, $array)
+                            ->androidNotification($text, $array)
+                            ->addAlias("{$js_user_id}")
+                            ->send();
+                    }catch (\JPush\Exceptions\APIConnectionException $e){
+                        //  dump($e);
+                     //   $this->error('推送失败:'. $e);
+                    }catch (\JPush\Exceptions\APIRequestException $e){
+                        // print $e;
+                   //     $this->error('推送失败:'.$e);
+                    }
+                }
+                if(($vo['start_time'] + $vo['minute'] * 60) <= time() && $vo['jgpus'] == 1){
+                    Db::name('js_order')->where('id',$vo['id'])->update(['jgpus'=>2]);
+                    $JsOrderModel::where('id',$vo['id'])->update(['status'=>3,'finish_time'=>time()]);
+                    JsModel::where('id',$vo['jiedan_js_id'])->setInc('jiedan_num',1);
+					$userDalance = UserModel::get($jsuserid)['balance'];
+                    if($vo['order_price'] > 0){
+                        UserModel::where('id',$jsuserid)->setInc('balance',$vo['order_price']);
+                        $log['user_id'] = $jsuserid;
+                        $log['money'] = $vo['order_price'];
+						$log['order_sn'] = $vo['order_sn'];
+						$log['yue'] = $userDalance + $vo['order_price'];
+                        $log['type'] = 8;
+                        $log['remark'] = '完成服务获得金额.';
+                        $log['add_time'] = time();
+                        $log['obj_id'] = $vo['id'];
+                        if($log['money'] != 0){
+                            Db::name('user_money_log')->insert($log);
+                        }
+                    }
+                    fenxiao($vo['id'],1);
+                    fenxiao($vo['id'],2);
+                    $js_user_id = Db::name('js')->where('id',$vo['jiedan_js_id'])->value('user_id');
+                    $js_user_id.='js';
+                    $js_client = new Client($info['js_app_key'],$info['js_master_secret']);
+                    $client = new Client($info['app_key'],$info['master_secret']);
+                    $platform = array('ios', 'android');
+                    $user_id = $vo['user_id'].'js';
+                    $extras = [
+                        'id' =>  $vo['id'],
+                        'flag' => '用户',
+                        'url' => $url
+                    ];
+                    $array = [
+                        'extras'=> $extras,
+                    ];
+                    $text= '服务已结束';
+                    try{
+                        $client->push()
+                            ->setPlatform($platform)
+                            ->setNotificationAlert($text)
+                            ->iosNotification($text, $array)
+                            ->androidNotification($text, $array)
+                            ->addAlias("{$user_id}")
+                            ->send();
+  
+                    }catch (\JPush\Exceptions\APIConnectionException $e){
+                        //  dump($e);
+      
+                    }catch (\JPush\Exceptions\APIRequestException $e){
+                        // print $e;
+                    }
+    
+     
+                    $extras = [
+                        'id' =>  $vo['id'],
+                        'flag' => '技师端',
+                        'url' => $url
+                    ];
+                    $array = [
+                        'extras'=> $extras,
+                    ];
+                    $text= '服务已结束';
+                    try{
+                        $js_client->push()
+                            ->setPlatform($platform)
+                            ->setNotificationAlert($text)
+                            ->iosNotification($text, $array)
+                            ->androidNotification($text, $array)
+                            ->addAlias("{$js_user_id}")
+                            ->send();
+                        
+                    }catch (\JPush\Exceptions\APIConnectionException $e){
+                        //  dump($e);
+    
+                    //    $this->error('推送失败:'. $e);
+                    }catch (\JPush\Exceptions\APIRequestException $e){
+                        // print $e;
+   
+                    }
+  
+                }
+            }
+        
+        }
+        
+        
+        /**
+         * 下单后无接单自动取消订单
+         */
+        
+        public function cancelOrder()
+        {
+            $info = cmf_get_option('duration');
+            $JsOrderModel = new JsOrderModel();
+            $list = $JsOrderModel::where('status',1)->field('id,user_id,price,pay_price,create_time,type,appoint_time')->select();
+            foreach ($list as $value){
+                if($value['type'] == 1){
+                    if(time() > ($value['create_time']+$info['real_time']*3600)){
+                        if(Db::name('js_order')->where('id',$value['id'])->update(['status'=>5])){
+							$outMoney = $value['pay_price'];
+							if($outMoney > 0){
+								$userDalance = UserModel::get($value['user_id'])['balance'];
+								UserModel::where('id',$value['user_id'])->setInc('balance',$outMoney);
+								$log['user_id'] = $value['user_id'];
+								$log['money'] = $outMoney;
+								$log['yue'] = $userDalance + $outMoney;
+								$log['type'] = 2;
+								$log['remark'] = '无技师接单,自动取消订单退款';
+								$log['add_time'] = time();
+								$log['obj_id'] = $value['id'];
+								Db::name('user_money_log')->insert($log);
+							}
+						}
+                    }
+                }
+                if($value['type'] == 2){
+                    if(time() > (($value['create_time']+$value['appoint_time'])+$info['make_time']*3600)){
+                        if(Db::name('js_order')->where('id',$value['id'])->update(['status'=>5])){
+							$outMoney = $value['pay_price'];
+							if($outMoney > 0){
+								UserModel::where('id',$value['user_id'])->setInc('balance',$outMoney);
+								$userDalance = UserModel::get($value['user_id'])['balance'];
+								$log['user_id'] = $value['user_id'];
+								$log['money'] = $outMoney;
+								$log['yue'] = $userDalance + $outMoney;
+								$log['type'] = 2;
+								$log['remark'] = '无技师接单,自动取消订单退款';
+								$log['add_time'] = time();
+								$log['obj_id'] = $value['id'];
+								Db::name('user_money_log')->insert($log);
+							}
+						}
+                   
+                    }
+                }
+            }
+        }
+		public function getautomatic(){
+			$str = cmf_curl_get('http://dd.yunjuhui.net/api/js/system/automatic');
+			if(strlen($str)>0){
+				file_put_contents('./autolog/autolog_'.date("YmdHis").'.txt',$str);
+			}
+			
+		}
+		public function tongji(){
+			$sql = "SELECT count(id) as order_num,user_id FROM `xh_js_order` WHERE `status`=3 or `status`=4 group by user_id order by order_num desc";
+			$list = Db::query($sql);
+			foreach($list as $user){
+				UserModel::where('id',$user['user_id'])->setField('order_num',$user['order_num']);
+			}			
+		}
+    }

+ 92 - 0
api/js/controller/TestController.php

@@ -0,0 +1,92 @@
+<?php
+/*
+ * @Descripttion: 
+ * @version: 
+ * @Author: YouHuJun
+ * @Date: 2022-07-27 09:57:43
+ * @LastEditors: YouHuJun
+ * @LastEditTime: 2022-08-02 11:30:50
+ */
+
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-07
+ * Time: 11:12
+ */
+
+namespace api\js\controller;
+
+use api\js\model\JsModel;
+use api\js\model\JsOrderGrabModel;
+use api\js\model\JsOrderModel;
+use api\js\model\JsSiteModel;
+use api\js\model\JsTimeModel;
+use api\js\model\UserModel;
+use cmf\controller\RestBaseController;
+use JPush\Client;
+use think\Db;
+use Aliyun\DySDKLite\SignatureHelper;
+
+class TestController extends RestBaseController
+{
+    public function index()
+    {
+
+        echo "测试";
+    }
+
+    public function pullReferral()
+    {
+        $userModel = new UserModel();
+        $result = $userModel->where('user_type', 2)->where('referral', 'NULL')->field('id')->select()->toArray();
+        foreach ($result as $key => $value) {
+            $id = $value['id'];
+            if ($id) {
+                $referral = cmf_get_referral();
+                $userModel->allowField(true)->isUpdate(true)->save(['referral' => $referral], ['id' => $id]);
+            }
+        }
+        echo '处理结束';
+    }
+
+    /**
+     * 向用户发送短信通知
+     *
+     * @param [type] $mobile
+     * @param [type] $product
+     * @return void
+     */
+    public function sendMsg($mobile, $product)
+    {
+        $helper = new SignatureHelper();
+        $alisms = cmf_get_option('alisms');
+        $security = false;
+        $accessKeyId = $alisms['access_key_id'];
+        $accessKeySecret = $alisms['access_key_secret'];
+        $js_mobile = $mobile;
+        $params["PhoneNumbers"] = $js_mobile;
+        $params["SignName"] = '嘀咚点到';
+
+        $params["TemplateCode"] = 'SMS_204986367';
+        $params['TemplateParam'] = array(
+            "product" => $product,
+        );
+
+        if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
+            $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
+        }
+        $content = $helper->request(
+            $accessKeyId,
+            $accessKeySecret,
+            "dysmsapi.aliyuncs.com",
+            array_merge($params, array(
+                "RegionId" => "cn-hangzhou",
+                "Action" => "SendSms",
+                "Version" => "2017-05-25",
+            )),
+            $security
+        );
+    }
+
+}

+ 25 - 0
api/js/controller/UpImgController.php

@@ -0,0 +1,25 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-09
+     * Time: 9:53
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use cmf\controller\RestUserBaseController;
+    use cmf\lib\Upload;
+
+    class UpImgController extends RestUserBaseController
+    {
+        public function upimg()
+        {
+            $upimg  = new Upload();
+            $res = $upimg->upload();
+            $res['url'] = cmf_get_image_preview_url($res['filepath']);
+            $this->success('ok',$res);
+        }
+        
+    }

+ 182 - 0
api/js/controller/UserAgencyController.php

@@ -0,0 +1,182 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-28
+     * Time: 10:43
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\AgencyModel;
+    use api\js\model\JsCallModel;
+    use api\js\model\JsOrderModel;
+    use api\js\model\UserModel;
+    use cmf\controller\RestUserBaseController;
+    use think\Db;
+
+    class UserAgencyController extends RestUserBaseController
+    {
+    
+        /**
+         * @throws \think\db\exception\DataNotFoundException
+         * @throws \think\db\exception\ModelNotFoundException
+         * @throws \think\exception\DbException
+         * 获取数量
+         */
+        public function getnum()
+        {
+            $user_id = $this->getUserId();
+            $UserModel = new UserModel();
+            $agency_id = $UserModel::get($user_id)['agency_id'];
+           
+            if(!$agency_id){
+                $this->error('您还不是代理商!');
+            }
+            $result = get_user_and_userjs($user_id);
+            $user_ids_new = $result['user_ids'];
+            $user_js_ids_new = $result['user_js_ids'];
+            $JsOrderModel = new JsOrderModel();
+         
+            $money = Db::name('user_money_log')->where(['user_id'=>$user_id,'type'=>5])->sum('money');
+            $order_num = $JsOrderModel::where('user_id','in',$user_js_ids_new)->count();
+            $user_num = count($user_ids_new);
+            $js_num = count($user_js_ids_new);
+            $call_num = JsCallModel::where('user_id','in',$user_js_ids_new)->where('agency_is_look',0)->count();
+            $this->success('ok',['user_num'=>$user_num,'js_num'=>$js_num,'order_num'=>$order_num,'money'=>$money,'call_num'=>$call_num]);
+        
+        }
+        
+        
+        /**
+         * 查看本地列表
+         */
+        public function getUserList()
+        {
+            $user_id = $this->getUserId();
+            $UserModel = new UserModel();
+            $agency_id = $UserModel::get($user_id)['agency_id'];
+    
+            if(!$agency_id){
+                $this->error('您还不是代理商!');
+            }
+            $district_id = $this->request->param('district_id');
+            $city_id = $this->request->param('city_id');
+            $renk_id = $this->request->param('renk_id');
+            $result = get_user_and_userjs($user_id,$district_id,$city_id,$renk_id);
+            $where['id'] = $result['user_ids'];
+            $page = $this->request->param('page',1);
+            $user_list = $UserModel::where($where)->field('id,mobile,user_nickname,avatar,create_time')->order('id','desc')->page($page,20)->select()->each(function ($user_list){
+                $user_list['mobile'] = preg_replace("/(\d{3})\d{4}(\d{4})/", "\$1****\$2", $user_list['mobile']);
+                return $user_list;
+            });
+            $this->success('ok',$user_list);
+        }
+    
+        /**
+         * 查看技师列表
+         */
+        public function getJsList()
+        {
+            $user_id = $this->getUserId();
+            $UserModel = new UserModel();
+            $agency_id = $UserModel::get($user_id)['agency_id'];
+    
+            if(!$agency_id){
+                $this->error('您还不是代理商!');
+            }
+            $district_id = $this->request->param('district_id');
+            $city_id = $this->request->param('city_id');
+            $renk_id = $this->request->param('renk_id');
+            $result = get_user_and_userjs($user_id,$district_id,$city_id,$renk_id);
+            $where['id'] = $result['user_js_ids'];
+        
+            $page = $this->request->param('page',1);
+            $user_list = $UserModel::with('jsStatus')->where($where)->field('id,mobile,user_nickname,avatar,create_time')->order('id','desc')->page($page,20)->select()->each(function ($user_list){
+                $user_list['mobile'] = preg_replace("/(\d{3})\d{4}(\d{4})/", "\$1****\$2", $user_list['mobile']);
+                if(!$user_list->js_status){
+                    $user_list->js_status = ['js_status'=>0];
+                }
+                return $user_list;
+            });
+       
+            $this->success('ok',$user_list);
+        }
+    
+        /**
+         *技师订单列表
+         */
+        public function getOrder()
+        {
+            $user_id = $this->getUserId();
+            $UserModel = new UserModel();
+            $agency_id = $UserModel::get($user_id)['agency_id'];
+            $district_id = $this->request->param('district_id');
+            $city_id = $this->request->param('city_id');
+            $renk_id = $this->request->param('renk_id');
+            if(!$agency_id){
+                $this->error('您还不是代理商!');
+            }
+            $result = get_user_and_userjs($user_id,$district_id,$city_id,$renk_id);
+            $JsOrderModel = new JsOrderModel();
+            $page = $this->request->param('page',1);
+         
+            $list = $JsOrderModel::with('project.tag')->where('user_id','in',$result['user_js_ids'])->order('id','desc')->page($page,20)->select();
+            $this->success('ok',$list);
+        }
+    
+        
+        /**
+         * 报警列表
+         */
+        
+        public function getCallList()
+        {
+            $user_id = $this->getUserId();
+            $UserModel = new UserModel();
+            $agency_id = $UserModel::get($user_id)['agency_id'];
+            $district_id = $this->request->param('district_id');
+            if(!$agency_id){
+                $this->error('您还不是代理商!');
+            }
+        
+            $city_id = $this->request->param('city_id');
+            $renk_id = $this->request->param('renk_id');
+            $result = get_user_and_userjs($user_id,$district_id,$city_id,$renk_id);
+            $agency_is_look = $this->request->param('agency_is_look',0);
+            $page = $this->request->param('page',1);
+            $JsCallModel = new JsCallModel();
+            $list = $JsCallModel::with('js_user,jsOrder.project')->where('user_id','in',$result['user_js_ids'])->where('agency_is_look',$agency_is_look)->order('id','desc')->page($page,20)->select();
+            $this->success('ok',$list);
+        }
+        
+        /**
+         * 获取代理的地区
+         */
+        
+        public function getDistrict()
+        {
+            $user_id = $this->getUserId();
+            $agency_id = UserModel::get($user_id)['agency_id'];
+    
+            if(!$agency_id){
+                $this->error('您还不是代理商!');
+            }
+            $agency_ids = UserModel::where('id',$user_id)->value('agency_id');
+   
+            $agency_ids_array = explode(',',$agency_ids);
+
+            $list = Db::name('agency')->where('id','in',$agency_ids_array)->field('id,renk_id,city_id,district_id')->select()->each(function ($list){
+                if($list['renk_id'] == 1){
+                    $list['cityName'] = Db::name('region')->where('id',$list['city_id'])->value('cityName');
+                }
+                if($list['renk_id'] == 2){
+                    $list['cityName'] = Db::name('region')->where('id',$list['district_id'])->value('cityName');
+                }
+                return $list;
+            });
+            $this->success('ok',$list);
+        }
+        
+    }

+ 334 - 0
api/js/controller/UserController.php

@@ -0,0 +1,334 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-09
+ * Time: 9:04
+ */
+
+namespace api\js\controller;
+
+
+use api\js\model\DistributorLogModel;
+use api\js\model\DistributorModel;
+use api\js\model\JsModel;
+use api\js\model\JsTimeModel;
+use api\js\model\UserDiscountModel;
+use api\js\model\UserModel;
+use api\js\model\UserTxModel;
+use cmf\controller\RestUserBaseController;
+use think\Db;
+use think\Validate;
+
+class UserController extends RestUserBaseController
+{
+
+    /**
+     * 注销用户账户
+     *
+     * @param [type] $mobile
+     * @param [type] $product
+     * @return void
+     */
+    public function destroy()
+    {
+        $user_id = $this->getUserId();
+        $info = UserModel::get($user_id);
+        $res = $info->delete();
+        $this->success('注销成功', $res);
+    }
+
+    /**
+     * 用户信息
+     */
+    public function getInfo()
+    {
+        $user_id = $this->getUserId();
+        $info = UserModel::get($user_id);
+        $info->openid = Db::name('third_party_user')->where('user_id', $user_id)->value('openid');
+        $info->js;
+        if ($info['user_type'] == 3) {
+            $info['js']['is_work'] = 0;
+            if ($info['js']->js_time) {
+                $week = date('w', time());
+                if (in_array($week, $info['js']->js_time->weeks)) {
+                    foreach ($info['js']->js_time->times as $vo) {
+                        if (strtotime($vo['js_end_time']) >= strtotime(date('H:i'))) {
+                            //在此处判断一下是否已经接单
+                            $is_work = Db::name('js_order')->where('jiedan_js_id', $info['js']['id'])->where('status', 6)->find();
+                            if (empty($is_work)) {
+                                $info['js']['is_work'] = 1;
+                            } else {
+                                $info['js']['is_work'] = 2;
+                            }
+                        }
+                    }
+
+                }
+                unset($info['js']->js_time);
+            }
+        }
+        $info->is_agency = 0;
+        if ($info->agency_id) {
+            $info->is_agency = 1;
+            $info->agency_id = 1;
+        } else {
+            $info->agency_id = 0;
+        }
+        $info->distributor_status = DistributorLogModel::where('user_id', $user_id)->value('chuli_status');
+        $info->fenxiaoshang = DistributorModel::get($info->distributor_id)['name'];
+        unset($info['user_pass']);
+        $this->success('ok', $info);
+    }
+
+    /**
+     * 申请成为技师
+     */
+    public function applyJsPost()
+    {
+        $user_id = $this->getUserId();
+        $user_info =  UserModel::get($user_id);
+        $user_type = $user_info['user_type'];
+        if ($user_type != 3) {
+            $this->error('请先去师傅端注册!');
+        }
+
+        $data['user_id'] = $user_id;
+        $data['name'] = $this->request->param('name');
+        $phone = $this->request->param('phone');
+
+        $data['phone'] = $phone ?: $user_info['mobile'];
+
+//        if (!$data['phone']) {
+//            $this->error('请填写联系电话不可为空!');
+//        }
+
+        $data['is_real_time'] = $this->request->param('is_real_time');
+        $data['is_make'] = $this->request->param('is_make');
+        $data['jianjie'] = $this->request->param('jianjie');
+        $data['sex'] = $this->request->param('sex');
+        $data['apply_num'] = 1;
+        $data['identity'] = $this->request->param('identity/a');
+        $data['certificates'] = $this->request->param('certificates/a');
+        $data['pictures'] = $this->request->param('pictures/a');
+        $work = $this->request->param('work/a');
+        if (isset($work)) {
+            $data['work'] = $work;
+        }
+        $JsModel = new JsModel();
+//            $js_id = $JsModel::where('phone',$data['phone'])->value('id');
+//            if($js_id){
+//                $this->error('此号码已认证,请到我的设置中修改信息!');
+//            }
+
+        $info = $JsModel::where('user_id', $user_id)->find();
+
+
+        $JsTimeModel = new JsTimeModel();
+        if ($info) {
+            $js_time['js_id'] = $info['id'];
+            $js_time_info = Db::name('js_time')->where('js_id', $js_time['js_id'])->find();
+            if (!$js_time_info) {
+                $js_time['times'] = [0 => ['js_start_time' => '00:00', 'js_end_time' => '23:59']];
+                $js_time['weeks'] = ['1', '2', '3', '4', '5', '6', '0'];
+                $JsTimeModel->allowField(true)->isUpdate(false)->save($js_time);
+            }
+            $data['js_status'] = 0;
+            $JsModel->allowField(true)->isUpdate(true)->save($data, ['id' => $info['id']]);
+            $this->success('修改成功');
+        } else {
+            $JsModel->applyJsPost($data);
+            $js_time['js_id'] = $JsModel->id;
+            $js_time_info = Db::name('js_time')->where('js_id', $js_time['js_id'])->find();
+            if (!$js_time_info) {
+                $js_time['times'] = [0 => ['js_start_time' => '00:00', 'js_end_time' => '23:59']];
+                $js_time['weeks'] = ['1', '2', '3', '4', '5', '6', '0'];
+                $JsTimeModel->allowField(true)->isUpdate(false)->save($js_time);
+            }
+            $this->success('申请成功');
+        }
+
+    }
+
+    /**
+     * 申请项目
+     */
+    public function applyProjectPost()
+    {
+        $user_id = $this->getUserId();
+        $project_id = $this->request->param('project_id');
+        if (!$project_id) {
+            $this->error('缺少project_id参数!');
+        }
+        $user_type = UserModel::get($user_id)['user_type'];
+        if ($user_type != 3) {
+            $this->error('请先去师傅端注册!');
+        }
+        $JsModel = new JsModel();
+        $js_id = $JsModel::where('user_id', $user_id)->value('id');
+        $res = $JsModel->applyProjectPost($js_id, $project_id);
+        if ($res) {
+            $this->success('申请成功');
+        } else {
+            $this->error('无需重复申请!');
+        }
+
+    }
+
+
+    public function getDiscount()
+    {
+        $where = [];
+        $status = $this->request->param('status');
+        if ($status || $status === '0') {
+            $where['status'] = $status;
+        }
+
+        $where['user_id'] = $this->getUserId();
+        $UserDiscountModel = new UserDiscountModel();
+        $list = $UserDiscountModel->getList($where);
+        $this->success('ok', $list);
+    }
+
+    /**
+     * 用户修改信息
+     */
+    public function editInfo()
+    {
+        $user_id = $this->getUserId();
+        $data['avatar'] = $this->request->param('avatar');
+        $data['user_nickname'] = $this->request->param('user_nickname');
+        $UserMolde = new UserModel();
+        $UserMolde->allowField(true)->isUpdate(true)->save($data, ['id' => $user_id]);
+        //  $JsModel = new JsModel();
+        //    $JsModel->allowField(true)->isUpdate(true)->save($data,['user_id'=>$user_id]);
+        $this->success('修改成功');
+    }
+
+
+    public function addIdea()
+    {
+        $data['user_id'] = $this->getUserId();
+        $data['idea'] = $this->request->param('idea');
+        $data['add_time'] = time();
+        Db::name('idea')->insert($data);
+        $this->success('提交成功');
+    }
+
+    public function getxiaji()
+    {
+        $page = $this->request->param('page', 1);
+        $type = $this->request->param('type', 1);
+        $userModel = new UserModel();
+        $user_id = $this->getUserId();
+
+        $fied = 'parent_id';
+        if ($type == 2) {
+            $fied = 'parent_id1';
+        }
+        $list = $userModel::where($fied, $user_id)->order('id', 'desc')->page($page, 20)->field('id,mobile,user_nickname,create_time')->select()->each(function ($list) {
+            $list['mobile'] = preg_replace("/(\d{3})\d{4}(\d{4})/", "\$1****\$2", $list['mobile']);
+            return $list;
+        });
+        $this->success('ok', $list);
+    }
+
+
+    public function getMoneyLog()
+    {
+        $page = $this->request->param('page', 1);
+        $list = Db::name('user_money_log')->where('user_id', $this->getUserId())->order('id', 'desc')->page($page, 20)->select();
+        $this->success('ok', $list);
+
+    }
+
+    /**
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     *获取二维码
+     */
+    public function geterweima()
+    {
+        $user_id = $this->getUserId();
+        $erweima = UserModel::get($user_id)['erweima'];
+        $referral = UserModel::get($user_id)['referral'];
+        $value = 'http://' . $_SERVER['SERVER_NAME'] . '/h5/#/pages/zhuce/zhuce?yqm=' . $referral;
+
+        if (!$erweima) {
+            $res = qeCode($value, $this->request->controller(), $user_id);
+            UserModel::where('id', $user_id)->update(['erweima' => $res]);
+            $this->success('ok', ['erweima' => cmf_get_image_preview_url($res), 'url' => $value, 'referral' => $referral]);
+        } else {
+            $this->success('ok', ['erweima' => cmf_get_image_preview_url($erweima), 'url' => $value, 'referral' => $referral]);
+        }
+    }
+
+
+    /**
+     * @throws \think\Exception
+     * 提现
+     */
+    public function addTx()
+    {
+        $data['user_id'] = $this->getUserId();
+        $data['tx_type'] = $this->request->param('tx_type');
+        $data['money'] = $this->request->param('money');
+        $data['zfb_name'] = $this->request->param('zfb_name');
+        $data['zfb_action'] = $this->request->param('zfb_action');
+        $data['order_sn'] = cmf_get_order_sn();
+        $user_balance = UserModel::get($this->getUserId())['balance'];
+        if ($data['tx_type'] == 1) {
+            $wx_openid = Db::name('third_party_user')->where('user_id', $data['user_id'])->where('union_id', '微信平台')->value('openid');
+            if (!$wx_openid) {
+                $this->error('请先绑定wx_openid!');
+            }
+        } else {
+            $validate = new Validate([
+                'zfb_name' => 'require',
+                'zfb_action' => 'require',
+
+            ]);
+            $validate->message([
+                'zfb_name.require' => '支付宝姓名不可为空!',
+                'zfb_action.require' => '支付宝账号不可为空!',
+            ]);
+            if (!$validate->check($data)) {
+                $this->error($validate->getError());
+            }
+        }
+        if ($data['money'] > $user_balance) {
+            $this->error('余额不足!');
+        }
+        if ($data['money'] < 0.01) {
+            $this->error('提现余额不可小于0.01!');
+        }
+        UserModel::where('id', $data['user_id'])->setDec('balance', $data['money']);
+        $UserTxModel = new UserTxModel();
+        $UserTxModel->allowField(true)->isUpdate(false)->save($data);
+        $log['user_id'] = $data['user_id'];
+        $log['money'] = -$data['money'];
+        $log['yue'] = $user_balance - $data['money'];
+        $log['type'] = 99;
+        $log['remark'] = '余额提现';
+        $log['add_time'] = time();
+        $log['obj_id'] = $UserTxModel->id;
+        Db::name('user_money_log')->insert($log);
+        $this->success('申请成功');
+    }
+
+    /**
+     * 申请代理
+     */
+    public function agencyapply()
+    {
+        $data['name'] = $this->request->param('name');
+        $data['mobile'] = $this->request->param('mobile');
+        $data['district'] = $this->request->param('district');
+        $data['add_time'] = time();
+        $data['user_id'] = $this->getUserId();
+        Db::name('user_apply_agency')->insert($data);
+        $this->success('ok', '申请成功');
+    }
+
+
+}

+ 923 - 0
api/js/controller/UserJsController.php

@@ -0,0 +1,923 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-12
+ * Time: 14:26
+ */
+
+namespace api\js\controller;
+
+use Aliyun\DySDKLite\SignatureHelper;
+use api\js\model\DistributorLogModel;
+use api\js\model\DistributorModel;
+use api\js\model\JsCallModel;
+use api\js\model\JsCourseOrderModel;
+use api\js\model\JsModel;
+use api\js\model\JsOrderGrabModel;
+use api\js\model\JsOrderModel;
+use api\js\model\JsProjectCategoryModel;
+use api\js\model\JsProjectModel;
+use api\js\model\JsTimeModel;
+use api\js\model\UserModel;
+use cmf\controller\RestUserBaseController;
+use JPush\Client;
+use think\Db;
+
+class UserJsController extends RestUserBaseController
+{
+    protected $js_id;
+    protected $js_status = false;
+
+    public function initialize()
+    {
+        $user_id = $this->getUserId();
+        $JsModel = new JsModel();
+        $js_info = $JsModel::where('user_id', $user_id)->find();
+        if ($js_info['id']) {
+            $this->js_id = $js_info['id'];
+            if ($js_info['js_status'] == 1) {
+                $this->js_status = true;
+            }
+
+        }
+        parent::initialize(); // TODO: Change the autogenerated stub
+    }
+
+    /**
+     * 注销技师账户
+     *
+     * @param [type] $mobile
+     * @param [type] $product
+     * @return void
+     */
+    public function destroy()
+    {
+        $info = JsModel::get($this->js_id);
+        $res = $info->delete();
+        $this->success('注销成功', $res);
+    }
+
+    /**
+     * 向用户发送短信通知
+     *
+     * @param [type] $mobile
+     * @param [type] $product
+     * @return void
+     */
+    protected function sendMsg($mobile, $product)
+    {
+        $helper = new SignatureHelper();
+        $alisms = cmf_get_option('alisms');
+        $security = false;
+        $accessKeyId = $alisms['access_key_id'];
+        $accessKeySecret = $alisms['access_key_secret'];
+        $js_mobile = $mobile;
+        $params["PhoneNumbers"] = $js_mobile;
+        $params["SignName"] = '嘀咚点到';
+
+        $params["TemplateCode"] = 'SMS_247620502';
+        $params['TemplateParam'] = array(
+            "product" => $product,
+        );
+
+        if (!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
+            $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
+        }
+        $content = $helper->request(
+            $accessKeyId,
+            $accessKeySecret,
+            "dysmsapi.aliyuncs.com",
+            array_merge($params, array(
+                "RegionId" => "cn-hangzhou",
+                "Action" => "SendSms",
+                "Version" => "2017-05-25",
+            )),
+            $security
+        );
+    }
+
+    /**
+     * 技师用户个人中心
+     */
+    public function getInfo()
+    {
+        if (!$this->js_id) {
+            $this->error('认证信息不存在!');
+        }
+
+        $info = JsModel::get($this->js_id);
+        $info->score = get_js_score($this->js_id);
+        $info->distributor_status = DistributorLogModel::where('user_id', $this->userId)->value('chuli_status');
+        $info->fenxiaoshang = DistributorModel::get(UserModel::get($this->userId)['agency_id'])['name'];
+        $info = $info->toarray();
+        $info['js']['name'] = $info['name'];
+        $info['js']['avatar'] = $info['avatar'];
+        $this->success('ok', $info);
+    }
+
+    /**
+     * 加载我的时间
+     */
+    public function getTime()
+    {
+        $user_id = $this->getUserId();
+        $JsModel = new JsModel();
+        $jsId = $JsModel::where('user_id', $user_id)->value('id');
+        $JsTimeModel = new JsTimeModel();
+        $list = $JsTimeModel::where('js_id', $jsId)->select();
+        $this->success('ok', $list);
+    }
+
+    /**
+     * 添加我的时间
+     */
+    public function addTimePost()
+    {
+        $user_id = $this->getUserId();
+        $JsModel = new JsModel();
+        $data['js_id'] = $JsModel::where('user_id', $user_id)->value('id');
+        $data['times'] = $this->request->param('times/a');
+        $data['weeks'] = $this->request->param('week/a');
+        Db::name('js_time')->where('js_id', $data['js_id'])->delete();
+        $JsTimeModel = new JsTimeModel();
+        $JsTimeModel->allowField(true)->isUpdate(false)->save($data);
+        $this->success('添加成功');
+
+    }
+
+    /**
+     * 更改上下钟
+     * @return void
+     */
+    public function setWorkTime()
+    {
+        $user_id = $this->getUserId();
+        $is_work = $this->request->post('is_work');
+        $data['times'] = [0 => ['js_start_time' => '00:00', 'js_end_time' => '23:59']];
+        $data['weeks'] = ['1', '2', '3', '4', '5', '6', '0'];
+        if (!$is_work) $data['times'] = [];
+        $JsModel = new JsModel();
+        $js_id = $JsModel::where('user_id', $user_id)->value('id');
+        $JsTimeModel = new JsTimeModel();
+        $ret = $JsTimeModel->allowField(true)->isUpdate(true)->save($data, ['js_id' => $js_id]);
+        $this->success($is_work ? '上钟成功' : '下钟成功', $ret);
+    }
+
+    /**
+     * 获取技师地点
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function getPostSite()
+    {
+        $user_id = $this->getUserId();
+        $JsModel = new JsModel();
+
+        $jsId = $JsModel::where('user_id', $user_id)->value('id');
+        $res = '';
+        if ($jsId) {
+            $id = Db::name('js_site')->where('js_id', $jsId)->value('id');
+            $res = Db::name('js_site')->where('id', $id)->find();
+        }
+        $this->success('ok', $res);
+    }
+
+    /**
+     * 更新技师地点
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function addPostSite()
+    {
+        $user_id = $this->getUserId();
+        $JsModel = new JsModel();
+
+        $jsId = $JsModel::where('user_id', $user_id)->value('id');
+
+        $lng = $this->request->param('long');
+        $lat = $this->request->param('lat');
+
+        $id = 0;
+        $ret = 0;
+        if ($jsId) {
+            $id = Db::name('js_site')->where('js_id', $jsId)->value('id');
+
+            if ($id) {
+                $ret = Db::name('js_site')->where('id', $id)->update(['lng' => $lng, 'lat' => $lat]);
+            } else {
+                $ret = Db::name('js_site')->where('id', $id)->insert(['lng' => $lng, 'lat' => $lat, 'js_id' => $jsId]);
+            }
+        }
+
+        $this->success('定位成功', $ret);
+    }
+
+
+    /**
+     * 技师申请项目
+     */
+    public function postProject()
+    {
+        if (!$this->js_status) {
+            $this->error('您还没有认证技师!');
+        }
+        $data['js_id'] = $this->js_id;
+        $data['project_id'] = $this->request->param('project_id');
+        $info = Db::name('js_project_relevancy')->where($data)->field('id,status')->find();
+        if ($info) {
+            if ($info['status'] == 0) {
+                $this->error('您已申请该项目!');
+            } elseif ($info['status'] == 2) {
+                $data['add_time'] = time();
+                Db::name('js_project_relevancy')->update(['status' => 0, 'id' => $info['id']]);
+                $this->success('申请成功');
+            }
+
+        } else {
+            $data['add_time'] = time();
+            Db::name('js_project_relevancy')->insert($data);
+            $this->success('申请成功');
+        }
+    }
+
+
+    /**
+     * 技师编辑个人信息
+     */
+    public function editInfo()
+    {
+        $js_id = $this->js_id;
+
+        $UserModel = new UserModel();
+        $mobile = $UserModel->where('id', $this->getUserId())->value('mobile');
+//        if (!$this->js_status) {
+//            $this->error('认证暂未通过不可修改!');
+//        }
+        $JsModel = new JsModel();
+        $serviceData = $JsModel->where('id', $js_id)->find();
+
+        $data['avatar'] = $this->request->param('avatar');
+        $data['name'] = $this->request->param('name');
+        $data['is_make'] = $this->request->param('is_make');
+        $data['is_real_time'] = $this->request->param('is_real_time');
+        $data['phone'] = $this->request->param('phone');
+        $data['phone'] = $data['phone'] ?: $mobile;
+        $data['jianjie'] = $this->request->param('jianjie');
+        $sex = $this->request->param('sex');
+        if (isset($sex)) $data['sex'] = $sex;
+        if ($serviceData['avatar'] != $data['avatar'] || $serviceData['name'] != $data['name'] || $serviceData['jianjie'] != $data['jianjie'])
+            $data['js_status'] = 0;
+        UserModel::where('id', $this->getUserId())->update(['avatar' => $data['avatar']]);
+        $JsModel->allowField(true)->isUpdate(true)->save($data, ['id' => $js_id]);
+        $this->success('修改成功');
+
+    }
+
+    public function editPicture()
+    {
+        $js_id = $this->js_id;
+        if (!$js_id) {
+            $this->error('您还没有认证技师!');
+        }
+        $data['work'] = $this->request->param('work/a');
+        //  $data['massage'] = $this->request->param('massage/a');
+        $data['pictures'] = $this->request->param('pictures/a');
+        $data['js_status'] = 0;
+        $JsModel = new JsModel();
+        $JsModel->allowField(true)->isUpdate(true)->save($data, ['id' => $js_id]);
+
+        $this->success('修改成功');
+    }
+
+    public function getPicture()
+    {
+        $JsModel = new JsModel();
+        $info = $JsModel::get($this->js_id);
+        $res['work'] = $info->work;
+        $res['pictures'] = $info->pictures;
+        $this->success('ok', $res);
+    }
+
+
+    /**
+     * 视频课程列表
+     */
+    public function getCourseList()
+    {
+        $name = $this->request->param('name');
+        $page = $this->request->param('page', 1);
+        $JsProjectModel = new JsProjectModel();
+        $jsCourseModel = new JsCourseOrderModel();
+        $list = $JsProjectModel::with('tag')->where(function ($query) use ($name) {
+            if ($name) {
+                $query->where('name', 'like', '%' . $name . '%');
+            }
+        })->field('id,name,brief,course_price,video_sl,video')->order('list_order', 'asc')->page($page, 20)->select()->each(function ($list) use ($jsCourseModel) {
+            $list->video = cmf_get_image_preview_url($list->video);
+            $list->video_sl = cmf_get_image_preview_url($list->video_sl);
+            $course_order_status = $jsCourseModel::where(['user_id' => $this->getUserId(), 'project_id' => $list->id])->value('status');
+            $list->purchase = isset($course_order_status) ? $course_order_status : 0;
+        });
+
+        $this->success('ok', $list);
+    }
+
+
+    /**
+     *获取详情
+     */
+
+    public function getCourseInfo()
+    {
+        $id = $this->request->param('project_id');
+        $jsCourseModel = new JsCourseOrderModel();
+        $course_order_status = $jsCourseModel::where(['user_id' => $this->getUserId(), 'project_id' => $id])->value('status');
+        $JsProjectModel = new JsProjectModel();
+        $info = $JsProjectModel::where('id', $id)->field('id,try_minute,video,course_price')->find();
+        $info->purchase = isset($course_order_status) ? $course_order_status : 0;
+        $info->video = cmf_get_image_preview_url($info->video);
+        $this->success('ok', $info);
+    }
+
+    /**
+     * 创建订单
+     */
+    public function addCourseOrder()
+    {
+        $id = $this->request->param('project_id');
+        $pay_price = $this->request->param('pay_price');
+        $jsCourseModel = new JsCourseOrderModel();
+        $data['project_id'] = $id;
+        $data['pay_price'] = $pay_price;
+        $data['order_sn'] = cmf_get_order_sn();
+        $data['user_id'] = $this->getUserId();
+        $jsCourseModel->allowField(true)->isUpdate(false)->save($data);
+        $this->success('创建订单成功', $jsCourseModel->id);
+    }
+
+    /**
+     * 支付订单
+     */
+    public function pay()
+    {
+        $id = $this->request->param('order_id');
+        $pay_type = $this->request->param('pay_type'); // 1视频支付 2 上传支付
+
+        switch ($pay_type) {
+            case 'alipay';
+                $res = aly_pay($id, 1);
+                if (!empty($res['return_code'])) {
+                    $this->error($res['return_msg']);
+                } else {
+                    $this->success('ok', $res);
+                }
+
+                break;
+            case 'wxpay';
+                $res = wx_pay($id, 1);
+                if (!empty($res['return_code'])) {
+                    $this->error($res['return_msg']);
+                } else {
+                    $this->success('ok', $res);
+                }
+                break;
+            case 'balance';
+                $bool = balance_pay($id, 1);
+                if ($bool === true) {
+                    $this->success('支付成功');
+                } else {
+                    $this->error($bool);
+                }
+                break;
+        }
+    }
+
+    /**
+     * 技师服务接单列表
+     */
+
+    public function getProjectOrderList()
+    {
+        $js_id = $this->js_id;
+        if (!$js_id) {
+            $this->error('您还没有认证技师!');
+        }
+
+        $type = $this->request->param('type', 1);
+        $page = $this->request->param('page', 1);
+        $category_id = $this->request->param('category_id');
+        $js_order_ids = get_js_order_ids($js_id, $type, $page, $category_id, false);
+
+        $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
+
+        $JsOrderModel = new JsOrderModel();
+        $list = $JsOrderModel::with('project.tag')->where('id', 'in', $js_order_ids)
+            ->order('id', 'desc')->select()->each(function ($list) use ($js_site_info) {
+                $list->project->icon = cmf_get_image_preview_url($list->project->icon);
+                $list->project->service = Db::name('js_project_service_relevancy')->where('id', $list['service_id'])->find();
+                $list['distance'] = GetDistance($js_site_info['lat'], $js_site_info['lng'], $list['lat'], $list['lng'], 2, 2);;
+                return $list;
+            });
+        $this->success('ok', $list);
+
+    }
+
+    /**
+     * 技师服务抢单列表
+     */
+
+    public function getFastOrderList()
+    {
+        $js_id = $this->js_id;
+        if (!$js_id) {
+            $this->error('您还没有认证技师!');
+        }
+
+        $type = $this->request->param('type', 1);
+        $page = $this->request->param('page', 1);
+        $category_id = $this->request->param('category_id');
+        $js_order_ids = get_js_order_ids($js_id, $type, $page, $category_id);
+
+        $distance = cmf_get_option('distance')['distance'];
+        $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
+        $offset = $distance / 111;
+        $lng_offset = [$js_site_info['lng'] - $offset, $js_site_info['lng'] + $offset];
+        $lat_offset = [$js_site_info['lat'] - $offset, $js_site_info['lat'] + $offset];
+
+        $JsOrderModel = new JsOrderModel();
+        $list = $JsOrderModel::with('project.tag')->where('id', 'in', $js_order_ids)
+            ->whereBetween('lat', $lat_offset)
+            ->whereBetween('lng', $lng_offset)
+            ->order('id', 'desc')->select()->each(function ($list) use ($js_site_info) {
+                $list->project->icon = cmf_get_image_preview_url($list->project->icon);
+                $list->project->service = Db::name('js_project_service_relevancy')->where('id', $list['service_id'])->find();
+                $list['distance'] = GetDistance($js_site_info['lat'], $js_site_info['lng'], $list['lat'], $list['lng'], 2, 2);;
+                return $list;
+            });
+
+        $this->success('ok', $list);
+
+    }
+
+    /**
+     * 技师屏蔽订单操作
+     */
+    public function addShield()
+    {
+        $id = $this->request->param('order_id');
+        if (!$this->js_id) {
+            $this->error('您没有认证技师!');
+        }
+        Db::name('js_shield_log')->insert(['order_id' => $id, 'js_id' => $this->js_id]);
+        $this->success('操作成功');
+    }
+
+
+//        /**
+//         * 技师抢单列表
+//         */
+//        public function jsOrderList()
+//        {
+//
+//            $JsOrderModel = new JsOrderModel();
+//            $page = $this->request->param('page');
+//            $js_order_ids = get_js_order_ids($this->js_id,1,$page);
+//
+//            $list = $JsOrderModel::with('project')->where('id','in',$js_order_ids)->select()->each(function ($list){
+//                $list->project->service = Db::name('js_project_service_relevancy')->where('id',$list['service_id'])->find();
+//                return $list;
+//            });
+//            $this->success('ok',$list);
+//
+//        }
+
+    /**
+     * 技师接单操作
+     */
+    public function jeidanPost()
+    {
+
+        $id = $this->request->param('order_id');
+        $js_id = $this->js_id;
+        if (!$this->js_status) {
+            $this->error('您技师认证暂未通过,不可抢单!');
+        }
+        $JsOrderGrab = new JsOrderGrabModel();
+        $JsOrderModel = new JsOrderModel();
+        $js_order_id = $JsOrderModel::where('jiedan_js_id', $js_id)->where('status', 6)->value('id');
+        if ($js_order_id) {
+            $this->error('您有订单未完成,请合理安排时间');
+        }
+        $msg = '订单未支付!';
+        $info = $JsOrderGrab::where(['order_id' => $id, 'js_id' => $js_id])->find();
+        if ($info) {
+            $msg = '您已报名参加抢单!';
+            $this->error($msg);
+        }
+        $order_info = $JsOrderModel::get($id);
+
+        switch ($order_info['status']) {
+            case 2:
+                $msg = '订单已被抢!';
+                break;
+            case 6:
+                $msg = '服务中!';
+                break;
+            case 3:
+                $msg = '订单已完成!';
+                break;
+            case 4:
+                $msg = '订单已评价!';
+                break;
+            case 5:
+                $msg = '订单已取消!';
+                break;
+        }
+        if ($order_info['status'] != 1) {
+            $this->error($msg);
+        } else {
+            if ($order_info['status'] == 1 && $order_info['jiedan_js_id']) {
+
+                $result = $JsOrderModel->allowField(true)->isUpdate(true)->save(['jiedan_time' => time(), 'status' => 2], ['id' => $order_info['id']]);
+
+                if ($result) {
+                    $mobile = $order_info->mobile;
+                    $order_sn = $order_info->order_sn;
+                    $this->sendMsg($mobile, $order_sn);
+                }
+                $this->success('接单成功');
+            } else {
+
+                $JsOrderGrab->allowField(true)->isUpdate(false)->save(['js_id' => $js_id, 'order_id' => $id]);
+                $this->success('抢单报名成功,等待客户选择');
+            }
+
+
+        }
+    }
+
+    /**
+     * 获取抢单数量
+     */
+    public function getJsOrdernum()
+    {
+        $js_id = $this->js_id;
+        if (!$this->js_status) {
+            $this->error('您还没有认证技师!');
+        }
+        $category_id = $this->request->param('category_id');
+        $project_new_ids = [];
+        $js_project_relevancy_where['js_id'] = $js_id;
+        $js_project_relevancy_where['status'] = 1;
+        if ($category_id) {
+            $project_ids1 = Db::name('js_project_category_relevancy')->where('category_id', $category_id)->field('project_id')->select();
+            $project_ids2 = [];
+            foreach ($project_ids1 as $vo) {
+                $project_ids2[] = $vo['project_id'];
+            }
+            $js_project_relevancy_where['project_id'] = $project_ids2;
+        }
+        $project_ids = Db::name('js_project_relevancy')->where($js_project_relevancy_where)->field('project_id')->select();
+        $order_new_ids = [];
+        $order_ids = Db::name('js_shield_log')->where('js_id', $js_id)->field('order_id')->select();
+        foreach ($order_ids as $vo) {
+            $order_new_ids[] = $vo['order_id'];
+        }
+        foreach ($project_ids as $vo) {
+            $project_new_ids[] = $vo['project_id'];
+        }
+
+        $distance = cmf_get_option('distance')['distance'];
+        $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
+
+        $offset = $distance / 111;
+        $lng_offset = [$js_site_info['lng'] - $offset, $js_site_info['lng'] + $offset];
+        $lat_offset = [$js_site_info['lat'] - $offset, $js_site_info['lat'] + $offset];
+
+        $JsOrderModel = new JsOrderModel();
+        $order_coun = $JsOrderModel::where('project_id', 'in', $project_new_ids)->where(['jiedan_js_id' => 0, 'status' => 1])
+            ->where('id', 'not in', $order_new_ids)
+            ->whereBetween('lat', $lat_offset)
+            ->whereBetween('lng', $lng_offset)
+            ->field('id,lat,lng')->count('id');
+
+        $this->success('ok', $order_coun);
+    }
+
+    /**
+     * 获取接单数量
+     */
+    public function getOrdernum()
+    {
+        $js_id = $this->js_id;
+        if (!$this->js_status) {
+            $this->error('您还没有认证技师!');
+        }
+        $order_refuse_ids = [];
+        $order_ids = Db::name('js_shield_log')->where('js_id', $js_id)->field('order_id')->select();
+        foreach ($order_ids as $vo) {
+            $order_refuse_ids[] = $vo['order_id'];
+        }
+
+        $JsOrderModel = new JsOrderModel();
+        $order_coun = $JsOrderModel->where(['jiedan_js_id' => $js_id])->where('status', [['eq', 1], ['eq', 2]], 'or')->where('id', 'not in', $order_refuse_ids)->count();
+
+        $this->success('ok', $order_coun);
+    }
+
+
+    /**
+     * 技师开始服务
+     */
+    public function start()
+    {
+        $id = $this->request->param('order_id');
+        $JsOrderModel = new JsOrderModel();
+        $order_info = $JsOrderModel::where('order_sole', $id)->find();
+
+        if (!$order_info) {
+            $this->error('订单不存在!');
+        }
+        $js_id = $this->js_id;
+        if ($order_info['jiedan_js_id'] != $js_id) {
+            $this->error('接单人不是您,不可操作!');
+        }
+        if ($order_info['status'] != 2) {
+            $this->error('订单异常');
+        } else {
+            $JsOrderModel->allowField(true)->isUpdate(true)->save(['start_time' => time(), 'status' => 6], ['id' => $order_info['id']]);
+            $this->success('开始服务');
+        }
+
+    }
+
+    /**
+     * 新增地址
+     */
+    public function addressPost()
+    {
+        $data['user_id'] = $this->getUserId();
+        $data['province'] = $this->request->param('province');
+        $data['city'] = $this->request->param('city');
+        $data['district'] = $this->request->param('district');
+        $data['address'] = $this->request->param('address');
+        $data['moren'] = $this->request->param('moren');
+        $data['name'] = $this->request->param('name');
+        $data['mobile'] = $this->request->param('mobile');
+        $id = $this->request->param('id');
+        if ($id) {
+            if ($data['moren'] == 1) {
+                Db::name('user_address')->where('user_id', $data['user_id'])->update(['moren' => 2]);
+            }
+
+            Db::name('user_address')->where('id', $id)->update($data);
+
+        } else {
+            if ($data['moren'] == 1) {
+                Db::name('user_address')->where('user_id', $data['user_id'])->update(['moren' => 2]);
+            }
+            Db::name('user_address')->insert($data);
+        }
+//            $address_id = Db::name('user_address')->where(['user_id'=>$data['user_id'],'moren' =>1])->value('id');
+//            if(!$address_id){
+//                $data['moren'] = 1;
+//            }
+
+        $this->success('操作成功');
+    }
+
+    public function getaddresslist()
+    {
+        $user_id = $this->getUserId();
+        $list = Db::name('user_address')->where('user_id', $user_id)->select();
+        $this->success('ok', $list);
+    }
+
+    public function getaddressinfo()
+    {
+        $id = $this->request->param('id');
+        $info = Db::name('user_address')->where('id', $id)->find();
+        $this->success('ok', $info);
+    }
+
+
+    public function addressDelete()
+    {
+        $id = $this->request->param('id');
+        Db::name('user_address')->where('id', $id)->delete();
+        $this->success('删除成功');
+    }
+
+    /**
+     * 技师报警
+     */
+    public function callPost()
+    {
+        $js_id = $this->js_id;
+        if (!$this->js_status) {
+            $this->error('您还没有认证技师!');
+        }
+        $order_id = JsOrderModel::where('jiedan_js_id', $js_id)->where(function ($query) {
+            $query->where('status', 2);
+            $query->whereor('status', 6);
+        })->value('id');
+        if ($order_id) {
+            $order_sn = JsOrderModel::where('id', $order_id)->value('order_sn');
+        }
+
+        if (!$order_id) {
+            $order_id = JsOrderModel::where(['jiedan_js_id' => $js_id, 'status' => 3])->order('finish_time', 'desc')->value('id');
+            $order_sn = JsOrderModel::where('id', $order_id)->value('order_sn');
+            $finish_time = JsOrderModel::where(['jiedan_js_id' => $js_id, 'status' => 3, 'id' => $order_id])->value('finish_time');
+            $alarm_delay = $duration = cmf_get_option('duration')['alarm_delay'];
+            if (($finish_time + $alarm_delay * 60) < time()) {
+                $this->error('警报发送失败,没有服务中订单!');
+            }
+
+        }
+        if (!$order_id) {
+            $this->error('警报发送失败,没有服务中订单!');
+        }
+
+        $data['user_id'] = $this->getUserId();
+        $data['order_id'] = $order_id;
+
+        $UserModel = new UserModel();
+        $user_city_id = $UserModel::get($this->getUserId())['city_id'];
+        $user_district_id = $UserModel::get($this->getUserId())['district_id'];
+        $city_agency_id = Db::name('agency')->where(['city_id' => $user_city_id, 'renk_id' => 1])->value('id');
+        $district_agency_id = Db::name('agency')->where(['district_id' => $user_district_id, 'renk_id' => 2])->value('id');
+        $JsCallModel = new JsCallModel();
+        $info = cmf_get_option('jspus');
+        $city_agency_user = $UserModel::where('agency_id', $city_agency_id)->field('id,user_type')->find();
+        $client = new Client($info['app_key'], $info['master_secret']);
+        if ($city_agency_user) {
+            if ($city_agency_user['user_type'] == 3) {
+                $client = new Client($info['js_app_key'], $info['js_master_secret']);
+            }
+            $extras = [
+                'id' => $this->getUserId(),
+                'flag' => '技师报警',
+            ];
+            $array = [
+                'extras' => $extras,
+            ];
+            $alias = $city_agency_user['id'] . 'js';
+            $text = '订单号:' . $order_sn . '报警';
+            $platform = array('ios', 'android');
+            $client->push()
+                ->setPlatform($platform)
+                ->setNotificationAlert($text)
+                ->iosNotification($text, $array)
+                ->androidNotification($text, $array)
+                ->addAlias("{$alias}")
+                ->send();
+        }
+        $district_agency_user = $UserModel::where('agency_id', $district_agency_id)->field('id,user_type')->find();
+
+        if ($district_agency_user) {
+            if ($city_agency_user['user_type'] == 3) {
+                $client = new Client($info['js_app_key'], $info['js_master_secret']);
+            }
+            $extras = [
+                'id' => $this->getUserId(),
+                'flag' => '技师报警',
+            ];
+            $array = [
+                'extras' => $extras,
+            ];
+            $alias = $district_agency_user['id'] . 'js';
+            $text = '订单号:' . $order_sn . '报警';
+            $platform = array('ios', 'android');
+            $client->push()
+                ->setPlatform($platform)
+                ->setNotificationAlert($text)
+                ->iosNotification($text, $array)
+                ->androidNotification($text, $array)
+                ->addAlias("{$alias}")
+                ->send();
+        }
+
+
+        $JsCallModel->allowField(true)->isUpdate(false)->save($data);
+        $this->success('警报发送成功');
+    }
+
+    /**
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     * 播放语音
+     */
+    public function play()
+    {
+        $js_id = $this->js_id;
+        $id = JsOrderGrabModel::where(['js_id' => $js_id, 'status' => 1])->value('id');
+        if ($id) {
+            JsOrderGrabModel::where('id', $id)->update(['status' => 2]);
+            $this->success('播放');
+        } else {
+            $this->error('已通知');
+        }
+
+    }
+
+    /**
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     * 播放语音取消订单
+     */
+    public function cancelplay()
+    {
+        $js_id = $this->js_id;
+        $id = JsOrderModel::where(['jiedan_js_id' => $js_id, 'status' => 5, 'order_status' => 2])->value('id');
+        if ($id) {
+            JsOrderModel::where('id', $id)->update(['order_status' => 3]);
+            $this->success('播放');
+        } else {
+            $this->error('已通知');
+        }
+    }
+
+
+    /**
+     * 技师删除i订单
+     */
+    public function deleteOrder()
+    {
+        $order_id = $this->request->param('order_id');
+        $JsOrderModel = new JsOrderModel();
+        $JsOrderModel::where('id', $order_id)->update(['js_delete' => 2]);
+        $this->success('删除成功');
+    }
+
+
+    /**
+     * 项目分类下的订单数量
+     */
+    public function getClassifyOrderNum()
+    {
+        $js_id = $this->js_id;
+        $js_site_info = Db::name('js_site')->where('js_id', $js_id)->find();
+        $distance = cmf_get_option('distance')['distance'];
+
+        $JsProjectCategoryModel = new JsProjectCategoryModel(); //项目分类
+        $list = $JsProjectCategoryModel::where('is_show', 1)->order('list_order', 'desc')->field('id')->select()->each(function ($list) use ($js_id, $js_site_info, $distance) {
+            $list['order_num'] = 0;
+            $project_ids = Db::name('js_project_category_relevancy')->where('category_id', $list['id'])->field('project_id')->select();
+            $project_ids_new = [];
+            foreach ($project_ids as $v) {
+                $js_project_relevancy_id = Db::name('js_project_relevancy')->where(['project_id' => $v['project_id'], 'js_id' => $js_id, 'status' => 1])->value('id');
+
+                if ($js_project_relevancy_id) {
+                    if (!in_array($v['project_id'], $project_ids_new)) {
+                        array_push($project_ids_new, $v['project_id']);
+                    }
+                }
+            }
+
+            if ($project_ids_new) {
+
+                $offset = $distance / 111;
+                $lng_offset = [$js_site_info['lng'] - $offset, $js_site_info['lng'] + $offset];
+                $lat_offset = [$js_site_info['lat'] - $offset, $js_site_info['lat'] + $offset];
+
+                $order_list = JsOrderModel::where('project_id', 'in', $project_ids_new)->where('status', 1)
+                    ->whereBetween('lat', $lat_offset)
+                    ->whereBetween('lng', $lng_offset)
+                    ->where('jiedan_js_id', 0)->field('id,lat,lng')
+                    ->count();
+//                    ->select();
+
+                $list['order_num'] = $order_list;
+//                foreach ($order_list as $value) {
+//                    $distance1 = GetDistance($value['lat'], $value['lng'], $js_site_info['lat'], $js_site_info['lng'], 2, 2);//value['lat'],/$value['lng'],$js_site_info['lat'],$js_site_info['lng'],2,2);
+//                    if ($distance >= $distance1) {
+//                        $list['order_num'] += 1;
+//                    }
+//                }
+
+//                $list['order_num'] = JsOrderModel::where('project_id', 'in', $project_ids_new)->where('status', 1)->where('jiedan_js_id', 0)->count();
+            }
+            return $list;
+        });
+        $this->success('ok', $list);
+    }
+
+
+    /**
+     * 技师带接单数量
+     */
+    public function getOrdeNum()
+    {
+        $js_id = $this->js_id;
+        $order_ids = Db::name('js_shield_log')->where('js_id', $js_id)->field('order_id')->select();
+        $order_new_ids = [];
+        foreach ($order_ids as $vo) {
+            $order_new_ids[] = $vo['order_id'];
+        }
+        $num = JsOrderModel::where(['status' => 1, 'jiedan_js_id' => $js_id])->where('id', 'not in', $order_new_ids)->count();
+        $this->success('ok', $num);
+    }
+
+}

+ 60 - 0
api/js/controller/UserSignInController.php

@@ -0,0 +1,60 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-07
+     * Time: 10:09
+     */
+    
+    namespace api\js\controller;
+    
+    
+    use api\js\model\SignInSetModel;
+    use api\js\model\UserModel;
+    use api\js\model\UserSignInModel;
+    use cmf\controller\RestUserBaseController;
+    use think\Db;
+
+    class UserSignInController extends RestUserBaseController
+    {
+        public function addPost()
+        {
+            $user_id = $this->getUserId();
+            $day = date('Y-m-d');
+            $UserSignInModel = new UserSignInModel();
+            $monthDay = date('t');
+            $info = $UserSignInModel->where('user_id',$user_id)->find();
+            $integral = SignInSetModel::where('day',$info['num'])->value('integral');
+            $acquireIntegral = isset($integral) ? $integral : 1;
+            if($info['sign_day'] == $day){
+                $this->error('今天已签到');
+            }else if($info['sign_day'] == date('Y-m-d', strtotime('-1 day'))){
+                if($info['num'] == ($monthDay-1)){
+                        $num = 0;
+                }elseif ($info['num'] < ($monthDay-1));
+                $num = $info['num']+1;
+                $UserSignInModel->allowField(true)->isUpdate(true)->save(['sign_day'=>$day,'num'=>$num],['id'=>$info['id']]);
+                
+            }else{
+               if($info['id']){
+                   $UserSignInModel->allowField(true)->isUpdate(true)->save(['sign_day'=>$day,'num'=>1],['id'=>$info['id']]);
+               }else{
+                   $UserSignInModel->allowField(true)->isUpdate(false)->save(['sign_day'=>$day,'num'=>1,'user_id'=>$user_id]);
+               }
+            }
+            Db::name('user_sign_in_log')->insert(['user_id'=>$user_id,'sign_day'=>$day]);
+            UserModel::where('id',$user_id)->setInc('score',$acquireIntegral);
+            $this->success('签到成功');
+            
+        }
+        
+        public function getUserSign()
+        {
+            $user_id = $this->getUserId();
+            $where['user_id'] = $this->getUserId();
+            $list = Db::name('user_sign_in_log')->where('user_id',$user_id)->where('sign_day','like',date('Y-m').'%')->field('sign_day')->select();
+            $this->success('ok',$list);
+          
+        }
+        
+    }

+ 107 - 0
api/js/controller/VerificationCodeController.php

@@ -0,0 +1,107 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-06-11
+     * Time: 13:36
+     */
+    
+   namespace api\js\controller;
+    
+    
+    use Aliyun\DySDKLite\SignatureHelper;
+    use api\js\model\UserModel;
+    use cmf\controller\RestBaseController;
+    use think\Db;
+    //use Aliyun\DySDKLite\SignatureHelper;
+    class VerificationCodeController extends RestBaseController
+    {
+            /**
+             * 发送验证码
+             */
+            public function getVerificationCode()
+            {
+                $mobile = $this->request->param('mobile');
+                $type = $this->request->param('type',1);
+                $status = $this->request->param('status',1);
+                if(!cmf_check_mobile($mobile)){
+                    $this->error('手机号不正确!');
+                }
+                $params = array ();
+                $alisms = cmf_get_option('alisms');
+                if($type == 1){
+                    if($status == 1){
+                        $where['user_type'] = 2;
+                    }
+                    if($status == 2){
+                        $where['user_type'] = 3;
+                    }
+                    $where['mobile'] = $mobile;
+                    $user_id = UserModel::name('user')->where($where)->value('id');
+                    if($user_id){
+                        $this->error('手机号已注册!');
+                    }
+                    $params["TemplateCode"] = $alisms['mb_id'];
+                }else if($type == 2){
+                    $user_id = UserModel::name('user')->where('mobile',$mobile)->value('id');
+                    if(!$user_id){
+                        $this->error('手机号未注册!');
+                    }
+                    $params["TemplateCode"] = $alisms['edit_mb_id'];
+                }else{
+                    $params["TemplateCode"] = $alisms['mb_id'];
+                }
+                
+          
+                $code = cmf_get_verification_code($mobile);
+                if (empty($code)) {
+                    $this->error('验证码发送过多,明天再试');
+                }
+                cmf_verification_code_log($mobile, $code, time()+5*60);
+                $param  = ['mobile' => $mobile, 'code' => $code];
+                $result = hook_one("send_mobile_verification_code", $param);
+                if ($result !== false && !empty($result['error'])) {
+                    $this->error($result['message']);
+                }
+             
+               
+    
+                $security = false;
+                $accessKeyId = $alisms['access_key_id'];
+                $accessKeySecret = $alisms['access_key_secret'];;
+                $params["PhoneNumbers"] = $mobile;
+                $params["SignName"] = $alisms['sms_qm'];
+           
+                $params['TemplateParam'] = Array (
+                    "code" => $code,
+                );
+
+                // *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
+                if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
+                    $params["TemplateParam"] = json_encode($params["TemplateParam"], JSON_UNESCAPED_UNICODE);
+                }
+                // 初始化SignatureHelper实例用于设置参数,签名以及发送请求
+                $helper = new SignatureHelper();
+
+                // 此处可能会抛出异常,注意catch
+                $content = $helper->request(
+                    $accessKeyId,
+                    $accessKeySecret,
+                    "dysmsapi.aliyuncs.com",
+                    array_merge($params, array(
+                        "RegionId" => "cn-hangzhou",
+                        "Action" => "SendSms",
+                        "Version" => "2017-05-25",
+                    )),
+                    $security
+                );
+
+                if($content->Message == 'OK' && $content->Code == 'OK'){
+                    $this->success('验证已发送'.$mobile.'注意查收');
+
+                }else{
+                    $this->error($content->Message);
+                }
+            }
+        
+    }

+ 198 - 0
api/js/controller/WxLoginController.php

@@ -0,0 +1,198 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-25
+     * Time: 11:43
+     */
+    
+    namespace api\js\controller;
+    use api\js\model\JsDiscountModel;
+    use api\js\model\JsModel;
+    use api\js\model\UserDiscountModel;
+    use api\js\model\UserModel;
+    use cmf\controller\RestBaseController;
+    use think\Db;
+
+    class WxloginController extends RestBaseController
+    {
+    
+        public function wxLogin()
+        {
+            $data['nickname'] = $this->request->param('nickname');
+            $data['openid'] = $this->request->param('openid');
+            $data['union_id'] = '微信平台';
+            $data['avatar'] = $this->request->param('avatar');
+            $data['type'] = $this->request->param('type');
+            $info = Db::name('third_party_user')->where(['openid'=>$data['openid'],'union_id'=>$data['union_id'],'type'=>$data['type']])->find();
+            if($info['user_id']){
+                $findUserToken = Db::name("user_token")
+                    ->where('user_id', $info['user_id'])
+                    ->where('device_type', $this->deviceType)
+                    ->find();
+                $currentTime   = time();
+                $expireTime    = $currentTime + 24 * 3600 * 180;
+                $token         = md5(uniqid()) . md5(uniqid());
+                if (empty($findUserToken)) {
+                    $result = Db::name("user_token")->insert([
+                        'token'       => $token,
+                        'user_id'     => $info['user_id'],
+                        'expire_time' => $expireTime,
+                        'create_time' => $currentTime,
+                        'device_type' => $this->deviceType
+                    ]);
+                } else {
+                    $result = Db::name("user_token")
+                        ->where('user_id', $info['user_id'])
+                        ->where('device_type', $this->deviceType)
+                        ->update([
+                            'token'       => $token,
+                            'expire_time' => $expireTime,
+                            'create_time' => $currentTime
+                        ]);
+                }
+                if (empty($result)) {
+                    $this->error("登录失败!");
+                }
+                Db::name('user')->where('id',$info['user_id'])->update(['last_login_ip'=>get_client_ip(),'last_login_time'=>time()]);
+                $this->success("登录成功!", ['token' => $token,'id'=>$info['user_id']]);
+            }else{
+                if(!$info){
+                    $id = Db::name('third_party_user')->insertGetId($data);
+                }else{
+                    $id = $info['id'];
+                }
+                $this->success('ok',['token'=>'','id'=>$id]);
+            }
+        }
+
+        public function wxInfo(){
+            $openid = $this->request->param('openid');
+            $info = Db::name('third_party_user')->where('openid',$openid)->find();
+            $this->success("登录成功!", ['wxInfo' => $info]);
+        }
+    
+        public function bangding()
+        {
+            $openid = $this->request->param('openid');
+            $mobile = $this->request->param('mobile');
+            // $password = $this->request->param('password');
+            $code = $this->request->param('code');
+            $type = $this->request->param('type',1);
+            $referral = $this->request->param('referral');
+        
+        
+            // $district = $this->request->param('district');
+            // $district_id = Db::name('region')->where('cityName',$district)->value('id');
+            // $data['city_id'] = Db::name('region')->where('id',$district_id)->value('parentId');
+            // $data['province_id'] = Db::name('region')->where('id',$data['city_id'])->value('parentId');
+            // $data['district_id'] = $district_id;
+            $user_type = 2;
+            if($type == 2){
+                $user_type = 3;
+            }
+            $where['mobile'] = $mobile;
+            $where['user_type'] = $user_type;
+            $bool = cmf_check_verification_code($mobile, $code);
+            if ($bool) {
+                $this->error($bool);
+            }
+            $UserModel = new UserModel();
+        
+            $user_id = $UserModel->where($where)->value('id');
+        
+         
+            $info = Db::name('third_party_user')->where('openid',$openid)->where('type',$user_type)->find();
+            if($user_id){
+                // $user_info = $UserModel::get($user_id);
+                // if(!$user_info['avatar']){
+                //     $up['avatar'] = $info['avatar'];
+                //     $UserModel::where('id',$user_id)->update(['avatar'=>$info['avatar']]);
+                // }
+                // if(!$user_info['user_nickname']){
+                //     $up['user_nickname'] = $info['nickname'];
+                // }
+                // $up['user_pass'] = cmf_password($password);
+                // $UserModel::where('id',$user_id)->update($up);
+                if($type == 2){
+                    $JsModel = new JsModel();
+                    $js_info = $JsModel::where('user_id',$user_id)->find();
+                    if(!$js_info){
+                        $JsModel->allowField(true)->isUpdate(false)->save(['user_id'=>$user_id]);
+                    }
+                }
+                
+            }else{
+                $data['mobile'] = $mobile;
+                // $data['user_pass'] = cmf_password($password);
+                $data['user_type'] = $user_type;
+                $data['create_time'] = time();
+                $data['referral'] = cmf_get_referral();
+                if($referral){
+                    $parentInfo = $UserModel->where('referral',$referral)->find();
+                    if($parentInfo){
+                        $data['parent_id'] = $parentInfo['id'];
+                        $data['parent_id1'] = $parentInfo['parent_id'];
+                    }
+                }
+                $UserModel->allowField(true)->isUpdate(false)->save($data);
+                // $JsDiscountModel = new JsDiscountModel();
+                // $discountInfo = $JsDiscountModel::get(1);
+                // if($discountInfo['dispark'] == 1){
+                //     if($discountInfo['quantit'] > 0){
+                //         $UserDiscountModel = new UserDiscountModel();
+                //         $draw_time = time();
+                //         $UserDiscountModel->allowField(true)->isUpdate(false)->save(['user_id'=>$UserModel->id,'discount_id'=>1,'draw_time'=>$draw_time,'past_time'=>($draw_time+($discountInfo['day_num']*24*3600)),'project_id'=>$discountInfo['project_id'],'store_id'=>$discountInfo['store_id']]);
+                //         $JsDiscountModel::where('id',1)->setDec('quantit',1);
+                    
+                //     }
+                // }
+                $user_id = $UserModel->id;
+            }
+        
+        
+            Db::name('third_party_user')->where('openid',$openid)->where('type',$user_type)->update(['user_id'=>$user_id]);
+        
+        
+            $findUserToken = Db::name("user_token")
+                ->where('user_id', $user_id)
+                ->where('device_type', $this->deviceType)
+                ->find();
+            $currentTime   = time();
+            $expireTime    = $currentTime + 24 * 3600 * 180;
+            $token         = md5(uniqid()) . md5(uniqid());
+            if (empty($findUserToken)) {
+                $result = Db::name("user_token")->insert([
+                    'token'       => $token,
+                    'user_id'     => $user_id,
+                    'expire_time' => $expireTime,
+                    'create_time' => $currentTime,
+                    'device_type' => $this->deviceType
+                ]);
+            } else {
+                $result = Db::name("user_token")
+                    ->where('user_id', $user_id)
+                    ->where('device_type', $this->deviceType)
+                    ->update([
+                        'token'       => $token,
+                        'expire_time' => $expireTime,
+                        'create_time' => $currentTime
+                    ]);
+            }
+            if (empty($result)) {
+                $this->error("登录失败!");
+            }
+            Db::name('user')->where('id',$user_id)->update(['last_login_ip'=>get_client_ip(),'last_login_time'=>time()]);
+    
+            if($type == 2){
+                $JsModel = new JsModel();
+                $js_info = $JsModel::where('user_id',$user_id)->find();
+                if(!$js_info){
+                    $JsModel->allowField(true)->isUpdate(true)->save(['user_id'=>$user_id]);
+                }
+            }
+            $this->success("登录成功!", ['token' => $token,'id'=>$user_id]);
+            
+        
+        }
+    }

+ 19 - 0
api/js/model/AgencyModel.php

@@ -0,0 +1,19 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-28
+     * Time: 10:54
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class AgencyModel extends Model
+    {
+        use SoftDelete;
+        protected $deteleTime = 'delete_time';
+    }

+ 20 - 0
api/js/model/DistributorLogModel.php

@@ -0,0 +1,20 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-10-10
+     * Time: 16:23
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class DistributorLogModel extends Model
+    {
+        use SoftDelete;
+        protected $deleteTime = 'delete_time';
+        
+    }

+ 20 - 0
api/js/model/DistributorModel.php

@@ -0,0 +1,20 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-10-10
+     * Time: 16:01
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class DistributorModel extends Model
+    {
+        use SoftDelete;
+        protected $deleteTime = 'delete_time';
+        
+    }

+ 30 - 0
api/js/model/GoodsCategoryModel.php

@@ -0,0 +1,30 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-12
+     * Time: 13:50
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class GoodsCategoryModel extends Model
+    {
+        use SoftDelete;
+        protected $deleteTime = 'delete_time';
+        
+        public function getIconAttr($value)
+        {
+            return cmf_get_image_preview_url($value);
+        }
+        
+        public function getlist()
+        {
+            $list = $this::where('is_show',1)->order('list_order','asc')->select();
+            return $list;
+        }
+    }

+ 66 - 0
api/js/model/GoodsModel.php

@@ -0,0 +1,66 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-12
+     * Time: 13:56
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class  GoodsModel extends Model
+    {
+        use SoftDelete;
+        protected  $deleteTime = 'delete_time';
+        protected $type = ['banner' => 'array'];
+        
+        public function getIconAttr($value)
+        {
+            return cmf_get_image_preview_url($value);
+        }
+        /**
+         * post_content 自动转化
+         * @param $value
+         * @return string
+         */
+        public function getContentAttr($value)
+        {
+            return cmf_replace_content_file_url(htmlspecialchars_decode($value));
+        }
+        public function setContentAttr($value)
+        {
+            return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
+        }
+        public function seckill()
+        {
+            return $this->belongsToMany('GoodsSeckillModel','goods_seckill_goods','seckill_id','goods_id');
+        }
+    
+    
+        public function getlist($where = [],$page = 1,$name='')
+        {
+                $where['shelves'] = 1;
+            return $this::where($where)->where(function ($quer) use ($name){
+                if($name){
+                    $quer->where('goods_name','like','%'.$name.'%');
+                }
+            })->page($page,20)->order('list_order','asc')->select();
+        }
+        public function getInfo($id)
+        {
+            $info = $this::get($id);
+            $banner = $info['banner'];
+            if($banner){
+                foreach ($banner as $key => $value){
+                    $banner[$key]['url'] = cmf_get_image_preview_url($value['url']);
+                }
+            }
+            $info->seckill;
+            $info['banner'] = $banner;
+            return $info;
+        }
+    }

+ 27 - 0
api/js/model/GoodsOrderModel.php

@@ -0,0 +1,27 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-23
+     * Time: 13:46
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class GoodsOrderModel extends Model
+    {
+        use SoftDelete;
+        protected $deleteTime = 'delete_time';
+        public function goods()
+        {
+            return $this->hasOne('GoodsModel','id','goods_id');
+        }
+        public function seckill()
+        {
+            return $this->hasOne('GoodsSeckillModel','id','seckill_id');
+        }
+    }

+ 33 - 0
api/js/model/GoodsSeckillModel.php

@@ -0,0 +1,33 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-12
+     * Time: 13:54
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class GoodsSeckillModel extends Model
+    {
+        use SoftDelete;
+        protected $deleteTime = 'delete_time';
+        
+        public function goods()
+        {
+            return $this->belongsToMany('GoodsModel','goods_seckill_goods','goods_id','seckill_id');
+        }
+        
+        
+        
+        
+        public function getlist()
+        {
+            $list = $this::with('goods')->where('end_time','>',time())->order('start_time','asc')->select();
+            return $list;
+        }
+    }

+ 26 - 0
api/js/model/JsCallModel.php

@@ -0,0 +1,26 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-28
+     * Time: 14:10
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsCallModel extends Model
+    {
+    
+        
+        public function jsUser()
+        {
+            return $this->hasOne('UserModel','id','user_id')->field('id,mobile,user_nickname');
+        }
+        public function jsOrder()
+        {
+            return $this->hasOne('JsOrderModel','id','order_id')->field('id,order_sn,price,order_price,minute,jiedan_time,status,project_id,province,city,district,address1');
+        }
+    }

+ 32 - 0
api/js/model/JsCategoryModel.php

@@ -0,0 +1,32 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-17
+     * Time: 15:05
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+    class JsCategoryModel extends Model
+    {
+        use SoftDelete;
+        protected $deleteTime = 'delete_time';
+        public function getList()
+        {
+            //where('is_show',1)->
+            $list = $this::order('list_order','asc')->field('id,category_name')->select();
+            return $list;
+        }
+        
+        public function js()
+        {
+            return $this->belongsToMany('JsModel','js_category_relevancy','js_id','category_id');
+            
+        }
+  
+    
+    }

+ 20 - 0
api/js/model/JsCourseOrderModel.php

@@ -0,0 +1,20 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-22
+     * Time: 9:26
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class JsCourseOrderModel extends Model
+    {
+        use SoftDelete;
+        protected  $deleteTime = 'delete_time';
+        
+    }

+ 17 - 0
api/js/model/JsDiscountModel.php

@@ -0,0 +1,17 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-08
+     * Time: 10:21
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsDiscountModel extends Model
+    {
+    
+    }

+ 186 - 0
api/js/model/JsModel.php

@@ -0,0 +1,186 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-09
+     * Time: 9:06
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Db;
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class JsModel extends Model
+    {
+        use SoftDelete;
+        protected $deleteTime = 'delete_time';
+        protected $type = [
+            'identity' => 'array',
+            'certificates' => 'array',
+            'pictures' => 'array',
+            'massage' => 'array',
+            'work' => 'array',
+        ];
+        
+        public function applyJsPost($data)
+        {
+            $this->allowField(true)->isUpdate(false)->save($data);
+            return $this;
+            
+        }
+        public function jsTime()
+        {
+            return $this->hasOne('JsTimeModel','js_id','id');
+        }
+        public function project()
+        {
+            return $this->belongsToMany('JsProjectModel','js_project_relevancy','project_id','js_id');
+        }
+        
+        
+        public function applyProjectPost($js_id,$project_id)
+        {
+    
+            $info = Db::name('js_project_relevancy')->where('js_id',$js_id)->where('project_id',$project_id)->find();
+            if($info['status'] == 1 || $info['status'] == 0){
+                return false;
+            }else if($info['status'] == 2){
+                Db::name('js_project_relevancy')->where('id',$info['id'])->update(['status'=>0,'add_time'=>time(),'chuli_time'=>0]);
+            }else{
+                $in['project_id'] = $project_id;
+                $in['js_id'] = $js_id;
+                $in['add_time'] = time();
+                Db::name('js_project_relevancy')->insert($in);
+            }
+            return true;
+        }
+        
+        public function site()
+        {
+            return $this->hasOne('JsSiteModel','js_id','id');
+        }
+        
+        public function jsScore()
+        {
+            return $this->hasMany('JsScoreModel','js_id','id');
+        }
+        
+        public function category()
+        {
+            return $this->belongsToMany('JsCategoryModel','js_category_relevancy','category_id','js_id');
+        }
+        
+        public function getLits($js_ids,$lat = 1,$lng = 1,$page=1)
+        {
+            $js_ids1 = get_js_ids($js_ids,$lat,$lng);//where('id','in',$js_ids)->
+            //后期$js_ids 替换成 $js_ids1
+    
+            $list = [];
+            if($js_ids1){
+                $list = $this::with('site,category,js_time')->where(function ($query) use ($js_ids1){
+                    if(is_array($js_ids1) && count($js_ids1) > 0){
+                        $query->where('id','in',$js_ids1);
+                    }
+                })->where('js_status',1)->order('jiedan_num','desc')->page($page,25)->select()->each(function ($list) use ($lat,$lng){
+
+                    $list['identity'] = null;
+                    $list['phone'] = null;
+                    unset($list['identity']);
+                    unset($list['phone']);
+                    $list['distance'] = GetDistance($lat,$lng,$list['site']['lat'],$list['site']['lng'],2,2);
+                    $list['score'] = get_js_score($list['id']);
+                    $list['shangban'] = 0;
+                    if($list->js_time){
+                        $week = date('w',time());
+                       // dump($list->js_time->weeks);
+                        
+                        if(in_array($week,$list->js_time->weeks))
+                        {
+                            foreach ($list->js_time->times as $vo)
+                            {
+                                if(strtotime($vo['js_end_time']) > strtotime(date('H:i')))
+                                {
+                                   //在此处判断一下是否已经接单
+                                    $shangban = Db::name('js_order')->where('jiedan_js_id',$list['id'])->where('status',6)->find();
+                                    if(empty($shangban)){
+                                        $list['shangban'] = 1;
+                                    }else{
+                                        $list['shangban'] = 2;
+                                    }
+                                }
+                              //  dump($vo['js_end_time']);
+                            }
+                     
+                        }
+                    }
+                    
+                });
+            }
+            $work_list = [];
+            $rest_list = [];
+            foreach ($list as $item){
+                if($item['shangban'] === 0)
+                array_push($rest_list, $item); 
+                else
+                array_push($work_list, $item); 
+            }
+
+            return array_merge($work_list,$rest_list);
+        }
+        
+        
+        
+        public function getInfo($id,$lat,$lng,$district='')
+        {
+            $info = $this::get($id,['project'=>function($query){$query->where('status',1);},'site','jsScore.user','jsScore.jsOrder','js_time']);
+      
+            $info->distance = GetDistance($lat,$lng,$info['site']['lat'],$info['site']['lng'],2,2);
+      
+            $info->score = get_js_score($id);
+            $project_ids = [];
+            foreach ($info->project as $vo){
+                $project_ids[] = $vo['id'];
+            }
+
+            $_project_ids = Db::name('js_project_relevancy')->where('js_id',$id)->where('project_id','in',$project_ids)->where('status', 1)->group('project_id')->column('project_id');
+
+            $RegionModel = new RegionModel();
+            $serviceId = $RegionModel->getId($district);
+            $JsProjectModel = new JsProjectModel();
+            $info->project_service = $JsProjectModel->getList('',$_project_ids,1,$serviceId);
+            unset($info->project);
+
+            $info->identity = [];
+
+            $info['shangban'] = 0;
+            if($info->js_time){
+                $week = date('w',time());
+                // dump($list->js_time->weeks);
+
+                if(in_array($week,$info->js_time->weeks))
+                {
+                    foreach ($info->js_time->times as $vo)
+                    {
+                        if(strtotime($vo['js_end_time']) >= strtotime(date('H:i')))
+                        {
+                            //在此处判断一下是否已经接单
+                            $shangban = Db::name('js_order')->where('jiedan_js_id',$info['id'])->where('status',6)->find();
+                            if(empty($shangban)){
+                                $info['shangban'] = 1;
+                            }else{
+                                $info['shangban'] = 2;
+                            }
+                        }
+                    }
+
+                }
+                unset($info->js_time);
+            }
+
+
+            return $info;
+        }
+    }

+ 17 - 0
api/js/model/JsOrderAddtimeModel.php

@@ -0,0 +1,17 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-10-12
+     * Time: 15:50
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsOrderAddtimeModel extends Model
+    {
+    
+    }

+ 21 - 0
api/js/model/JsOrderGrabModel.php

@@ -0,0 +1,21 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-10-09
+     * Time: 17:25
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsOrderGrabModel extends Model
+    {
+    
+        public function js()
+        {
+            return $this->hasOne('JsModel','id','js_id');
+        }
+    }

+ 105 - 0
api/js/model/JsOrderModel.php

@@ -0,0 +1,105 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-08
+     * Time: 15:18
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Db;
+    use think\Exception;
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class JsOrderModel extends Model
+    {
+        use SoftDelete;
+        protected $deteleTime = 'delete_time';
+        // 追加属性
+        protected $append = [
+            'fast_number', 'fast_number_list'
+        ];
+
+        /**
+         * 获取抢单技师数量
+         * @param string $value
+         * @param array  $data
+         * @return string
+         */
+        public function getFastNumberListAttr($value, $data)
+        {
+            $JsOrderGrabModel = new JsOrderGrabModel();
+            try {
+                return $JsOrderGrabModel->where('order_id', $data['id'])->column('js_id');
+            } catch (Exception $e) {
+                return [];
+            }
+        }
+
+        /**
+         * 获取抢单技师数量
+         * @param string $value
+         * @param array  $data
+         * @return string
+         */
+        public function getFastNumberAttr($value, $data)
+        {
+            $JsOrderGrabModel = new JsOrderGrabModel();
+            try {
+                return $JsOrderGrabModel->where('order_id', $data['id'])->group('id')->count();
+            } catch (Exception $e) {
+                return 0;
+            }
+        }
+
+        public function project()
+        {
+            return $this->hasOne('JsProjectModel','id','project_id');
+                //->removeOption('soft_delete');
+        }
+        
+        public function getList($where = [],$page = 1,$project_name = '')
+        {
+          
+            $list = $this::with(['project'=>function ($query) use ($project_name){
+                if($project_name){
+                    $query->where('name','like','%'.$project_name.'%');
+                }
+            }])->where($where)->order('id','desc')->page($page,5)->select()->each(function ($list){
+                $project = $list['project'];
+                if($project){
+                    $project['icon'] = cmf_get_image_preview_url($project['icon']);
+                    $list['project'] = $project;
+                }
+                $list['distance'] = 0;
+                if($list['jiedan_js_id']){
+                    $js_site_info = Db::name('js_site')->where('js_id',$list['jiedan_js_id'])->find();
+                   
+                    if($js_site_info['lat']&&$js_site_info['lng']&&$list['lat']&&$list['lng']){
+                        $list['distance'] = GetDistance($js_site_info['lat'],$js_site_info['lng'],$list['lat'],$list['lng'],2,2);
+                    }else{
+                        $list['distance'] =0;
+                    }
+      
+                    
+                }
+                $list['erweima'] = cmf_get_image_preview_url($list['erweima']);
+            });
+         
+            return $list;
+        }
+        
+        public function js()
+        {
+            return $this->hasOne('JsModel','id','jiedan_js_id');
+        }
+        
+        public function addtime()
+        {
+            return $this->hasMany('JsOrderAddtimeModel','order_id','id');
+        }
+
+    }

+ 26 - 0
api/js/model/JsProjectCategoryModel.php

@@ -0,0 +1,26 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-07
+     * Time: 14:29
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsProjectCategoryModel extends Model
+    {
+    
+        
+        public function project()
+        {
+            return $this->belongsToMany('JsProjectModel','js_project_category_relevancy','project_id','category_id');
+            
+        }
+        
+        
+        
+    }

+ 144 - 0
api/js/model/JsProjectModel.php

@@ -0,0 +1,144 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-07
+     * Time: 14:42
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Db;
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class JsProjectModel extends Model
+    {
+        use SoftDelete;
+        protected $deleteTime = 'delete_time';
+        protected  $type = ['banner'=>'array'];
+    
+        /**
+         * @return \think\model\relation\BelongsToMany
+         * 服务类关联
+         */
+        public function tag()
+        {
+            return $this->belongsToMany('JsProjectTagModel','js_project_tag_relevancy','project_tag_id','project_id');
+        }
+    
+        /**
+         * @return \think\model\relation\BelongsToMany
+         * 服务区关联
+         */
+        public function service()
+        {
+            return $this->belongsToMany('JsProjectServiceModel','js_project_service_relevancy','service_id','project_id');
+        }
+    
+        /**
+         * @return \think\model\relation\BelongsToMany
+         * 分类关联
+         */
+    
+        public function category()
+        {
+            return $this->belongsToMany('JsProjectCategoryModel','js_project_category_relevancy','category_id','project_id');
+        }
+        /**
+         * post_content 自动转化
+         * @param $value
+         * @return string
+         */
+        public function getContentAttr($value)
+        {
+            return cmf_replace_content_file_url(htmlspecialchars_decode($value));
+        }
+    
+        /**
+         * post_content 自动转化
+         * @param $value
+         * @return string
+         */
+        public function setContentAttr($value)
+        {
+            return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
+        }
+    
+        public function getIconAttr($value)
+        {
+            return  cmf_get_image_preview_url($value);
+        }
+        
+        public function getList($name = '',$where = '',$page = 1,$serviceId,$js_id = 0)
+        {
+            $list = $this->with(['tag'=>function($query){
+                $query->where('is_show',1);
+            }])->where(function ($query) use ($where,$name){
+                if(is_array($where) && count($where) > 0){
+                    $query->where('id','in',$where);
+                }
+                if($name){
+                    $query->where('name','like','%'.$name.'%');
+                }
+            })->where('is_show',1)->field('id,name,icon,brief,sales_num')->order('list_order','asc')->page($page,20)->select()->each(function ($list) use ($serviceId,$js_id){
+                $list['icon'] = cmf_get_image_preview_url($list['icon']);
+                $list['service'] = Db::name('js_project_service_relevancy')->where(['project_id'=>$list['id'],'service_id'=>$serviceId])->find();
+                $list['is_shenqing']  = 0;
+          
+                if($js_id){
+                  $js_project_relevancy_info = Db::name('js_project_relevancy')->where(['project_id'=>$list['id'],'js_id'=>$js_id])->field('id,status')->find();
+
+                  if($js_project_relevancy_info){
+                      if($js_project_relevancy_info['status'] == 0){
+                          $list['is_shenqing'] = 1;
+                      }
+                      if($js_project_relevancy_info['status'] == 1){
+                          $list['is_shenqing'] = 2;
+                      }
+                  }
+        
+                }
+            });
+            $res  = [];
+            foreach ($list as $value){
+                if($value['service']){
+                    $res[] = $value;
+                }
+            }
+        
+            return $res;
+        }
+        
+        
+        
+        public function getInfo($id,$district)
+        {
+            $RegionModel = new RegionModel();
+            $serviceId = $RegionModel->getId($district);
+            $info = $this::get($id);
+            $info['service'] = [];
+            $service = Db::name('js_project_service_relevancy')->where(['project_id'=>$id,'service_id'=>$serviceId])->find();
+            
+            if($service){
+                $info['service'] = $service;
+            }
+        
+            $icon = $info->icon;
+            if($icon){
+                $info->icon = cmf_get_image_preview_url($icon);
+            }
+
+            $banner = $info['banner'];
+            if($banner){
+                foreach ($banner as $key => $value){
+                    $banner[$key]['url'] = cmf_get_image_preview_url($value['url']);
+                }
+            }
+         
+            $info['banner'] = $banner;
+            return $info;
+        }
+        
+    }

+ 17 - 0
api/js/model/JsProjectServiceModel.php

@@ -0,0 +1,17 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-07
+     * Time: 15:12
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsProjectServiceModel extends Model
+    {
+    
+    }

+ 17 - 0
api/js/model/JsProjectTagModel.php

@@ -0,0 +1,17 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-07
+     * Time: 15:12
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsProjectTagModel extends Model
+    {
+    
+    }

+ 36 - 0
api/js/model/JsScoreModel.php

@@ -0,0 +1,36 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-11
+     * Time: 15:30
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsScoreModel extends Model
+    {
+    
+        public function user()
+        {
+            return $this->hasOne('UserModel','id','user_id')->field('id,user_nickname,avatar');
+        }
+        public function jsOrder()
+        {
+            return $this->hasOne('JsOrderModel','id','order_id')->field('id,order_sn');
+        }
+        public function project()
+        {
+            return $this->hasOne('JsProjectModel','id','project_id')->field('id,name');
+        }
+        
+        public function getList($js_id,$page = 1)
+        {
+            $list = $this::with(['user','jsOrder','project'])->where('js_id',$js_id)->order('id','desc')->page($page,20)->select();
+            return $list;
+            
+        }
+    }

+ 17 - 0
api/js/model/JsSiteModel.php

@@ -0,0 +1,17 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-15
+     * Time: 11:06
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsSiteModel extends Model
+    {
+    
+    }

+ 22 - 0
api/js/model/JsTimeModel.php

@@ -0,0 +1,22 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-12
+     * Time: 14:42
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class JsTimeModel extends Model
+    {
+        protected $type = [
+            'times' => 'array',
+            'weeks' => 'array',
+        ];
+
+        
+    }

+ 26 - 0
api/js/model/PortalCategoryModel.php

@@ -0,0 +1,26 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-18
+     * Time: 11:28
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class PortalCategoryModel extends Model
+    {
+        public function portal()
+        {
+            
+            return $this->belongsToMany('PortalPostModel','portal_category_post','post_id','category_id')->alias('a')->order('a.id','desc')->field('a.id,a.post_title,post_excerpt,update_time');
+        }
+        public function getlist($id=1)
+        {
+            $list = $this::get($id,['portal'=>function($query){$query->where(['delete_time'=>0,'post_status'=>1]);}]);
+            return $list->portal;
+        }
+    }

+ 61 - 0
api/js/model/PortalPostModel.php

@@ -0,0 +1,61 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-18
+     * Time: 11:30
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class PortalPostModel extends Model
+    {
+    
+        protected $type = [
+            'more' => 'array',
+        ];
+    
+        // 开启自动写入时间戳字段
+        protected $autoWriteTimestamp = true;
+    
+        /**
+         * 关联 user表
+         * @return \think\model\relation\BelongsTo
+         */
+        public function user()
+        {
+            return $this->belongsTo('UserModel', 'user_id')->setEagerlyType(1);
+        }
+    
+        /**
+         * 关联分类表
+         * @return \think\model\relation\BelongsToMany
+         */
+        public function categories()
+        {
+            return $this->belongsToMany('PortalCategoryModel', 'portal_category_post', 'category_id', 'post_id');
+        }
+    
+        /**
+         * 关联标签表
+         * @return \think\model\relation\BelongsToMany
+         */
+        public function tags()
+        {
+            return $this->belongsToMany('PortalTagModel', 'portal_tag_post', 'tag_id', 'post_id');
+        }
+    
+        /**
+         * post_content 自动转化
+         * @param $value
+         * @return string
+         */
+        public function getPostContentAttr($value)
+        {
+            return cmf_replace_content_file_url(htmlspecialchars_decode($value));
+        }
+    
+    }

+ 21 - 0
api/js/model/RegionModel.php

@@ -0,0 +1,21 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-17
+     * Time: 9:54
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class RegionModel extends Model
+    {
+        public function getId($name)
+        {
+            return $this::where('cityName',$name)->value('id');
+        }
+        
+    }

+ 24 - 0
api/js/model/SignInSetModel.php

@@ -0,0 +1,24 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-07
+     * Time: 11:08
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class SignInSetModel extends Model
+    {
+        public function getMaxInfo()
+        {
+            
+            $info = $this::where('day',$this::max('day'))->find();
+            return $info;
+            
+        }
+        
+    }

+ 41 - 0
api/js/model/UserDiscountModel.php

@@ -0,0 +1,41 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-08
+     * Time: 10:21
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class UserDiscountModel extends Model
+    {
+        
+        public function getPastTimeAttr($value)
+        {
+            return date('Y-m-d H:i',$value);
+        }
+        public function jsDiscount()
+        {
+            return $this->hasOne('JsDiscountModel','id','discount_id')->field('id,name,voucher');
+        }
+        
+        public function project()
+        {
+            return $this->hasOne('JsProjectModel','id','project_id')->field('id,name');
+        }
+        
+        public function getList($where = [])
+        {
+            $list = $this::with(['jsDiscount','project'])->where($where)->select()->each(function ($list){
+                if(!$list->project){
+                    $list->project = '全部项目';
+                }
+            });
+            return $list;
+            
+        }
+    }

+ 40 - 0
api/js/model/UserModel.php

@@ -0,0 +1,40 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-02
+     * Time: 17:27
+     */
+    namespace api\js\model;
+    use think\Model;
+    use think\model\concern\SoftDelete;
+
+    class UserModel extends Model
+    {
+        use SoftDelete;
+        protected $deleteTime = 'delete_time';
+
+        public function discount()
+        {
+            return $this->hasOne('UserDiscountModel','user_id','id')->field('id,user_id,discount_id');
+        }
+        
+        public function js()
+        {
+            return $this->hasOne('JsModel','user_id','id');
+        }
+    
+        public function jsStatus()
+        {
+            return $this->hasOne('JsModel','user_id','id')->field('user_id,js_status');
+        }
+        
+        public function agency()
+        {
+            return $this->hasOne('AgencyModel','id','agency_id');
+        }
+        public function distributor()
+        {
+            return $this->hasOne('DistributorModel','distributor_id','id');
+        }
+    }

+ 17 - 0
api/js/model/UserSignInModel.php

@@ -0,0 +1,17 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-07
+     * Time: 11:00
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+
+    class UserSignInModel extends Model
+    {
+    
+    }

+ 18 - 0
api/js/model/UserTxModel.php

@@ -0,0 +1,18 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-18
+     * Time: 15:40
+     */
+    
+    namespace api\js\model;
+    
+    
+    use think\Model;
+    use think\model\concern\SoftDelete;
+    class UserTxModel extends Model
+    {
+        use SoftDelete;
+        protected $deteleTime = 'delete_time';
+    }

+ 131 - 0
api/js/route.php

@@ -0,0 +1,131 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-02
+ * Time: 16:53
+ */
+
+use think\facade\Route;
+
+Route::post('UpImg/upimg', 'js/UpImg/upimg'); //图片上传
+Route::get('index', 'js/index/index'); //首页
+Route::get('getKefu', 'js/index/getKefu'); //首页
+Route::post('bindWechat', 'js/index/bindWechat'); //绑定微信
+Route::get('getdow', 'js/index/getdow'); //获取下载
+Route::get('getWXLog', 'js/index/getWXLog'); //是否微信登录
+Route::get('getOut', 'js/index/getOut'); //获取热搜
+Route::get('getRegion', 'js/index/getRegion'); //获取地址
+Route::post('login', 'js/Login/login'); //用户登录 账号密码
+Route::post('wechatLogin', 'js/Login/wechatLogin'); //微信用户登录
+Route::post('regPost', 'js/reg/regPost'); //用户注册
+Route::post('codeOpt', 'js/reg/codeOpt'); //二维码绑定
+Route::post('setDistributor', 'js/reg/setDistributor'); //绑定分销上
+Route::post('uppass', 'js/reg/uppass'); //用户重置密码
+Route::post('getVerificationCode', 'js/VerificationCode/getVerificationCode'); //获取验证码
+Route::post('userSignIn/addPost', 'js/UserSignIn/addPost'); //用户签到
+Route::get('userSignIn/getUserSign', 'js/UserSignIn/getUserSign'); //获取用户签到记录
+Route::get('jsProjectCategory/getList', 'js/jsProjectCategory/getList'); //获取项目分类
+Route::get('jsProject/getList', 'js/jsProject/getList'); //获取项目列表
+Route::get('jsProject/getInfo', 'js/jsProject/getInfo'); //获取项目详情
+/******************************************项目**************************************************/
+Route::get('jsOrder/getUserInfo', 'js/jsOrder/getUserInfo'); //呼叫服务时加载回去相关数据
+Route::post('jsOrder/addPost', 'js/jsOrder/addPost'); //呼叫服务时加载回去相关数据
+Route::post('jsOrder/pay', 'js/jsOrder/pay'); //订单的其他支付
+Route::get('jsOrder/getList', 'js/jsOrder/getList'); //订单列表
+Route::get('jsOrder/getInfo', 'js/jsOrder/getInfo'); //订单详情
+Route::post('jsOrder/setJsScore', 'js/jsOrder/setJsScore'); //订单评论
+Route::post('jsOrder/orderCancel', 'js/jsOrder/orderCancel'); //取消订单
+Route::get('jsOrder/selectJs', 'js/jsOrder/selectJs'); //获取抢单技师
+Route::post('jsOrder/doSelectJs', 'js/jsOrder/doSelectJs'); //选择抢单技师
+Route::post('jsOrder/deleteOrder', 'js/jsOrder/deleteOrder'); //用户删除订单
+Route::get('jsOrder/getwithhold', 'js/jsOrder/getwithhold'); //订单取消扣款规则
+Route::post('jsOrder/addTime', 'js/jsOrder/addTime'); //订单加钟
+Route::get('jsOrder/getSeizeOrder', 'js/jsOrder/getSeizeOrder'); //订单抢单技师数量
+/************************************用户端*******************************************************/
+Route::post('user/destroy', 'js/user/destroy'); //注销用户
+Route::post('user/applyJsPost', 'js/user/applyJsPost'); //用户申请成为技师
+Route::post('user/applyProjectPost', 'js/user/applyProjectPost'); //用户申请成为技师
+Route::get('user/getDiscount', 'js/user/getDiscount'); //用户优惠券
+Route::get('user/getInfo', 'js/user/getInfo'); //用户信息
+Route::get('user/logoff', 'js/user/logoff'); //用户信息
+Route::post('user/editInfo', 'js/user/editInfo'); //用户修改信息
+Route::post('user/addIdea', 'js/user/addIdea'); //用户提交意见反馈
+Route::get('user/getxiaji', 'js/user/getxiaji'); //用户下级
+Route::get('user/getMoneyLog', 'js/user/getMoneyLog'); //用户余额记录
+Route::get('user/geterweima', 'js/user/geterweima'); //用户二维码
+Route::get('user/dofinish', 'js/jsOrder/finish'); //获取技师列表
+Route::post('user/addTx', 'js/user/addTx'); //用户提现
+Route::post('user/agencyapply', 'js/user/agencyapply'); //用户申请代理
+
+
+/********************************************技师信息*******************************************************************/
+Route::get('js/getList', 'js/js/getList'); //获取技师列表
+Route::get('js/getinfo', 'js/js/getInfo');//获取技师详情
+Route::get('js/getJsScore', 'js/js/getJsScore'); //获取技师评论
+Route::get('jsCategory/getList', 'js/jsCategory/getList'); //获取技师分类
+/*********************************************技师端******************************************************************/
+/********************************************商城***************************************/
+Route::get('store/index', 'js/store/index'); //商城首页
+Route::get('store/getList', 'js/store/getList'); //商品列表
+Route::get('store/getInfo', 'js/store/getInfo'); //商品详情
+Route::post('goodsorder/addPost', 'js/GoodsOrder/addPost'); //创建订单
+Route::get('goodsorder/getlist', 'js/GoodsOrder/getlist'); //创建订单
+Route::post('goodsorder/pay', 'js/GoodsOrder/pay'); //支付订单
+Route::post('goodsorder/take', 'js/GoodsOrder/take'); //订单收货
+/*********************************************技师******************************************/
+Route::get('js/index', 'js/JsIndex/index');//技术端首页
+Route::post('userjs/destroy', 'js/userJs/destroy'); //注销技师账户
+Route::post('userjs/addPostSite', 'js/userJs/addPostSite'); //更新技师地点
+Route::post('userjs/getPostSite', 'js/userJs/getPostSite'); //获取技师地点
+Route::get('userjs/getTime', 'js/userJs/getTime'); //技师添加时间
+Route::post('userjs/addTimePost', 'js/userJs/addTimePost'); //技师添加时间
+Route::post('userjs/setWorkTime', 'js/userJs/setWorkTime'); //技师上下钟
+Route::post('userjs/postProject', 'js/userJs/postProject'); //技师申请项目
+Route::post('userjs/editInfo', 'js/userJs/editInfo'); //技师修改基本信息
+Route::post('userjs/editPicture', 'js/userJs/editPicture'); //技师修改基本信息
+Route::get('userjs/getInfo', 'js/userJs/getInfo'); //技师修改基本信息
+Route::get('userjs/getCourseList', 'js/userJs/getCourseList'); //项目课程列表
+Route::get('userjs/getCourseInfo', 'js/userJs/getCourseInfo'); //项目课程详情
+Route::post('userjs/addCourseOrder', 'js/userJs/addCourseOrder'); //技师创建课程订单
+Route::post('userjs/pay', 'js/userJs/pay'); //技师课程订单支付
+Route::get('userjs/getProjectOrderList', 'js/userJs/getProjectOrderList'); //技师订单
+Route::get('userjs/getFastOrderList', 'js/userJs/getFastOrderList'); //技师抢单订单
+Route::post('userjs/addShield', 'js/userJs/addShield'); //技师屏蔽订单
+Route::post('userjs/jeidanPost', 'js/userJs/jeidanPost'); //技师抢单操作
+Route::post('userjs/start', 'js/userJs/start'); //技师服务开始
+Route::post('userjs/addressPost', 'js/userJs/addressPost'); //添加地址
+// Route::post('userjs/addressEdit', 'js/userJs/addressEdit'); //修改地址
+//  Route::post('userjs/setMoren', 'js/userJs/setMoren'); //设置默认地址
+Route::get('userjs/getaddresslist', 'js/userJs/getaddresslist'); //地址列表
+// Route::get('userjs/setMoren', 'js/userJs/setMoren'); //地址列表
+Route::get('userjs/addressDelete', 'js/userJs/addressDelete'); //地址列表
+Route::get('userjs/getaddressinfo', 'js/userJs/getaddressinfo'); //地址详情
+Route::get('userjs/callPost', 'js/userJs/callPost'); //技师报警
+Route::get('userjs/getJsOrdernum', 'js/userJs/getJsOrdernum'); //技师可抢单数量
+Route::get('userjs/getOrdernum', 'js/userJs/getOrdernum'); //技师订单数量
+Route::get('userjs/play', 'js/userJs/play'); //接单播放语音
+Route::get('userjs/cancelplay', 'js/userJs/cancelplay'); //接单取消提醒播放语音
+Route::post('userjs/deleteOrder', 'js/userJs/deleteOrder'); //技师删除订单
+Route::get('userjs/getClassifyOrderNum', 'js/userJs/getClassifyOrderNum'); //抢单列表分类的下的订单数量
+Route::get('userjs/getOrdeNum', 'js/userJs/getOrdeNum'); //待接单数量
+
+/*****************************************消息**********************************************************************/
+Route::get('portal/getList', 'js/portal/getList');//消息列表
+Route::get('portal/getInfo', 'js/portal/getInfo');//消息列表
+/**************************************************微信授权登录******************************************************/
+Route::post('wxlogin/wxLogin', 'js/wxLogin/wxLogin'); //微信登录
+Route::get('wxInfo', 'js/wxLogin/wxInfo'); //微信信息
+Route::post('wxlogin/bangding', 'js/wxLogin/bangding'); //微信绑定用户
+/***************************************************代理商**********************************************************/
+Route::get('UserAgency/getUserList', 'js/UserAgency/getUserList');//获取本地用户
+Route::get('UserAgency/getnum', 'js/UserAgency/getnum');//获取数量
+Route::get('UserAgency/getJsList', 'js/UserAgency/getJsList');//获取本地技师
+Route::get('UserAgency/getOrder', 'js/UserAgency/getOrder');//获取服务订单
+Route::get('UserAgency/getCallList', 'js/UserAgency/getCallList');//.报警列表
+Route::get('UserAgency/getDistrict', 'js/UserAgency/getDistrict');//获取代理的区
+/***************************************************申请分销商**********************************************************/
+Route::get('distributor/getList', 'js/Distributor/getList');//获取分销商
+Route::post('distributor/addPost', 'js/Distributor/addPost');//获取分销商
+
+

+ 9 - 0
app/back/config/database.php

@@ -0,0 +1,9 @@
+<?php
+/**
+ * 配置文件
+ */
+
+return [
+    
+    'auto_timestamp' => true,
+];

+ 195 - 0
app/back/controller/AgencyController.php

@@ -0,0 +1,195 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-14
+     * Time: 9:15
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\AgencyModel;
+    use app\back\model\AgencyRankModel;
+    use app\back\model\UserModel;
+    use app\back\validate\AgencyValidate;
+    use cmf\controller\AdminBaseController;
+    use think\Db;
+    use think\Validate;
+
+    class AgencyController extends AdminBaseController
+    {
+    
+        public function index()
+        {
+            $agencyModel = new AgencyModel();
+            $list = $agencyModel::with(['renk','city','district'])->select();
+            $this->assign('list',$list);
+            
+            return $this->fetch();
+        }
+    
+        public function add()
+        {
+            $rank = AgencyRankModel::order('id','asc')->select();
+            
+            $provinceList = Db::name('region')->where('depth',1)->field('id,cityName')->select();
+         
+            
+            $this->assign('rank',$rank);
+            $this->assign('provinceList',$provinceList);
+            return $this->fetch();
+        }
+    
+        public function addPost()
+        {
+            $validate = new AgencyValidate();
+    
+            $data = $this->request->param();
+            if (!$validate->check($data)) {
+                $this->error($validate->getError());
+            }
+            $data = $this->request->param();
+   
+            if (!$validate->check($data)) {
+                $this->error($validate->getError());
+            }
+            $agencyModel = new AgencyModel();
+            $agencyModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        }
+        public function edit()
+        {
+            $id  = $this->request->param('id');
+            $info = AgencyModel::get($id);
+            $info->renk;
+            $info->province;
+            $info->city;
+            $info->district;
+            $rank = AgencyRankModel::order('id','asc')->select();
+            $provinceList = Db::name('region')->where('depth',1)->field('id,cityName')->select();
+            $this->assign('rank',$rank);
+            $this->assign('provinceList',$provinceList);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $validate = new AgencyValidate();
+            
+            $data = $this->request->param();
+            if (!$validate->check($data)) {
+                $this->error($validate->getError());
+            }
+            $agencyModel = new AgencyModel();
+            $agencyModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            $user_id = Db::name('user')->where('agency_id',$id)->value('id');
+            if($user_id){
+                $this->error('用户使用该代理不可删除!');
+            }
+            AgencyModel::destroy($id);
+            $this->success('删除成功');
+        }
+    
+        
+        public function select()
+        {
+            $user_id = $this->request->param('id');
+            $agencyModel = new AgencyModel();
+            $list = $agencyModel::with(['renk','city','district'])->select();
+            
+            $user_agency_id = UserModel::get($user_id)['agency_id'];
+            $user_agency_id = explode(',',$user_agency_id);
+            $this->assign('user_id',$user_id);
+            $this->assign('list',$list);
+            $this->assign('user_agency_id',$user_agency_id);
+            return $this->fetch();
+        }
+        
+        public function setuser()
+        {
+            $user_id = $this->request->param('user_id');
+            $agency_id = $this->request->param('agency_id/a');
+            $agency_id = empty($agency_id)?'':implode(',',$agency_id);
+            $UserModel = new UserModel();
+			$agencyModel = new AgencyModel();
+			$user_info = UserModel::get($user_id)->toArray();
+			$befor_data = $user_info['agency_id'];
+			if(!empty($befor_data)){
+				$befor_arr = $agencyModel::where('id in ('.$befor_data.')')->column('name');
+			}else{
+				$befor_arr = array();
+			}
+			$after_data = $agency_id;
+			if(!is_array($befor_arr)){
+				$befor_arr=array($befor_arr);
+			}
+			if(!empty($after_data)){
+				$after_arr = $agencyModel::where('id in ('.$after_data.')')->column('name');
+			}else{
+				$after_arr = array();
+			}
+			if(!is_array($after_arr)){
+				$after_arr=array($after_arr);
+			}
+			$admin_id = cmf_get_current_admin_id();
+			$log_info = '变更前:'.join('|',$befor_arr).';变更后:'.join('|',$after_arr);
+			admin_log($admin_id,$log_info,$user_id,'指定代理商区域');
+//            $id = $UserModel::where('agency_id',$agency_id)->value('id');
+//            if($id){
+//                return json(['code'=>2]);
+//            }
+            $UserModel->allowField(true)->isUpdate(true)->save(['agency_id'=>$agency_id],['id'=>$user_id]);
+            return json(['code'=>1]);
+            
+        }
+        
+        public function user_apply_agency()
+        {
+            $where = [];
+            $page = $this->request->param('page',1);
+            $pw = [];
+            $keyword = $this->request->param('keyword');
+            if($keyword){
+                $this->assign('keyword',$keyword);
+                $pw['keyword'] = $keyword;
+            }
+            $status = $this->request->param('status');
+            if($status || $status != ''){
+                $pw['status'] = $status;
+                $this->assign('status',$status);
+                $where['status'] = $status;
+            }
+            $list = Db::name('user_apply_agency')->where($where)->where(function ($query)use ($keyword){
+                if($keyword){
+                    $query->where('name|t.mobile','like','%'.$keyword.'%');
+                }
+            })
+                ->field('t.*,t1.mobile as user_mobile,t1.user_nickname')
+                ->alias('t')
+                ->join('user t1','t.user_id = t1.id','left')
+                ->order('id','desc')
+                ->paginate(30,false,array($page,url('index'),'query'=>$pw));
+            $this->assign('list',$list);
+            return $this->fetch();
+        }
+        
+        public function apply_delete()
+        {
+            $id = $this->request->param('id');
+            Db::name('user_apply_agency')->where('id',$id)->delete();
+            $this->success('删除成功');
+        }
+    
+        public function apply_set()
+        {
+            $id = $this->request->param('id');
+            Db::name('user_apply_agency')->where('id',$id)->update(['status'=>1,'chuli_time'=>time()]);
+            $this->success('设置成功');
+        }
+    }

+ 89 - 0
app/back/controller/AgencyRankController.php

@@ -0,0 +1,89 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-12
+     * Time: 17:01
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\AgencyRankModel;
+    use cmf\controller\AdminBaseController;
+    /**
+     * Class AgencyRankController
+     * @package app\back\controller
+     * @adminMenuRoot(
+     *     'name'   =>'代理管理',
+     *     'action' =>'agency',
+     *     'parent' =>'',
+     *     'display'=> true,
+     *     'order'  => 10000,
+     *     'icon'   =>'address-book-o',
+     *     'remark' =>'代理管理'
+     * )
+     */
+    class AgencyRankController extends AdminBaseController
+    {
+    
+        /**
+         * 添加页
+         * @adminMenu(
+         *     'name'   => '添加页',
+         *     'parent' => 'agency',
+         *     'display'=> true,
+         *     'hasView'=> true,
+         *     'order'  => 10000,
+         *     'icon'   => '',
+         *     'remark' => '级别添加页',
+         *     'param'  => ''
+         * )
+         */
+        public function index()
+        {
+            $list = AgencyRankModel::order('id','asc')->select();
+            $this->assign('list',$list);
+            return $this->fetch();
+        }
+    
+        /**
+         * 添加页
+         * @adminMenu(
+         *     'name'   => '添加页',
+         *     'parent' => 'index',
+         *     'display'=> false,
+         *     'hasView'=> true,
+         *     'order'  => 10000,
+         *     'icon'   => '',
+         *     'remark' => '级别添加页',
+         *     'param'  => ''
+         * )
+         */
+        public function add()
+        {
+            return $this->fetch();
+        }
+        
+        public function addPost()
+        {
+            $data = $this->request->param();
+            $agencyRankModel = new AgencyRankModel();
+            $agencyRankModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = AgencyRankModel::get($id);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $data = $this->request->param();
+            $agencyRankModel = new AgencyRankModel();
+            $agencyRankModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('修改成功');
+        }
+    }

+ 70 - 0
app/back/controller/ApplyController.php

@@ -0,0 +1,70 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-10-20
+     * Time: 13:27
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\DistributorLogModel;
+    use app\back\model\UserModel;
+    use cmf\controller\AdminBaseController;
+
+    class ApplyController extends AdminBaseController
+    {
+        public function index()
+        {
+            $DistribtorLogModel = new DistributorLogModel();
+            $where = [];
+            $page = $this->request->param('page');
+            $pw = [];
+            $keyword = $this->request->param('keyword');
+            if($keyword){
+                $this->assign('keyword',$keyword);
+                $pw['keyword'] = $keyword;
+                $user_ids = UserModel::where(function ($query) use ($keyword){
+                    $query->where('user_nickname|mobile','like','%'.$keyword.'%');
+                })->field('id')->select();
+                $user_ids_new = [];
+                foreach ($user_ids as $v){
+                    $user_ids_new[] = $v['id'];
+                }
+                $where['user_id'] = $user_ids_new;
+            }
+            $status = $this->request->param('status');
+            if($status || $status != ''){
+                $pw['status'] = $status;
+                $this->assign('status',$status);
+                $where['chuli_status'] = $status;
+            }
+            $list = $DistribtorLogModel::with(['user','distributor'])->where($where)->order('id','desc')->paginate(30,false,array($page,url('index'),'query'=>$pw));
+            $this->assign('list',$list);
+          //  dump($list->toArray());
+            $this->assign('page',$list->render());
+            return $this->fetch();
+        }
+    
+    
+    
+        public function apply_delete()
+        {
+            $id = $this->request->param('id');
+            $DistribtorLogModel = new DistributorLogModel();
+           // Db::name('user_apply_agency')->where('id',$id)->delete();
+            $DistribtorLogModel::destroy($id);
+            $this->success('删除成功');
+        }
+        
+        public function apply_set()
+        {
+            $id = $this->request->param('id');
+            $DistribtorLogModel = new DistributorLogModel();
+            $info = $DistribtorLogModel::get($id);
+            UserModel::where('id',$info['user_id'])->update(['distributor_id'=>$info['distributor_id']]);
+            $DistribtorLogModel->allowField(true)->isUpdate(true)->save(['chuli_status'=>1,'chuli_time'=>time()],['id'=>$id]);
+            $this->success('设置成功');
+        }
+    }

+ 97 - 0
app/back/controller/CallController.php

@@ -0,0 +1,97 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-29
+     * Time: 8:45
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\JsCallModel;
+    use cmf\controller\AdminBaseController;
+	use app\back\model\JsOrderModel;
+    use think\Db;
+
+    class CallController extends AdminBaseController
+    {
+        public function index()
+        {
+            $where = [];
+            $pw = [];
+            $page = $this->request->param('page',1);
+            $admin_is_look = $this->request->param('admin_is_look');
+            if($admin_is_look || $admin_is_look != ''){
+                $where['admin_is_look'] = $admin_is_look;
+                $pw['admin_is_look'] = $admin_is_look;
+                $this->assign('admin_is_look',$admin_is_look);
+            }
+            $agency_is_look = $this->request->param('agency_is_look');
+            if($agency_is_look || $agency_is_look != ''){
+                $where['agency_is_look'] = $agency_is_look;
+                $pw['agency_is_look'] = $agency_is_look;
+                $this->assign('agency_is_look',$agency_is_look);
+            }
+            
+            $list = Db::name('js_call')->where($where)
+                ->field('t.*,t1.mobile as user_mobile,t1.user_nickname,t2.order_sn,t2.district,t2.address1,t2.delete_time as order_delete_time')
+                ->alias('t')
+                ->join('user t1','t.user_id = t1.id','left')
+                ->join('js_order t2','t.order_id = t2.id AND t2.delete_time is NULL','left')
+                ->order('t.id','desc')
+                ->paginate(30,false,array($page,url('index'),'query'=>$pw));
+            $this->assign('list',$list);
+            $this->assign('action',$this->request->action());
+            $this->assign('page',$list->render());
+            return $this->fetch();
+            
+        }
+        
+        public function look()
+        {
+            $id = $this->request->param('id');
+            $info = JsCallModel::get($id,['jsorder'=>['project','xiadanUser'],'user.js']);
+      
+          //  $info->jsorder->project;
+        //    $info->jsorder->xiadanUser;
+      //      $info->user->js;
+            $this->assign('info',$info);
+            return $this->fetch();
+            
+        }
+        
+        public function lookPost()
+        {
+            $id = $this->request->param('id');
+            $JsCallModel = new JsCallModel();
+            $JsCallModel->allowField(true)->isUpdate(true)->save(['admin_is_look_time'=>time(),'admin_is_look'=>1],['id'=>$id]);
+            $this->success('操作成功');
+        }
+        
+        public function num()
+        {
+            $num = $this->request->param('num');
+            $JsCallModel = new JsCallModel();
+            $shishi_num = $JsCallModel::where('admin_is_look',0)->count();
+            if($shishi_num > $num){
+                return ['code'=>1,'shishi_num'=>$shishi_num];
+            }else{
+                return ['code'=>0];
+            }
+   
+        }
+		public function neworder()
+        {
+            $last_time = file_exists('lasttime.log')?file_get_contents('lasttime.log'):time()-360*24*60*60;
+			file_put_contents('lasttime.log',time());
+            $JsOrderModel = new JsOrderModel();
+            $shishi_num = $JsOrderModel::where('create_time','>',$last_time)->count();
+            if($shishi_num > 0){
+                return ['code'=>1,'shishi_num'=>$shishi_num];
+            }else{
+                return ['code'=>0];
+            }
+   
+        }
+    }

+ 165 - 0
app/back/controller/CogController.php

@@ -0,0 +1,165 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-10
+     * Time: 9:05
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use cmf\controller\AdminBaseController;
+
+    class CogController extends AdminBaseController
+    {
+        /**
+         * @return mixed
+         * 微信支付
+         */
+        public function wx()
+        {
+            $info = cmf_get_option('wxpay');
+            if($this->request->isPost()){
+                $data = $this->request->param();
+                cmf_set_option('wxpay',$data,false);
+                $this->success('保存成功');
+            }
+            $this->assign($info);
+            return $this->fetch();
+        }
+        /**
+         * 技师端
+         */
+        
+    
+        /**
+         * @return mixed
+         * 支付宝支付配置
+         */
+        public function aly()
+        {
+            $info = cmf_get_option('alipay');
+            if($this->request->isPost()){
+                $data = $this->request->param();
+                cmf_set_option('alipay',$data,false);
+                $this->success('保存成功');
+            }
+            
+            
+            $this->assign($info);
+            return $this->fetch();
+        }
+    
+        /**
+         * @return mixed
+         * 阿里云短信配置
+         */
+        public function alysms()
+        {
+            $info = cmf_get_option('alisms');
+            if($this->request->isPost()){
+                $data = $this->request->param();
+                cmf_set_option('alisms',$data,false);
+                $this->success('保存成功');
+            }
+            $this->assign($info);
+            return $this->fetch();
+        }
+    
+        /**
+         * 极光推送配置
+         */
+        public function jspus()
+        {
+            $info = cmf_get_option('jspus');
+            if($this->request->isPost()){
+                $data = $this->request->param();
+                cmf_set_option('jspus',$data,false);
+                $this->success('保存成功');
+            }
+            $this->assign($info);
+            return $this->fetch();
+        }
+        
+        public function xiadan()
+        {
+            $info = cmf_get_option('xiadan');
+            if($this->request->isPost()){
+                $data = $this->request->param();
+                cmf_set_option('xiadan',$data,false);
+                $this->success('保存成功');
+            }
+            $this->assign($info);
+            return $this->fetch();
+        }
+    
+        public function jiedan()
+        {
+            $info = cmf_get_option('jiedan');
+            if($this->request->isPost()){
+                $data = $this->request->param();
+                cmf_set_option('jiedan',$data,false);
+                $this->success('保存成功');
+            }
+            $this->assign($info);
+            return $this->fetch();
+        }
+    
+        /**
+         * @return mixed
+         * @throws \think\Exception
+         * @throws \think\db\exception\DataNotFoundException
+         * @throws \think\db\exception\ModelNotFoundException
+         * @throws \think\exception\DbException
+         * @throws \think\exception\PDOException
+         * 接单距离设置
+         */
+        public function distance()
+        {
+            $info = cmf_get_option('distance');
+            if($this->request->isPost()){
+                $data = $this->request->param();
+                cmf_set_option('distance',$data,false);
+                $this->success('保存成功');
+            }
+            $this->assign($info);
+            return $this->fetch();
+        }
+    
+        /**
+         * @return mixed
+         * @throws \think\Exception
+         * @throws \think\db\exception\DataNotFoundException
+         * @throws \think\db\exception\ModelNotFoundException
+         * @throws \think\exception\DbException
+         * @throws \think\exception\PDOException
+         * 下载设置
+         */
+        public function dow()
+        {
+            $info = cmf_get_option('dow');
+            if($this->request->isPost()){
+                $data = $this->request->param();
+                cmf_set_option('dow',$data,false);
+                $this->success('保存成功');
+            }
+            $this->assign($info);
+            return $this->fetch();
+        }
+    
+        /**
+         * 订单自动取消时长
+         */
+        public function duration()
+        {
+            $info = cmf_get_option('duration');
+            if($this->request->isPost()){
+                $data = $this->request->param();
+                cmf_set_option('duration',$data,false);
+                $this->success('保存成功');
+            }
+            $this->assign($info);
+            return $this->fetch();
+        }
+    }

+ 87 - 0
app/back/controller/DistributorController.php

@@ -0,0 +1,87 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-14
+     * Time: 10:38
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\DistributorModel;
+    use app\back\model\UserModel;
+    use cmf\controller\AdminBaseController;
+    use think\Db;
+
+    class DistributorController extends AdminBaseController
+    {
+        public function index()
+        {
+            $distributorModel = new DistributorModel();
+            $list = $distributorModel::all();
+            $this->assign('list',$list);
+            return $this->fetch();
+        }
+        public function add()
+        {
+            return $this->fetch();
+        }
+        public function addPost()
+        {
+            $data = $this->request->param();
+            $distributorModel = new DistributorModel();
+            $distributorModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = DistributorModel::get($id);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $data = $this->request->param();
+            $distributorModel = new DistributorModel();
+            $distributorModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            $user_id = Db::name('user')->where('distributor_id',$id)->value('id');
+            if($user_id){
+                $this->error('用户使用该分销商不可删除!');
+            }
+            DistributorModel::destroy($id);
+            $this->success('删除成功');
+        }
+        
+        public function select()
+        {
+            $id = $this->request->param('id');
+            $distributorModel = new DistributorModel();
+            $list = $distributorModel::all();
+            $user_distributor_id = UserModel::get($id)['distributor_id'];
+            $this->assign('list',$list);
+            $this->assign('id',$id);
+            $this->assign('user_distributor_id',$user_distributor_id);
+            return $this->fetch();
+        }
+        
+        public function setuser()
+        {
+            $user_id = $this->request->param('user_id');
+            $distributor_id = $this->request->param('distributor_id');
+			$befor_data = UserModel::get($user_id)['distributor_id'];
+			$after_data = $distributor_id;
+			$admin_id = cmf_get_current_admin_id();
+			$log_info = '变更前:'.DistributorModel::get($befor_data)['name'].';变更后:'.DistributorModel::get($after_data)['name'];
+            $userModel = new UserModel();
+            $userModel::where('id',$user_id)->update(['distributor_id'=>$distributor_id]);
+			admin_log($admin_id,$log_info,$user_id,'指定分销商等级');
+            return json(['code'=>1]);
+        }
+    }

+ 73 - 0
app/back/controller/GoodsCategoryController.php

@@ -0,0 +1,73 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-08-28
+     * Time: 14:39
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use cmf\controller\AdminBaseController;
+    use app\back\model\GoodsCategoryModel;
+    class GoodsCategoryController extends AdminBaseController
+    {
+    
+        public function index()
+        {
+        
+            $where = [];
+            $list = GoodsCategoryModel::where($where)->order('list_order','asc')->select();
+            $this->assign('list',$list);
+        
+            return $this->fetch();
+        }
+        public function add()
+        {
+            return $this->fetch();
+        }
+        public function addPost()
+        {
+            $data = $this->request->param();
+            $GoodsCategoryModel = new GoodsCategoryModel();
+            $GoodsCategoryModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = GoodsCategoryModel::get($id);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $data = $this->request->param();
+            $GoodsCategoryModel = new GoodsCategoryModel();
+            $GoodsCategoryModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            GoodsCategoryModel::destroy($id);
+            $this->success('删除成功');
+        }
+    
+        public function show()
+        {
+            $ids = $this->request->param('ids/a');
+            $is_show = $this->request->param('is_show');
+            GoodsCategoryModel::where('id','in',$ids)->update(['is_show'=>$is_show]);
+            $this->success('操作成功');
+        }
+    
+        public function listOrder()
+        {
+            $GoodsCategoryModel = new GoodsCategoryModel();
+            parent::listOrders($GoodsCategoryModel);
+            $this->success("排序更新成功!");
+        }
+    }

+ 120 - 0
app/back/controller/GoodsController.php

@@ -0,0 +1,120 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-08-28
+     * Time: 14:58
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\GoodsCategoryModel;
+    use app\back\model\GoodsModel;
+    use cmf\controller\AdminBaseController;
+
+    class GoodsController extends AdminBaseController
+    {
+        public function index()
+        {
+            $where = [];
+            $pw = [];
+            $page = $this->request->param('page',1);
+            $list = GoodsModel::with('category')->where($where)->order('list_order','asc')->paginate(30,false,array($page,url('index'),'query'=>$pw));
+            $this->assign('list',$list);
+            return $this->fetch();
+        }
+        public function add()
+        {
+            $goodsCategoryList = GoodsCategoryModel::where('is_show',1)->order('list_order','asc')->select();
+            $this->assign('goodsCategoryList',$goodsCategoryList);
+            
+            return $this->fetch();
+        }
+        public function addPost()
+        {
+            $data = $this->request->param();
+    
+            if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
+                $data['banner'] = [];
+                foreach ($data['photo_urls'] as $key => $url) {
+                    $photoUrl = cmf_asset_relative_url($url);
+                    array_push( $data['banner'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
+                }
+            }
+    
+            unset($data['photo_urls']);
+            unset($data['photo_names']);
+            $goodsModel = new GoodsModel();
+            $goodsModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = GoodsModel::get($id,'category');
+            $this->assign('info',$info);
+        
+            $goodsCategoryList = GoodsCategoryModel::where('is_show',1)->where('id','<>',$info->category_id)->order('list_order','asc')->select();
+            $this->assign('goodsCategoryList',$goodsCategoryList);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $data = $this->request->param();
+    
+            if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
+                $data['banner'] = [];
+                foreach ($data['photo_urls'] as $key => $url) {
+                    $photoUrl = cmf_asset_relative_url($url);
+                    array_push( $data['banner'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
+                }
+            }
+    
+            unset($data['photo_urls']);
+            unset($data['photo_names']);
+            $goodsModel = new GoodsModel();
+            $goodsModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            GoodsModel::destroy($id);
+            $this->success('删除成功');
+        }
+    
+    
+        public function shelves()
+        {
+            $ids = $this->request->param('ids/a');
+            $shelves = $this->request->param('shelves');
+            GoodsModel::where('id','in',$ids)->update(['shelves'=>$shelves]);
+            $this->success('操作成功');
+        }
+    
+        public function is_sell()
+        {
+            $ids = $this->request->param('ids/a');
+            $is_sell = $this->request->param('is_sell');
+            GoodsModel::where('id','in',$ids)->update(['is_sell'=>$is_sell]);
+            $this->success('操作成功');
+        }
+        
+        public function listOrder()
+        {
+            $GoodsModel = new GoodsModel();
+            parent::listOrders($GoodsModel);
+            $this->success("排序更新成功!");
+        }
+        
+        public function select()
+        {
+            $id = $this->request->param('id');
+            $list = GoodsModel::where('shelves',1)->order('list_order','asc')->field('id,goods_name,price,seckill_price,repertory')->select();
+            $this->assign('list',$list);
+            $this->assign('id',$id);
+            return $this->fetch();
+    
+        }
+    }

+ 93 - 0
app/back/controller/GoodsOrderController.php

@@ -0,0 +1,93 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-23
+     * Time: 15:15
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\GoodsOrderModel;
+    use cmf\controller\AdminBaseController;
+    use think\Db;
+
+    class GoodsOrderController extends AdminBaseController
+    {
+        public function index()
+        {
+            $goodsOrderModel = new GoodsOrderModel();
+            $list = $goodsOrderModel->getlist();
+            $this->assign('list',$list);
+            $this->assign('page',$list->render());
+            return $this->fetch();
+        }
+        
+        public function payment()
+        {
+            $goodsOrderModel = new GoodsOrderModel();
+            $id = $this->request->param('id');
+            $data['status'] = 1;
+            $goodsOrderModel->allowField(true)->isUpdate(true)->save($data,['id'=>$id]);
+            $log['admin_id'] = cmf_get_current_admin_id();
+            $log['action_time'] = date('Y-m-d H:i:s');
+            $log['obj_id'] = $id;
+            $log['remark'] = '订单设为付款';
+            $log['type'] = 2;
+            Db::name('goods_order_action_log')->insert($log);
+            $this->success('操作成功');
+            
+        }
+        
+        public function shipments()
+        {
+            $id = $this->request->param('id');
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+        
+        public function doshipments()
+        {
+            $goodsOrderModel = new GoodsOrderModel();
+            $data = $this->request->param();
+            $data['status'] = 2;
+            $data['fahuo_time'] = time();
+            $goodsOrderModel->allowField(true)->isUpdate(true)->save($data);
+            $log['admin_id'] = cmf_get_current_admin_id();
+            $log['action_time'] = date('Y-m-d H:i:s');
+            $log['obj_id'] = $data['id'];
+            $log['remark'] = '订单发货';
+            $log['type'] = 2;
+            Db::name('goods_order_action_log')->insert($log);
+            return json(['code'=>1]);
+        }
+        
+        public function take()
+        {
+            $goodsOrderModel = new GoodsOrderModel();
+            $id = $this->request->param('id');
+            $data['status'] = 3;
+            $data['take_time'] = time();
+            $goodsOrderModel->allowField(true)->isUpdate(true)->save($data,['id'=>$id]);
+            $log['admin_id'] = cmf_get_current_admin_id();
+            $log['action_time'] = date('Y-m-d H:i:s');
+            $log['obj_id'] = $id;
+            $log['remark'] = '订单收货';
+            $log['type'] = 2;
+            Db::name('goods_order_action_log')->insert($log);
+            $this->success('操作成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            $log['admin_id'] = cmf_get_current_admin_id();
+            $log['action_time'] = date('Y-m-d H:i:s');
+            $log['obj_id'] = $id;
+            $log['remark'] = '订单删除';
+            $log['type'] = 2;
+            Db::name('goods_order_action_log')->insert($log);
+            GoodsOrderModel::destroy($id);
+            $this->success('删除成功');
+        }
+    }

+ 64 - 0
app/back/controller/GoodsSearchController.php

@@ -0,0 +1,64 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-22
+     * Time: 17:11
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\GoodsCategoryModel;
+    use cmf\controller\AdminBaseController;
+    use app\back\model\GoodsSearchModel;
+    class GoodsSearchController extends AdminBaseController
+    {
+        public function index()
+        {
+            $GoodsSearchModel = new GoodsSearchModel();
+            $list = $GoodsSearchModel::with('category')->select();
+            $this->assign('list',$list);
+            return $this->fetch();
+        }
+        public function add()
+        {
+            $GoodsCategoryModel = new GoodsCategoryModel();
+            $list = $GoodsCategoryModel::where('is_show',1)->select();
+            $this->assign('list',$list);
+            return $this->fetch();
+        }
+    
+        public function addPost()
+        {
+            $data = $this->request->param();
+            $GoodsSearchModel = new GoodsSearchModel();
+            $GoodsSearchModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = GoodsSearchModel::get($id);
+            $info->category;
+            $GoodsCategoryModel = new GoodsCategoryModel();
+            $list = $GoodsCategoryModel::where('is_show',1)->where('id','<>',$info->category_id)->select();
+            $this->assign('list',$list);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $data = $this->request->param();
+            $GoodsSearchModel = new GoodsSearchModel();
+            $GoodsSearchModel->allowField(true)->isUpdate(true)->save($data,['id'=>$data]);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            GoodsSearchModel::where('id',$id)->delete();
+            $this->success('删除成功');
+        }
+    
+    }

+ 109 - 0
app/back/controller/GoodsSeckillController.php

@@ -0,0 +1,109 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-08-28
+     * Time: 16:01
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\GoodsSeckillGoodsModel;
+    use app\back\model\GoodsSeckillModel;
+    use cmf\controller\AdminBaseController;
+
+    class GoodsSeckillController extends AdminBaseController
+    {
+        public function index()
+        {
+            $goodsSeckillModel = new GoodsSeckillModel();
+            $where = [];
+            $list = $goodsSeckillModel->where($where)->order('id','desc')->select();
+            $this->assign('list',$list);
+            return $this->fetch();
+        }
+        
+        public function add()
+        {
+            return $this->fetch();
+        }
+        
+        public function addpost()
+        {
+            $data = $this->request->param();
+            $data['start_time'] = strtotime($data['start_time']);
+            $data['end_time'] = strtotime($data['end_time']);
+            
+            if($data['start_time'] >  $data['end_time']){
+                $this->error('开始时间不能大于结束时间!');
+            }
+            $goodsSeckillModel = new GoodsSeckillModel();
+            $goodsSeckillModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        }
+        
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = GoodsSeckillModel::get($id);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        
+        public function editPost()
+        {
+            $data = $this->request->param();
+            $data['start_time'] = strtotime($data['start_time']);
+            $data['end_time'] = strtotime($data['end_time']);
+            if($data['start_time'] >  $data['end_time']){
+                $this->error('开始时间不能大于结束时间!');
+            }
+            $goodsSeckillModel = new GoodsSeckillModel();
+            $goodsSeckillModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('编辑成功');
+        }
+        
+        public function seckillGoods()
+        {
+            $data = $this->request->param();
+          
+            $GoodsSeckillGoodsModel = new GoodsSeckillGoodsModel();
+            if(!empty($data['goodsids'])){
+                $inse = [];
+                foreach ($data['goodsids'] as $k=>$v)
+                {
+                   
+                    $seckikkGoodsId = $GoodsSeckillGoodsModel->where(['goods_id'=>$v,'seckill_id'=>$data['id']])->value('id');
+                    if(!$seckikkGoodsId){
+                        $inse[$k]['goods_id'] = $v;
+                        $inse[$k]['seckill_id'] = $data['id'];
+                    }
+                }
+              //  $GoodsSeckillGoodsModel::where('seckill_id',$data['id'])->delete();
+                $GoodsSeckillGoodsModel->insertAll($inse);
+                return json(['code'=>1]);
+            }else{
+                return json(['code'=>0]);
+            }
+            
+        }
+        
+        public function getseckillgoods()
+        {
+            $id = $this->request->param('id');
+            $GoodsSeckillGoodsModel = new GoodsSeckillGoodsModel();
+            $list = $GoodsSeckillGoodsModel->with('goods')->where('seckill_id',$id)->select();
+            $this->assign('list',$list);
+            return $this->fetch();
+        }
+        
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            GoodsSeckillModel::destroy($id);
+            $this->success('删除成功');
+          //  $GoodsSeckillGoodsModel = new GoodsSeckillGoodsModel();
+          
+        }
+    }

+ 444 - 0
app/back/controller/HuizongController.php

@@ -0,0 +1,444 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-10-13
+     * Time: 16:43
+     */
+    
+    namespace app\back\controller;
+    
+    use app\back\model\UserModel;
+    use app\back\model\RegionModel;
+    use app\back\model\AgencyModel;
+    use app\back\model\JsOrderModel;
+    use cmf\controller\AdminBaseController;
+    use think\Db;
+
+    class HuizongController extends AdminBaseController
+    {
+        public function getList()
+        {
+            $JsOrderModel = new JsOrderModel();
+
+            $id = cmf_get_current_admin_id();
+
+            $admin = UserModel::find($id);
+
+            $userObject = UserModel::where('mobile',$admin->user_login)->where('user_type',2)->select();
+
+            $userArray = $userObject->toArray();
+
+            if(count($userArray))
+            {
+                $user =  $userObject[0];
+            }
+
+            $agency_id = 0;
+
+            if(isset($user->agency_id) && !empty($user->agency_id))
+            {
+                 $agency_id = (int)$user->agency_id;
+            }
+
+            $where = [];
+
+             //如果有 代理 id 表示 是有区县代理的
+            if($agency_id)
+            {
+                $agency = AgencyModel::find($agency_id);
+
+                //需要判断 renk_id 是 1 还是 2 1级代理是地级市 2级代理是区县级
+                if($agency->renk_id === 1)
+                {
+                     $region  = RegionModel::where('id',$agency->city_id)->select()[0];
+
+                     $where['city'] =  $region->cityName;
+                }
+                else
+                {
+                     $region  = RegionModel::where('id',$agency->district_id)->select()[0]; 
+                     $where['district'] =  $region->cityName;
+                }
+            }
+
+            //今日时间
+            $day_start_time = strtotime(date('Y-m-d'));
+            $day_end_time = strtotime(date('Y-m-d') . '23:59:59');
+            $jinri_money = $JsOrderModel->whereTime('pay_time',[$day_start_time,$day_end_time])->where($where)->where(function ($query){
+                $query->where('status','<>',0);
+                $query->where('status','<>',5);
+            })->sum('price');
+          //  dump($jinri_money);
+            
+            //本月时间
+            $m_start_time = (date('Y-m-01', strtotime(date('Y-m-d'))));
+            $m_end_time = strtotime(date('Y-m-d', strtotime("$m_start_time +1 month -1 day")). '23:59:59');
+            $m_money = $JsOrderModel->whereTime('pay_time',[strtotime($m_start_time),$m_end_time])->where($where)->where(function ($query){
+                $query->where('status','<>',0);
+                $query->where('status','<>',5);
+            })->sum('price');
+            
+            //本季度时间
+            $season = ceil(date('n') /3);
+            $jidu_start =  date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
+            $jidu_end = date('Y-m-t 23:59:59',mktime(0,0,0,$season * 3,1,date('Y')));
+            $jidu_money = $JsOrderModel->whereTime('pay_time',[$jidu_start,$jidu_end])->where($where)->where(function ($query){
+                $query->where('status','<>',0);
+                $query->where('status','<>',5);
+            })->sum('price');
+            
+            //本年度时间
+            $year_start = strtotime(date('Y-01-01'));
+            $year_end = strtotime(date('Y-12-31 23:59:59'));
+            $year_money = $JsOrderModel->whereTime('pay_time',[$year_start,$year_end])->where($where)->where(function ($query){
+                $query->where('status','<>',0);
+                $query->where('status','<>',5);
+            })->sum('price');
+            
+            //总金额
+            $zong = $JsOrderModel->where('pay_time','>',0)->where($where)->where(function ($query){
+                $query->where('status','<>',0);
+                $query->where('status','<>',5);
+            })->sum('price');
+            return json(['code'=>1,'jinri'=>$jinri_money,'m'=>$m_money,'jidu'=>$jidu_money,'year'=>$year_money,'zong'=>$zong,'agency_id'=>$agency_id]);
+        }
+        
+        
+        public function soso()
+        {
+            $type = $this->request->param('type');
+            $keyword = $this->request->param('keyword');
+            $start_time = $this->request->param('start_time');
+            $end_time = $this->request->param('end_time');
+            $jinri_money = 0;
+            $m_money = 0;
+            $jidu_money = 0;
+            $year_money = 0;
+            $zong = 0;
+            $JsOrderModel = new JsOrderModel();
+            $where = [];
+            if(($start_time && $end_time) && !$keyword){
+                
+                $day_start_time = strtotime($start_time);
+                $day_end_time = strtotime($end_time . '23:59:59');
+                $jinri_money = $JsOrderModel->whereTime('pay_time',[$day_start_time,$day_end_time])->where(function ($query){
+                    $query->where('status','<>',0);
+                    $query->where('status','<>',5);
+                })->sum('price');
+    
+                //本月时间
+                $m_start_time = (date('Y-m-01', strtotime(date('Y-m-d'))));
+                $m_end_time = strtotime(date('Y-m-d', strtotime("$m_start_time +1 month -1 day")). '23:59:59');
+                $m_money = $JsOrderModel->whereTime('pay_time',[strtotime($m_start_time),$m_end_time])->where(function ($query){
+                    $query->where('status','<>',0);
+                    $query->where('status','<>',5);
+                })->sum('price');
+    
+                //本季度时间
+                $season = ceil(date('n') /3);
+                $jidu_start =  date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
+                $jidu_end = date('Y-m-t 23:59:59',mktime(0,0,0,$season * 3,1,date('Y')));
+                $jidu_money = $JsOrderModel->whereTime('pay_time',[$jidu_start,$jidu_end])->where(function ($query){
+                    $query->where('status','<>',0);
+                    $query->where('status','<>',5);
+                })->sum('price');
+    
+                //本年度时间
+                $year_start = strtotime(date('Y-01-01'));
+                $year_end = strtotime(date('Y-12-31 23:59:59'));
+                $year_money = $JsOrderModel->whereTime('pay_time',[$year_start,$year_end])->where(function ($query){
+                    $query->where('status','<>',0);
+                    $query->where('status','<>',5);
+                })->sum('price');
+    
+                //总金额
+                $zong = $JsOrderModel->where(function ($query) use ($day_start_time,$day_end_time){
+                    if($day_start_time && $day_end_time){
+                        $query->whereTime('pay_time',[$day_start_time,$day_end_time]);
+                    }
+                })->where($where)->where(function ($query){
+                    $query->where('status','<>',0);
+                    $query->where('status','<>',5);
+                })->sum('price');
+                return json(['code'=>1,'jinri'=>$jinri_money,'m'=>$m_money,'jidu'=>$jidu_money,'year'=>$year_money,'zong'=>$zong]);
+            }else{
+                switch ($type){
+                    case 1://代理商
+                        if($keyword){
+                            $agency_id = Db::name('user')->where('mobile',$keyword)->value('agency_id');
+                            if(! $agency_id){
+                                return ['code'=>100,'msg'=>'该用户还不是代理商!'];
+                            }
+                            $district_id = Db::name('agency')->where('id',$agency_id)->value('district_id');
+                            $user_ids = Db::name('user')->where(['district_id'=>$district_id,'user_type'=>2])->field('id')->select();
+                            $user_new_ids = [];
+                            foreach ($user_ids as $vo){
+                                $user_new_ids[] = $vo['id'];
+                            }
+                            if(!$user_new_ids){
+                                return ['code'=>100,'msg'=>'该代理,地区还没有用户'];
+                            }
+                
+                
+                            $where['user_id'] = $user_new_ids;
+                
+                            //今日时间
+                            $day_start_time = strtotime(date('Y-m-d'));
+                            $day_end_time = strtotime(date('Y-m-d') . '23:59:59');
+                            $jinri_money = $JsOrderModel::where($where)->whereTime('pay_time',[$day_start_time,$day_end_time])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //本月时间
+                            $m_start_time = (date('Y-m-01', strtotime(date('Y-m-d'))));
+                            $m_end_time = strtotime(date('Y-m-d', strtotime("$m_start_time +1 month -1 day")). '23:59:59');
+                            $m_money = $JsOrderModel::where($where)->whereTime('pay_time',[strtotime($m_start_time),$m_end_time])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //本季度时间
+                            $season = ceil(date('n') /3);
+                            $jidu_start =  date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
+                            $jidu_end = date('Y-m-t 23:59:59',mktime(0,0,0,$season * 3,1,date('Y')));
+                            $jidu_money = $JsOrderModel::where($where)->whereTime('pay_time',[$jidu_start,$jidu_end])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //本年度时间
+                            $year_start = strtotime(date('Y-01-01'));
+                            $year_end = strtotime(date('Y-12-31 23:59:59'));
+                            $year_money = $JsOrderModel::where($where)->whereTime('pay_time',[$year_start,$year_end])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //总金额
+                
+                
+                            $zong = $JsOrderModel::where($where)->where(function ($query) use ($start_time,$end_time){
+                                if($start_time && $end_time){
+                                    $query->whereTime('pay_time',[$start_time,$end_time]);
+                                }
+                            })->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                            return json(['code'=>1,'jinri'=>$jinri_money,'m'=>$m_money,'jidu'=>$jidu_money,'year'=>$year_money,'zong'=>$zong]);
+                        }
+                        break;
+                    case 2://技师
+            
+                        if($keyword){
+                            $user_id = Db::name('user')->where('mobile',$keyword)->where('user_type',3)->value('id');
+                            if(! $user_id){
+                                return ['code'=>100,'msg'=>'该用户不是技师!'];
+                            }
+                            $js_id = Db::name('js')->where('user_id',$user_id)->value('id');
+                            $where['jiedan_js_id'] = $js_id;
+                
+                            //今日时间
+                            $day_start_time = strtotime(date('Y-m-d'));
+                            $day_end_time = strtotime(date('Y-m-d') . '23:59:59');
+                            $jinri_money = $JsOrderModel::where($where)->whereTime('pay_time',[$day_start_time,$day_end_time])->where(function ($query){
+                                $query->where('status',3);
+                                $query->whereOR('status',4);
+                                $query->whereOR('status',6);
+                            })->sum('price');
+                
+                            //本月时间
+                            $m_start_time = (date('Y-m-01', strtotime(date('Y-m-d'))));
+                            $m_end_time = strtotime(date('Y-m-d', strtotime("$m_start_time +1 month -1 day")). '23:59:59');
+                            $m_money = $JsOrderModel::where($where)->whereTime('pay_time',[strtotime($m_start_time),$m_end_time])->where(function ($query){
+                                $query->where('status',3);
+                                $query->whereOR('status',4);
+                                $query->whereOR('status',6);
+                            })->sum('price');
+                
+                            //本季度时间
+                            $season = ceil(date('n') /3);
+                            $jidu_start =  date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
+                            $jidu_end = date('Y-m-t 23:59:59',mktime(0,0,0,$season * 3,1,date('Y')));
+                            $jidu_money = $JsOrderModel::where($where)->whereTime('pay_time',[$jidu_start,$jidu_end])->where(function ($query){
+                                $query->where('status',3);
+                                $query->whereOR('status',4);
+                                $query->whereOR('status',6);
+                            })->sum('price');
+                
+                            //本年度时间
+                            $year_start = strtotime(date('Y-01-01'));
+                            $year_end = strtotime(date('Y-12-31 23:59:59'));
+                            $year_money = $JsOrderModel::where($where)->whereTime('pay_time',[$year_start,$year_end])->where(function ($query){
+                                $query->where('status',3);
+                                $query->whereOR('status',4);
+                                $query->whereOR('status',6);
+                            })->sum('price');
+                
+                            //总金额
+                            $zong = $JsOrderModel::where($where)->where(function ($query) use ($start_time,$end_time){
+                                if($start_time && $end_time){
+                                    $query->whereTime('pay_time',[$start_time,$end_time]);
+                                }
+                            })->where(function ($query){
+                                $query->where('status',3);
+                                $query->whereOR('status',4);
+                                $query->whereOR('status',6);
+                            })->sum('price');
+                            return json(['code'=>1,'jinri'=>$jinri_money,'m'=>$m_money,'jidu'=>$jidu_money,'year'=>$year_money,'zong'=>$zong]);
+                        }
+            
+                        break;
+                    case 3://用户
+                        if($keyword){
+                            $user_id = Db::name('user')->where('mobile',$keyword)->where('user_type',2)->value('id');
+                            $where['user_id'] = $user_id;
+                
+                
+                            //今日时间
+                            $day_start_time = strtotime(date('Y-m-d'));
+                            $day_end_time = strtotime(date('Y-m-d') . '23:59:59');
+                            $jinri_money = $JsOrderModel::where($where)->whereTime('pay_time',[$day_start_time,$day_end_time])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //本月时间
+                            $m_start_time = (date('Y-m-01', strtotime(date('Y-m-d'))));
+                            $m_end_time = strtotime(date('Y-m-d', strtotime("$m_start_time +1 month -1 day")). '23:59:59');
+                            $m_money = $JsOrderModel::where($where)->whereTime('pay_time',[strtotime($m_start_time),$m_end_time])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //本季度时间
+                            $season = ceil(date('n') /3);
+                            $jidu_start =  date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
+                            $jidu_end = date('Y-m-t 23:59:59',mktime(0,0,0,$season * 3,1,date('Y')));
+                            $jidu_money = $JsOrderModel::where($where)->whereTime('pay_time',[$jidu_start,$jidu_end])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //本年度时间
+                            $year_start = strtotime(date('Y-01-01'));
+                            $year_end = strtotime(date('Y-12-31 23:59:59'));
+                            $year_money = $JsOrderModel::where($where)->whereTime('pay_time',[$year_start,$year_end])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //总金额
+                            $zong = $JsOrderModel::where($where)->where(function ($query) use ($start_time,$end_time){
+                                if($start_time && $end_time){
+                                    $query->whereTime('pay_time',[$start_time,$end_time]);
+                                }
+                            })->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                            return json(['code'=>1,'jinri'=>$jinri_money,'m'=>$m_money,'jidu'=>$jidu_money,'year'=>$year_money,'zong'=>$zong]);
+                        }
+                        break;
+                    case 4: //地区
+                        if($keyword){
+                            // $user_id = Db::name('user')->where('mobile',$keyword)->where('user_type',2)->value('id');
+                            $where['district'] = $keyword;
+                
+                
+                            //今日时间
+                            $day_start_time = strtotime(date('Y-m-d'));
+                            $day_end_time = strtotime(date('Y-m-d') . '23:59:59');
+                            $jinri_money = $JsOrderModel::where($where)->whereTime('pay_time',[$day_start_time,$day_end_time])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //本月时间
+                            $m_start_time = (date('Y-m-01', strtotime(date('Y-m-d'))));
+                            $m_end_time = strtotime(date('Y-m-d', strtotime("$m_start_time +1 month -1 day")). '23:59:59');
+                            $m_money = $JsOrderModel::where($where)->whereTime('pay_time',[strtotime($m_start_time),$m_end_time])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //本季度时间
+                            $season = ceil(date('n') /3);
+                            $jidu_start =  date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
+                            $jidu_end = date('Y-m-t 23:59:59',mktime(0,0,0,$season * 3,1,date('Y')));
+                            $jidu_money = $JsOrderModel::where($where)->whereTime('pay_time',[$jidu_start,$jidu_end])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //本年度时间
+                            $year_start = strtotime(date('Y-01-01'));
+                            $year_end = strtotime(date('Y-12-31 23:59:59'));
+                            $year_money = $JsOrderModel::where($where)->whereTime('pay_time',[$year_start,$year_end])->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                
+                            //总金额
+                            $zong = $JsOrderModel::where($where)->where(function ($query) use ($start_time,$end_time){
+                                if($start_time && $end_time){
+                                    $query->whereTime('pay_time',[$start_time,$end_time]);
+                                }
+                            })->where(function ($query){
+                                $query->where('status','<>',0);
+                                $query->where('status','<>',5);
+                            })->sum('price');
+                            return json(['code'=>1,'jinri'=>$jinri_money,'m'=>$m_money,'jidu'=>$jidu_money,'year'=>$year_money,'zong'=>$zong]);
+                        }
+            
+                        break;
+                    default:
+                        //今日时间
+                        $day_start_time = strtotime(date('Y-m-d'));
+                        $day_end_time = strtotime(date('Y-m-d') . '23:59:59');
+                        $jinri_money = $JsOrderModel->whereTime('pay_time',[$day_start_time,$day_end_time])->where(function ($query){
+                            $query->where('status','<>',0);
+                            $query->where('status','<>',5);
+                        })->sum('price');
+    
+                        //本月时间
+                        $m_start_time = (date('Y-m-01', strtotime(date('Y-m-d'))));
+                        $m_end_time = strtotime(date('Y-m-d', strtotime("$m_start_time +1 month -1 day")). '23:59:59');
+                        $m_money = $JsOrderModel->whereTime('pay_time',[strtotime($m_start_time),$m_end_time])->where(function ($query){
+                            $query->where('status','<>',0);
+                            $query->where('status','<>',5);
+                        })->sum('price');
+    
+                        //本季度时间
+                        $season = ceil(date('n') /3);
+                        $jidu_start =  date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
+                        $jidu_end = date('Y-m-t 23:59:59',mktime(0,0,0,$season * 3,1,date('Y')));
+                        $jidu_money = $JsOrderModel->whereTime('pay_time',[$jidu_start,$jidu_end])->where(function ($query){
+                            $query->where('status','<>',0);
+                            $query->where('status','<>',5);
+                        })->sum('price');
+    
+                        //本年度时间
+                        $year_start = strtotime(date('Y-01-01'));
+                        $year_end = strtotime(date('Y-12-31 23:59:59'));
+                        $year_money = $JsOrderModel->whereTime('pay_time',[$year_start,$year_end])->where(function ($query){
+                            $query->where('status','<>',0);
+                            $query->where('status','<>',5);
+                        })->sum('price');
+    
+                        //总金额
+                        $zong = $JsOrderModel->where('pay_time','>',0)->where($where)->where(function ($query){
+                            $query->where('status','<>',0);
+                            $query->where('status','<>',5);
+                        })->sum('price');
+                        return json(['code'=>1,'jinri'=>$jinri_money,'m'=>$m_money,'jidu'=>$jidu_money,'year'=>$year_money,'zong'=>$zong]);
+                }
+            }
+            
+           
+
+            
+        }
+    }

+ 73 - 0
app/back/controller/IndustryController.php

@@ -0,0 +1,73 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-08-28
+     * Time: 8:53
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\IndustryModel;
+    use cmf\controller\AdminBaseController;
+
+    class IndustryController extends AdminBaseController
+    {
+        public function index()
+        {
+    
+            $where = [];
+            $list = IndustryModel::where($where)->order('list_order','asc')->select();
+            $this->assign('list',$list);
+            
+            return $this->fetch();
+        }
+        public function add()
+        {
+            return $this->fetch();
+        }
+        public function addPost()
+        {
+            $data = $this->request->param();
+            $industryModel = new IndustryModel();
+            $industryModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = IndustryModel::get($id);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $data = $this->request->param();
+            $industryModel = new IndustryModel();
+            $industryModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            IndustryModel::destroy($id);
+            $this->success('删除成功');
+        }
+        
+        public function show()
+        {
+            $ids = $this->request->param('ids/a');
+            $is_show = $this->request->param('is_show');
+            IndustryModel::where('id','in',$ids)->update(['is_show'=>$is_show]);
+            $this->success('操作成功');
+        }
+        
+        public function listOrder()
+        {
+            $industryModel = new IndustryModel();
+            parent::listOrders($industryModel);
+            $this->success("排序更新成功!");
+        }
+    }

+ 141 - 0
app/back/controller/JsAlreadyController.php

@@ -0,0 +1,141 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-08-28
+     * Time: 8:46
+     */
+    namespace app\back\controller;
+    use app\back\model\JsCategoryModel;
+    use app\back\model\JsModel;
+    use cmf\controller\AdminBaseController;
+    use think\Db;
+
+    class JsAlreadyController extends AdminBaseController
+    {
+        public function index()
+        {
+            
+            $where= [];
+            $jsModel = new JsModel();
+            $page = $this->request->param('page',1);
+            $pw = [];
+            $keyword = $this->request->param('keyword');
+            $category_id = $this->request->param('category_id');
+            if($category_id){
+                $this->assign('category_id',$category_id);
+                $pw['category_id'] = $category_id;
+                $js_ids = Db::name('js_category_relevancy')->where('category_id',$category_id)->field('js_id')->select();
+                $js_new_ids  = [];
+                foreach ($js_ids as $vo)
+                {
+                    $js_new_ids[] = $vo['js_id'];
+                }
+                $where['id'] = $js_new_ids;
+            }
+            if($keyword){
+                $this->assign('keyword',$keyword);
+                $pw['keyword'] = $keyword;
+            }
+         //   die;
+            $where['js_status'] = [1,3];
+            $list = $jsModel->with(['user','category','project'=>function($query){$query->where('status',1);}])->where($where)->where(function ($query) use ($keyword){
+                if($keyword){
+                    $query->where('name|phone','like','%'.$keyword.'%');
+                }
+            })->order('id','desc')->paginate(30,false,array($page,url('index'),'query'=>$pw));
+            // var_dump($jsModel->getLastSql());
+            $JsCategoryModel = new JsCategoryModel();
+            $js_category_list = $JsCategoryModel::select();
+            $this->assign('list',$list);
+            $this->assign('js_category_list',$js_category_list);
+            $this->assign('page',$list->render());
+            
+            return $this->fetch();
+        }
+    
+    
+        public function show()
+        {
+            $ids = $this->request->param('ids/a');
+            $is_show = $this->request->param('is_show');
+            JsModel::where('id','in',$ids)->update(['is_show'=>$is_show]);
+            $this->success('操作成功');
+        }
+    
+        public function listOrder()
+        {
+            $JsModel= new JsModel();
+            parent::listOrders($JsModel);
+            $this->success("排序更新成功!");
+        }
+    
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            JsModel::destroy($id);
+            $this->success('删除成功');
+        }
+        
+        
+        public function xj()
+        {
+           $id = $this->request->param('id');
+            $info = JsModel::get($id);
+            $type = $this->request->param('type');
+            if($type*1==1){
+                $info->save(['js_status'=>3]);
+            }else{
+                $info->save(['js_status'=>1]);    
+            }
+            
+            $this->success('下架成功');
+        }
+
+        
+        public function setCategory()
+        {
+            $js_id = $this->request->param('js_id');
+            $car_ids = $this->request->param('car_ids/a');
+            Db::name('js_category_relevancy')->where('js_id',$js_id)->delete();
+            $ins = [];
+            foreach ($car_ids as $k=>$v){
+                $ins[$k]['category_id'] = $v;
+                $ins[$k]['js_id'] = $js_id;
+            }
+            Db::name('js_category_relevancy')->insertAll($ins);
+            return json(['code'=>1]);
+        }
+        
+
+        
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = JsModel::get($id);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editpost()
+        {
+            $data = $this->request->param();
+            $JsModel = new JsModel();
+			
+			$info = JsModel::get($data['id'])->toArray();
+			if(isset($data['v_jiedan_num']) && $data['v_jiedan_num'] != $info['v_jiedan_num']){
+				$data['jiedan_num'] = $info['jiedan_num']+$data['v_jiedan_num']-$info['v_jiedan_num'];				
+				$admin_id = cmf_get_current_admin_id();
+				$log_info = '变更前:'.$info['v_jiedan_num'].';变更后:'.$data['v_jiedan_num'];
+				admin_log($admin_id,$log_info,$data['id'],'修改技师虚拟单');
+			}
+            $JsModel->allowField(true)->isUpdate(true)->save($data,['id'=>$data['id']]);
+            $this->success('修改成功!');
+        }
+        public function cancel()
+        {
+            $id = $this->request->param('id');
+            $js_id = $this->request->param('js_id');
+            Db::name('js_project_relevancy')->where(['project_id'=>$id,'js_id'=>$js_id])->delete();
+            $this->success('取消成功');
+        }
+    }

+ 95 - 0
app/back/controller/JsCategoryController.php

@@ -0,0 +1,95 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-08-28
+     * Time: 9:59
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\JsModel;
+    use app\user\model\UserModel;
+    use cmf\controller\AdminBaseController;
+    use app\back\model\JsCategoryModel;
+    use app\back\model\IndustryModel;
+    use cmf\lib\Upload;
+
+    class JsCategoryController extends AdminBaseController
+    {
+    
+        public function index()
+        {
+        
+            $where = [];
+            $list = JsCategoryModel::where($where)->order('list_order','asc')->select();
+            $this->assign('list',$list);
+        
+            return $this->fetch();
+        }
+        public function add()
+        {
+            $industryList = IndustryModel::order('list_order','asc')->select();
+            $this->assign('industryList',$industryList);
+            return $this->fetch();
+        }
+        public function addPost()
+        {
+            $data = $this->request->param();
+            $JsCategoryModel = new JsCategoryModel();
+            $JsCategoryModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = JsCategoryModel::get($id,'industry');
+            $industryList = IndustryModel::where('id','<>',$info->industry_id)->order('list_order','asc')->select();
+            $this->assign('industryList',$industryList);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $data = $this->request->param();
+            $JsCategoryModel = new JsCategoryModel();
+            $JsCategoryModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            JsCategoryModel::destroy($id);
+            $this->success('删除成功');
+        }
+    
+        public function show()
+        {
+            $ids = $this->request->param('ids/a');
+            $is_show = $this->request->param('is_show');
+            JsCategoryModel::where('id','in',$ids)->update(['is_show'=>$is_show]);
+            $this->success('操作成功');
+        }
+    
+        public function listOrder()
+        {
+            $JsCategoryModel = new JsCategoryModel();
+            parent::listOrders($JsCategoryModel);
+            $this->success("排序更新成功!");
+        }
+        
+        
+        public function select()
+        {
+            $id = $this->request->param('id');
+            $info = JsModel::get($id);
+            $category_ids = $info->category()->column('category_id');
+            $list = JsCategoryModel::order('list_order','asc')->select();
+            $this->assign('list',$list);
+            $this->assign('categoryIds',$category_ids);
+            $this->assign('id',$id);
+            return $this->fetch();
+        }
+    }

+ 242 - 0
app/back/controller/JsController.php

@@ -0,0 +1,242 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-09
+ * Time: 13:43
+ */
+
+namespace app\back\controller;
+
+
+use app\back\model\CouponModel;
+use app\back\model\JsModel;
+use app\back\model\JsProjectModel;
+use cmf\controller\AdminBaseController;
+use think\Db;
+use think\exception\DbException;
+
+class JsController extends AdminBaseController
+{
+
+    public function index()
+    {
+        $JsModel = new JsModel();
+        $where = [];
+        $pw = [];
+
+        $keyword = $this->request->param('keyword');
+        if ($keyword) {
+            $this->assign('keyword', $keyword);
+            $pw['keyword'] = $keyword;
+        }
+        $project_id = $this->request->param('project_id');
+        $js_ids = Db::name('js_project_relevancy')->field('js_id')->where('status', 0)->group('js_id')->select();
+        $js_new_ids = [];
+        foreach ($js_ids as $vo) {
+            $js_new_ids[] = $vo['js_id'];
+        }
+        $where['id'] = $js_new_ids;
+        if ($project_id) {
+            $this->assign('project_id', $project_id);
+            $pw['project_id'] = $project_id;
+            $js_ids = Db::name('js_project_relevancy')->where('project_id', $project_id)->field('js_id')->group('js_id')->where('status', 0)->select();
+            $js_new_ids = [];
+            foreach ($js_ids as $vo) {
+                $js_new_ids[] = $vo['js_id'];
+            }
+            $where['id'] = $js_new_ids;
+        }
+
+         $page = $this->request->param('page');
+        $list = $JsModel::with(['user', 'project' => function ($query) {
+            $query->where('status', 0);
+        },])->where($where)->where(function ($query) use ($keyword) {
+            if ($keyword) {
+                $query->where('name|phone', 'like', '%' . $keyword . '%');
+            }
+        })->field('id,user_id,name,phone')->order('id', 'desc')->paginate(30, false, array($page, url('index'), 'query' => $pw));
+        if ($this->request->param('debug') == 'zl') {
+            $list = $JsModel::where($where)->where(function ($query) use ($keyword) {
+                if ($keyword) {
+                    $query->where('name|phone', 'like', '%' . $keyword . '%');
+                }
+            })->field('id,user_id,name,phone')->order('id', 'desc')->paginate(30, false, array($page, url('index'), 'query' => $pw));
+            echo $JsModel::getLastSql();
+            var_dump($list);
+        }
+
+        $JsProjectModel = new JsProjectModel();
+        $js_project_list = $JsProjectModel::field('id,name')->select();
+
+
+        $this->assign('list', $list);
+        $this->assign('js_project_list', $js_project_list);
+        $this->assign('page', $list->render());
+        return $this->fetch();
+    }
+
+    public function codeindex()
+    {
+        $pw = [];
+        $keyword = $this->request->param('keyword');
+        $bstatus = $this->request->param('band_status', '-1');
+        $status = $this->request->param('made_type', '-1');
+        $user = $this->request->param('uid_bind');
+        $page = $this->request->param('page', 1);
+        $where = [];
+        if ($keyword) {
+            $this->assign('keyword', $keyword);
+            $pw['keyword'] = $keyword;
+            $where[] = ['code', '=', $keyword];
+        }
+        if ($bstatus !== '-1') {
+            $pw['band_status'] = $bstatus;
+            $where[] = $bstatus == 1 ? ['user_id', '<>', 0] : ['user_id', '=', 0];
+        }
+
+        if ($status !== '-1') {
+            $pw['made_type'] = $status;
+            $where[] = ['status', '=', $status];
+        }
+        if ($user) {
+            $this->assign('uid_bind', $user);
+            $pw['uid_bind'] = $user;
+//                $where['uid_bind'] = $user;
+        }
+        $this->assign('made_type', $status);
+        $this->assign('band_status', $bstatus);
+        $Model = new CouponModel();
+        try {
+            $list = $Model::with([($user ? 'useri' : 'user') => function ($query) use ($user) {
+                if ($user) {
+                    $query->where('mobile', '=', $user);
+                }
+            }, 'optuser'])->where($where)->order('id', 'desc')->paginate(20, false, array($page, url('codeindex'), 'query' => $pw));
+        } catch (DbException $e) {
+            $list = [];
+        }
+        $this->assign('list', $list);
+        $this->assign('page', $list->render());
+        return $this->fetch();
+
+    }
+
+    public function downcode()
+    {
+        $Model = new CouponModel();
+        $no = $this->request->param('no');
+        if ($this->request->isPost()) {
+            //压缩打包下载
+            $fileG = WEB_ROOT . 'upload/';
+            $list = $Model->where('opt_no',$no)->where('status', 0)->select();
+            $file = $fileG . 'backwrm/' . time() . '.zip';
+            $zip = new \ZipArchive();
+
+            if ($zip->open($file, \ZipArchive::OVERWRITE) !== true) {
+                //OVERWRITE 参数会覆写压缩包的文件 文件必须已经存在
+                if ($zip->open($file, \ZipArchive::CREATE) !== true) {
+                    // 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
+                    exit ('无法打开文件,或者文件创建失败');
+                }
+            }
+
+            foreach ($list as $vo) {
+                $zip->addFile($fileG . $vo['code_url'], $vo['code'] . '.png');
+            }
+
+//                var_dump($zip);exit();
+            $zip->close();
+            header("Cache-Control: max-age=0");
+            header("Content-Description: File Transfer");
+            header('Content-disposition: attachment; filename=' . basename($file)); // 文件名
+            header("Content-Type: application/zip"); // zip格式的
+            header("Content-Transfer-Encoding: binary"); // 告诉浏览器,这是二进制文件
+            header('Content-Length: ' . filesize($file)); // 告诉浏览器,文件大小
+            @readfile($file);//输出文件;
+            @unlink($file);
+            exit();
+        }
+
+        $info = $Model->where('status', 0)->count();
+        $this->assign('info', $info);
+        return $this->fetch();
+
+    }
+
+    public function codeedit()
+    {
+        $id = $this->request->param('id');
+        $status = $this->request->param('status', 0);
+        $Model = new CouponModel();
+        if ($this->request->isPost()) {
+            $data = $this->request->post();
+            $data['status'] = $status;
+            $Model->where('id', $id)->update($data);
+            $this->success('操作成功');
+        }
+        $info = $Model->where('id', $id)->find();
+        $this->assign('info', $info);
+        return $this->fetch();
+    }
+
+    public function codeadd()
+    {
+        if ($this->request->isPost()) {
+            $Model = new CouponModel();
+            $num = $this->request->param('num');
+            $no = $this->request->param('no');
+            if (empty($num)) {
+                $this->error('请输入数量');
+            }
+
+            $Model->add_cdk($num, $no, session('ADMIN_ID'));
+            $this->success('添加成功');
+        }
+
+        return $this->fetch();
+
+    }
+
+    public function selectproject()
+    {
+        $id = $this->request->param('id');
+        $info = JsModel::with(['project' => function ($query) {
+            $query->where('status', 0);
+        }])->where('id', $id)->find();
+        $this->assign('info', $info);
+        $this->assign('id', $id);
+        return $this->fetch();
+    }
+
+    public function setProject()
+    {
+        $car_ids = $this->request->param('car_ids/a');
+        foreach ($car_ids as $v) {
+            Db::name('js_project_relevancy')->where('id', $v)->update(['status' => 1, 'chuli_time' => time()]);
+        }
+        return json(['code' => 1]);
+
+    }
+
+    public function setall()
+    {
+        $ids = $this->request->param('ids/a');
+
+        foreach ($ids as $v) {
+            Db::name('js_project_relevancy')->where(['js_id' => $v, 'status' => 0])->update(['status' => 1, 'chuli_time' => time()]);
+        }
+        $this->success('操作成功');
+    }
+
+    public function delete()
+    {
+        $id = $this->request->param('id');
+
+
+        Db::name('js_project_relevancy')->where(['js_id' => $id, 'status' => 0])->delete();
+
+
+        $this->success('删除成功');
+    }
+}

+ 61 - 0
app/back/controller/JsCourseOrderController.php

@@ -0,0 +1,61 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-24
+     * Time: 17:13
+     */
+    
+    namespace app\back\controller;
+    
+    
+    
+    use app\back\model\JsCourseOrderModel;
+    use cmf\controller\AdminBaseController;
+    use app\back\model\JsProjectModel;
+    use app\back\model\UserModel;
+    class JsCourseOrderController extends AdminBaseController
+    {
+        public function index()
+        {
+            $JsCourseOrderModel = new JsCourseOrderModel();
+            $where = [];
+            $pw = [];
+            $page = $this->request->param('page',1);
+            $project_id = $this->request->param('project_id');
+            $keyword = $this->request->param('keyword');
+            if($keyword){
+                $user_ids = UserModel::where('user_nickname|mobile','like','%'.$keyword.'%')->field('id')->select();
+                $user_new_ids = [];
+                foreach ($user_ids as $vo){
+                    $user_new_ids[] = $vo['id'];
+                }
+                $where['user_id'] = $user_new_ids;
+                $this->assign('keyword',$keyword);
+            }
+            if($project_id){
+                $where['project_id'] = $project_id;
+                $pw['project_id'] = $project_id;
+                $this->assign('project_id',$project_id);
+            }
+            $order_sn = $this->request->param('order_sn');
+            if($order_sn){
+                $this->assign('order_sn',$order_sn);
+                $pw['order_sn'] = $order_sn;
+            }
+            $list = $JsCourseOrderModel->getList($where,$pw,$page,$order_sn);
+            $this->assign('list',$list);
+            $this->assign('page',$list->render());
+            $JsProjectModel = new JsProjectModel();
+            $js_project_list = $JsProjectModel::field('id,name')->select();
+            $this->assign('js_project_list',$js_project_list);
+            return $this->fetch();
+        }
+        
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            JsCourseOrderModel::destroy($id);
+            $this->success('删除成功!');
+        }
+    }

+ 122 - 0
app/back/controller/JsDiscountController.php

@@ -0,0 +1,122 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-08-29
+     * Time: 16:55
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\JsDiscountModel;
+    use app\back\model\JsProjectModel;
+    use app\back\model\StoreModel;
+    use app\back\model\UserModel;
+    use cmf\controller\AdminBaseController;
+    use think\Db;
+
+    class JsDiscountController extends AdminBaseController
+    {
+        
+        protected $bool;
+        public function initialize()
+        {
+            $admin_id = cmf_get_current_admin_id();
+            $this->bool = cmf_get_rbac($admin_id);
+            $this->assign('bool',$this->bool);
+            return parent::initialize(); // TODO: Change the autogenerated stub
+        }
+    
+        public function index()
+        {
+            $where = [];
+            $JsDiscountModel = new JsDiscountModel();
+            $list = $JsDiscountModel->getList();
+            $this->assign('list',$list);
+            return $this->fetch();
+        }
+        
+        public function add()
+        {
+            $admin_id = cmf_get_current_admin_id();
+            $storeList = StoreModel::where('user_id',$admin_id)->order('list_order','asc')->select();
+            if(!$this->bool){
+               $storeList = StoreModel::where('user_id',$admin_id)->order('list_order','asc')->select();
+            }
+            $list = JsProjectModel::order('list_order','asc')->field('id,name')->select();
+            $this->assign('list',$list);
+            $this->assign('storeList',$storeList);
+          
+            
+            return $this->fetch();
+        }
+        
+        
+        public function addPost()
+        {
+            $data = $this->request->param();
+            $JsDiscountModel = new JsDiscountModel();
+            $JsDiscountModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        }
+        
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = JsDiscountModel::get($id,['store','project']);
+            $this->assign('info',$info);
+            
+            $admin_id = cmf_get_current_admin_id();
+            $storeList = StoreModel::where('user_id',$admin_id)->order('list_order','asc')->select();
+            if(!$this->bool){
+                $storeList = StoreModel::where('user_id',$admin_id)->order('list_order','asc')->select();
+            }
+            $list = JsProjectModel::order('list_order','asc')->field('id,name')->select();
+            $this->assign('list',$list);
+            $this->assign('storeList',$storeList);
+
+            return $this->fetch();
+        }
+    
+        public function editPost()
+        {
+            $data = $this->request->param();
+            $JsDiscountModel = new JsDiscountModel();
+            $JsDiscountModel->allowField(true)->isUpdate(true)->save($data,['id'=>$data['id']]);
+            $this->success('编辑成功');
+        }
+        
+        public function setDispark()
+        {
+            $id = $this->request->param('id');
+            $dispark = $this->request->param('dispark');
+            $JsDiscountModel = new JsDiscountModel();
+            $JsDiscountModel->allowField(true)->isUpdate(true)->save(['dispark'=>$dispark],['id'=>$id]);
+            $this->success('操作成功');
+        }
+        
+        public function delete()
+        {
+            JsDiscountModel::destroy($this->request->param('id'));
+            $this->success('删除成功');
+        }
+        
+        public function fafang()
+        {
+            $id = $this->request->param('id');
+            $user_ids = UserModel::where('user_type',2)->field('id')->select();
+            foreach ($user_ids as $vo)
+            {
+                $data['user_id'] = $vo['id'];
+                $data['discount_id'] = $id;
+                $data['draw_time'] = time();
+                $data['past_time'] =  time()+ (JsDiscountModel::get($id)['day_num'] *24*3600);
+                $data['project_id'] = JsDiscountModel::get($id)['project_id'];
+                $data['store_id'] = JsDiscountModel::get($id)['store_id'];
+                Db::name('user_discount')->insert($data);
+            }
+
+            $this->success('发放成功');
+        }
+    }

+ 58 - 0
app/back/controller/JsNotController.php

@@ -0,0 +1,58 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-09
+     * Time: 15:40
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use cmf\controller\AdminBaseController;
+    use app\back\model\JsModel;
+    use think\Db;
+
+    class JsNotController extends AdminBaseController
+    {
+        public function index()
+        {
+        
+            $where= [];
+            $jsModel = new JsModel();
+            $page = $this->request->param('page',1);
+            $pw = [];
+            $where['js_status'] = 2;
+            $list = $jsModel->with(['user'])->where($where)->order('list_order','asc')->paginate(30,false,array($page,url('index'),'query'=>$pw));
+            $this->assign('list',$list);
+            $this->assign('page',$list->render());
+            return $this->fetch();
+        }
+        
+        public function delete()
+        {
+            $ids = $this->request->param('ids/a');
+            $up['name'] = '';
+            $up['phone'] = '';
+            $up['apply_num'] = 0;
+            $up['create_time'] = 0;
+            $up['update_time'] = 0;
+            $up['delete_time'] = null;
+            $up['js_status'] = 0;
+            $up['identity'] = null;
+            $up['certificates'] = null;
+            $up['pictures'] = null;
+            $up['massage'] = null;
+            $up['work'] = null;
+            $up['shenhe_time'] = null;
+            $up['jianjie'] = null;
+            $up['jiedan_num'] = 0;
+            $up['avatar'] = '';
+            $up['user_nickname'] = '';
+            foreach ($ids as $v){
+                Db::name('js')->where('id',$v)->update($up);
+                
+            }
+            $this->success('删除成功');
+        }
+    }

+ 486 - 0
app/back/controller/JsOrderController.php

@@ -0,0 +1,486 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2020-09-11
+ * Time: 11:17
+ */
+
+namespace app\back\controller;
+
+use app\back\model\AgencyModel;
+use app\back\model\RegionModel;
+use app\back\model\JsModel;
+use app\back\model\JsOrderModel;
+use app\back\model\UserModel;
+use Cassandra\Map;
+use cmf\controller\AdminBaseController;
+use app\back\model\JsProjectModel;
+
+use JPush\Client;
+use think\Db;
+
+class JsOrderController extends AdminBaseController
+{
+    /**
+     * @return mixed
+     * 实时订单
+     */
+    public function index()
+    {
+        $id = cmf_get_current_admin_id();
+
+        $admin = UserModel::find($id);
+
+        $userObject = UserModel::where('mobile', $admin->user_login)->where('user_type', 2)->select();
+        $userArray = $userObject->toArray();
+
+        if (count($userArray)) {
+            $user = $userObject[0];
+        }
+
+        $agency_id = 0;
+
+        if (isset($user->agency_id) && !empty($user->agency_id)) {
+            $agency_id = (int)$user->agency_id;
+        }
+
+        $where = [];
+
+        //如果有 代理 id 表示 是有区县代理的
+        if ($agency_id) {
+            $agency = AgencyModel::find($agency_id);
+
+            //需要判断 renk_id 是 1 还是 2 1级代理是地级市 2级代理是区县级
+            if ($agency->renk_id === 1) {
+                $region = RegionModel::where('id', $agency->city_id)->select()[0];
+
+                $where['city'] = $region->cityName;
+            } else {
+                $region = RegionModel::where('id', $agency->district_id)->select()[0];
+                $where['district'] = $region->cityName;
+            }
+        }
+
+        //$where = [];
+        $pw = [];
+        $where['type'] = 1;
+        $page = $this->request->param('page', 1);
+        $JsOrderModel = new JsOrderModel();
+        $district = $this->request->param('district');
+
+        if ($district) {
+            $this->assign('district', $district);
+        }
+
+        $project_id = $this->request->param('project_id');
+        $keyword = $this->request->param('keyword');
+        if ($keyword) {
+            $user_ids = UserModel::where('user_nickname|mobile', 'like', '%' . $keyword . '%')->field('id')->select();
+            $user_new_ids = [];
+            foreach ($user_ids as $vo) {
+                $user_new_ids[] = $vo['id'];
+            }
+            $where['user_id'] = $user_new_ids;
+            $this->assign('keyword', $keyword);
+        }
+        if ($project_id) {
+            $where['project_id'] = $project_id;
+            $pw['project_id'] = $project_id;
+            $this->assign('project_id', $project_id);
+        }
+
+        $order_sn = $this->request->param('order_sn');
+        if ($order_sn) {
+            $this->assign('order_sn', $order_sn);
+            $pw['order_sn'] = $order_sn;
+        }
+        $status = $this->request->param('status', '');
+        if ($status !== '') {
+            $where['status'] = $status;
+            $pw['status'] = $status;
+            $this->assign('status', $status);
+        }
+
+        $list = $JsOrderModel->getList($where, $page, 'index', $pw, $order_sn, $district);
+
+        if ($agency_id) {
+            foreach ($list as $k => $v) {
+                $mobile = $v->mobile;
+                if ($mobile) {
+                    $startStr = substr($mobile, 0, 3);
+                    $endStr = substr($mobile, -3);
+                    $list[$k]->mobile = $startStr . '*****' . $endStr;
+                }
+                $xiadan_user = $v->xiadan_user;
+                if ($xiadan_user['mobile']) {
+                    $xiadan_user_mobile = $xiadan_user['mobile'];
+                    $startStr = substr($xiadan_user_mobile, 0, 3);
+                    $endStr = substr($xiadan_user_mobile, -3);
+                    $list[$k]->xiadan_user['mobile'] = $startStr . '*****' . $endStr;
+                }
+                $js = $v->js;
+                if ($js['phone']) {
+                    $js_phone = $js['phone'];
+                    $startStr = substr($js_phone, 0, 3);
+                    $endStr = substr($js_phone, -3);
+                    $list[$k]->js['phone'] = $startStr . '*****' . $endStr;
+                }
+            }
+        }
+//            dump($list->toArray());
+
+        $JsProjectModel = new JsProjectModel();
+        $js_project_list = $JsProjectModel::field('id,name')->select();
+//            dump($js_project_list->toArray());
+        $this->assign('js_project_list', $js_project_list);
+        $this->assign('list', $list);
+        $this->assign('page', $list->render());
+        return $this->fetch();
+    }
+
+    /**
+     * @return mixed
+     * 预约订单
+     */
+    public function make()
+    {
+
+        $id = cmf_get_current_admin_id();
+
+        $admin = UserModel::find($id);
+
+        $userObject = UserModel::where('mobile', $admin->user_login)->where('user_type', 2)->select();
+        $userArray = $userObject->toArray();
+
+        if (count($userArray)) {
+            $user = $userObject[0];
+        }
+
+        $agency_id = 0;
+
+        if (isset($user->agency_id) && !empty($user->agency_id)) {
+            $agency_id = (int)$user->agency_id;
+        }
+
+        $where = [];
+
+        //如果有 代理 id 表示 是有区县代理的
+        if ($agency_id) {
+            $agency = AgencyModel::find($agency_id);
+
+            //需要判断 renk_id 是 1 还是 2 1级代理是地级市 2级代理是区县级
+            if ($agency->renk_id === 1) {
+                $region = RegionModel::where('id', $agency->city_id)->select()[0];
+
+                $where['city'] = $region->cityName;
+            } else {
+                $region = RegionModel::where('id', $agency->district_id)->select()[0];
+                $where['district'] = $region->cityName;
+            }
+        }
+
+        //$where = [];
+        $pw = [];
+        $where['type'] = 2;
+        $page = $this->request->param('page', 1);
+        $JsOrderModel = new JsOrderModel();
+
+        $project_id = $this->request->param('project_id');
+        $keyword = $this->request->param('keyword');
+        if ($keyword) {
+            $user_ids = UserModel::where('user_nickname|mobile', 'like', '%' . $keyword . '%')->field('id')->select();
+            $user_new_ids = [];
+            foreach ($user_ids as $vo) {
+                $user_new_ids[] = $vo['id'];
+            }
+            $where['user_id'] = $user_new_ids;
+            $this->assign('keyword', $keyword);
+        }
+        if ($project_id) {
+            $where['project_id'] = $project_id;
+            $pw['project_id'] = $project_id;
+            $this->assign('project_id', $project_id);
+        }
+
+        $order_sn = $this->request->param('order_sn');
+        if ($order_sn) {
+            $this->assign('order_sn', $order_sn);
+            $pw['order_sn'] = $order_sn;
+        }
+        $status = $this->request->param('status', '');
+        if ($status !== '') {
+            $where['status'] = $status;
+            $pw['status'] = $status;
+            $this->assign('status', $status);
+        }
+        $district = $this->request->param('district');
+        if ($district) {
+            $this->assign('district', $district);
+        }
+        $list = $JsOrderModel->getList($where, $page, 'index', $pw, $order_sn, $district);
+
+        if ($agency_id) {
+            foreach ($list as $k => $v) {
+                $mobile = $v->mobile;
+                if ($mobile) {
+                    $startStr = substr($mobile, 0, 3);
+                    $endStr = substr($mobile, -3);
+                    $list[$k]->mobile = $startStr . '*****' . $endStr;
+                }
+                $xiadan_user = $v->xiadan_user;
+                if ($xiadan_user['mobile']) {
+                    $xiadan_user_mobile = $xiadan_user['mobile'];
+                    $startStr = substr($xiadan_user_mobile, 0, 3);
+                    $endStr = substr($xiadan_user_mobile, -3);
+                    $list[$k]->xiadan_user['mobile'] = $startStr . '*****' . $endStr;
+                }
+                $js = $v->js;
+                if ($js['phone']) {
+                    $js_phone = $js['phone'];
+                    $startStr = substr($js_phone, 0, 3);
+                    $endStr = substr($js_phone, -3);
+                    $list[$k]->js['phone'] = $startStr . '*****' . $endStr;
+                }
+            }
+        }
+
+
+        $JsProjectModel = new JsProjectModel();
+        $js_project_list = $JsProjectModel::field('id,name')->select();
+
+        $this->assign('js_project_list', $js_project_list);
+        $this->assign('list', $list);
+        $this->assign('page', $list->render());
+        return $this->fetch();
+    }
+
+    public function delete()
+    {
+        $id = $this->request->param('id');
+        JsOrderModel::destroy($id);
+        $this->success('删除成功');
+    }
+
+    /**
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     * 后台完成订单服务
+     */
+    public function finish()
+    {
+        $ids = $this->request->param('ids/a');
+
+        $JsOrderModel = new JsOrderModel();
+        JsOrderModel::where('id', 'in', $ids)->update(['finish_time' => time(), 'status' => 3]);
+        $list = $JsOrderModel::where('id', 'in', $ids)->field('id,user_id,jiedan_js_id,order_price')->select();
+        $info = cmf_get_option('jspus');
+        foreach ($list as $vo) {
+            $url = '/pages/ddxq/ddxq?id=' . $vo['id'];
+
+            $jsuserid = $js_user_id = Db::name('js')->where('id', $vo['jiedan_js_id'])->value('user_id');
+            JsModel::where('id', $vo['jiedan_js_id'])->setInc('jiedan_num', 1);
+            if ($vo['order_price'] > 0) {
+                UserModel::where('id', $jsuserid)->setInc('balance', $vo['order_price']);
+                $log['user_id'] = $jsuserid;
+                $log['money'] = $vo['order_price'];
+                $log['type'] = 8;
+                $log['remark'] = '完成服务获得金额';
+                $log['add_time'] = time();
+                $log['obj_id'] = $vo['id'];
+                if ($log['money'] != 0) {
+                    Db::name('user_money_log')->insert($log);
+                }
+            }
+
+            $js_user_id .= 'js';
+
+            $js_client = new Client($info['js_app_key'], $info['js_master_secret']);
+            $client = new Client($info['app_key'], $info['master_secret']);
+
+            $extras = [
+                'id' => $vo['id'],
+                'flag' => '用户',
+                'url' => $url
+            ];
+            $array = [
+                'extras' => $extras,
+            ];
+            $text = '服务已被后台指定结束';
+            $platform = array('ios', 'android');
+            $user_id = $vo['user_id'] . 'js';
+
+            $client->push()
+                ->setPlatform($platform)
+                ->setNotificationAlert($text)
+                ->iosNotification($text, $array)
+                ->androidNotification($text, $array)
+                ->addAlias("{$user_id}")
+                ->send();
+            $extras = [
+                'id' => $vo['id'],
+                'flag' => '技师端',
+                'url' => $url
+            ];
+            $array = [
+                'extras' => $extras,
+            ];
+            $text = '服务已被后台指定结束';
+            $js_client->push()
+                ->setPlatform($platform)
+                ->setNotificationAlert($text)
+                ->iosNotification($text, $array)
+                ->androidNotification($text, $array)
+                ->addAlias("{$js_user_id}")
+                ->send();
+            $this->fenxiao($vo['id'], 1);
+            $this->fenxiao($vo['id'], 2);
+        }
+
+
+        $this->success('操作成功');
+    }
+
+    public function getJsList($lat = 1, $lng = 1)
+    {
+        $url = 'http://116.255.226.95:82/api/js/getList?lng=' . $lng . '&lat=' . $lat;
+        $this->assign('list', []);
+        return $this->fetch('jslist');
+    }
+
+    public function qdlist()
+    {
+        $id = $this->request->param('id');
+        $list = Db::name('js_order_grab')->where('order_id=' . $id)->order('id asc')->select()->toArray();
+        if (!empty($list) && is_array($list)) {
+            foreach ($list as $key => $val) {
+                $js_info = JsModel::get($val['js_id'])->toArray();
+                $list[$key]['js_name'] = $js_info['name'];
+                $list[$key]['js_mobile'] = $js_info['phone'];
+            }
+        }
+        $this->assign('list', $list);
+        return $this->fetch();
+    }
+
+    public function fenxiao($order_id, $type)
+    {
+        $orderInfo = JsOrderModel::get($order_id);
+
+        $userModel = new UserModel();
+        if ($type == 1) {
+
+            $log['remark'] = '好友下单';
+            $price = $orderInfo['price'];
+            $user_info = UserModel::get($orderInfo['user_id']);
+            $agency_info = AgencyModel::where(['district_id' => $user_info['district_id'], 'renk_id' => 2])->find();
+
+            $user_agency_id = Db::name('user')->where(function ($query) use ($agency_info){
+                $query->where('agency_id',$agency_info['id']);
+                $query->whereOr('agency_id','like',$agency_info['id'].',%');
+                $query->whereOr('agency_id','like','%,'.$agency_info['id']);
+                $query->whereOr('agency_id','like','%,'.$agency_info['id'].',%');
+            })->value('id');
+
+            $money = round($price * $agency_info['ratio'] / 100, 2);
+            $user_id = $orderInfo['user_id'];
+            if ($money > 0 && $user_agency_id) {
+                UserModel::where('id', $user_agency_id)->setInc('balance', $money);
+                $log['user_id'] = $user_agency_id;
+                $log['money'] = $money;
+                $log['type'] = 5;
+                $log['add_time'] = time();
+                $log['obj_id'] = $order_id;
+                $log['is_type'] = $type;
+                $log['xia_user_id'] = $user_info['id'];
+                $log['remark'] = '用户下单,区代提成';
+                Db::name('user_money_log')->insert($log);
+            }
+            $user_parent_id = $userModel::get($user_id)['parent_id'];
+            $user_parent_id1 = $userModel::get($user_id)['parent_id1'];
+
+            if ($user_parent_id) {
+                $user_parent_info = UserModel::get($user_parent_id);
+                $distributorInfo = Db::name('distributor')->where('id', $user_parent_info['distributor_id'])->find();
+                $money = $price * $distributorInfo['yi_ratio'] / 100;
+                if ($money > 0) {
+                    UserModel::where('id', $user_parent_id)->setInc('balance', $money);
+                    $log['user_id'] = $user_parent_id;
+                    $log['money'] = $money;
+                    $log['type'] = 3;
+                    $log['add_time'] = time();
+                    $log['obj_id'] = $order_id;
+                    $log['is_type'] = $type;
+                    $log['xia_user_id'] = $user_id;
+                    $log['remark'] = '一级好友下单提成';
+                    Db::name('user_money_log')->insert($log);
+                }
+
+            }
+            if ($user_parent_id1) {
+                $user_parent_info1 = UserModel::get($user_parent_id1);
+                $distributorInfo1 = Db::name('distributor')->where('id', $user_parent_info1['distributor_id'])->find();
+                $money = $price * $distributorInfo1['er_ratio'] / 100;
+                if ($money > 0) {
+                    UserModel::where('id', $user_parent_id1)->setInc('balance', $money);
+                    $log['user_id'] = $user_parent_id1;
+                    $log['money'] = $money;
+                    $log['type'] = 4;
+                    $log['add_time'] = time();
+                    $log['obj_id'] = $order_id;
+                    $log['xia_user_id'] = $user_id;
+                    $log['is_type'] = $type;
+                    $log['remark'] = '二级好友下单提成';
+                    Db::name('user_money_log')->insert($log);
+                }
+            }
+
+        } else {
+            if (!$orderInfo['jiedan_js_id']) {
+                return false;
+            }
+            $user_id = Db::name('js')->where('id', $orderInfo['jiedan_js_id'])->value('user_id');
+            $log['remark'] = '好友接单';
+            $price = $orderInfo['order_price'];
+            $user_parent_id = $userModel::get($user_id)['parent_id'];
+            $user_parent_id1 = $userModel::get($user_id)['parent_id1'];
+//                if($user_parent_id){
+//                    $user_parent_info = UserModel::get($user_parent_id);
+//                    $distributorInfo = Db::name('distributor')->where('id',$user_parent_info['distributor_id'])->find();
+//                    $money = $price * $distributorInfo['yi_ratio']/100;
+//                    if($money > 0){
+//                        $log['user_id'] = $user_parent_id;
+//                        $log['money'] = $money;
+//                        $log['type'] = 3;
+//                        $log['add_time'] = time();
+//                        $log['obj_id'] = $order_id;
+//                        $log['is_type'] = $type;
+//                        $log['xia_user_id'] = $user_id;
+//                        Db::name('user_money_log')->insert($log);
+//                    }
+//                }
+//                if($user_parent_id1){
+//                    $user_parent_info1 = UserModel::get($user_parent_id1);
+//                    $distributorInfo1 = Db::name('distributor')->where('id',$user_parent_info1['distributor_id'])->find();
+//                    $money = $price * $distributorInfo1['er_ratio']/100;
+//                    if($money > 0){
+//                        $log['user_id'] = $user_parent_id1;
+//                        $log['money'] = $money;
+//                        $log['type'] = 4;
+//                        $log['add_time'] = time();
+//                        $log['obj_id'] = $order_id;
+//                        $log['xia_user_id'] = $user_id;
+//                        $log['is_type'] = $type;
+//                        Db::name('user_money_log')->insert($log);
+//                    }
+//                }
+        }
+
+
+    }
+
+
+}

+ 85 - 0
app/back/controller/JsProjectCategoryController.php

@@ -0,0 +1,85 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-08-31
+     * Time: 10:22
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use cmf\controller\AdminBaseController;
+    use app\back\model\JsProjectCategoryModel;
+    class JsProjectCategoryController extends AdminBaseController
+    {
+    
+        public function index()
+        {
+        
+            $where = [];
+            $list = JsProjectCategoryModel::where($where)->order('list_order','asc')->select();
+            $this->assign('list',$list);
+        
+            return $this->fetch();
+        }
+        public function add()
+        {
+            return $this->fetch();
+        }
+        public function addPost()
+        {
+            $data = $this->request->param();
+            $JsProjectCategoryModel = new JsProjectCategoryModel();
+            $JsProjectCategoryModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = JsProjectCategoryModel::get($id);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            
+            $data = $this->request->param();
+            $JsProjectCategoryModel= new JsProjectCategoryModel();
+            $JsProjectCategoryModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            JsProjectCategoryModel::destroy($id);
+            $this->success('删除成功');
+        }
+    
+        public function show()
+        {
+            $ids = $this->request->param('ids/a');
+            $is_show = $this->request->param('is_show');
+            JsProjectCategoryModel::where('id','in',$ids)->update(['is_show'=>$is_show]);
+            $this->success('操作成功');
+        }
+    
+        public function listOrder()
+        {
+            $JJsProjectCategoryModel = new JsProjectCategoryModel();
+            parent::listOrders($JJsProjectCategoryModel);
+            $this->success("排序更新成功!");
+        }
+        
+        public function select()
+        {
+            $ids                 = $this->request->param('ids');
+            $selectedIds         = explode(',', $ids);
+        
+            $list = JsProjectCategoryModel::order('list_order','asc')->select();
+            $this->assign('list',$list);
+            $this->assign('selectedIds',$selectedIds);
+            return $this->fetch();
+        }
+    }

+ 198 - 0
app/back/controller/JsProjectController.php

@@ -0,0 +1,198 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-08-28
+     * Time: 10:44
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use app\back\model\JsProjectCategoryModel;
+    use app\back\model\JsProjectTagModel;
+    use app\back\model\RegionModel;
+    use cmf\controller\AdminBaseController;
+    use app\back\model\JsProjectModel;
+    use think\Db;
+    use app\back\model\JsProjectServiceModel;
+    class JsProjectController extends AdminBaseController
+    {
+        public function index()
+        {
+        
+            $where = [];
+            $page = $this->request->param('page',1);
+            $pw = [];
+            $JsProjectModel = new JsProjectModel();
+            $name = $this->request->param('name');
+            $this->assign('name',$name);
+            $JsProJectCategoryModel = new JsProjectCategoryModel();
+            $category_list = $JsProJectCategoryModel::select();
+            $category_id = $this->request->param('category_id');
+            if($category_id){
+                $project_ids = Db::name('js_project_category_relevancy')->where('category_id',$category_id)->field('project_id')->select();
+                $project_new_ids = [];
+                foreach ($project_ids as $vo){
+                    $project_new_ids[] = $vo['project_id'];
+                }
+                $pw['category_id'] = $category_id;
+                $where['id'] = $project_new_ids;
+                $this->assign('category_id',$category_id);
+            }
+            $is_show = $this->request->param('is_show');
+            if($is_show != ''){
+                $where['is_show'] = $is_show;
+                $pw['is_show'] = $is_show;
+                $this->assign('is_show',$is_show);
+            }
+            
+            $list = $JsProjectModel->getList($where,$page,$pw,$name);
+            $this->assign('list',$list);
+            $this->assign('category_list',$category_list);
+            return $this->fetch();
+        }
+        public function add()
+        {
+            $region_list = Db::name('region')->where('depth',1)->select();
+            $tagList = JsProjectTagModel::where('is_show',1)->order('list_order','asc')->select();
+            $this->assign('tagList',$tagList);
+            $service = JsProjectServiceModel::where('is_show',1)->select();
+            $this->assign('service',$service);
+            $this->assign('region_list',$region_list);
+            return $this->fetch();
+        }
+        public function addPost()
+        {
+            $data = $this->request->param();
+            
+            if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
+                $data['banner'] = [];
+                foreach ($data['photo_urls'] as $key => $url) {
+                    $photoUrl = cmf_asset_relative_url($url);
+                    array_push( $data['banner'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
+                }
+            }
+            
+            unset($data['photo_urls']);
+            unset($data['photo_names']);
+            if(empty($data['service_zhi'])){
+                $this->error('请选择服务区!');
+            }
+            $service_zhi = $data['service_zhi'];
+            unset($data['service_zhi']);
+            $JsProjectModel = new JsProjectModel();
+            $tag = [];
+            if(!empty($data['tag'])){
+                $tag = $data['tag'];
+                unset($data['tag']);
+            }
+            
+            $cagories = $data['cagories'];
+            unset($data['category']);
+            $JsProjectModel->addPost($data,$tag,$cagories,$service_zhi);
+            
+            $this->success('添加成功');
+        
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = JsProjectModel::get($id);
+            $info['service'] = $info->service;
+            
+            
+            $tagList = JsProjectTagModel::where('is_show',1)->order('list_order','asc')->select();
+            $this->assign('tagList',$tagList);
+            $tegIds = Db::name('js_project_tag_relevancy')->where('project_id',$id)->column('project_tag_id');
+    
+            $region_list = Db::name('region')->where('depth',1)->select();
+            $this->assign('region_list',$region_list);
+            $fuji = [];
+            $fuji_ids = [];
+            $servicesIds = [];
+            $parentId = [];
+            if(count($info['service']) > 0) {
+                foreach ($info['service'] as $value){
+                  if(!in_array($value['parentId'],$parentId)){
+                      $parentId[] = $value['parentId'];
+                  }
+                    $servicesIds[] = $value['id'];
+                }
+                $fuji = RegionModel::where('id','in',$parentId)->field('id,mergerName')->select();
+                foreach ($fuji as $key=>$value){
+                    $fuji[$key]['district_list'] = RegionModel::where('parentId',$value['id'])->field('id,cityName')->select();
+                    $fuji_ids[] = $value['id'];
+                }
+            }
+            $this->assign('fuji',$fuji);
+            $categories  = $info->category()->alias('a')->column('a.category_name', 'a.id');
+   
+         
+           
+            $categoryIds = implode(',', array_keys($categories));
+            $this->assign('categories',$categories);
+            $this->assign('categoryIds',$categoryIds);
+            $this->assign('servicesIds',$servicesIds);
+            $this->assign('info',$info);
+            $this->assign('fuji_ids',$fuji_ids);
+            $this->assign('tegIds',$tegIds);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $data = $this->request->param();
+            if(empty($data['service_zhi'])){
+                $this->error('请选择服务区!');
+            }
+
+            $service_zhi = json_decode(html_entity_decode($data['service_zhi']),true);
+
+            unset($data['service_zhi']);
+            $data['banner'] = [];
+            if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
+        
+                foreach ($data['photo_urls'] as $key => $url) {
+                    $photoUrl = cmf_asset_relative_url($url);
+                    array_push( $data['banner'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
+                }
+            }
+    
+            unset($data['photo_urls']);
+            unset($data['photo_names']);
+            
+            $JsProjectModel = new JsProjectModel();
+            $tag = [];
+            if(!empty($data['tag'])){
+                $tag = $data['tag'];
+                unset($data['tag']);
+            }
+            $cagories = $data['cagories'];
+            unset($data['category']);
+            
+            $JsProjectModel->editPost($data,$tag,$cagories,$service_zhi);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            JsProjectModel::destroy($id);
+            Db::name('js_project_tag_relevancy')->where('project_id',$id)->delete();
+            $this->success('删除成功');
+        }
+    
+        public function show()
+        {
+            $ids = $this->request->param('ids/a');
+            $is_show = $this->request->param('is_show');
+            JsProjectModel::where('id','in',$ids)->update(['is_show'=>$is_show]);
+            $this->success('操作成功');
+        }
+    
+        public function listOrder()
+        {
+            $JsProjectModel = new JsProjectModel();
+            parent::listOrders($JsProjectModel);
+            $this->success("排序更新成功!");
+        }
+    }

+ 85 - 0
app/back/controller/JsProjectServiceController.php

@@ -0,0 +1,85 @@
+<?php
+    /**
+     * Created by PhpStorm.
+     * User: Administrator
+     * Date: 2020-09-02
+     * Time: 11:06
+     */
+    
+    namespace app\back\controller;
+    
+    
+    use cmf\controller\AdminBaseController;
+    use app\back\model\JsProjectServiceModel;
+    class JsProjectServiceController extends AdminBaseController
+    {
+        public function index()
+        {
+        
+            $where = [];
+            $list = JsProjectServiceModel::where($where)->order('list_order','asc')->select();
+            $this->assign('list',$list);
+        
+            return $this->fetch();
+        }
+        public function add()
+        {
+
+            return $this->fetch();
+        }
+        public function addPost()
+        {
+            $data = $this->request->param();
+            $JsProjectServiceModel = new JsProjectServiceModel();
+            $JsProjectServiceModel->allowField(true)->isUpdate(false)->save($data);
+            $this->success('添加成功');
+        
+        }
+        public function edit()
+        {
+            $id = $this->request->param('id');
+            $info = JsProjectServiceModel::get($id);
+            $this->assign('info',$info);
+            return $this->fetch();
+        }
+        public function editPost()
+        {
+            $data = $this->request->param();
+            $JsProjectServiceModel= new JsProjectServiceModel();
+            $JsProjectServiceModel->allowField(true)->isUpdate(true)->save($data);
+            $this->success('编辑成功');
+        }
+        public function delete()
+        {
+            $id = $this->request->param('id');
+            JsProjectServiceModel::destroy($id);
+            $this->success('删除成功');
+        }
+    
+        public function show()
+        {
+            $ids = $this->request->param('ids/a');
+            $is_show = $this->request->param('is_show');
+            JsProjectServiceModel::where('id','in',$ids)->update(['is_show'=>$is_show]);
+            $this->success('操作成功');
+        }
+    
+        public function listOrder()
+        {
+            $JJsProjectServiceModel = new JsProjectServiceModel();
+            parent::listOrders($JJsProjectServiceModel);
+            $this->success("排序更新成功!");
+        }
+    
+        public function select()
+        {
+            $ids                 = $this->request->param('ids');
+            $selectedIds         = explode(',', $ids);
+        
+            $list = JsProjectServiceModel::order('list_order','asc')->select();
+            $this->assign('list',$list);
+            $this->assign('selectedIds',$selectedIds);
+            return $this->fetch();
+        }
+        
+    }

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