first
This commit is contained in:
commit
ed1278a5e3
|
@ -0,0 +1 @@
|
|||
APP_KEY = '#APP_KEY#'
APP_DEBUG = false
INSTALLED = true
QUEUE_NAME = default
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = '#DB_HOST#'
HOSTPORT = '#DB_PORT#'
USERNAME = '#DB_USER#'
PASSWORD = '#DB_PWD#'
DATABASE = '#DB_NAME#'
PREFIX = '#DB_PREFIX#'
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
[REDIS]
REDIS_HOSTNAME = '#RB_HOST#'
PORT = '#RB_PORT#'
REDIS_PASSWORD = '#RB_PWD#'
SELECT = '#RB_SELECT#'
|
|
@ -0,0 +1,11 @@
|
|||
/.idea
|
||||
/.vscode
|
||||
*.log
|
||||
.env
|
||||
.constant
|
||||
install/install.lock
|
||||
public/static/download/*
|
||||
public/phpExcel/*
|
||||
app/controller/api/Test.php
|
||||
public/protocol.html
|
||||
runtime/*
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace PHPSTORM_META {
|
||||
|
||||
use think\Container;
|
||||
use function \app;
|
||||
|
||||
override(
|
||||
\app(),
|
||||
map([
|
||||
'json' => \crmeb\services\ApiResponseService::class
|
||||
])
|
||||
);
|
||||
|
||||
override(
|
||||
\think\Container::make(),
|
||||
map([
|
||||
''=>'@'
|
||||
])
|
||||
);
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
sudo: false
|
||||
|
||||
language: php
|
||||
|
||||
branches:
|
||||
only:
|
||||
- stable
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
before_install:
|
||||
- composer self-update
|
||||
|
||||
install:
|
||||
- composer install --no-dev --no-interaction --ignore-platform-reqs
|
||||
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
|
||||
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
|
||||
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
|
||||
|
||||
script:
|
||||
- php think unit
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
|
||||
file:
|
||||
- ThinkPHP_Core.zip
|
||||
- ThinkPHP_Full.zip
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
|
@ -0,0 +1,53 @@
|
|||
# 使用基础镜像
|
||||
FROM leekay0218/crmeb-mer
|
||||
|
||||
## 复制代码
|
||||
## 在本地调试注释掉,使用映射把文件映射进去
|
||||
#ADD ./ /var/www
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /var/www
|
||||
|
||||
# 设置时区为上海
|
||||
ENV TZ=Asia/Shanghai
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
|
||||
echo $TZ > /etc/timezone && \
|
||||
echo '[PHP]\ndate.timezone = "'$TZ'"\n' > /usr/local/etc/php/conf.d/tzone.ini
|
||||
|
||||
# 创建 mer_s.conf 配置文件
|
||||
RUN echo "[program:mer_s]" > /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "command=php think swoole restart" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "directory=/var/www/" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "autorestart=true" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "startsecs=3" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "startretries=3" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "stdout_logfile=/var/log/supervisor/mer_s.out.log" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "stderr_logfile=/var/log/supervisor/mer_s.err.log" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "stdout_logfile_maxbytes=2MB" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "stderr_logfile_maxbytes=2MB" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "user=root" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "priority=999" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "numprocs=1" >> /etc/supervisor/conf.d/mer_s.conf && \
|
||||
echo "process_name=%(program_name)s_%(process_num)02d" >> /etc/supervisor/conf.d/mer_s.conf
|
||||
|
||||
# 创建 mer_q.conf 配置文件
|
||||
RUN echo "[program:mer_q]" > /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "command=php think queue:work --tries 2" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "directory=/var/www/" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "autorestart=true" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "startsecs=3" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "startretries=3" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "stdout_logfile=/var/log/supervisor/mer_q.out.log" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "stderr_logfile=/var/log/supervisor/mer_q.err.log" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "stdout_logfile_maxbytes=2MB" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "stderr_logfile_maxbytes=2MB" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "user=root" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "priority=999" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "numprocs=1" >> /etc/supervisor/conf.d/mer_q.conf && \
|
||||
echo "process_name=%(program_name)s_%(process_num)02d" >> /etc/supervisor/conf.d/mer_q.conf
|
||||
|
||||
# 设置入口命令
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
# 创建日志文件
|
||||
RUN touch /var/www/service.err.log /var/www/service.out.log
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
|
||||
版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
|
||||
All rights reserved。
|
||||
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
|
||||
|
||||
Apache Licence是著名的非盈利开源组织Apache采用的协议。
|
||||
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
|
||||
允许代码修改,再作为开源或商业软件发布。需要满足
|
||||
的条件:
|
||||
1. 需要给代码的用户一份Apache Licence ;
|
||||
2. 如果你修改了代码,需要在被修改的文件中说明;
|
||||
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
|
||||
带有原来代码中的协议,商标,专利声明和其他原来作者规
|
||||
定需要包含的说明;
|
||||
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
|
||||
件中需要带有本协议内容。你可以在Notice中增加自己的
|
||||
许可,但不可以表现为对Apache Licence构成更改。
|
||||
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,338 @@
|
|||
CRMEB MER TP6+Swoole4
|
||||
===============
|
||||
|
||||
> 运行环境要求PHP7.1、 7.2、7.3、7.4,其他版本暂不推荐。不支持windows环境运行
|
||||
|
||||
## 开发规范
|
||||
#### 命名规范
|
||||
ThinkPHP6.0遵循PSR-2命名规范和PSR-4自动加载规范,并且注意如下规范:
|
||||
|
||||
1. 目录和文件
|
||||
2. 目录使用小写+下划线;
|
||||
3. 类库、函数文件统一以.php为后缀;
|
||||
4. 类的文件名均以命名空间定义,并且命名空间的路径和类库文件所在路径一致;
|
||||
5. 类(包含接口和Trait)文件采用驼峰法命名(首字母大写),其它文件采用小写+下划线命名;
|
||||
6. 类名(包括接口和Trait)和文件名保持一致,统一采用驼峰法命名(首字母大写);
|
||||
|
||||
#### 函数和类、属性命名
|
||||
|
||||
1. 类的命名采用驼峰法(首字母大写),例如 User、UserType;
|
||||
2. common函数的命名使用小写字母和下划线(小写字母开头)的方式,例如 get_client_ip;
|
||||
3. 控制器里面的方法使用小写字母和下划线(小写字母开头)的方式,例如 get_client_ip
|
||||
4. 方法的命名使用驼峰法(首字母小写),例如 getUserName;
|
||||
5. 属性的命名使用驼峰法(首字母小写),例如 tableName、instance;
|
||||
6. 特例:以双下划线__打头的函数或方法作为魔术方法,例如 __call 和 __autoload;
|
||||
|
||||
#### 常量和配置
|
||||
1. 常量以大写字母和下划线命名,例如 APP_PATH;
|
||||
2. 配置参数以小写字母和下划线命名,例如 url_route_on 和url_convert;
|
||||
3. 环境变量定义使用大写字母和下划线命名,例如APP_DEBUG;
|
||||
|
||||
#### 数据表和字段
|
||||
1. 数据表和字段采用小写加下划线方式命名,并注意字段名不要以下划线开头,例如 think_user 表和 user_name字段,不建议使用驼峰和中文作为数据表及字段命名
|
||||
|
||||
注意:请理解并尽量遵循以上命名规范,可以减少在开发过程中出现不必要的错误
|
||||
|
||||
#### 语法规范
|
||||
1. 尽量使用php7新语法
|
||||
2. 每个 namespace 命名空间声明语句和 use 声明语句块后面,必须 插入一个空白行
|
||||
3. 类的开始花括号({) 必须 写在类声明后自成一行,结束花括号(})也 必须 写在类主体后自成一行
|
||||
4. 方法的开始花括号({) 必须 写在函数声明后自成一行,结束花括号(})也 必须 写在函数主体后自成一行。
|
||||
5. 类的属性和方法 必须 添加访问修饰符(private、protected 以及 public),abstract 以及 final 必须 声明在访问修饰符之前,而 static 必须 声明在访问修饰符之后
|
||||
6. 控制结构的关键字后 必须 要有一个空格符,而调用方法或函数时则 一定不可 有
|
||||
7. 控制结构的开始花括号({) 必须 写在声明的同一行,而结束花括号(}) 必须 写在主体后自成一行
|
||||
8. 纯 PHP 代码文件 必须 省略最后的 ?> 结束标签
|
||||
9. 所有方法,类,控制器类,都 必须 添加访问修饰符
|
||||
~~~
|
||||
|
||||
/**
|
||||
* 中文注释
|
||||
* @param string $str 声明类型
|
||||
* @param array $arr
|
||||
* @return bool
|
||||
*/
|
||||
public function action(string $str, array $arr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
~~~
|
||||
10. 参数列表中,每个逗号后面 必须 要有一个空格,而逗号前面 一定不可 有空格
|
||||
~~~
|
||||
function foo($arg1, &$arg2, $arg3 = [])
|
||||
{
|
||||
// method body
|
||||
}
|
||||
~~~
|
||||
11. 参数 可以 分列成多行,此时包括第一个参数在内的每个参数都 尽量 单独成行。
|
||||
~~~
|
||||
<?php
|
||||
$foo->bar(
|
||||
$longArgument,
|
||||
$longerArgument,
|
||||
$muchLongerArgument
|
||||
);
|
||||
~~~
|
||||
12. 标准的 if 结构如下代码所示,请留意「括号」、「空格」以及「花括号」的位置,
|
||||
注意 else 和 elseif 都与前面的结束花括号在同一行
|
||||
~~~
|
||||
<?php
|
||||
if ($expr1) {
|
||||
// if body
|
||||
} elseif ($expr2) {
|
||||
// elseif body
|
||||
} else {
|
||||
// else body;
|
||||
}
|
||||
~~~
|
||||
13. 赋值等号前后必须加空格符
|
||||
~~~
|
||||
<?php
|
||||
$arr = [];
|
||||
~~~
|
||||
|
||||
|
||||
#### PHP 7.1+ 常用新语法
|
||||
|
||||
1. 三元运算符
|
||||
~~~
|
||||
<?php
|
||||
|
||||
$arr = ['crmeb'=>true];
|
||||
之前
|
||||
echo isset($arr['crmeb']) ? $arr['crmeb'] : '';
|
||||
之后
|
||||
echo $arr['crmeb'] ?? '';
|
||||
~~~
|
||||
2. define() 定义常量数组
|
||||
~~~
|
||||
<?php
|
||||
define('ARR',['a','b']);
|
||||
~~~
|
||||
3. 命名空间优化
|
||||
~~~
|
||||
<?php
|
||||
//PHP7之前语法
|
||||
use FooLibrary\Bar\Baz\ClassA;
|
||||
use FooLibrary\Bar\Baz\ClassB;
|
||||
// PHP7新语法写法
|
||||
use FooLibrary\Bar\Baz\{ ClassA, ClassB};
|
||||
|
||||
~~~
|
||||
#### CRMEB规范
|
||||
1. 所有数据验证放在模块下的 validates 目录下
|
||||
2. JSON返回使用父级 AuthController类中的success 和 fail
|
||||
3. 错误判断抛出异常,由一个错误类统一控制输出
|
||||
~~~
|
||||
<?php
|
||||
|
||||
throw new AuthException('错误信息',400);
|
||||
~~~
|
||||
4. 错误码和错误提示语应该统一管理,方便切换多语言
|
||||
5. 数据库操作使用模型类,不能使用Db::table()
|
||||
6. 获取表单数据使用 app\Request
|
||||
~~~
|
||||
<?php
|
||||
use app\Request;
|
||||
|
||||
|
||||
public function index(Request $request) {
|
||||
|
||||
//获取提交的数据,并以二维数组形式返回
|
||||
$arr = $request->getMore([
|
||||
'name',
|
||||
'nickname'
|
||||
]);
|
||||
//获取提交的数据,并以二维数组形式返回并附加默认值
|
||||
$arr = $request->getMore([
|
||||
['name','123'],
|
||||
['nickname','0']
|
||||
]);
|
||||
//获取提交的数据,并以一维数组形式返回并附加默认值
|
||||
[$name, $nickname] = $request->getMore([
|
||||
['name','123'],
|
||||
['nickname','0']
|
||||
],true);
|
||||
|
||||
}
|
||||
~~~
|
||||
7. 所有控制器类命令和表名对应,按照大驼峰命名规范
|
||||
8. 所有文件夹命名按照小写字母加下划线定义
|
||||
9. 所有属性名,变量名尽量遵守小驼峰命名规范
|
||||
10. 复杂逻辑,多状态应适当添加行内注释
|
||||
|
||||
## 主要特性
|
||||
|
||||
有详细的代码注释,有完整系统手册
|
||||
### TP6框架
|
||||
使用最新的 ThinkPHP 6.0 + Swoole4框架开发
|
||||
### 前端采用Vue CLI框架
|
||||
前端使用Vue CLI框架nodejs打包,页面加载更流畅,用户体验更好
|
||||
### 标准接口
|
||||
标准接口、前后端分离,二次开发更方便
|
||||
### 支持队列
|
||||
降低流量高峰,解除耦合,高可用
|
||||
### 长连接
|
||||
减少CPU及内存使用及网络堵塞,减少请求响应时长
|
||||
### 无缝事件机制
|
||||
行为扩展更方便,方便二次开发
|
||||
### 后台快速生成表单
|
||||
后台应用form-builder 无需写页面快速增删改查
|
||||
### 数据表格导出
|
||||
PHPExcel数据导出,导出表格更加美观可视;
|
||||
### 数据统计分析
|
||||
后台使用ECharts图表统计,实现用户、产品、订单、资金等统计分析
|
||||
### 强大的后台权限管理
|
||||
后台多种角色、多重身份权限管理,权限可以控制到每一步操作
|
||||
### 一键安装
|
||||
自动检查系统环境一键安装
|
||||
|
||||
# 安装
|
||||
本安装教程针对的是宝塔面板安装 环境为 nginx1.18 mysql5.7 php7.3
|
||||
## 站点配置
|
||||
1. 创建站点 (注:创建站点注意php版本选择纯静态)
|
||||
2. 上传你的代码到站点根目录下
|
||||
3. 点开站点设置,网站目录标签下,配置运行目录为 /public
|
||||
4. ssl标签中,配置https证书
|
||||
5. 反向代理标签下,配置站点反向代理,目标URL填写为 http://127.0.0.1:8324 ,点击提交,在列表中点击配置文件,将下方代码复制替换全部。
|
||||
~~~
|
||||
#PROXY-START/
|
||||
location ~* \.(php|jsp|cgi|asp|aspx)$
|
||||
{
|
||||
proxy_pass http://127.0.0.1:8324;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header REMOTE-HOST $remote_addr;
|
||||
}
|
||||
location /
|
||||
{
|
||||
if (!-e $request_filename) {
|
||||
proxy_pass http://127.0.0.1:8324;
|
||||
}
|
||||
proxy_http_version 1.1;
|
||||
proxy_read_timeout 360s;
|
||||
proxy_redirect off;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header REMOTE-HOST $remote_addr;
|
||||
|
||||
add_header X-Cache $upstream_cache_status;
|
||||
|
||||
#Set Nginx Cache
|
||||
|
||||
add_header Cache-Control no-cache;
|
||||
expires 12h;
|
||||
}
|
||||
#PROXY-END/
|
||||
~~~
|
||||
|
||||
## 环境配置
|
||||
### php配置,进入宝塔的软件商店,进入php的设置
|
||||
1. 将项目中 install/swoole-loader/swoole_loader73.so 复制到 /www/server/php/73/lib/php/extensions/no-debug-non-zts-20180731 目录下 (注:根据你安装的 php 版本选择扩展)
|
||||
2. 点击安装扩展标签,安装 fileinfo,redis,Swoole4 这三个扩展
|
||||
3. 点击配置修改标签,将 memory_limit 脚本内存控制改为 256M
|
||||
4. 点击配置文件标签,将 extension = swoole_loader73.so 代码添加在最下方,然后保存。
|
||||
5. 点击服务标签,重启 php 服务。
|
||||
### mysql配置,进入宝塔的软件商店,进入mysql的设置
|
||||
1. 点击配置修改标签,找到 sql-mode ,将后面的值修改为 NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
|
||||
2. 点击服务标签,重启 mysql 服务。
|
||||
|
||||
## 启动swoole
|
||||
1. 打开命令行执行命令: `php -v` 查看命令行版本是否为配置的 PHP 版本
|
||||
2. 命令行切换到站点目录下执行启动命令: `php think swoole restart`
|
||||
3. 在浏览器中输入你的域名(例如:www.yourdomain.com)安装程序会自动执行安装。期间系统会提醒你输入数据库信息以完成安装。
|
||||
4. 再次打开命令行换到站点目录下执行重启命令: `php think swoole restart`
|
||||
5. 利用Supervisor进行守护进程:`php think swoole restart`
|
||||
|
||||
## 访问地址
|
||||
### 后台访问地址:
|
||||
域名/admin
|
||||
### 公众号和H5首页访问地址:
|
||||
域名/
|
||||
### 安装过程中请牢记您的账号密码!
|
||||
|
||||
## 重新安装
|
||||
1. 清除数据库
|
||||
2. 删除 install/install.lock 文件
|
||||
3. 执行重启命令: `php think swoole restart`
|
||||
4. 执行完安装后再次执行重启命令: `php think swoole restart`
|
||||
|
||||
## 手动安装
|
||||
1. 创建数据库,倒入数据库文件
|
||||
数据库文件目录/public/install/crmeb_merchant.sql
|
||||
2. 修改数据库连接文件
|
||||
配置文件路径/.env
|
||||
~~~
|
||||
APP_DEBUG = true
|
||||
INSTALLED = true
|
||||
SHOW_PHONE = true
|
||||
|
||||
[APP]
|
||||
DEFAULT_TIMEZONE = Asia/Shanghai
|
||||
|
||||
[DATABASE]
|
||||
TYPE = mysql
|
||||
HOSTNAME = 127.0.0.1 #数据库连接地址
|
||||
DATABASE = test #数据库名称
|
||||
USERNAME = username #数据库登录账号
|
||||
PASSWORD = password #数据库登录密码
|
||||
HOSTPORT = 3306 #数据库端口
|
||||
CHARSET = utf8
|
||||
DEBUG = true
|
||||
|
||||
[REDIS]
|
||||
REDIS_HOSTNAME = 127.0.0.1 #redis地址
|
||||
PORT = 6379 #redis端口
|
||||
REDIS_PASSWORD = '' #redis密码
|
||||
SELECT = 0 #redis数据库
|
||||
|
||||
~~~
|
||||
3. 修改目录权限(linux系统)777
|
||||
/public
|
||||
/runtime
|
||||
4. 启动swoole,需要使用Supervisor进行守护进程
|
||||
~~~
|
||||
php think swoole restart
|
||||
~~~
|
||||
|
||||
## 启动命令
|
||||
|
||||
开启
|
||||
```sh
|
||||
php think swoole restart
|
||||
```
|
||||
|
||||
## 文档
|
||||
|
||||
[使用手册](https://doc.crmeb.com/)
|
||||
||
|
||||
[TP6开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content)
|
||||
||
|
||||
[Swoole开发手册](https://wiki.swoole.com/#/)
|
||||
|
||||
## 参与开发
|
||||
|
||||
请参阅 [CRMEB](https://github.com/crmeb/CRMEB)
|
||||
|
||||
## 版权信息
|
||||
|
||||
|
||||
本项目包含的第三方源码和二进制文件之版权信息另行标注。
|
||||
|
||||
版权所有Copyright © 2017-2024 by [CRMEB](http://www.crmeb.com)
|
||||
|
||||
All rights reserved。
|
||||
|
||||
CRMEB® 商标和著作权所有者为西安众邦网络科技有限公司。
|
||||
|
||||
###开发团队:
|
||||
|
||||
##### 技术:xaboy、Qinii、郭小萌、旺仔
|
||||
##### 产品:Amy
|
||||
##### 设计:xy-yyds, LXT
|
||||
##### 测试:夏天、绵绵羊、王多鱼
|
||||
|
||||
注:排名不分前后
|
|
@ -0,0 +1 @@
|
|||
deny from all
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\Service;
|
||||
|
||||
/**
|
||||
* 应用服务类
|
||||
*/
|
||||
class AppService extends Service
|
||||
{
|
||||
|
||||
public function register()
|
||||
{
|
||||
defined('TOP_PRECISION') || define('TOP_PRECISION', 2);
|
||||
// 服务注册
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// 服务启动
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\db\exception\PDOException;
|
||||
use think\exception\ErrorException;
|
||||
use think\exception\Handle;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 应用异常处理类
|
||||
*/
|
||||
class ExceptionHandle extends Handle
|
||||
{
|
||||
/**
|
||||
* 不需要记录信息(日志)的异常类列表
|
||||
* @var array
|
||||
*/
|
||||
protected $ignoreReport = [
|
||||
HttpException::class,
|
||||
HttpResponseException::class,
|
||||
ModelNotFoundException::class,
|
||||
DataNotFoundException::class,
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
* @access public
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Throwable $exception): void
|
||||
{
|
||||
// 使用内置的方式记录异常日志
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
$this->report($e);
|
||||
// 其他错误交给系统处理
|
||||
if ($e instanceof ValidateException)
|
||||
return app('json')->fail($e->getMessage());
|
||||
else if ($e instanceof DataNotFoundException)
|
||||
return app('json')->fail(isDebug() ? $e->getMessage() : '数据不存在');
|
||||
else if ($e instanceof ModelNotFoundException)
|
||||
return app('json')->fail(isDebug() ? $e->getMessage() : '数据不存在');
|
||||
else if ($e instanceof PDOException)
|
||||
return app('json')->fail(isDebug() ? $e->getMessage() : '数据库操作失败', isDebug() ? $e->getData() : []);
|
||||
else if ($e instanceof ErrorException)
|
||||
return app('json')->fail(isDebug() ? $e->getMessage() : '系统错误', isDebug() ? $e->getData() : []);
|
||||
else if ($e instanceof \PDOException)
|
||||
return app('json')->fail(isDebug() ? $e->getMessage() : '数据库连接失败');
|
||||
else if ($e instanceof \EasyWeChat\Core\Exceptions\HttpException)
|
||||
return app('json')->fail($e->getMessage());
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
```
|
||||
├── command #自定义命令行工具
|
||||
├── common #服务和model等层级模块
|
||||
│ ├── dao #数据库操作层
|
||||
│ │ ├── article #文章管理
|
||||
│ │ ├── community #社区
|
||||
│ │ ├── delivery #同城配送
|
||||
│ │ ├── openapi #开放接口
|
||||
│ │ ├── store #商城商品等模块
|
||||
│ │ ├── system #商城系统配置等模块
|
||||
│ │ ├── user #用户模块
|
||||
│ │ └── wechat #微信相关
|
||||
│ ├── middleware #中间件
|
||||
│ ├── model #model层
|
||||
│ │ ├── article #文章
|
||||
│ │ ├── community #社区
|
||||
│ │ ├── delivery #同城配送
|
||||
│ │ ├── openapi #开放接口
|
||||
│ │ ├── store #商品等模块
|
||||
│ │ ├── system #系统配置相关
|
||||
│ │ ├── user #用户管理
|
||||
│ │ └── wechat #微信相关
|
||||
│ └── repositories #服务层
|
||||
│ ├── article #文章管理
|
||||
│ ├── community #社区
|
||||
│ ├── delivery #同城配送
|
||||
│ ├── openapi #开放接口
|
||||
│ ├── store #商品等
|
||||
│ ├── system #系统配置
|
||||
│ ├── user #用户
|
||||
│ └── wechat #微信相关
|
||||
├── controller #控制器层
|
||||
│ ├── admin #平台后台模块控制器
|
||||
│ │ ├── article #文章
|
||||
│ │ ├── community #社区
|
||||
│ │ ├── delivery #同城配送
|
||||
│ │ ├── order #订单/退款单等
|
||||
│ │ ├── parameter #商品参数
|
||||
│ │ ├── points #积分商城
|
||||
│ │ ├── store #商品及活动商品
|
||||
│ │ ├── system #系统配置等
|
||||
│ │ ├── user #用户
|
||||
│ │ └── wechat #微信相关
|
||||
│ ├── api #移动端控制器
|
||||
│ │ ├── article #文章
|
||||
│ │ ├── community #社区
|
||||
│ │ ├── server #客服
|
||||
│ │ ├── store #商品相关
|
||||
│ │ └── user #用户
|
||||
│ ├── merchant #商户后台模块
|
||||
│ │ ├── store #商品相关
|
||||
│ │ ├── system #系统配置等
|
||||
│ │ └── user #用户
|
||||
│ ├── openapi #开放接口模块
|
||||
│ │ └── store
|
||||
│ ├── pc #PC端专属接口 (只有购买PC端才会有此模块)
|
||||
│ │ └── store
|
||||
│ └── service #客服
|
||||
├── validate #验证器
|
||||
│ ├── admin
|
||||
│ ├── api
|
||||
│ └── merchant
|
||||
├── view #view页面层
|
||||
│ ├── install #安装页面
|
||||
│ └── mobile #手机模拟
|
||||
└── webscoket #长链接
|
||||
└── handler #客服聊天长链接处理,消息等
|
||||
```
|
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app;
|
||||
|
||||
use crmeb\traits\Macro;
|
||||
use think\File;
|
||||
use think\file\UploadedFile;
|
||||
|
||||
class Request extends \think\Request
|
||||
{
|
||||
use Macro;
|
||||
|
||||
protected $cache = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->filter[] = function ($val) {
|
||||
return is_string($val) ? trim($val) : $val;
|
||||
};
|
||||
}
|
||||
|
||||
public function ip(): string
|
||||
{
|
||||
return $this->header('remote-host') ?? parent::ip();
|
||||
}
|
||||
|
||||
public function isApp()
|
||||
{
|
||||
return $this->header('Form-type') === 'app';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $db
|
||||
* @param $key
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/10/22
|
||||
*/
|
||||
public function hasCache($db, $key)
|
||||
{
|
||||
return isset($this->cache[$db][$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $db
|
||||
* @param $key
|
||||
* @return array|mixed|string
|
||||
* @author xaboy
|
||||
* @day 2020/10/22
|
||||
*/
|
||||
public function getCache($db, $key)
|
||||
{
|
||||
if (is_array($key)) {
|
||||
$data = [];
|
||||
foreach ($key as $v) {
|
||||
$data[$v] = $this->getCache($db, $v);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
return $this->cache[$db][$key] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $db
|
||||
* @param $key
|
||||
* @param null $value
|
||||
* @author xaboy
|
||||
* @day 2020/10/22
|
||||
*/
|
||||
public function setCache($db, $key, $value = null)
|
||||
{
|
||||
if (!isset($this->cache[$db])) $this->cache[$db] = [];
|
||||
if (is_array($key)) {
|
||||
foreach ($key as $k => $v) {
|
||||
$this->setCache($db, $k, $v);
|
||||
}
|
||||
return;
|
||||
}
|
||||
$this->cache[$db][$key] = $value;
|
||||
}
|
||||
|
||||
public function clearCache()
|
||||
{
|
||||
$this->cache = [];
|
||||
}
|
||||
|
||||
public function params(array $names, $filter = '')
|
||||
{
|
||||
$data = [];
|
||||
$flag = false;
|
||||
if ($filter === true) {
|
||||
$filter = '';
|
||||
$flag = true;
|
||||
}
|
||||
foreach ($names as $name) {
|
||||
if (!is_array($name))
|
||||
$data[$name] = $this->param($name, '', $filter);
|
||||
else
|
||||
$data[$name[0]] = $this->param($name[0], $name[1], $filter);
|
||||
}
|
||||
|
||||
return $flag ? array_values($data) : $data;
|
||||
}
|
||||
|
||||
public function merId()
|
||||
{
|
||||
return intval($this->hasMacro('merchantId') ? $this->merchantId() : 0);
|
||||
}
|
||||
|
||||
public function merAdminId()
|
||||
{
|
||||
return intval($this->hasMacro('adminId') ? $this->adminId() : 0);
|
||||
}
|
||||
|
||||
public function setOriginFile($name, $array)
|
||||
{
|
||||
$this->file[$name] = $array;
|
||||
}
|
||||
|
||||
public function getOriginFile($name)
|
||||
{
|
||||
return $this->file[$name] ?? null;
|
||||
}
|
||||
|
||||
|
||||
protected function dealUploadFile(array $files, string $name): array
|
||||
{
|
||||
$array = [];
|
||||
foreach ($files as $key => $file) {
|
||||
if (is_array($file['name'])) {
|
||||
$item = [];
|
||||
$keys = array_keys($file);
|
||||
$count = count($file['name']);
|
||||
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if ($file['error'][$i] > 0) {
|
||||
if ($name == $key) {
|
||||
$this->throwUploadFileError($file['error'][$i]);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$temp['key'] = $key;
|
||||
|
||||
foreach ($keys as $_key) {
|
||||
$temp[$_key] = $file[$_key][$i];
|
||||
|
||||
$name = explode('.',$temp['name']);
|
||||
$num = count($name);
|
||||
$suffix = strtolower($name[$num - 1]);
|
||||
array_pop($name);
|
||||
$temp['name'] = implode('.',$name).'.'.$suffix;
|
||||
}
|
||||
|
||||
$item[] = new UploadedFile($temp['tmp_name'], $temp['name'], $temp['type'], $temp['error']);
|
||||
}
|
||||
|
||||
$array[$key] = $item;
|
||||
} else {
|
||||
if ($file instanceof File) {
|
||||
$array[$key] = $file;
|
||||
} else {
|
||||
if ($file['error'] > 0) {
|
||||
if ($key == $name) {
|
||||
$this->throwUploadFileError($file['error']);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$name = explode('.',$file['name']);
|
||||
$num = count($name);
|
||||
$suffix = strtolower($name[$num - 1]);
|
||||
array_pop($name);
|
||||
$file['name'] = implode('.',$name).'.'.$suffix;
|
||||
|
||||
$array[$key] = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['error']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\repositories\system\attachment\AttachmentRepository;
|
||||
use app\common\repositories\system\auth\MenuRepository;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
/**
|
||||
* Class FormatMenuPath
|
||||
* @package app\command
|
||||
* @author xaboy
|
||||
* @day 2020/8/26
|
||||
*/
|
||||
class ClearCacheAttachment extends Command
|
||||
{
|
||||
/**
|
||||
* @author xaboy
|
||||
* @day 2020/9/21
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('clear:attachment')
|
||||
->setDescription('clear cache attachment');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
* @author xaboy
|
||||
* @day 2020/9/21
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('开始清理');
|
||||
app()->make(AttachmentRepository::class)->clearCache();
|
||||
$output->writeln('开始完毕');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\command;
|
||||
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Db;
|
||||
|
||||
class ClearMerchantData extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('clear:merchant')
|
||||
->setDescription('清空数据(除系统配置以外的所有数据)');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$flag = $output->confirm($input, '清空数据前务必做好数据库的备份,防止数据被误删 !!!', false);
|
||||
if (!$flag) return;
|
||||
$tables = Db::query('SHOW TABLES FROM ' . env('database.database', ''));
|
||||
$pre = env('database.prefix', '');
|
||||
$bakTables = [
|
||||
$pre . 'page_link',
|
||||
$pre . 'page_category',
|
||||
$pre . 'diy',
|
||||
$pre . 'city_area',
|
||||
$pre . 'express',
|
||||
$pre . 'system_admin',
|
||||
$pre . 'system_city',
|
||||
$pre . 'system_config',
|
||||
$pre . 'system_config_classify',
|
||||
$pre . 'system_config_value',
|
||||
$pre . 'system_group',
|
||||
$pre . 'system_group_data',
|
||||
$pre . 'system_menu',
|
||||
$pre . 'system_role',
|
||||
$pre . 'template_message',
|
||||
$pre . 'system_notice_config',
|
||||
$pre . 'cache',
|
||||
];
|
||||
|
||||
foreach ($tables as $table) {
|
||||
$name = array_values($table)[0];
|
||||
if (!in_array($name, $bakTables)) {
|
||||
Db::table($name)->delete(true);
|
||||
}
|
||||
}
|
||||
Db::table( $pre . 'cache')->whereNotIn('key','copyright_context,copyright_image,copyright_status')->delete(true);
|
||||
$output->info('删除成功');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\command;
|
||||
|
||||
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
|
||||
class ClearRedundancy extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('clear:redundancy')
|
||||
->setDescription('已删除的商户的商品相关数据');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
try{
|
||||
app()->make(MerchantRepository::class)->clearRedundancy();
|
||||
}catch (\Exception $exception){
|
||||
Log::info('清除冗余错误:'.$exception->getMessage());
|
||||
}
|
||||
$output->info('执行成功');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\repositories\system\auth\MenuRepository;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
/**
|
||||
* Class FormatMenuPath
|
||||
* @package app\command
|
||||
* @author xaboy
|
||||
* @day 2020/8/26
|
||||
*/
|
||||
class FormatMenuPath extends Command
|
||||
{
|
||||
/**
|
||||
* @author xaboy
|
||||
* @day 2020/8/26
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('menu:format')
|
||||
->setDescription('the format menu command');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
* @author xaboy
|
||||
* @day 2020/8/26
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('开启修复');
|
||||
$menuRepository = app()->make(MenuRepository::class);
|
||||
$menuRepository->formatPath(0);
|
||||
$menuRepository->formatPath(1);
|
||||
$output->writeln('执行成功');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\command;
|
||||
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
|
||||
class VersionUpdate extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('version:update')
|
||||
->setDescription('crmeb_merchant 版本更新命令')
|
||||
->addOption('package', 'p', Option::VALUE_REQUIRED, '指定更新包的路径');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$flag = $output->confirm($input, '更新之前请务必做好数据库和代码的备份,防止数据或代码在更新中被覆盖 !!!', false);
|
||||
if (!$flag) return;
|
||||
$flag = $output->confirm($input, '请确保swoole服务和队列服务已关闭,防止意外报错', false);
|
||||
if (!$flag) return;
|
||||
|
||||
$version = get_crmeb_version_code();
|
||||
ini_set('memory_limit', '-1');
|
||||
set_time_limit(0);
|
||||
|
||||
$packagePath = $input->getOption('package') ?: 'auto_update.zip';
|
||||
$updateFilePath = app()->getRootPath() . ltrim($packagePath, '/= ');
|
||||
$updatePath = dirname($updateFilePath);
|
||||
$unzipPath = $updatePath . '/_update_runtime_' . str_replace('.', '_', $version);
|
||||
if (!is_file($updateFilePath)) {
|
||||
$output->warning($updateFilePath . ' 更新包不存在');
|
||||
return;
|
||||
}
|
||||
$zip = new \ZipArchive();
|
||||
if ($zip->open($updateFilePath) === true) {
|
||||
$zip->extractTo($unzipPath);
|
||||
$zip->close();
|
||||
} else {
|
||||
$output->warning($updateFilePath . ' 更新包打开失败');
|
||||
return;
|
||||
}
|
||||
|
||||
$unlink = function () use ($unzipPath) {
|
||||
@unlink($unzipPath . '/update.sql');
|
||||
@unlink($unzipPath . '/update.zip');
|
||||
@unlink($unzipPath . '/AutoUpdate.php');
|
||||
@unlink($unzipPath . '/.env');
|
||||
@unlink($unzipPath . '/.config');
|
||||
@rmdir($unzipPath);
|
||||
};
|
||||
|
||||
if (!is_file($unzipPath . '/.env') && !is_file($unzipPath . '/.config')) {
|
||||
$output->warning('文件不完整');
|
||||
$unlink();
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_file($unzipPath . '/.env')) {
|
||||
$env = parse_ini_file($unzipPath . '/.env', true) ?: [];
|
||||
}
|
||||
|
||||
if (is_file($unzipPath . '/.config')) {
|
||||
$env = parse_ini_file($unzipPath . '/.config', true) ?: [];
|
||||
}
|
||||
if (($env['NAME'] ?? '') !== 'CRMEB-MERCHANT' || ((($env['OLD_VERSION'] ?? '') && ($env['OLD_VERSION'] ?? '') !== $version))) {
|
||||
if (($env['TYPE'] ?? '') !== 'MODEL') {
|
||||
$output->warning('版本号对比失败,请检查当前版本号(.version/更新包)是否被修改');
|
||||
$unlink();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$confirm = [];
|
||||
if (isset($env['confirm'])) {
|
||||
$confirm = is_array($env['confirm']) ? $env['confirm'] : [$env['confirm']];
|
||||
}
|
||||
foreach ($confirm as $item) {
|
||||
if (!$output->confirm($input, $item, false)) {
|
||||
$unlink();
|
||||
return;
|
||||
}
|
||||
}
|
||||
$installHost = systemConfig('site_url');
|
||||
if (substr($installHost, 0, 5) == 'https'){
|
||||
$_url = str_replace('//' ,'\\\/\\\/', $installHost);
|
||||
} else {
|
||||
$_url = str_replace('http://' ,'http:\\\/\\\/', $installHost);
|
||||
}
|
||||
|
||||
if (is_file($unzipPath . '/update.sql')) {
|
||||
$str = preg_replace('/--.*/i', '', file_get_contents($unzipPath . '/update.sql'));
|
||||
$str = preg_replace('/\/\*.*\*\/(\;)?/i', '', $str);
|
||||
$sqlList = explode(";\n", $str);
|
||||
} else {
|
||||
$sqlList = [];
|
||||
}
|
||||
$autoUpdateData = null;
|
||||
if (is_file($unzipPath . '/AutoUpdate.php')) {
|
||||
try {
|
||||
require_once $unzipPath . '/AutoUpdate.php';
|
||||
$autoUpdateData = new \crmeb\update\AutoUpdate($input, $output);
|
||||
} catch (\Throwable $e) {}
|
||||
}
|
||||
|
||||
if ($autoUpdateData) $autoUpdateData->autoUpdateStart();
|
||||
$output->info('开始更新');
|
||||
$pre = env('database.prefix');
|
||||
try {
|
||||
Db::transaction(function () use ($pre, $output, $unzipPath, $sqlList, $autoUpdateData,$installHost,$_url) {
|
||||
if ($autoUpdateData) $autoUpdateData->autoUpdateBefore();
|
||||
$count = count($sqlList);
|
||||
if ($count && $autoUpdateData) {
|
||||
$autoUpdateData->autoSqlBefore();
|
||||
}
|
||||
foreach ($sqlList as $idx => $sql) {
|
||||
$sql = trim($sql, " \xEF\xBB\xBF\r\n");
|
||||
if (!$sql) continue;
|
||||
if ($pre && $pre !== 'eb_') {
|
||||
$sql = str_replace('eb_', $pre, $sql);
|
||||
}
|
||||
$sql = str_replace('https://mer1.crmeb.net', $installHost , $sql);
|
||||
$sql = str_replace('https:\\\/\\\/mer1.crmeb.net', $_url , $sql);
|
||||
Db::query($sql . ';');
|
||||
if (!($idx % 50)) {
|
||||
$output->info("导入中($idx/$count)");
|
||||
}
|
||||
}
|
||||
if ($count) {
|
||||
if ($autoUpdateData) $autoUpdateData->autoSqlAfter();
|
||||
$output->info('数据库更新成功');
|
||||
}
|
||||
$zip = new \ZipArchive();
|
||||
if ($zip->open($unzipPath . '/update.zip') === true) {
|
||||
if ($autoUpdateData) $autoUpdateData->autoCopyBefore();
|
||||
$zip->extractTo(app()->getRootPath());
|
||||
$zip->close();
|
||||
if ($autoUpdateData) $autoUpdateData->autoCopyAfter();
|
||||
} else {
|
||||
throw new Exception('更新文件覆盖失败');
|
||||
}
|
||||
});
|
||||
if ($autoUpdateData) $autoUpdateData->autoUpdateAfter();
|
||||
} catch (\Throwable $e) {
|
||||
$output->warning('更新失败:' . $e->getMessage());
|
||||
$unlink();
|
||||
if ($autoUpdateData) $autoUpdateData->autoUpdateFail($e);
|
||||
return;
|
||||
}
|
||||
|
||||
$unlink();
|
||||
if ($autoUpdateData) $autoUpdateData->autoUpdateEnd();
|
||||
$output->info('版本更新成功, 请重启swoole服务和队列服务');
|
||||
|
||||
update_crmeb_compiled();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use crmeb\jobs\SyncProductTopJob;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\Queue;
|
||||
|
||||
class changeHotTop extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('change:hotTop')
|
||||
->setDescription('清楚缓存:php think change:hotTop');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
* @author Qinii
|
||||
* @day 4/24/22
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
Queue::push(SyncProductTopJob::class,[]);
|
||||
$output->writeln('开始执行队列');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use Swoole\Coroutine\MySQL\Exception;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\event\RouteLoaded;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Route;
|
||||
use app\common\repositories\system\auth\MenuRepository;
|
||||
|
||||
class clearCache extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('clearCache')
|
||||
->addArgument('cacheType',Argument::OPTIONAL, 'php think menu [1] / [2]')
|
||||
->setDescription('清楚缓存:php think clearCache 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
* @author Qinii
|
||||
* @day 4/24/22
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$type = $input->getArgument('cacheType');
|
||||
$tag = ['sys_login_freeze','mer_login_freeze'];
|
||||
$msg = '';
|
||||
switch ($type) {
|
||||
case 0:
|
||||
$msg = '平台登录限制';
|
||||
$tag = 'sys_login_freeze';
|
||||
break;
|
||||
case 1:
|
||||
$msg = '商户登录限制';
|
||||
$tag = 'mer_login_freeze';
|
||||
break;
|
||||
}
|
||||
Cache::tag($tag)->clear();
|
||||
$output->writeln('清楚缓存'.$msg);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\article\ArticleCategory;
|
||||
use app\common\model\community\Community;
|
||||
use app\common\model\community\CommunityTopic;
|
||||
use app\common\model\store\broadcast\BroadcastGoods;
|
||||
use app\common\model\store\broadcast\BroadcastRoom;
|
||||
use app\common\model\store\Guarantee;
|
||||
use app\common\model\store\product\Product;
|
||||
use app\common\model\store\product\ProductAssistUser;
|
||||
use app\common\model\store\product\ProductAttrValue;
|
||||
use app\common\model\store\product\ProductGroupUser;
|
||||
use app\common\model\store\product\ProductReply;
|
||||
use app\common\model\store\product\Spu;
|
||||
use app\common\model\store\service\StoreService;
|
||||
use app\common\model\store\StoreCategory;
|
||||
use app\common\model\store\StoreSeckillTime;
|
||||
use app\common\model\system\attachment\Attachment;
|
||||
use app\common\model\system\financial\Financial;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\model\system\merchant\MerchantIntention;
|
||||
use app\common\model\user\MemberInterests;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserBrokerage;
|
||||
use crmeb\services\ImageHostService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\facade\Log;
|
||||
|
||||
class resetImagePath extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('reset:imagePath')
|
||||
->addArgument('origin', Argument::OPTIONAL, 'path:http:/crmeb.com')
|
||||
->addArgument('replace', Argument::OPTIONAL, 'path:http:/crmeb.com')
|
||||
->setDescription('php think reset:imagePath http://old.com http://new.com');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$origin = $input->getArgument('origin');
|
||||
$replace = $input->getArgument('replace');
|
||||
$output->writeln('开始执行');
|
||||
$service = ImageHostService::getInstance();
|
||||
$res = $service->execute($origin,$replace);
|
||||
if ($res) {
|
||||
$output->info('执行完成');
|
||||
} else {
|
||||
$output->warning('执行过程中存在错误,请在runtime/log中查看具体错误信息');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\repositories\system\admin\AdminRepository;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\Output;
|
||||
use think\console\input\Option;
|
||||
|
||||
class resetPassword extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('reset:password')
|
||||
->addArgument('root', Argument::OPTIONAL, 'root : admin')
|
||||
->addOption('pwd', null, Option::VALUE_REQUIRED, 'pwd : 123456')
|
||||
->setDescription('php think reset:password admin --pwd 123456');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/15
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$account = $input->getArgument('root');
|
||||
if ($input->hasOption('pwd')){
|
||||
$pwd = $input->getOption('pwd');
|
||||
}
|
||||
$make = app()->make(AdminRepository::class);
|
||||
$accountData = $make->accountByAdmin($account);
|
||||
if(!$accountData) {
|
||||
$output->warning('管理员账号不存在');
|
||||
}else{
|
||||
$pwd_ = $make->passwordEncode($pwd);
|
||||
$accountData->pwd = $pwd_;
|
||||
$accountData->save();
|
||||
$output->info('账号:'.$account.';密码已重置:'.$pwd);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use Swoole\Coroutine\MySQL\Exception;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\event\RouteLoaded;
|
||||
use think\facade\Route;
|
||||
use app\common\repositories\system\auth\MenuRepository;
|
||||
|
||||
class updateAuth extends Command
|
||||
{
|
||||
protected $k = [];
|
||||
protected $kv =[];
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('setAuth')
|
||||
->addArgument('prompt',Argument::OPTIONAL, 'php think menu [s] / [e]')
|
||||
->setDescription('使用方法: `php think menu` , 可选传参数 s 只显示成功信息');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/15
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$prompt = $input->getArgument('prompt');
|
||||
$output->writeln('开始执行');
|
||||
$output->writeln('<----------------');
|
||||
$output->writeln('开始平台权限');
|
||||
$sys = $this->routeList('sys',$prompt);
|
||||
|
||||
$output->writeln('开始商户权限');
|
||||
|
||||
$mer = $this->routeList('mer',$prompt);
|
||||
$output->writeln('<----------------');
|
||||
$output->writeln('平台执行成功,合计: '. $sys .'条 , 商户执行成功,合计: '. $mer .'条');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/15
|
||||
* @param string|null $dir
|
||||
* @return mixed
|
||||
*/
|
||||
public function routeList($type, $prompt)
|
||||
{
|
||||
$this->k = [];
|
||||
$this->kv = [];
|
||||
$this->app->route->setTestMode(true);
|
||||
$this->app->route->clear();
|
||||
$path = $this->app->getRootPath() . 'route' . DIRECTORY_SEPARATOR;
|
||||
|
||||
if ($type == 'sys')
|
||||
include $path . 'admin.php';
|
||||
// include $path . 'admin/config.php';
|
||||
if ($type == 'mer')
|
||||
include $path . 'merchant.php';
|
||||
//触发路由载入完成事件
|
||||
$this->app->event->trigger(RouteLoaded::class);
|
||||
$routeList = $this->app->route->getRuleList();
|
||||
$resp = [];
|
||||
|
||||
foreach ($routeList as $k => $item) {
|
||||
if ($item['option'] && isset($item['option']['_auth']) && $item['option']['_auth']) {
|
||||
if (!(strpos($item['name'], '/') !== false) && !(strpos($item['name'], '@') !== false)) {
|
||||
if (isset($item['option']['_init'])) {
|
||||
$route = (new $item['option']['_init'][0]())->create($item, $item['option']['_init'][1]);
|
||||
} else {
|
||||
$route = [$item];
|
||||
}
|
||||
if ($route) {
|
||||
foreach ($route as $one) {
|
||||
if (!isset($one['option']['_name'])) $one['option']['_name'] = $one['name'];
|
||||
$this->menu($one['option']['_path'] ?? '', $one['option'], $resp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return app()->make(MenuRepository::class)->commandMenu($type, $resp, $prompt);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param $_path
|
||||
* @param $data
|
||||
* @param array $resp
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 3/18/22
|
||||
*/
|
||||
protected function menu($_path, $data, &$resp = [], $isAppend = 0)
|
||||
{
|
||||
$check = true;
|
||||
if ($_path && is_array($data)) {
|
||||
$v = [
|
||||
'route' => $data['_name'],
|
||||
'menu_name' => $data['_alias'] ?? '权限',
|
||||
'params' => $data['_params'] ?? '',
|
||||
];
|
||||
if (!isset($data['_repeat']) || (isset($data['_repeat']) && !$data['_repeat'])){
|
||||
$check = $this->checkRepeat($v['route'], $v['menu_name']);
|
||||
$this->k[] = $v['route'];
|
||||
$this->kv[$v['route']] = $v['menu_name'];
|
||||
}
|
||||
|
||||
if (!$check) {
|
||||
throw new Exception( "路由名重复 < " . $v['route']. ' >' . '「'. $v['menu_name']. ' 」');
|
||||
}
|
||||
if ($isAppend) {
|
||||
$_path = 'append_'.$_path;
|
||||
}
|
||||
|
||||
$resp[$_path][$data['_name']] = $v;
|
||||
|
||||
if (isset($data['_append']) && !empty($data['_append'])) {
|
||||
foreach ($data['_append'] as $datum) {
|
||||
$datum['_repeat'] = true;
|
||||
$this->menu($datum['_path'] ?? $data['_path'], $datum, $resp, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
protected function checkRepeat($key, $value)
|
||||
{
|
||||
if (in_array($key, $this->k)) {
|
||||
if ($value != $this->kv[$key]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\repositories\store\CityAreaRepository;
|
||||
use app\common\repositories\store\product\SpuRepository;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\console\input\Option;
|
||||
|
||||
class updateCityArea extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('update:city')
|
||||
->setDescription('更新数据地址信息,城市数据');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/15
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln('开始执行');
|
||||
$this->updateData();
|
||||
$this->changSnum();
|
||||
$output->writeln('执行完成');
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果需要重新导入数据,将需要导入的文件 addres.txt 文件放到项目目录下 和 public平级
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2024/1/19
|
||||
*/
|
||||
public function updateData()
|
||||
{
|
||||
$fiel = root_path().'addres.txt';
|
||||
if (file_exists($fiel)) {
|
||||
app()->make(CityAreaRepository::class)->updateCityForTxt($fiel);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计每个地址的子集数量
|
||||
* @author Qinii
|
||||
* @day 2024/1/19
|
||||
*/
|
||||
public function changSnum()
|
||||
{
|
||||
app()->make(CityAreaRepository::class)->sumChildren();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use app\common\repositories\store\product\SpuRepository;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\console\input\Option;
|
||||
|
||||
class updateSpu extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->setName('spu')
|
||||
->addOption('productType', null, Option::VALUE_REQUIRED, 'product type :0,1,2,3')
|
||||
->setDescription('the update spu command');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/15
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return int|void|null
|
||||
*/
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$prodcutType = [];
|
||||
if ($input->hasOption('productType')){
|
||||
$tyep = $input->getOption('productType');
|
||||
if(in_array($tyep,[0,1,2,3,4,20])) $prodcutType = [$tyep];
|
||||
}
|
||||
$output->writeln('开始执行');
|
||||
$this->checkAndUpdateSpu($prodcutType);
|
||||
$output->writeln('执行完成');
|
||||
}
|
||||
|
||||
public function checkAndUpdateSpu($prodcutType)
|
||||
{
|
||||
//TODO 如果数据量过大运行时间过长请设置脚本运行时间
|
||||
// set_time_limit(0);
|
||||
app()->make(SpuRepository::class)->updateSpu($prodcutType);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,310 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\Collection;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\db\Query;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* Class BaseDao
|
||||
* @package app\common\dao
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
abstract class BaseDao
|
||||
{
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
abstract protected function getModel(): string;
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public function getPk()
|
||||
{
|
||||
return ($this->getModel())::tablePk();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-03-27
|
||||
*/
|
||||
public function exists(int $id)
|
||||
{
|
||||
return $this->fieldExists($this->getPk(), $id);
|
||||
}
|
||||
|
||||
public function merInExists(int $merId, $ids)
|
||||
{
|
||||
$pk = ($this->getModel())::getDB()->where('mer_id',$merId)->where($this->getPk(),'in',$ids)->column($this->getPk());
|
||||
$ids = is_array($ids) ? $ids : explode(',',$ids);
|
||||
sort($ids);
|
||||
sort($pk);
|
||||
return $ids == $pk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return BaseModel
|
||||
*/
|
||||
public function query(array $where):Query
|
||||
{
|
||||
return ($this->getModel())::getInstance()->where($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param int|null $except
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
public function fieldExists($field, $value, ?int $except = null): bool
|
||||
{
|
||||
$query = ($this->getModel())::getDB()->where($field, $value);
|
||||
if (!is_null($except)) $query->where($this->getPk(), '<>', $except);
|
||||
return $query->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return self|Model
|
||||
* @author xaboy
|
||||
* @day 2020-03-27
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
return ($this->getModel())::create($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-03-27
|
||||
*/
|
||||
public function update(int $id, array $data)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where($this->getPk(), $id)->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param array $data
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function updates(array $ids, array $data)
|
||||
{
|
||||
return ($this->getModel())::getDB()->whereIn($this->getPk(), $ids)->update($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-03-27
|
||||
*/
|
||||
public function delete(int $id)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where($this->getPk(), $id)->delete();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-03-27
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return ($this->getModel())::getInstance()->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param string $field
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/1
|
||||
*/
|
||||
public function getWhere(array $where, string $field = '*', array $with = [])
|
||||
{
|
||||
return ($this->getModel())::getInstance()->where($where)->when($with, function ($query) use ($with) {
|
||||
$query->with($with);
|
||||
})->field($field)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param string $field
|
||||
* @return Collection
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/1
|
||||
*/
|
||||
public function selectWhere(array $where, string $field = '*')
|
||||
{
|
||||
return ($this->getModel())::getInstance()->where($where)->field($field)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param array $with
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-03-27
|
||||
*/
|
||||
public function getWith(int $id, $with = [])
|
||||
{
|
||||
return ($this->getModel())::getInstance()->with($with)->find($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return int
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function insertAll(array $data)
|
||||
{
|
||||
return ($this->getModel())::getDB()->insertAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 通过条件判断是否存在
|
||||
* @param array $where
|
||||
* @author Qinii
|
||||
* @day 2020-06-13
|
||||
*/
|
||||
public function getWhereCount(array $where)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where($where)->count();
|
||||
}
|
||||
|
||||
public function existsWhere($where)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where($where)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 查询,如果不存在就创建
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/9/8
|
||||
* @param array $where
|
||||
* @return array|Model|null
|
||||
*/
|
||||
public function findOrCreate(array $where)
|
||||
{
|
||||
$res = ($this->getModel()::getDB())->where($where)->find();
|
||||
if(!$res)$res = $this->getModel()::create($where);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 搜索
|
||||
* @param $where
|
||||
* @return BaseModel
|
||||
* @author Qinii
|
||||
* @day 2020-10-16
|
||||
*/
|
||||
public function getSearch(array $where)
|
||||
{
|
||||
foreach ($where as $key => $item) {
|
||||
if ($item !== '') {
|
||||
$keyArray[] = $key;
|
||||
$whereArr[$key] = $item;
|
||||
}
|
||||
}
|
||||
if(empty($keyArray)){
|
||||
return ($this->getModel())::getDB();
|
||||
}else{
|
||||
return ($this->getModel())::withSearch($keyArray, $whereArr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 自增
|
||||
* @param array $id
|
||||
* @param string $field
|
||||
* @param int $num
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 1/11/21
|
||||
*/
|
||||
public function incField(int $id, string $field , $num = 1)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where($this->getPk(),$id)->inc($field,$num)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 自减
|
||||
* @param array $id
|
||||
* @param string $field
|
||||
* @param int $num
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 1/11/21
|
||||
*/
|
||||
public function decField(int $id, string $field , $num = 1)
|
||||
{
|
||||
return ($this->getModel()::getDB())
|
||||
->where($this->getPk(),$id)
|
||||
->where($field, '>=' ,$num)
|
||||
->dec($field,$num)->update();
|
||||
}
|
||||
|
||||
public function merHas(int $merId, int $id, ?int $isDel = 0)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where($this->getPk(), $id)->where('mer_id', $merId)
|
||||
->when(!is_null($isDel), function($query) use($isDel) {
|
||||
$query->where('is_del', $isDel);
|
||||
})->count($this->getPk()) > 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\article;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\article\ArticleCategory;
|
||||
use app\common\model\BaseModel;
|
||||
use think\Collection;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* Class ArticleCategoryDao
|
||||
* @package app\common\dao\article
|
||||
* @author xaboy
|
||||
* @day 2020-04-20
|
||||
*/
|
||||
class ArticleCategoryDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ArticleCategory::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $mer_id
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020-04-20
|
||||
*/
|
||||
public function getAllOptions($mer_id = 0)
|
||||
{
|
||||
return ArticleCategory::getDB()->where('mer_id', $mer_id)->order('sort DESC')->column('pid,title', $this->getPk());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $mer_id
|
||||
* @return Collection
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-20
|
||||
*/
|
||||
public function getAll($mer_id = 0,$status = null)
|
||||
{
|
||||
return ArticleCategory::getDB()->where('mer_id', $mer_id)->when($status,function($query)use($status){
|
||||
$query->where('status',$status);
|
||||
})->order('sort DESC')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return \think\db\BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/9/18
|
||||
*/
|
||||
public function search(array $where)
|
||||
{
|
||||
return ArticleCategory::getDB()->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
$query->where('status', $where['status']);
|
||||
})->when(isset($where['pid']) && $where['pid'] !== '', function ($query) use ($where) {
|
||||
$query->where('pid', $where['pid']);
|
||||
})->order('sort DESC, article_category_id DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-20
|
||||
*/
|
||||
public function merFieldExists(int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->where('mer_id', $merId)->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param int $id
|
||||
* @param null $except
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-20
|
||||
*/
|
||||
public function merExists(int $merId, int $id, $except = null)
|
||||
{
|
||||
return $this->merFieldExists($merId, $this->getPk(), $id, $except);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $merId
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-15
|
||||
*/
|
||||
public function get( $id, $merId = 0)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where('mer_id', 0)->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $merId
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-04-20
|
||||
*/
|
||||
public function delete(int $id, $merId = 0)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->delete();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\article;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class ArticleContentDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ArticleContentDao::class;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\article;
|
||||
|
||||
use think\Collection;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\BaseModel;
|
||||
use think\Model;
|
||||
|
||||
class ArticleDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return Article::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $mer_id
|
||||
* @return Collection
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function getAll($mer_id = 0)
|
||||
{
|
||||
return Article::getDB()->with('content')->where('mer_id', $mer_id)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索列表
|
||||
* @param $merId
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author Qinii
|
||||
*/
|
||||
public function search($merId,array $where)
|
||||
{
|
||||
$query = Article::getDB();
|
||||
if (isset($where['cid']) && $where['cid'] !== '') $query->where('cid', (int)$where['cid']);
|
||||
if (isset($where['title']) && $where['title'] !== '') $query->whereLike('title', "%{$where['title']}%");
|
||||
if (isset($where['status']) && $where['status'] !== '') $query->where('status', $where['status']);
|
||||
if (isset($where['wechat_news_id']) && $where['wechat_news_id'] !== '') $query->where('wechat_news_id', $where['wechat_news_id']);
|
||||
|
||||
if (isset($where['article_id']) && $where['article_id'] !== ''){
|
||||
if (is_array($where['article_id'])) {
|
||||
$query->whereIn('article_id', $where['article_id']);
|
||||
} else {
|
||||
$query->where('article_id', $where['article_id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$query->with(['content','articleCategory']);
|
||||
|
||||
return $query->where('mer_id',$merId)->order('sort DESC,create_time DESC');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据 字段名查询
|
||||
* @param int $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
*/
|
||||
public function merFieldExists(int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->where('mer_id', $merId)->where('wechat_news_id',0)->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $merId
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-04-20
|
||||
*/
|
||||
public function delete(int $id, int $merId = 0)
|
||||
{
|
||||
$result = ($this->getModel())::getDB()->where('mer_id', $merId)
|
||||
->where($this->getPk(),$id)
|
||||
->with('content')
|
||||
->find();
|
||||
return $result->together(['content'])->delete();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 关联添加
|
||||
* @param array $data
|
||||
* @return BaseDao|Model|void
|
||||
* @author Qinii
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
Db::transaction(function()use($data){
|
||||
$content = $data['content'];
|
||||
unset($data['content']);
|
||||
$article = $this->getModel()::create($data);
|
||||
$article->content()->save(['content' => $content]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联更新
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
* @return int|void
|
||||
* @author Qinii
|
||||
*/
|
||||
public function update(int $id, array $data)
|
||||
{
|
||||
Db::transaction(function()use($id,$data){
|
||||
$content = $data['content'];
|
||||
unset($data['content']);
|
||||
|
||||
$this->getModel()::where($this->getPk(),$id)->update($data);
|
||||
|
||||
$article = $this->getModel()::find($id);
|
||||
$article->content->content = $content;
|
||||
$article->together(['content'])->save();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段获取 主键值
|
||||
* @param int $vale
|
||||
* @param null $field
|
||||
* @return array
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getKey(int $vale,$field = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where($field,$vale)->column($this->getPk());
|
||||
}
|
||||
|
||||
public function wechatNewIdByData($id)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where('wechat_news_id', $id)->select();
|
||||
}
|
||||
|
||||
public function switchStatus($id, $data)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where($this->getPk(),$id)->update($data);
|
||||
}
|
||||
|
||||
public function incVisit($id)
|
||||
{
|
||||
$this->getModel()::getDB()->where($this->getPk(),$id)->inc('visit',1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\community;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\community\CommunityCategory;
|
||||
use crmeb\traits\CategoresDao;
|
||||
|
||||
class CommunityCategoryDao extends BaseDao
|
||||
{
|
||||
use CategoresDao;
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return CommunityCategory::class;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\community;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\community\Community;
|
||||
use app\common\model\system\Relevance;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
|
||||
class CommunityDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return Community
|
||||
*
|
||||
* @date 2023/10/21
|
||||
* @author yyw
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return Community::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = Community::hasWhere('author', function($query) use ($where){
|
||||
$query->when(isset($where['username']) && $where['username'] !== '', function ($query) use($where) {
|
||||
$query->whereLike('real_name|phone|nickname',"%{$where['username']}%");
|
||||
});
|
||||
$query->where(true);
|
||||
});
|
||||
$query->when(isset($where['search_type']) && $where['search_type'] !== '', function ($query) use ($where) {
|
||||
if(isset($where['keyword']) && $where['keyword'] !== ''){
|
||||
if($where['search_type'] == 'all'){
|
||||
$query->whereLike('Community.title|Community.content|User.nickname',"%{$where['keyword']}%");
|
||||
}
|
||||
if($where['search_type'] == 'content'){
|
||||
$query->whereLike('Community.title|Community.content',"%{$where['keyword']}%");
|
||||
}
|
||||
if($where['search_type'] == 'user'){
|
||||
$query->whereLike('User.nickname',"%{$where['keyword']}%");
|
||||
}
|
||||
}
|
||||
},function ($query) use ($where) { // 兼容之前逻辑
|
||||
if(isset($where['keyword']) && $where['keyword'] !== ''){
|
||||
$query->whereLike('Community.title',"%{$where['keyword']}%");
|
||||
}
|
||||
})
|
||||
// ->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use($where) {
|
||||
// $query->whereLike('Community.title',"%{$where['keyword']}%");
|
||||
// })
|
||||
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.uid',$where['uid']);
|
||||
})
|
||||
->when(isset($where['uids']) && $where['uids'] !== '', function ($query) use($where) {
|
||||
$query->whereIn('Community.uid',$where['uids']);
|
||||
})
|
||||
->when(isset($where['topic_id']) && $where['topic_id'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.topic_id',$where['topic_id']);
|
||||
})
|
||||
->when(isset($where['community_id']) && $where['community_id'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.community_id',$where['community_id']);
|
||||
})
|
||||
->when(isset($where['not_id']) && $where['not_id'] !== '', function ($query) use($where) {
|
||||
$query->whereNotIn('Community.community_id',$where['not_id']);
|
||||
})
|
||||
->when(isset($where['in_id']) && $where['in_id'] !== '', function ($query) use($where) {
|
||||
$query->whereOr(function($query) use($where){
|
||||
$query->whereIn('Community.community_id',$where['in_id']);
|
||||
});
|
||||
})
|
||||
->when(isset($where['community_ids']) && $where['community_ids'] !== '', function ($query) use($where) {
|
||||
$query->whereIn('Community.community_id',$where['community_ids']);
|
||||
})
|
||||
->when(isset($where['is_type']) && $where['is_type'] !== '', function ($query) use($where) {
|
||||
$query->whereIn('Community.is_type',$where['is_type']);
|
||||
})
|
||||
->when(isset($where['is_show']) && $where['is_show'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.is_show',$where['is_show']);
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.status',$where['status']);
|
||||
})
|
||||
->when(isset($where['start']) && $where['start'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.start',$where['start']);
|
||||
})
|
||||
->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.is_del',$where['is_del']);
|
||||
})
|
||||
->when(isset($where['category_id']) && $where['category_id'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.category_id',$where['category_id']);
|
||||
})
|
||||
->when(isset($where['spu_id']) && $where['spu_id'] !== '', function ($query) use($where) {
|
||||
$id = Relevance::where('right_id', $where['spu_id'])
|
||||
->where('type',RelevanceRepository::TYPE_COMMUNITY_PRODUCT)
|
||||
->column('left_id');
|
||||
$query->where('community_id','in', $id);
|
||||
});
|
||||
|
||||
$order = 'Community.create_time DESC';
|
||||
|
||||
if (isset($where['order']) && $where['order'] == 'start') {
|
||||
$order = 'Community.start DESC,Community.create_time DESC';
|
||||
}
|
||||
|
||||
$query->order($order);
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function uidExists(int $id, int $uid)
|
||||
{
|
||||
return $this->getModel()::getDb()->where('uid',$uid)->where($this->getPk(),$id)->count() > 0;
|
||||
}
|
||||
|
||||
public function exists(int $id)
|
||||
{
|
||||
return $this->getModel()::getDb()->where('is_del',0)->where($this->getPk(),$id)->count() > 0;
|
||||
}
|
||||
|
||||
public function destoryByUid($uid)
|
||||
{
|
||||
return $this->getModel()::getDb()->where('uid' ,$uid)->update(['is_del' => 1]);
|
||||
}
|
||||
|
||||
public function joinUser($where)
|
||||
{
|
||||
return Community::hasWhere('relevanceRight',function($query) use($where){
|
||||
$query->where('type',RelevanceRepository::TYPE_COMMUNITY_START)->where('left_id',$where['uid']);
|
||||
})
|
||||
->when(isset($where['is_type']) && $where['is_type'] !== '', function ($query) use($where) {
|
||||
$query->whereIn('Community.is_type',$where['is_type']);
|
||||
})
|
||||
->when(isset($where['is_show']) && $where['is_show'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.is_show',$where['is_show']);
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.status',$where['status']);
|
||||
})
|
||||
->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.is_del',$where['is_del']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计每个用户的帖子数量
|
||||
* @return mixed
|
||||
*
|
||||
* @date 2023/10/21
|
||||
* @author yyw
|
||||
*/
|
||||
public function getCountByGroupUid()
|
||||
{
|
||||
return $this->getModel()::getDb()->where('is_del', 0)->field('uid,count(community_id) as count')->group('uid')->select()->toArray();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\community;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\community\CommunityReply;
|
||||
|
||||
class CommunityReplyDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return CommunityReply::class;
|
||||
}
|
||||
|
||||
public function uidExists(int $id, int $uid)
|
||||
{
|
||||
return $this->getModel()::getDb()->where($this->getPk(), $id)->where('uid', $uid)->where('is_del', 0)->find();
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = CommunityReply::hasWhere('author',function($query) use($where) {
|
||||
$query->when(isset($where['username']) && $where['username'] !== '', function ($query) use($where) {
|
||||
$query->whereLike('nickname',"%{$where['username']}%");
|
||||
});
|
||||
$query->where(true);
|
||||
});
|
||||
|
||||
$query->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use($where) {
|
||||
$query->whereLike('content',"%{$where['keyword']}%");
|
||||
});
|
||||
$query->when(isset($where['date']) && $where['date'] !== '', function ($query) use($where) {
|
||||
getModelTime($query, $where['date'], 'CommunityReply.create_time');
|
||||
});
|
||||
$query->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use($where) {
|
||||
$query->where('is_del',$where['is_del']);
|
||||
});
|
||||
|
||||
$query->when(isset($where['pid']) && $where['pid'] !== '', function ($query) use($where) {
|
||||
$query->where('pid',$where['pid']);
|
||||
});
|
||||
|
||||
$query->when(isset($where['community_id']) && $where['community_id'] !== '', function ($query) use($where) {
|
||||
$query->where('community_id',$where['community_id']);
|
||||
});
|
||||
return $query->order('CommunityReply.create_time DESC');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\community;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\community\CommunityTopic;
|
||||
|
||||
class CommunityTopicDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return CommunityTopic::class;
|
||||
}
|
||||
|
||||
public function countInc(int $id, string $filed, int $inc = 1)
|
||||
{
|
||||
return $this->getModel()::getDb()->where($this->getPk(), $id)->inc($filed, $inc)->update();
|
||||
}
|
||||
|
||||
public function countDec(int $id, string $filed, int $dec = 1)
|
||||
{
|
||||
try{
|
||||
return $this->getModel()::getDb()->where($this->getPk(), $id)->dec($filed, $dec)->update();
|
||||
}catch (\Exception $exception) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\delivery;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\delivery\DeliveryOrder;
|
||||
|
||||
class DeliveryOrderDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return DeliveryOrder::class;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\delivery;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\delivery\DeliveryStation;
|
||||
|
||||
class DeliveryStationDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return DeliveryStation::class;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\openapi;
|
||||
|
||||
use app\common\model\openapi\OpenAuth;
|
||||
use app\common\dao\BaseDao;
|
||||
|
||||
class OpenAuthDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return OpenAuth::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = $this->getModel()::getDB()
|
||||
->when(isset($where['type']) && $where['type'] !== '',function($query) use($where){
|
||||
$query->where('type',$where['type']);
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query) use($where){
|
||||
$query->where('mer_id',$where['mer_id']);
|
||||
});
|
||||
$query->order('create_time DESC');
|
||||
return $query;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\CityArea;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class CityAreaDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return CityArea::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
return CityArea::getDB()->when(isset($where['pid']) && $where['pid'] !== '', function ($query) use ($where) {
|
||||
$query->where('parent_id', $where['pid']);
|
||||
})->when(isset($where['address']) && $where['address'] !== '', function ($query) use ($where) {
|
||||
$address = explode('/', trim($where['address'], '/'));
|
||||
$p = array_shift($address);
|
||||
$_p = $p;
|
||||
if (mb_strlen($p) - 1 === mb_strpos($p, '市')) {
|
||||
$p = mb_substr($p, 0, -1);
|
||||
} elseif (mb_strlen($p) - 1 === mb_strpos($p, '省')) {
|
||||
$p = mb_substr($p, 0, -1);
|
||||
} elseif (mb_strlen($p) - 3 === mb_strpos($p, '自治区')) {
|
||||
$p = mb_substr($p, 0, -3);
|
||||
}
|
||||
$pcity = $this->search([])->where('name', $p)->find();
|
||||
if (!$pcity) $pcity = $this->search([])->where('name', $_p)->find();
|
||||
if (!$pcity) throw new ValidateException('获取地址失败'.$_p);
|
||||
$street = array_pop($address);
|
||||
if ($pcity) {
|
||||
$path = '/' . $pcity->id . '/';
|
||||
$query->whereLike('path', "/{$pcity->id}/%");
|
||||
foreach ($address as $item) {
|
||||
$id = $this->search([])->whereLike('path', $path . '%')->where('name', $item)->value('id');
|
||||
if ($id) {
|
||||
$path .= $id . '/';
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$query->whereLike('path', $path . '%')->where('name', $street);
|
||||
});
|
||||
}
|
||||
|
||||
public function getCityList(CityArea $city)
|
||||
{
|
||||
if (!$city->parent_id) return [$city];
|
||||
$lst = $this->search([])->where('id', 'in', explode('/', trim($city->path, '/')))->order('id ASC')->select();
|
||||
$lst[] = $city;
|
||||
return $lst;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\model\store\Excel;
|
||||
use app\common\dao\BaseDao;
|
||||
|
||||
class ExcelDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return string
|
||||
* @author Qinii
|
||||
* @day 2020-07-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return Excel::class;
|
||||
}
|
||||
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = $this->getModel()::getDB()
|
||||
->when(isset($where['type']) && $where['type'] !== '',function($query) use($where){
|
||||
$query->where('type',$where['type']);
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query) use($where){
|
||||
$query->where('mer_id',$where['mer_id']);
|
||||
})
|
||||
->when(isset($where['admin_id']) && $where['admin_id'] !== '',function($query) use($where){
|
||||
$query->where('admin_id',$where['admin_id']);
|
||||
});
|
||||
$query->order('create_time DESC');
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取小于某个时间的文件
|
||||
* @param $time
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-08-15
|
||||
*/
|
||||
public function getDelByTime($time)
|
||||
{
|
||||
return $this->getModel()::getDB()->whereTime('create_time','<',$time)->column('path','excel_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 类型
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 9/28/21
|
||||
*/
|
||||
public function getTypeData()
|
||||
{
|
||||
$data = (new Excel())->typeData;
|
||||
foreach ($data as $k => $v) {
|
||||
$ret[] = [
|
||||
'key' => $k,
|
||||
'value' => $v,
|
||||
];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\Guarantee;
|
||||
|
||||
class GuaranteeDao extends BaseDao
|
||||
{
|
||||
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return Guarantee::class;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\GuaranteeTemplate;
|
||||
|
||||
class GuaranteeTemplateDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return GuaranteeTemplate::class;
|
||||
}
|
||||
|
||||
public function clear($id,$field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\GuaranteeValue;
|
||||
|
||||
class GuaranteeValueDao extends BaseDao
|
||||
{
|
||||
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return GuaranteeValue::class;
|
||||
}
|
||||
|
||||
public function chageStatus(int $id,int $status)
|
||||
{
|
||||
$this->getModel()::getDB()->where('guarantee_id',$id)->update(['status' => $status]);
|
||||
}
|
||||
|
||||
public function clear($id)
|
||||
{
|
||||
$this->getModel()::getDB()->where('guarantee_template_id',$id)->delete();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\PriceRule;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
|
||||
class PriceRuleDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return PriceRule::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
return PriceRule::getDB()->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('rule_name', "%{$where['keyword']}%");
|
||||
})->when(isset($where['is_show']) && $where['is_show'] !== '', function ($query) use ($where) {
|
||||
$query->where('is_show', $where['is_show']);
|
||||
})->when(isset($where['cate_id']) && $where['cate_id'] !== '', function ($query) use ($where) {
|
||||
$ids = app()->make(RelevanceRepository::class)->query([
|
||||
'type' => RelevanceRepository::PRICE_RULE_CATEGORY
|
||||
])->where(function ($query) use ($where) {
|
||||
if (is_array($where['cate_id'])) {
|
||||
$query->whereIn('right_id', $where['cate_id']);
|
||||
} else {
|
||||
$query->where('right_id', (int)$where['cate_id']);
|
||||
}
|
||||
})->group('left_id')->column('left_id');
|
||||
$ids[] = -1;
|
||||
$query->where(function ($query) use ($ids) {
|
||||
$query->whereIn('rule_id', $ids)->whereOr('is_default', 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\StoreActivity;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class StoreActivityDao
|
||||
* @package app\common\dao\system\merchant
|
||||
*/
|
||||
class StoreActivityDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreActivity::class;
|
||||
}
|
||||
|
||||
public function search(array $where = [], array $with = [])
|
||||
{
|
||||
$where['is_del'] = 0;
|
||||
return $this->getSearch($where)->when(!empty($with), function ($query) use ($with) {
|
||||
$query->with($with);
|
||||
});
|
||||
}
|
||||
|
||||
public function incTotal($id, $inc = 1)
|
||||
{
|
||||
$res = $this->getModel()::getDb()->where($this->getPk(), $id)->find();
|
||||
if (empty($res)) {
|
||||
throw new ValidateException('活动数据异常');
|
||||
}
|
||||
$total = $res['total'] + $inc;
|
||||
if ($res['count'] && $res['count'] < $total) throw new ValidateException('超出总数限制');
|
||||
$res->total = $total;
|
||||
$res->save();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\StoreActivity;
|
||||
use app\common\model\store\StoreActivityRelated;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class StoreActivityDao
|
||||
* @package app\common\dao\system\merchant
|
||||
*/
|
||||
class StoreActivityRelatedDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreActivityRelated::class;
|
||||
}
|
||||
|
||||
public function search(array $where = [])
|
||||
{
|
||||
return $this->getSearch($where);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\StoreAttrTemplate;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* Class StoreAttrTemplateDao
|
||||
* @package app\common\dao\store
|
||||
* @author xaboy
|
||||
* @day 2020-05-06
|
||||
*/
|
||||
class StoreAttrTemplateDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreAttrTemplate::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $merId
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020-05-06
|
||||
*/
|
||||
public function search($merId, array $where = [])
|
||||
{
|
||||
return StoreAttrTemplate::getDB()->when(isset($where['keyword']),function($query) use($where){
|
||||
$query->whereLike('template_name',"%{$where['keyword']}%");
|
||||
})->where('mer_id', $merId)->order('attr_template_id DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param int $id
|
||||
* @param null $except
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-15
|
||||
*/
|
||||
public function merExists(int $merId, int $id, $except = null)
|
||||
{
|
||||
return $this->merFieldExists($merId, $this->getPk(), $id, $except);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-04-15
|
||||
*/
|
||||
public function merFieldExists(int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->where('mer_id', $merId)->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $merId
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020-04-15
|
||||
*/
|
||||
public function get( $id, $merId = 0)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where('mer_id', $merId)->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $merId
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-04-15
|
||||
*/
|
||||
public function delete($id, $merId = 0)
|
||||
{
|
||||
$query = ($this->getModel())::getDB()->where('mer_id', $merId);
|
||||
if (is_array($id)) {
|
||||
$query->where($this->getPk(), 'in',$id);
|
||||
} else {
|
||||
$query->where($this->getPk(), $id);
|
||||
}
|
||||
return $query->delete();
|
||||
}
|
||||
|
||||
public function getList($merId)
|
||||
{
|
||||
return ($this->getModel())::getDB()->where('mer_id',$merId)->field('attr_template_id,template_name,template_value')->select();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\StoreBrandCategory as model;
|
||||
use crmeb\traits\CategoresDao;
|
||||
|
||||
class StoreBrandCategoryDao extends BaseDao
|
||||
{
|
||||
|
||||
use CategoresDao;
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
public function getMaxLevel()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getAll($mer_id = 0,$status = null)
|
||||
{
|
||||
return $this->getModel()::getDB()->when(($status !== null),function($query)use($status){
|
||||
$query->where($this->getStatus(),$status);
|
||||
})->order('sort DESC')->select();
|
||||
}
|
||||
|
||||
public function merFieldExists(int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()
|
||||
->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})
|
||||
->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
public function getAllByField( $field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()
|
||||
->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})
|
||||
->where($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/7/22
|
||||
*/
|
||||
public function options()
|
||||
{
|
||||
return model::getDB()->where('is_show', 1)->order('sort DESC')->column('pid,cate_name', 'store_brand_category_id');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\StoreBrand as model;
|
||||
use crmeb\traits\CategoresDao;
|
||||
|
||||
class StoreBrandDao extends BaseDao
|
||||
{
|
||||
|
||||
use CategoresDao;
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
$query = $this->getModel()::hasWhere('brandCategory',function($query){
|
||||
$query->where('is_show',1);
|
||||
});
|
||||
$query->where('StoreBrand.is_show',1);
|
||||
$list = $query->order('StoreBrand.sort DESC,StoreBrand.create_time DESC')->select()->toArray();
|
||||
array_push($list,[
|
||||
"brand_id" => 0,
|
||||
"brand_category_id" => 0,
|
||||
"brand_name" => "其他",
|
||||
"sort" => 999,
|
||||
"pic" => "",
|
||||
"is_show" => 1,
|
||||
"create_time" => "",
|
||||
]);
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
public function merFieldExists($field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()
|
||||
->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})
|
||||
->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = $this->getModel()::getDB();
|
||||
if(isset($where['brand_category_id']) && $where['brand_category_id'])
|
||||
$query->where('brand_category_id',$where['brand_category_id']);
|
||||
if(isset($where['brand_name']) && $where['brand_name'])
|
||||
$query->where('brand_name','like','%'.$where['brand_name'].'%');
|
||||
if((isset($where['ids']) && $where['ids']))
|
||||
$query->where($this->getPk(),'in',$where['ids']);
|
||||
return $query->order('sort DESC,create_time desc');
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\StoreCategory as model;
|
||||
use crmeb\traits\CategoresDao;
|
||||
|
||||
class StoreCategoryDao extends BaseDao
|
||||
{
|
||||
|
||||
use CategoresDao;
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
public function getAll($mer_id = 0,$status = null, $type = 0)
|
||||
{
|
||||
return $this->getModel()::getDB()
|
||||
->where('mer_id', $mer_id)
|
||||
->where('type',$type)
|
||||
->when(($status !== null),function($query)use($status){
|
||||
$query->where($this->getStatus(),$status);
|
||||
})
|
||||
->order('sort DESC,'.$this->getPk().' DESC')
|
||||
->select()
|
||||
->append(['has_product']);
|
||||
}
|
||||
|
||||
public function findChildrenId($id)
|
||||
{
|
||||
return model::getDB()->whereLike('path', '%/'. $id . '/%')->column('store_category_id');
|
||||
}
|
||||
|
||||
public function selectChildrenId(array $ids)
|
||||
{
|
||||
if (!is_array($ids) || empty($ids)) return [];
|
||||
$query = model::getDB()->where(function($query) use($ids){
|
||||
foreach ($ids as $id) {
|
||||
$query->whereOr('path', 'like','%/'. $id . '/%');
|
||||
}
|
||||
});
|
||||
return $query->column('store_category_id');
|
||||
}
|
||||
|
||||
|
||||
public function fieldExistsList(?int $merId,$field,$value,$except = null)
|
||||
{
|
||||
return ($this->getModel()::getDB())->when($except ,function($query)use($field,$except){
|
||||
$query->where($field,'<>',$except);
|
||||
})->when(($merId !== null) ,function($query)use($merId){
|
||||
$query->where('mer_id',$merId);
|
||||
})->where($field,$value);
|
||||
|
||||
}
|
||||
|
||||
public function getTwoLevel($merId = 0)
|
||||
{
|
||||
$pid = model::getDB()->where('pid', 0)->where('is_show',1)->where('type',0)->where('mer_id', $merId)->order('sort DESC')->column('store_category_id');
|
||||
return model::getDB()->whereIn('pid', $pid)->where('is_show', 1)->where('mer_id', $merId)->limit(20)->order('sort DESC')->column('store_category_id,cate_name,pid');
|
||||
}
|
||||
|
||||
public function children($pid, $merId = 0)
|
||||
{
|
||||
return model::getDB()->where('pid', $pid)->where('mer_id', $merId)->where('is_show', 1)->order('sort DESC')->column('store_category_id,cate_name,pic');
|
||||
}
|
||||
|
||||
public function allChildren($id)
|
||||
{
|
||||
$path = model::getDB()->where('store_category_id', is_array($id) ? 'IN' : '=', $id)->where('mer_id', 0)->column('path', 'store_category_id');
|
||||
if (!count($path)) return [];
|
||||
return model::getDB()->where(function ($query) use ($path) {
|
||||
foreach ($path as $k => $v) {
|
||||
$query->whereOr('path', 'LIKE', "$v$k/%");
|
||||
}
|
||||
})->where('mer_id', 0)->order('sort DESC')->column('store_category_id');
|
||||
}
|
||||
|
||||
public function idsByAllChildren(array $ids)
|
||||
{
|
||||
$paths = model::getDB()->whereIn('store_category_id', $ids)->where('mer_id', 0)->column('path');
|
||||
if (!count($paths)) return [];
|
||||
return model::getDB()->where(function ($query) use ($paths) {
|
||||
foreach ($paths as $path) {
|
||||
$query->whereOr('path', 'LIKE', "$path%");
|
||||
}
|
||||
})->where('mer_id', 0)->order('sort DESC')->column('store_category_id');
|
||||
}
|
||||
|
||||
public function getMaxLevel($merId = null)
|
||||
{
|
||||
if($merId) return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function searchLevelAttr($query, $value)
|
||||
{
|
||||
$query->where('level', $value);
|
||||
}
|
||||
|
||||
public function clear(int $id, string $field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\StorePrinter;
|
||||
|
||||
class StorePrinterDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StorePrinter::class;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,260 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\model\store\StoreSeckillActive;
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\repositories\store\order\StoreOrderProductRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\store\product\ProductAttrValueRepository;
|
||||
use app\common\repositories\store\product\ProductRepository;
|
||||
use app\common\repositories\store\product\SpuRepository;
|
||||
use app\common\repositories\store\StoreSeckillActiveRepository;
|
||||
use think\facade\Log;
|
||||
|
||||
class StoreSeckillActiveDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return string
|
||||
* @author Qinii
|
||||
* @day 2020-07-30
|
||||
*/
|
||||
public function getModel(): string
|
||||
{
|
||||
return StoreSeckillActive::class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
* @param array $where
|
||||
* @return mixed
|
||||
* FerryZhao 2024/4/12
|
||||
*/
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = $this->getModel()::getDB()
|
||||
->when(isset($where['name']) && $where['name'] !== '', function ($query) use ($where) {
|
||||
$query->where('name', 'like', '%' . $where['name'] . '%');
|
||||
})
|
||||
->when(isset($where['active_status']) && $where['active_status'] !== '', function ($query) use ($where) {
|
||||
$query->where('active_status', $where['active_status']);
|
||||
})
|
||||
->when(isset($where['seckill_active_status']) && $where['seckill_active_status'] !== '', function ($query) use ($where) {
|
||||
$query->where('status', $where['seckill_active_status']);
|
||||
})
|
||||
->when(isset($where['seckill_active_id']) && $where['seckill_active_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('seckill_active_id', $where['seckill_active_id']);
|
||||
})
|
||||
->when(isset($where['active_name']) && $where['active_name'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('name', "%{$where['active_name']}%");
|
||||
})
|
||||
->when(isset($where['active_name']) && $where['active_name'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('name', "%{$where['active_name']}%");
|
||||
})
|
||||
->when(!isset($where['sign']), function ($query) use ($where) {
|
||||
$query->where('sign', 1);
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'], function ($query) use ($where) {
|
||||
$timeWhere = explode('-', $where['date']);
|
||||
$query->whereTime('start_day', '>=', $timeWhere[0]);
|
||||
$query->whereTime('end_day', '<=', date('Y-m-d', strtotime($timeWhere[1]) + 24 * 60 * 60));
|
||||
});
|
||||
|
||||
$query->order('status desc,seckill_active_id desc');
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测活动状态关闭spu
|
||||
* @return void
|
||||
* FerryZhao 2024/4/19
|
||||
*/
|
||||
public function valActiveStatus()
|
||||
{
|
||||
try {
|
||||
$storeSeckillActiveRepository = app()->make(StoreSeckillActiveRepository::class);
|
||||
$changeStartIds = $this->getModel()::getDB()->where(['active_status' => 0])->whereTime('start_day', '<', date('Y-m-d H:i:s', time()))->whereTime('end_day', '>', time())->column('seckill_active_id');
|
||||
if (!empty($changeStartIds)) {
|
||||
$storeSeckillActiveRepository->getSearch([])->whereIn('seckill_active_id', $changeStartIds)->update(['active_status' => 1]);
|
||||
}
|
||||
$changeStartingIds = $this->getModel()::getDB()->where(['active_status' => 1])->whereTime('end_day', '<', time())->column('seckill_active_id');
|
||||
if (!empty($changeStartingIds)) {
|
||||
$storeSeckillActiveRepository->getSearch([])->whereIn('seckill_active_id', $changeStartingIds)->update(['active_status' => '-1']);
|
||||
app()->make(SpuRepository::class)->getSearch([
|
||||
'product_type' => 1,
|
||||
'activity_ids' => $changeStartingIds
|
||||
])->update(['status' => 0]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('检测活动状态关闭spu失败,' . $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 不同状态商品
|
||||
* @param $status
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-08-19
|
||||
*/
|
||||
public function getStatus($status)
|
||||
{
|
||||
$day = date('Y-m-d', time());
|
||||
$_h = date('H', time());
|
||||
$query = $this->getModel()::getDB();
|
||||
if ($status == 1) //未开始
|
||||
$query->where('status', '<>', -1)->where(function ($query) use ($day, $_h) {
|
||||
$query->whereTime('start_day', '>', $day)->whereOr(function ($query) use ($day, $_h) {
|
||||
$query->whereTime('start_day', '<=', $day)->where('start_time', '>', $_h);
|
||||
});
|
||||
});
|
||||
|
||||
if ($status == 2)//进行中
|
||||
$query->where('status', 1)
|
||||
->whereTime('start_day', '<=', $day)->whereTime('end_day', '>', $day)
|
||||
->where('start_time', '<=', $_h)->where('end_time', '>', $_h);
|
||||
|
||||
if ($status == 3) //结束
|
||||
$query->where('status', -1)->whereOr(function ($query) use ($day, $_h) {
|
||||
$query->whereTime('end_day', '<', $day)
|
||||
->whereOr(function ($query) use ($day, $_h) {
|
||||
$query->whereTime('start_day', '<=', $day)->whereTime('end_day', '>=', $day)->where('end_time', '<=', $_h);
|
||||
});
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动参与人列表统计
|
||||
* @param $activeId
|
||||
* @param $merId
|
||||
* @param $where
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return void
|
||||
* FerryZhao 2024/4/28
|
||||
*/
|
||||
public function chartPeople($activeId, $merId = null, $where, int $page = 1, int $limit = 10)
|
||||
{
|
||||
$storeOrderRepository = app()->make(StoreOrderRepository::class);
|
||||
$query = $storeOrderRepository->getSearch([])->alias('ORDERA')
|
||||
->leftJoin('StoreOrderProduct ORDERB', 'ORDERA.order_id = ORDERB.order_id')
|
||||
->leftJoin('User USER', 'USER.uid = ORDERA.uid')
|
||||
->when($merId, function ($query) use ($merId) {
|
||||
$query->where('ORDERA.mer_id', '=', $merId);
|
||||
})
|
||||
->when(isset($where['keyword']) && $where['keyword'], function ($query) use ($where) {
|
||||
$query->whereLike('USER.uid|USER.nickname|USER.phone', "%{$where['keyword']}%");
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'], function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'ORDERA.create_time');
|
||||
})
|
||||
->where([
|
||||
'ORDERB.activity_id' => $activeId,
|
||||
'ORDERA.paid' => 1,
|
||||
'ORDERA.activity_type' => 1,
|
||||
])
|
||||
->where('ORDERA.status','>',-1)
|
||||
->group('ORDERA.uid');
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)
|
||||
->field('sum(ORDERA.total_num) as sum_total_num,sum(ORDERA.pay_price) as sum_pay_price,USER.nickname,USER.uid,count(ORDERA.order_id) as order_count,max(ORDERA.create_time) as create_time,ORDERA.is_del,ORDERA.paid,ORDERA.order_type')
|
||||
->select();
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 活动订单统计列表
|
||||
* @param $activeId
|
||||
* @param $merId
|
||||
* @param $where
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return void
|
||||
* FerryZhao 2024/4/28
|
||||
*/
|
||||
public function chartOrder($activeId, $merId = null, $where, $statusWhere = [], int $page = 1, int $limit = 10)
|
||||
{
|
||||
$storeOrderRepository = app()->make(StoreOrderRepository::class);
|
||||
$orderWhere = [
|
||||
'ORDERB.activity_id' => $activeId,
|
||||
];
|
||||
if (isset($where['status']) && $where['status'] != '') {
|
||||
$orderWhere['StoreOrder.status'] = $where['status'];
|
||||
}
|
||||
$query = $storeOrderRepository->getSearch([])->alias('StoreOrder')
|
||||
->leftJoin('User USER', 'StoreOrder.uid = USER.uid')
|
||||
->leftJoin('StoreOrderProduct ORDERB', 'StoreOrder.order_id = ORDERB.order_id')
|
||||
->when(isset($where['keyword']) && $where['keyword'], function ($query) use ($where) {
|
||||
$query->whereLike('USER.uid|USER.nickname|USER.phone', "%{$where['keyword']}%");
|
||||
})
|
||||
->when($merId, function ($query) use ($merId) {
|
||||
$query->where('StoreOrder.mer_id', '=', $merId);
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'], function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'StoreOrder.create_time');
|
||||
})
|
||||
->where($orderWhere)->where($statusWhere);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)
|
||||
->field('StoreOrder.order_sn,USER.nickname,USER.uid,StoreOrder.status,StoreOrder.pay_price,StoreOrder.total_num,StoreOrder.create_time,StoreOrder.pay_time,StoreOrder.is_del,StoreOrder.paid,StoreOrder.order_type')
|
||||
->order('StoreOrder.order_id desc')
|
||||
->select();
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动商品统计列表
|
||||
* @param $activeId
|
||||
* @param $merId
|
||||
* @param $where
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return void
|
||||
* FerryZhao 2024/4/28
|
||||
*/
|
||||
public function chartProduct($activeId, $merId = null, $where, int $page = 1, int $limit = 10)
|
||||
{
|
||||
$productRepository = app()->make(ProductRepository::class);
|
||||
$storeOrderRepository = app()->make(StoreOrderRepository::class);
|
||||
$storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
|
||||
$productAttrValueRepository = app()->make(ProductAttrValueRepository::class);
|
||||
$productWhere = [
|
||||
'product_type' => 1,
|
||||
'seckill_active_id' => $activeId
|
||||
];
|
||||
if (isset($where['keyword']) && $where['keyword']) {
|
||||
$productWhere['keyword'] = $where['keyword'];
|
||||
}
|
||||
$with = ['attr', 'attrValue', 'merCateId.category', 'storeCategory', 'content', 'seckillActive',
|
||||
'merchant' => function ($query) {
|
||||
$query->with(['typeName', 'categoryName'])->field('mer_id,category_id,type_id,mer_avatar,mer_name,is_trader');
|
||||
},
|
||||
|
||||
];
|
||||
$query = $productRepository->search($merId, $productWhere)->with($with);
|
||||
$count = $query->count();
|
||||
$filed = 'Product.product_id,Product.active_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,U.ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type,param_temp_id,mer_svip_status,svip_price,svip_price_type';
|
||||
$list = $query->page($page, $limit)->setOption('field', [])->where(['Product.is_del' => 0, 'Product.delete' => 0])->field($filed)->select();
|
||||
foreach ($list as &$item){
|
||||
$item['sales'] = $storeOrderRepository->seckillOrderCounut($item['active_id'], $item['product_id']);
|
||||
$item['stock'] = $productAttrValueRepository->getSearch([])->where(['product_id'=>$item['product_id']])->sum('stock');
|
||||
}
|
||||
return compact('count', 'list');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store;
|
||||
|
||||
use app\common\model\store\StoreSeckillTime;
|
||||
use app\common\dao\BaseDao;
|
||||
|
||||
class StoreSeckillTimeDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return string
|
||||
* @author Qinii
|
||||
* @day 2020-07-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreSeckillTime::class;
|
||||
}
|
||||
|
||||
public function getTime($status)
|
||||
{
|
||||
foreach (StoreSeckillTime::ISTIME as $k => $item){
|
||||
if($status && $k !== 24){
|
||||
$time [] = ['value' => $k, 'label' => $item];
|
||||
}
|
||||
if(!$status && $k !== 0){
|
||||
$time [] = ['value' => $k, 'label' => $item];
|
||||
}
|
||||
}
|
||||
return $time;
|
||||
}
|
||||
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = $this->getModel()::getDB()
|
||||
->when(isset($where['status']) && $where['status'] !== '',function($query) use($where){
|
||||
$query->where('status',$where['status']);
|
||||
})
|
||||
->when(isset($where['title']) && $where['title'] !== '',function($query) use($where){
|
||||
$query->where('title','like','%'.$where['title'].'%');
|
||||
})
|
||||
->when(isset($where['start_time']) && $where['start_time'] !== '',function($query) use($where){
|
||||
$query->whereTime('start_time','<=',intval($where['start_time']));
|
||||
})
|
||||
->when(isset($where['end_time']) && $where['end_time'] !== '',function($query) use($where){
|
||||
$query->whereTime('end_time','>=',intval($where['end_time']));
|
||||
});
|
||||
$query->order('start_time ASC');
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 开始时间 在别的时间段中
|
||||
* @param $time
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-07-31
|
||||
*/
|
||||
public function valStartTime($time,$id)
|
||||
{
|
||||
return $this->getModel()::getDB()
|
||||
->when($id,function ($query)use($id){
|
||||
$query->where($this->getPk(),'<>',$id);
|
||||
})->where('start_time','<=',$time)->where('end_time','>',$time)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 结束时间在别的时间段中
|
||||
* @param $time
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-07-31
|
||||
*/
|
||||
public function valEndTime($time,$id)
|
||||
{
|
||||
return $this->getModel()::getDB()
|
||||
->when($id,function ($query)use($id){
|
||||
$query->where($this->getPk(),'<>',$id);
|
||||
})->where('start_time','<',$time)->where('end_time','>=',$time)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 时间段包含了别的时间段
|
||||
* @param array $data
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-07-31
|
||||
*/
|
||||
public function valAllTime(array $data,$id)
|
||||
{
|
||||
return $this->getModel()::getDB()
|
||||
->when($id,function ($query)use($id){
|
||||
$query->where($this->getPk(),'<>',$id);
|
||||
})->where('start_time','>',$data['start_time'])->where('end_time','<=',$data['end_time'])->count();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\store\broadcast;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\broadcast\BroadcastAssistant;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class BroadcastAssistantDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return BroadcastAssistant::class;
|
||||
}
|
||||
|
||||
public function merExists(int $id, int $merId)
|
||||
{
|
||||
return $this->existsWhere([$this->getPk() => $id, 'is_del' => 0, 'mer_id' => $merId]);
|
||||
}
|
||||
|
||||
public function intersection(?string $ids, int $merId)
|
||||
{
|
||||
if (!$ids) return [0];
|
||||
return $this->getModel()::getDb()->whereIn('assistant_id',$ids)->where('mer_id', $merId)->column('assistant_id');
|
||||
}
|
||||
|
||||
public function existsAll($ids, $merId)
|
||||
{
|
||||
foreach ($ids as $id) {
|
||||
$has = $this->getModel()::getDb()->where('assistant_id',$id)->where('mer_id',$merId)->count();
|
||||
if (!$has) throw new ValidateException('ID:'.$id.' 不存在');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\broadcast;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\broadcast\BroadcastGoods;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DbException;
|
||||
|
||||
/**
|
||||
* Class BroadcastGoodsDao
|
||||
* @package app\common\dao\store\broadcast
|
||||
* @author xaboy
|
||||
* @day 2020/7/29
|
||||
*/
|
||||
class BroadcastGoodsDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/7/29
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return BroadcastGoods::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/7/30
|
||||
*/
|
||||
public function delete(int $id)
|
||||
{
|
||||
return $this->update($id, ['is_del' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/7/30
|
||||
*/
|
||||
public function exists(int $id)
|
||||
{
|
||||
return $this->existsWhere(['broadcast_goods_id' => $id, 'is_del' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $merId
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/7/30
|
||||
*/
|
||||
public function merExists(int $id, int $merId)
|
||||
{
|
||||
return $this->existsWhere(['broadcast_goods_id' => $id, 'is_del' => 0, 'is_mer_del' => 0, 'mer_id' => $merId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/7/30
|
||||
*/
|
||||
public function search(array $where)
|
||||
{
|
||||
if (isset($where['is_trader']) && $where['is_trader'] !== '') {
|
||||
$query = BroadcastGoods::hasWhere('merchant', function ($query) use ($where) {
|
||||
$query->where('is_trader', $where['is_trader']);
|
||||
});
|
||||
} else {
|
||||
$query = BroadcastGoods::getDB()->alias('BroadcastGoods');
|
||||
}
|
||||
$query->when(isset($where['mer_id']), function ($query) use ($where) {
|
||||
$query->where('BroadcastGoods.mer_id', $where['mer_id']);
|
||||
})->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('BroadcastGoods.goods_id|BroadcastGoods.mark|BroadcastGoods.name|BroadcastGoods.broadcast_goods_id', "%{$where['keyword']}%");
|
||||
})->when(isset($where['valid']) && $where['valid'] !== '', function ($query) use ($where) {
|
||||
$query->where('BroadcastGoods.is_show', 1);
|
||||
})->when(isset($where['mer_valid']) && $where['mer_valid'] !== '', function ($query) use ($where) {
|
||||
$query->where('BroadcastGoods.is_show', 1)->where('BroadcastGoods.is_mer_show', 1);
|
||||
})->when(isset($where['broadcast_goods_id']) && $where['broadcast_goods_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('BroadcastGoods.broadcast_goods_id', $where['broadcast_goods_id']);
|
||||
})->when(isset($where['status_tag']) && $where['status_tag'] !== '', function ($query) use ($where) {
|
||||
if ($where['status_tag'] == 1) {
|
||||
$query->where('BroadcastGoods.status', 2);
|
||||
} else if ($where['status_tag'] == -1) {
|
||||
$query->where('BroadcastGoods.status', -1);
|
||||
} else if ($where['status_tag'] == 0) {
|
||||
$query->whereIn('BroadcastGoods.status', [0, 1]);
|
||||
}
|
||||
})->where('BroadcastGoods.is_del', 0)->where('BroadcastGoods.is_mer_del', 0);
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function goodsStatusAll()
|
||||
{
|
||||
return BroadcastGoods::getDB()->where('goods_id', '>', 0)->whereIn('audit_status', [0, 1])->column('audit_status', 'goods_id');
|
||||
}
|
||||
|
||||
public function updateGoods($goods_id, $data)
|
||||
{
|
||||
return BroadcastGoods::getDB()->where('goods_id', $goods_id)->update($data);
|
||||
}
|
||||
|
||||
public function goodsList($merId, array $ids)
|
||||
{
|
||||
return BroadcastGoods::getDB()->whereIn('broadcast_goods_id', $ids)->where('mer_id', $merId)->where('is_show', 1)->where('is_mer_show', 1)->where('is_del', 0)->where('status', 2)->select();
|
||||
}
|
||||
|
||||
public function merDelete(int $id)
|
||||
{
|
||||
return $this->update($id, ['is_mer_del' => 1]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\broadcast;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\broadcast\BroadcastRoom;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* Class BroadcastRoomDao
|
||||
* @package app\common\dao\store\broadcast
|
||||
* @author xaboy
|
||||
* @day 2020/7/29
|
||||
*/
|
||||
class BroadcastRoomDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/7/29
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return BroadcastRoom::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/7/30
|
||||
*/
|
||||
public function delete(int $id)
|
||||
{
|
||||
return $this->update($id, ['is_del' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/7/30
|
||||
*/
|
||||
public function exists(int $id)
|
||||
{
|
||||
return $this->existsWhere(['broadcast_room_id' => $id, 'is_del' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $merId
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/7/30
|
||||
*/
|
||||
public function merExists(int $id, int $merId)
|
||||
{
|
||||
return $this->existsWhere(['broadcast_room_id' => $id, 'is_del' => 0, 'is_mer_del' => 0, 'mer_id' => $merId]);
|
||||
}
|
||||
|
||||
public function merDelete(int $id)
|
||||
{
|
||||
return $this->update($id, ['is_mer_del' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/7/30
|
||||
*/
|
||||
public function search(array $where)
|
||||
{
|
||||
if(isset($where['is_trader']) && $where['is_trader'] !== ''){
|
||||
$query = BroadcastRoom::hasWhere('merchant',function($query)use($where){
|
||||
$query->where('is_trader',$where['is_trader']);
|
||||
});
|
||||
}else{
|
||||
$query = BroadcastRoom::getDB()->alias('BroadcastRoom');
|
||||
}
|
||||
$query->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('room_id|name|anchor_name|anchor_wechat|broadcast_room_id', "%{$where['keyword']}%");
|
||||
})->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('BroadcastRoom.mer_id', $where['mer_id']);
|
||||
})->when(isset($where['live_status']) && $where['live_status'] !== '', function ($query) use ($where) {
|
||||
$query->where('BroadcastRoom.live_status', $where['live_status']);
|
||||
})->when(isset($where['star']) && $where['star'] !== '', function ($query) use ($where) {
|
||||
$query->where('BroadcastRoom.star', $where['star']);
|
||||
})->when(isset($where['show_tag']) && $where['show_tag'] !== '', function ($query) use ($where) {
|
||||
$query->where('is_show', 1)->where('is_mer_show', 1)->where('status', 2);
|
||||
})->when(isset($where['hot']) && $where['hot'] !== '', function ($query) use ($where) {
|
||||
$query->order('live_status ASC,star DESC,sort DESC');
|
||||
})->when(isset($where['broadcast_room_id']) && $where['broadcast_room_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('BroadcastRoom.broadcast_room_id', $where['broadcast_room_id']);
|
||||
})->when(isset($where['status_tag']) && $where['status_tag'] !== '', function ($query) use ($where) {
|
||||
if ($where['status_tag'] == 1) {
|
||||
$query->where('BroadcastRoom.status', 2);
|
||||
} else if ($where['status_tag'] == -1) {
|
||||
$query->where('BroadcastRoom.status', -1);
|
||||
} else if ($where['status_tag'] == 0) {
|
||||
$query->whereIn('BroadcastRoom.status', [0, 1]);
|
||||
}
|
||||
})->when(isset($where['show_type']) && $where['show_type'] !== '', function ($query) use ($where) {
|
||||
if ($where['show_type'] == 3) {
|
||||
$query->where('BroadcastRoom.is_mer_show', 1)->where('BroadcastRoom.is_show', 1);
|
||||
} else if ($where['show_type'] == 2) {
|
||||
$query->where('BroadcastRoom.is_mer_show', 0)->where('BroadcastRoom.is_show', 1);
|
||||
} else if ($where['show_type'] == 1) {
|
||||
$query->where('BroadcastRoom.is_mer_show', 1)->where('BroadcastRoom.is_show', 0);
|
||||
} else if ($where['show_type'] == 0) {
|
||||
$query->where('BroadcastRoom.is_mer_show', 0)->where('BroadcastRoom.is_show', 0);
|
||||
}
|
||||
})->where('BroadcastRoom.is_del', 0)->where('BroadcastRoom.is_mer_del', 0);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $roomId
|
||||
* @param $merId
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/7/31
|
||||
*/
|
||||
public function validRoom($roomId, $merId)
|
||||
{
|
||||
return BroadcastRoom::getDB()->where('broadcast_room_id', $roomId)->where('mer_id', $merId)->where('status', 2)->where('is_show', 1)->find();
|
||||
}
|
||||
|
||||
public function getRooms(array $roomIds)
|
||||
{
|
||||
return BroadcastRoom::getDB()->whereIn('room_id', $roomIds)->column('live_status,broadcast_room_id', 'room_id');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\broadcast;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\broadcast\BroadcastRoomGoods;
|
||||
use app\common\repositories\store\order\StoreCartRepository;
|
||||
|
||||
class BroadcastRoomGoodsDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return BroadcastRoomGoods::class;
|
||||
}
|
||||
|
||||
public function clear($id)
|
||||
{
|
||||
return BroadcastRoomGoods::getDB()->where('broadcast_room_id', $id)->delete();
|
||||
}
|
||||
|
||||
public function goodsId($id)
|
||||
{
|
||||
return BroadcastRoomGoods::getDB()->where('broadcast_room_id', $id)->column('broadcast_goods_id');
|
||||
}
|
||||
|
||||
public function rmGoods($goodsId, $roomId)
|
||||
{
|
||||
return BroadcastRoomGoods::getDB()->where('broadcast_room_id', $roomId)->where('broadcast_goods_id', $goodsId)->delete();
|
||||
}
|
||||
|
||||
public function getGoodsList($roomId, $page, $limit)
|
||||
{
|
||||
$query = BroadcastRoomGoods::getDB()->where('broadcast_room_id', $roomId);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->with('goods.product')->select()->toArray();
|
||||
$ids = array_column($list, 'broadcast_goods_id');
|
||||
if (count($ids)) {
|
||||
$sourcePayInfo = app()->make(StoreCartRepository::class)->getSourcePayInfo(1, $ids);
|
||||
$data = [];
|
||||
foreach ($sourcePayInfo as $item) {
|
||||
$data[$item['source_id']] = $item;
|
||||
}
|
||||
foreach ($list as $k => $goods) {
|
||||
$list[$k]['goods']['pay_num'] = $data[$goods['broadcast_goods_id']]['pay_num'] ?? 0;
|
||||
$list[$k]['goods']['pay_price'] = $data[$goods['broadcast_goods_id']]['pay_price'] ?? 0;
|
||||
}
|
||||
}
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
public function deleteGoods($goodsId)
|
||||
{
|
||||
return BroadcastRoomGoods::getDB()->where('broadcast_goods_id', $goodsId)->delete();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,350 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\coupon;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\coupon\StoreCoupon;
|
||||
use app\common\model\store\coupon\StoreCouponUser;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use think\Collection;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* Class StoreCouponIssueDao
|
||||
* @package app\common\dao\store\coupon
|
||||
* @author xaboy
|
||||
* @day 2020-05-14
|
||||
*/
|
||||
class StoreCouponDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreCoupon::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020-05-14
|
||||
*/
|
||||
public function search(?int $merId, array $where)
|
||||
{
|
||||
if(isset($where['is_trader']) && $where['is_trader'] !== ''){
|
||||
$query = StoreCoupon::hasWhere('merchant',function($query)use($where){
|
||||
$query->where('is_trader',$where['is_trader']);
|
||||
});
|
||||
}else{
|
||||
$query = StoreCoupon::getDB()->alias('StoreCoupon');
|
||||
}
|
||||
$query->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreCoupon.status', (int)$where['status']);
|
||||
})->when(isset($where['coupon_name']) && $where['coupon_name'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('title', "%{$where['coupon_name']}%");
|
||||
})->when(isset($where['coupon_id']) && $where['coupon_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('coupon_id', (int)$where['coupon_id']);
|
||||
})->when(isset($where['send_type']) && $where['send_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('send_type', (int)$where['send_type']);
|
||||
})->when(isset($where['not_send_type']) && $where['not_send_type'] !== '', function ($query) use ($where) {
|
||||
$query->whereNotIn('send_type', $where['not_send_type']);
|
||||
})->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
|
||||
$query->where('type', (int)$where['type']);
|
||||
})->when($merId !== null, function ($query) use ($merId) {
|
||||
$query->where('StoreCoupon.mer_id', $merId);
|
||||
})->when(isset($where['is_mer']) && $where['is_mer'] !== '', function ($query) use ($merId) {
|
||||
$query->where('type', '<', 10);
|
||||
});
|
||||
return $query->where('StoreCoupon.is_del', 0)->order(($merId ? 'StoreCoupon.sort DESC,' : '') . 'coupon_id DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $type
|
||||
* @param int $send_type
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/6/18
|
||||
*/
|
||||
public function validCouponQuery($type = null, $send_type = 0)
|
||||
{
|
||||
$query = StoreCoupon::getDB()
|
||||
->where('status', 1)
|
||||
->where('send_type', $send_type)
|
||||
->where('is_del', 0)
|
||||
->order('sort DESC,coupon_id DESC')
|
||||
->when(!is_null($type), function ($query) use ($type) {
|
||||
$query->where('type', $type);
|
||||
});
|
||||
$query->where(function (BaseQuery $query) {
|
||||
$query->where('is_limited', 0)->whereOr(function (BaseQuery $query) {
|
||||
$query->where('is_limited', 1)->where('remain_count', '>', 0);
|
||||
});
|
||||
})
|
||||
->where(function (BaseQuery $query) {
|
||||
$query->where('is_timeout', 0)->whereOr(function (BaseQuery $query) {
|
||||
$time = date('Y-m-d H:i:s');
|
||||
$query->where('is_timeout', 1)->where('start_time', '<', $time)->where('end_time', '>', $time);
|
||||
});
|
||||
})
|
||||
->where(function (BaseQuery $query) {
|
||||
$query->where('coupon_type', 0)->whereOr(function (BaseQuery $query) {
|
||||
$query->where('coupon_type', 1)->where('use_end_time', '>', date('Y-m-d H:i:s'));
|
||||
});
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function validCouponQueryWithMerchant($where,$uid = null)
|
||||
{
|
||||
$query = StoreCoupon::alias('C')->leftJoin('Merchant M','C.mer_id = M.mer_id')
|
||||
->where('C.status', 1)
|
||||
->where('C.is_del', 0)
|
||||
->when(isset($where['type']) && !is_null($where['type']), function ($query) use ($where) {
|
||||
if ($where['type'] == '') {
|
||||
$query->where('C.type', 'in', [0,10,11,12]);
|
||||
} else {
|
||||
$query->where('C.type', $where['type']);
|
||||
}
|
||||
})
|
||||
->when(isset($where['send_type']) && $where['send_type'] !== '', function($query) use($where){
|
||||
$query->where('C.send_type', $where['send_type']);
|
||||
})
|
||||
->when(isset($where['not_svip']) && $where['not_svip'] !== '', function($query) use($where){
|
||||
$query->where('C.send_type', '<>',StoreCouponRepository::GET_COUPON_TYPE_SVIP);
|
||||
})
|
||||
->when($uid, function($query) use($uid){
|
||||
$couponId = StoreCouponUser::where('uid',$uid)->whereIn('status',[1,2])->column('coupon_id');
|
||||
$query->whereNotIn('C.coupon_id', $couponId);
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function($query) use($where){
|
||||
$query->where('C.mer_id', $where['mer_id']);
|
||||
})
|
||||
->where(function (BaseQuery $query) {
|
||||
$query->where('is_limited', 0)->whereOr(function (BaseQuery $query) {
|
||||
$query->where('is_limited', 1)->where('remain_count', '>', 0);
|
||||
});
|
||||
})
|
||||
->where(function (BaseQuery $query) {
|
||||
$query->where('is_timeout', 0)->whereOr(function (BaseQuery $query) {
|
||||
$time = date('Y-m-d H:i:s');
|
||||
$query->where('is_timeout', 1)->where('start_time', '<', $time)->where('end_time', '>', $time);
|
||||
});
|
||||
})
|
||||
->where(function (BaseQuery $query) {
|
||||
$query->where('C.mer_id', 0)->whereOr(function (BaseQuery $query) {
|
||||
$query->where('M.is_del',0)->where('M.status',1)->where('M.mer_state',1);
|
||||
});
|
||||
})
|
||||
->where(function (BaseQuery $query) {
|
||||
$query->where('coupon_type', 0)->whereOr(function (BaseQuery $query) {
|
||||
$query->where('coupon_type', 1)->where('use_end_time', '>', date('Y-m-d H:i:s'));
|
||||
});
|
||||
});
|
||||
return $query->order('C.sort DESC,C.create_time DESC');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $uid
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/19
|
||||
*/
|
||||
public function validCoupon($id, $uid)
|
||||
{
|
||||
return $this->validCouponQuery()->when($uid, function (BaseQuery $query, $uid) {
|
||||
$query->with(['issue' => function (BaseQuery $query) use ($uid) {
|
||||
$query->where('uid', $uid);
|
||||
}]);
|
||||
})->where('coupon_id', $id)->find();
|
||||
}
|
||||
|
||||
public function validSvipCoupon($id, $uid)
|
||||
{
|
||||
return $this->validCouponQuery(null,StoreCouponRepository::GET_COUPON_TYPE_SVIP)->when($uid, function (BaseQuery $query, $uid) {
|
||||
$query->with(['svipIssue' => function (BaseQuery $query) use ($uid) {
|
||||
$query->where('uid', $uid);
|
||||
}]);
|
||||
})->where('coupon_id', $id)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $merId
|
||||
* @param null $uid
|
||||
* @return Collection
|
||||
* @throws DbException
|
||||
* @throws DataNotFoundException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/1
|
||||
*/
|
||||
public function validMerCoupon($merId, $uid = null, $type = 0)
|
||||
{
|
||||
return $this->validCouponQuery($type)->when($uid, function (BaseQuery $query, $uid) {
|
||||
$query->with(['issue' => function (BaseQuery $query) use ($uid) {
|
||||
$query->where('uid', $uid);
|
||||
}]);
|
||||
})->where('mer_id', $merId)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $merId
|
||||
* @param null $uid
|
||||
* @return int
|
||||
* @author xaboy
|
||||
* @day 2020/6/19
|
||||
*/
|
||||
public function validMerCouponExists($merId, $uid = null)
|
||||
{
|
||||
return $this->validCouponQuery(0)->when($uid, function (BaseQuery $query, $uid) {
|
||||
$query->with(['issue' => function (BaseQuery $query) use ($uid) {
|
||||
$query->where('uid', $uid);
|
||||
}]);
|
||||
})->where('mer_id', $merId)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $couponIds
|
||||
* @param null $uid
|
||||
* @return Collection
|
||||
* @throws DbException
|
||||
* @throws DataNotFoundException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/1
|
||||
*/
|
||||
public function validProductCoupon(array $couponIds, $uid = null)
|
||||
{
|
||||
return $this->validCouponQuery(1)->when($uid, function (BaseQuery $query, $uid) {
|
||||
$query->with(['issue' => function (BaseQuery $query) use ($uid) {
|
||||
$query->where('uid', $uid);
|
||||
}]);
|
||||
})->whereIn('coupon_id', $couponIds)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $couponIds
|
||||
* @param null $uid
|
||||
* @return int
|
||||
* @author Qinii
|
||||
*/
|
||||
public function validProductCouponExists(array $couponIds, $uid = null)
|
||||
{
|
||||
return $this->validCouponQuery(1)->when($uid, function (BaseQuery $query, $uid) {
|
||||
$query->with(['issue' => function (BaseQuery $query) use ($uid) {
|
||||
$query->where('uid', $uid);
|
||||
}]);
|
||||
})->whereIn('coupon_id', $couponIds)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-05-13
|
||||
*/
|
||||
public function delete(int $id)
|
||||
{
|
||||
return StoreCoupon::getDB()->where($this->getPk(), $id)->update(['is_del' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-05-13
|
||||
*/
|
||||
public function exists(int $id)
|
||||
{
|
||||
return StoreCoupon::getDB()->where($this->getPk(), $id)->where('is_del', 0)->count($this->getPk()) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param int $id
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-05-13
|
||||
*/
|
||||
public function merDelete(int $merId, int $id)
|
||||
{
|
||||
return StoreCoupon::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->update(['is_del' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020-05-13
|
||||
*/
|
||||
public function merExists(int $merId, int $id)
|
||||
{
|
||||
return StoreCoupon::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->where('is_del', 0)->count($this->getPk()) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/18
|
||||
*/
|
||||
public function newPeopleCoupon()
|
||||
{
|
||||
return $this->validCouponQuery(null, 2)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $ids
|
||||
* @return Collection
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/19
|
||||
*/
|
||||
public function getGiveCoupon(array $ids = null)
|
||||
{
|
||||
return $this->validCouponQuery(null, 3)->when($ids, function ($query, $ids) {
|
||||
$query->whereIn('coupon_id', $ids);
|
||||
})->select();
|
||||
}
|
||||
|
||||
public function clear($id,$field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\coupon;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\coupon\StoreCouponIssueUser;
|
||||
use think\db\BaseQuery;
|
||||
|
||||
/**
|
||||
* Class StoreCouponIssueUserDao
|
||||
* @package app\common\dao\store\coupon
|
||||
* @author xaboy
|
||||
* @day 2020/6/2
|
||||
*/
|
||||
class StoreCouponIssueUserDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/2
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreCouponIssueUser::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/6/2
|
||||
*/
|
||||
public function search(array $where)
|
||||
{
|
||||
return StoreCouponIssueUser::getDB()->when(isset($where['coupon_id']) && $where['coupon_id'] != '', function ($query) use ($where) {
|
||||
$query->where('coupon_id', $where['coupon_id']);
|
||||
})->when(isset($where['uid']) && $where['uid'] != '', function ($query) use ($where) {
|
||||
$query->where('uid', $where['uid']);
|
||||
})->order('create_time');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\coupon;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\coupon\StoreCouponProduct;
|
||||
use think\Collection;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
|
||||
/**
|
||||
* Class StoreCouponProductDao
|
||||
* @package app\common\dao\store\coupon
|
||||
* @author xaboy
|
||||
* @day 2020-05-13
|
||||
*/
|
||||
class StoreCouponProductDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreCouponProduct::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return int
|
||||
* @author xaboy
|
||||
* @day 2020-05-13
|
||||
*/
|
||||
public function insertAll(array $data)
|
||||
{
|
||||
return StoreCouponProduct::getDB()->insertAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $couponId
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020-05-13
|
||||
*/
|
||||
public function clear($couponId)
|
||||
{
|
||||
return StoreCouponProduct::getDB()->where('coupon_id', $couponId)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $productId
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/6/1
|
||||
*/
|
||||
public function productByCouponId($productId)
|
||||
{
|
||||
return StoreCouponProduct::getDB()->whereIn('product_id', $productId)->column('coupon_id');
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
return StoreCouponProduct::getDB()
|
||||
->when(isset($where['coupon_id']) && $where['coupon_id'] !== '', function ($query) use ($where) {
|
||||
return $query->where('coupon_id', $where['coupon_id']);
|
||||
})
|
||||
->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
|
||||
return $query->where('type', $where['type']);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\coupon;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\coupon\StoreCouponSend;
|
||||
|
||||
class StoreCouponSendDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreCouponSend::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
return StoreCouponSend::getDB()->alias('A')->leftJoin('StoreCoupon B', 'B.coupon_id = A.coupon_id')
|
||||
->when(isset($where['coupon_name']) && $where['coupon_name'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('B.title', "%{$where['coupon_name']}%");
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'A.create_time');
|
||||
})
|
||||
->when(isset($where['coupon_type']) && $where['coupon_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('B.type', $where['coupon_type']);
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
$query->where('A.status', $where['status']);
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('A.mer_id', $where['mer_id']);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\coupon;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\coupon\StoreCouponUser;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* Class StoreCouponUserDao
|
||||
* @package app\common\dao\store\coupon
|
||||
* @author xaboy
|
||||
* @day 2020-05-14
|
||||
*/
|
||||
class StoreCouponUserDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return BaseModel
|
||||
* @author xaboy
|
||||
* @day 2020-03-30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreCouponUser::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
return StoreCouponUser::when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
|
||||
$query->hasWhere('user', [['nickname', 'LIKE', "%{$where['username']}%"]]);
|
||||
})->when(isset($where['coupon_type']) && $where['coupon_type'] !== '', function ($query) use ($where) {
|
||||
$query->hasWhere('coupon', ['type' => $where['coupon_type']]);
|
||||
})->alias('StoreCouponUser')->when(isset($where['coupon']) && $where['coupon'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('StoreCouponUser.coupon_title', "%{$where['coupon']}%");
|
||||
})->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreCouponUser.status', $where['status']);
|
||||
})->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreCouponUser.uid', $where['uid']);
|
||||
})->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreCouponUser.mer_id', $where['mer_id']);
|
||||
})->when(isset($where['coupon_id']) && $where['coupon_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreCouponUser.coupon_id', $where['coupon_id']);
|
||||
})->when(isset($where['coupon']) && $where['coupon'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('StoreCouponUser.coupon_title|StoreCouponUser.coupon_id', "%{$where['coupon']}%");
|
||||
})->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreCouponUser.type', $where['type']);
|
||||
})->when(isset($where['send_id']) && $where['send_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreCouponUser.send_id', $where['send_id'])->where('StoreCouponUser.type', 'send');
|
||||
})->when(isset($where['is_mer']) && $where['is_mer'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreCouponUser.mer_id', '<>',0);
|
||||
})->when(isset($where['statusTag']) && $where['statusTag'] !== '', function ($query) use ($where) {
|
||||
if ($where['statusTag'] == 1) {
|
||||
$query->where('StoreCouponUser.status', 0);
|
||||
} else {
|
||||
$query->whereIn('StoreCouponUser.status', [1, 2])->where('StoreCouponUser.create_time', '>', date('Y-m-d H:i:s', strtotime('-60 day')));
|
||||
}
|
||||
})->order('StoreCouponUser.coupon_user_id DESC');
|
||||
}
|
||||
|
||||
public function validIntersection($merId, $uid, array $ids): array
|
||||
{
|
||||
$time = date('Y-m-d H:i:s');
|
||||
return StoreCouponUser::getDB()->whereIn('coupon_user_id', $ids)->where('start_time', '<', $time)->where('end_time', '>', $time)
|
||||
->where('is_fail', 0)->where('status', 0)->where('mer_id', $merId)->where('uid', $uid)->column('coupon_user_id');
|
||||
}
|
||||
|
||||
public function validQuery($type)
|
||||
{
|
||||
$time = date('Y-m-d H:i:s');
|
||||
return StoreCouponUser::getDB()
|
||||
->when($type, function ($query) use($time){
|
||||
$query->where('start_time', '<', $time);
|
||||
})
|
||||
->where('end_time', '>', $time)->where('is_fail', 0)->where('status', 0);
|
||||
}
|
||||
|
||||
public function failCoupon($uid = 0)
|
||||
{
|
||||
$time = date('Y-m-d H:i:s');
|
||||
$res = StoreCouponUser::getDB()
|
||||
->where('end_time', '<', $time)
|
||||
->where('is_fail', 0)
|
||||
->where('status', 0)
|
||||
->when($uid, function($query) use($uid){
|
||||
$query->where('uid', $uid);
|
||||
})
|
||||
->update(['status' => 2]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function userTotal($uid, $type = 1)
|
||||
{
|
||||
return $this->validQuery($type)->where('uid', $uid)->count();
|
||||
}
|
||||
|
||||
public function usedNum($couponId)
|
||||
{
|
||||
return StoreCouponUser::getDB()->where('coupon_id', $couponId)->where('status', 1)->count();
|
||||
}
|
||||
|
||||
public function sendNum($couponId, $sendId = null, $status = null)
|
||||
{
|
||||
return StoreCouponUser::getDB()->where('coupon_id', $couponId)->when($sendId, function ($query, $sendId) {
|
||||
$query->where('type', 'send')->where('send_id', $sendId);
|
||||
})->when(isset($status), function ($query) use ($status) {
|
||||
$query->where('status', $status);
|
||||
})->count();
|
||||
}
|
||||
|
||||
public function validUserPlatformCoupon($uid)
|
||||
{
|
||||
$time = date('Y-m-d H:i:s');
|
||||
return StoreCouponUser::getDB()->where('uid', $uid)->where('mer_id', 0)->where('start_time', '<', $time)->where('end_time', '>', $time)
|
||||
->where('is_fail', 0)->where('status', 0)
|
||||
->with(['product' => function ($query) {
|
||||
$query->field('coupon_id,product_id');
|
||||
}, 'coupon' => function ($query) {
|
||||
$query->field('coupon_id,type,send_type');
|
||||
}])->order('coupon_price DESC, coupon_user_id ASC')->select();
|
||||
}
|
||||
|
||||
public function clear($id,$field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\MerchantReconciliation as model;
|
||||
use app\common\repositories\system\admin\AdminRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
|
||||
class MerchantReconciliationDao extends BaseDao
|
||||
{
|
||||
public function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = ($this->getModel()::getDB())
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] != '' ,function($query)use($where){
|
||||
$query->where('mer_id',$where['mer_id']);
|
||||
})->when(isset($where['status']) && $where['status'] != '' ,function($query)use($where){
|
||||
$query->where('status',$where['status']);
|
||||
})->when(isset($where['is_accounts']) && $where['is_accounts'] != '' ,function($query)use($where){
|
||||
$query->where('is_accounts',$where['is_accounts']);
|
||||
})->when(isset($where['date']) && $where['date'] != '' ,function($query)use($where){
|
||||
getModelTime($query,$where['date']);
|
||||
})->when(isset($where['reconciliation_id']) && $where['reconciliation_id'] != '' ,function($query)use($where){
|
||||
$query->where('reconciliation_id',$where['reconciliation_id']);
|
||||
})
|
||||
->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){
|
||||
$make = app()->make(AdminRepository::class);
|
||||
$admin_id = $make->getSearch(['real_name' => $where['keyword']],null,false)->column('admin_id');
|
||||
$query->where(function($query) use($admin_id,$where){
|
||||
if(isset($where['mer_id'])){
|
||||
$query->where('admin_id','in',$admin_id);
|
||||
}else {
|
||||
$mer_make = app()->make(MerchantRepository::class);
|
||||
$mer_id = $mer_make->getSearch(['keyword' => $where['keyword']])->column('mer_id');
|
||||
$query->where('admin_id','in',$admin_id)->whereOr('mer_id','in',$mer_id);
|
||||
}
|
||||
});
|
||||
});
|
||||
return $query->order('create_time DESC,status DESC');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\MerchantReconciliationOrder as model;
|
||||
|
||||
class MerchantReconciliationOrderDao extends BaseDao
|
||||
{
|
||||
public function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
|
||||
public function search($where)
|
||||
{
|
||||
return ($this->getModel()::getDB())->when(isset($where['reconciliation_id']) && $where['reconciliation_id'] !== '',function ($query)use ($where){
|
||||
$query->where('reconciliation_id',$where['reconciliation_id']);
|
||||
})->when(isset($where['type']) && $where['type'] !== '',function ($query)use ($where){
|
||||
$query->where('type',$where['type']);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\order\PresellOrder;
|
||||
|
||||
class PresellOrderDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return PresellOrder::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
return PresellOrder::getDB()->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) {
|
||||
$query->whereIn('pay_type', $where['pay_type']);
|
||||
})->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||
$query->where('paid', $where['paid']);
|
||||
})->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->when(isset($where['order_ids']) && $where['order_ids'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_id','in',$where['order_ids']);
|
||||
});
|
||||
}
|
||||
|
||||
public function userOrder($uid, $orderId)
|
||||
{
|
||||
return PresellOrder::getDB()->where('uid', $uid)->where('order_id', $orderId)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $time
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/11/3
|
||||
*/
|
||||
public function getTimeOutIds($time)
|
||||
{
|
||||
return PresellOrder::getDB()->where('status', 1)->where('paid', 0)
|
||||
->where('final_end_time', '<', $time)->column('presell_order_id');
|
||||
}
|
||||
|
||||
public function sendSmsIds($date)
|
||||
{
|
||||
return PresellOrder::getDB()->where('status', 1)->where('paid', 0)
|
||||
->whereLike('final_start_time', $date . '%')->column('order_id');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\order\StoreCart;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\repositories\store\order\StoreCartRepository;
|
||||
use think\model\Relation;
|
||||
|
||||
class StoreCartDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreCart::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param $uid
|
||||
* @param int|null $merId
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/6/5
|
||||
*/
|
||||
public function validIntersection(array $ids, $uid, int $merId = null): array
|
||||
{
|
||||
return StoreCart::getDB()->whereIn('cart_id', $ids)
|
||||
->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})
|
||||
->where('is_del', 0)->where('is_fail', 0)->where('is_pay', 0)->where('uid', $uid)->column('cart_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/6/1
|
||||
* @param int $uid
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAll(int $uid)
|
||||
{
|
||||
$query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])
|
||||
->with([
|
||||
'product' => function ($query) {
|
||||
$query->field('product_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,is_used,product_type,once_max_count,once_min_count,pay_limit,mer_svip_status,svip_price_type');
|
||||
},
|
||||
'productAttr' => function ($query) {
|
||||
$query->field('product_id,stock,price,unique,sku,image,svip_price');
|
||||
},
|
||||
// 'merchant' => function ($query) {
|
||||
// $query->field('mer_id,mer_name,mer_state,mer_avatar,is_trader,type_id')->with(['type_name']);
|
||||
// }
|
||||
])->limit(StoreCartRepository::CART_LIMIT_COUNT)->order('create_time DESC')->select();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function cartIbByData(array $ids, int $uid, ?UserAddress $address)
|
||||
{
|
||||
return StoreCart::getDb()->where('uid', $uid)->with([
|
||||
'product' => function (Relation $query) use ($address) {
|
||||
$query->field('product_id,cate_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,temp_id,give_coupon_ids,is_gift_bag,is_used,product_type,old_product_id,integral_rate,delivery_way,delivery_free,type,extend,pay_limit,once_max_count,once_min_count,mer_svip_status,svip_price_type,refund_switch,mer_form_id,active_id');
|
||||
if ($address) {
|
||||
$cityIds = array_filter([$address->province_id, $address->city_id, $address->district_id, $address->street_id]);
|
||||
$query->with([
|
||||
'temp' => [
|
||||
'region' => function (Relation $query) use ($cityIds) {
|
||||
$query->where(function ($query) use ($cityIds) {
|
||||
foreach ($cityIds as $v) {
|
||||
$query->whereOr('city_id', 'like', "%/{$v}/%");
|
||||
}
|
||||
$query->whereOr('city_id', '0');
|
||||
})->order('shipping_template_region_id DESC')->withLimit(1);
|
||||
},
|
||||
'undelives' => function ($query) use ($cityIds) {
|
||||
foreach ($cityIds as $v) {
|
||||
$query->whereOr('city_id', 'like', "%/{$v}/%");
|
||||
}
|
||||
},
|
||||
'free' => function (Relation $query) use ($cityIds) {
|
||||
foreach ($cityIds as $v) {
|
||||
$query->whereOr('city_id', 'like', "%/{$v}/%");
|
||||
}
|
||||
$query->order('shipping_template_free_id DESC')->withLimit(1);
|
||||
}]]);
|
||||
}
|
||||
},
|
||||
'productAttr' => function (Relation $query) {
|
||||
$query->field('value_id,image,extension_one,extension_two,product_id,stock,price,unique,sku,volume,weight,ot_price,cost,svip_price')
|
||||
->append(['bc_extension_one', 'bc_extension_two']);
|
||||
},
|
||||
// 'merchant' => function (Relation $query) use ($uid) {
|
||||
// $query->field('mer_id,mer_name,mer_state,mer_avatar,delivery_way,commission_rate,category_id')
|
||||
// ->with([
|
||||
// 'coupon' => function ($query) use ($uid) {
|
||||
// $query->where('uid', $uid);
|
||||
// },
|
||||
// 'config' => function ($query) {
|
||||
// $query->whereIn('config_key', ['mer_integral_status', 'mer_integral_rate', 'mer_store_stock', 'mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time']);
|
||||
// },
|
||||
// 'merchantCategory'
|
||||
// ]);
|
||||
// }
|
||||
])->whereIn('cart_id', $ids)->order('product_type DESC,cart_id DESC')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cartIds
|
||||
* @param int $uid
|
||||
* @author Qinii
|
||||
*/
|
||||
public function batchDelete(array $cartIds, int $uid)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where('uid', $uid)->whereIn('cart_id', $cartIds)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getCartCount(int $uid)
|
||||
{
|
||||
$data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])->field('SUM(cart_num) as count')->select();
|
||||
$data[0]['count'] = $data[0]['count'] ? $data[0]['count'] : 0;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $source
|
||||
* @param array|null $ids
|
||||
* @author xaboy
|
||||
* @day 2020/8/31
|
||||
*/
|
||||
public function getSourcePayInfo($source, ?array $ids = null)
|
||||
{
|
||||
return StoreCart::getDB()->alias('A')->where('A.source', $source)->where('A.is_pay', 1)->when($ids, function ($query, $ids) {
|
||||
$query->whereIn('A.source_id', $ids);
|
||||
})->leftJoin('StoreOrderProduct B', 'A.cart_id = B.cart_id')
|
||||
->field('sum(B.product_num) as pay_num,sum(B.product_price) as pay_price,A.source_id')->group('A.source_id')->select();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
|
||||
/**
|
||||
* Class StoreGroupOrderDao
|
||||
* @package app\common\dao\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
class StoreGroupOrderDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreGroupOrder::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $uid
|
||||
* @return int
|
||||
* @author xaboy
|
||||
* @day 2020/6/11
|
||||
*/
|
||||
public function orderNumber($uid = null)
|
||||
{
|
||||
return $this->search(['uid' => $uid,'is_del' => 0,'paid' => 0],0)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return \think\db\BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function search(array $where,$is_points = null)
|
||||
{
|
||||
$query = StoreGroupOrder::getDB()
|
||||
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||
$query->where('paid', $where['paid']);
|
||||
})
|
||||
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('uid', $where['uid']);
|
||||
})
|
||||
->when(!is_null($is_points), function ($query) use ($is_points) {
|
||||
if ($is_points) {
|
||||
$query->where('activity_type', 20);
|
||||
} else {
|
||||
$query->where('activity_type', '<>',20);
|
||||
}
|
||||
})
|
||||
->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
|
||||
$query->where('is_del', $where['is_del']);
|
||||
}, function ($query) {
|
||||
$query->where('is_del', 0);
|
||||
});
|
||||
return $query->order('create_time DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $time
|
||||
* @param bool $is_remind
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function getTimeOutIds($time, $is_remind = false)
|
||||
{
|
||||
return StoreGroupOrder::getDB()->where('is_del', 0)->where('paid', 0)
|
||||
->when($is_remind, function ($query) {
|
||||
$query->where('is_remind', 0);
|
||||
})->where('create_time', '<=', $time)->column('group_order_id');
|
||||
}
|
||||
|
||||
public function isRemind($id)
|
||||
{
|
||||
return StoreGroupOrder::getDB()->where('group_order_id', $id)->update(['is_remind' => 1]);
|
||||
}
|
||||
|
||||
public function totalNowMoney($uid)
|
||||
{
|
||||
return StoreGroupOrder::getDB()->where('pay_type', 0)->where('uid', $uid)->sum('pay_price') ?: 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreImport;
|
||||
|
||||
class StoreImportDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return string
|
||||
* @author Qinii
|
||||
* @day 3/16/21
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreImport::class;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreImportDelivery;
|
||||
|
||||
class StoreImportDeliveryDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @return string
|
||||
* @author Qinii
|
||||
* @day 3/16/21
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreImportDelivery::class;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,966 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreOrderProduct;
|
||||
use app\common\model\store\order\StoreOrderStatus;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\store\order\StoreOrderStatusRepository;
|
||||
use app\common\repositories\store\product\ProductAssistSetRepository;
|
||||
use app\common\repositories\store\product\ProductGroupBuyingRepository;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* Class StoreOrderDao
|
||||
* @package app\common\dao\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
class StoreOrderDao extends BaseDao
|
||||
{
|
||||
//订单状态(0:待发货;1:待收货;2:待评价;3:已完成; 9: 拼团中 10: 待付尾款 11:尾款超时未付 -1:已退款)
|
||||
const ORDER_STATUS_BE_SHIPPED = 0;
|
||||
const ORDER_STATUS_BE_RECEIVE = 1;
|
||||
const ORDER_STATUS_REPLY = 2;
|
||||
const ORDER_STATUS_SUCCESS = 3;
|
||||
const ORDER_STATUS_SPELL = 9;
|
||||
const ORDER_STATUS_TAIL = 10;
|
||||
const ORDER_STATUS_TAIL_FAIL = 11;
|
||||
const ORDER_STATUS_REFUND = -1;
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreOrder::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param int $sysDel
|
||||
* @return BaseQuery
|
||||
* @author xaboyCRMEB
|
||||
* @day 2020/6/16
|
||||
*/
|
||||
public function search(array $where, $sysDel = 0)
|
||||
{
|
||||
$query = StoreOrder::hasWhere('merchant', function ($query) use ($where) {
|
||||
if (isset($where['is_trader']) && $where['is_trader'] !== '') {
|
||||
$query->where('is_trader', $where['is_trader']);
|
||||
}
|
||||
$query->where('is_del', 0);
|
||||
});
|
||||
$query->where('StoreOrder.activity_type', '<>', 20);
|
||||
$query->when(($sysDel !== null), function ($query) use ($sysDel) {
|
||||
$query->where('is_system_del', $sysDel);
|
||||
});
|
||||
$query->when(isset($where['order_type']) && $where['order_type'] >= 0 && $where['order_type'] !== '', function ($query) use ($where) {
|
||||
if ($where['order_type'] == 2) {
|
||||
$query->where('is_virtual', 1);
|
||||
} else if ($where['order_type'] == 3) { // 卡密商品
|
||||
$query->where('is_virtual', 2);
|
||||
} else {
|
||||
$query->where('order_type', $where['order_type']);
|
||||
}
|
||||
});
|
||||
$query->when(isset($where['activity_type']) && $where['activity_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreOrder.activity_type', $where['activity_type']);
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
switch ($where['status']) {
|
||||
case 0 :
|
||||
$query->whereIn('StoreOrder.status', [0, 9]);
|
||||
break;
|
||||
case -2 :
|
||||
$query->where('paid', 1)->whereNotIn('StoreOrder.status', [10, 11]);
|
||||
break;
|
||||
case 10 :
|
||||
$query->where('paid', 1)->whereIn('StoreOrder.status', [10, 11]);
|
||||
break;
|
||||
default:
|
||||
$query->where('StoreOrder.status', $where['status']);
|
||||
break;
|
||||
}
|
||||
})
|
||||
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('uid', $where['uid']);
|
||||
})
|
||||
->when(isset($where['is_spread']) && $where['is_spread'] !== '', function ($query) use ($where) {
|
||||
if ($where['is_spread']) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('StoreOrder.spread_uid', '>', 0)->whereOr('StoreOrder.top_uid', '>', 0);
|
||||
});
|
||||
}
|
||||
})
|
||||
->when(isset($where['is_user']) && $where['is_user'] !== '', function ($query) use ($where) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('order_type', 0)->whereOr(function ($query) {
|
||||
$query->where('order_type', 1)->where('main_id', 0);
|
||||
});
|
||||
});
|
||||
})
|
||||
//待核销订单
|
||||
->when(isset($where['is_verify']) && $where['is_verify'], function ($query) use ($where) {
|
||||
$query->where('StoreOrder.order_type', 1)->where('StoreOrder.status', 0)->where('paid', 1);
|
||||
})
|
||||
->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) {
|
||||
if (is_int($where['pay_type'])) {
|
||||
$query->where('StoreOrder.pay_type', $where['pay_type']);
|
||||
} else {
|
||||
$query->whereIn('StoreOrder.pay_type', $where['pay_type']);
|
||||
}
|
||||
})
|
||||
->when(isset($where['order_ids']) && $where['order_ids'] !== '', function ($query) use ($where) {
|
||||
$query->whereIn('order_id', $where['order_ids']);
|
||||
})
|
||||
->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_id', $where['order_id']);
|
||||
})
|
||||
->when(isset($where['take_order']) && $where['take_order'] != '', function ($query) use ($where) {
|
||||
$query->where('order_type', 1)->whereNotNull('verify_time');
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreOrder.mer_id', $where['mer_id']);
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'StoreOrder.create_time');
|
||||
})
|
||||
->when(isset($where['verify_date']) && $where['verify_date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['verify_date'], 'verify_time');
|
||||
})
|
||||
->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_sn', 'like', '%' . $where['order_sn'] . '%');
|
||||
})
|
||||
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreOrder.paid', $where['paid']);
|
||||
})
|
||||
->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreOrder.is_del', $where['is_del']);
|
||||
})
|
||||
->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('service_id', $where['service_id']);
|
||||
})
|
||||
->when(isset($where['delivery_id']) && $where['delivery_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('delivery_id', $where['delivery_id']);
|
||||
})
|
||||
->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
|
||||
$query->join('User U', 'StoreOrder.uid = U.uid')
|
||||
->where(function ($query) use ($where) {
|
||||
$query->where('nickname', 'like', "%{$where['username']}%")
|
||||
->whereOr('phone', 'like', "%{$where['username']}%")
|
||||
->whereOr('StoreOrder.user_phone', 'like', "%{$where['username']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['spread_name']) && $where['spread_name'] !== '', function ($query) use ($where) {
|
||||
$uid = User::where('nickname', 'like', "%{$where['spread_name']}%")->column('uid');
|
||||
$query->whereIn('StoreOrder.spread_uid', $uid);
|
||||
})
|
||||
->when(isset($where['top_spread_name']) && $where['top_spread_name'] !== '', function ($query) use ($where) {
|
||||
$uid = User::where('nickname', 'like', "%{$where['top_spread_name']}%")->column('uid');
|
||||
$query->whereIn('StoreOrder.top_uid', $uid);
|
||||
})
|
||||
->when(isset($where['store_name']) && $where['store_name'] !== '', function ($query) use ($where) {
|
||||
$orderId = StoreOrderProduct::alias('op')
|
||||
->join('storeProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['store_name']}%")
|
||||
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->column('order_id');
|
||||
$query->whereIn('order_id', $orderId ?: '');
|
||||
})
|
||||
->when(isset($where['search']) && $where['search'] !== '', function ($query) use ($where) {
|
||||
$orderId = StoreOrderProduct::alias('op')
|
||||
->join('storeProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['search']}%")
|
||||
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->column('order_id');
|
||||
$query->where(function ($query) use ($orderId, $where) {
|
||||
$query->whereIn('order_id', $orderId ? $orderId : '')
|
||||
->whereOr('order_sn', 'like', "%{$where['search']}%")
|
||||
->whereOr('StoreOrder.user_phone', 'like', "%{$where['search']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['group_order_sn']) && $where['group_order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->join('StoreGroupOrder GO', 'StoreOrder.group_order_id = GO.group_order_id')->where('group_order_sn', $where['group_order_sn']);
|
||||
})
|
||||
->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
|
||||
$query->where(function ($query) use ($where) {
|
||||
$query->whereLike('StoreOrder.real_name|StoreOrder.user_phone|order_sn', "%" . $where['keywords'] . "%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['filter_delivery']) && $where['filter_delivery'] !== '', function ($query) use ($where) {
|
||||
//1 快递 2 配送 3 虚拟
|
||||
//按发货方式:1快递订单、2配送订单、4核销订单、3虚拟发货、6自动发货
|
||||
switch ($where['filter_delivery']) {
|
||||
case 1:
|
||||
$query->whereIn('delivery_type', '1,4');
|
||||
break;
|
||||
case 2:
|
||||
$query->whereIn('delivery_type', '2,5');
|
||||
break;
|
||||
case 3:
|
||||
$query->whereIn('delivery_type', '3');
|
||||
break;
|
||||
case 4:
|
||||
$query->where('order_type', 1);
|
||||
break;
|
||||
case 6:
|
||||
$query->whereIn('delivery_type', '6');
|
||||
break;
|
||||
}
|
||||
})
|
||||
->when(isset($where['filter_product']) && $where['filter_product'] !== '', function ($query) use ($where) {
|
||||
// 1 实物商品、2虚拟商品、3卡密商品
|
||||
switch ($where['filter_product']) {
|
||||
case 1:
|
||||
$query->where('is_virtual', 0);
|
||||
break;
|
||||
case 2:
|
||||
$query->where('is_virtual', 1);
|
||||
break;
|
||||
case 3:
|
||||
$query->where('is_virtual', 2);
|
||||
break;
|
||||
}
|
||||
})
|
||||
->order('StoreOrder.create_time DESC');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function searchAll(array $where, $sysDel = 0, $is_points = null)
|
||||
{
|
||||
$query = StoreOrder::getDB()->alias('StoreOrder');
|
||||
$query->when(($sysDel !== null), function ($query) use ($sysDel) {
|
||||
$query->where('is_system_del', $sysDel);
|
||||
});
|
||||
$query->when(!is_null($is_points), function ($query) use ($is_points) {
|
||||
if ($is_points) {
|
||||
$query->where('activity_type', 20);
|
||||
} else {
|
||||
$query->where('activity_type', '<>', 20);
|
||||
}
|
||||
});
|
||||
$query->when(isset($where['order_type']) && $where['order_type'] >= 0 && $where['order_type'] !== '', function ($query) use ($where) {
|
||||
if ($where['order_type'] == 2) {
|
||||
$query->where('is_virtual', 1);
|
||||
} else if ($where['order_type'] == 0) { //实体发货订单
|
||||
$query->where('order_type', 0)->where('is_virtual', 0);
|
||||
} else if ($where['order_type'] == 3) { //发货订单
|
||||
$query->where('order_type', 0);
|
||||
} else {
|
||||
$query->where('order_type', $where['order_type']);
|
||||
}
|
||||
});
|
||||
$query->when(isset($where['activity_type']) && $where['activity_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('activity_type', $where['activity_type']);
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
switch ($where['status']) {
|
||||
case 0 :
|
||||
$query->whereIn('StoreOrder.status', [0, 9])->where('paid', 1)->where('is_del', 0);
|
||||
break;
|
||||
case -2 :
|
||||
$query->where('paid', 1)->whereNotIn('StoreOrder.status', [10, 11])->where('is_del', 0);
|
||||
break;
|
||||
case -3 :
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
break;
|
||||
case 10 :
|
||||
$query->where('paid', 1)->whereIn('StoreOrder.status', [10, 11])->where('is_del', 0);
|
||||
break;
|
||||
default:
|
||||
$query->where('StoreOrder.status', $where['status'])->where('is_del', 0);
|
||||
break;
|
||||
}
|
||||
|
||||
})
|
||||
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('uid', $where['uid']);
|
||||
})
|
||||
->when(isset($where['is_user']) && $where['is_user'] !== '', function ($query) use ($where) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('order_type', 0)->whereOr(function ($query) {
|
||||
$query->where('order_type', 1)->where('main_id', 0);
|
||||
});
|
||||
});
|
||||
})
|
||||
//待核销订单
|
||||
->when(isset($where['is_verify']) && $where['is_verify'], function ($query) use ($where) {
|
||||
$query->where('StoreOrder.order_type', 1)->where('StoreOrder.status', 0);
|
||||
})
|
||||
->when(isset($where['pay_type']) && $where['pay_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreOrder.pay_type', $where['pay_type']);
|
||||
})
|
||||
->when(isset($where['order_ids']) && $where['order_ids'] !== '', function ($query) use ($where) {
|
||||
$query->whereIn('order_id', $where['order_ids']);
|
||||
})
|
||||
->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_id', $where['order_id']);
|
||||
})
|
||||
->when(isset($where['take_order']) && $where['take_order'] != '', function ($query) use ($where) {
|
||||
$query->where('order_type', 1)->whereNotNull('verify_time');
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'StoreOrder.create_time');
|
||||
})
|
||||
->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_sn', 'like', '%' . $where['order_sn'] . '%');
|
||||
})
|
||||
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreOrder.paid', $where['paid']);
|
||||
})
|
||||
->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreOrder.is_del', $where['is_del']);
|
||||
})
|
||||
->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('service_id', $where['service_id']);
|
||||
})
|
||||
->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
|
||||
$query->join('User U', 'StoreOrder.uid = U.uid')
|
||||
->where(function ($query) use ($where) {
|
||||
$query->where('nickname', 'like', "%{$where['username']}%")
|
||||
->whereOr('phone', 'like', "%{$where['username']}%")
|
||||
->whereOr('user_phone', 'like', "%{$where['username']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['nickname']) && $where['nickname'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('StoreOrder.real_name', "%" . $where['nickname'] . "%");
|
||||
})
|
||||
->when(isset($where['phone']) && $where['phone'] !== '', function ($query) use ($where) {
|
||||
$query->join('User U', 'StoreOrder.uid = U.uid')->where('phone', 'like', "%{$where['phone']}%");
|
||||
})
|
||||
->when(isset($where['store_name']) && $where['store_name'] !== '', function ($query) use ($where) {
|
||||
$orderId = StoreOrderProduct::alias('op')
|
||||
->join('storeProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['store_name']}%")
|
||||
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->column('order_id');
|
||||
$query->whereIn('order_id', $orderId ?: '');
|
||||
})
|
||||
->when(isset($where['search']) && $where['search'] !== '', function ($query) use ($where) {
|
||||
$orderId = StoreOrderProduct::alias('op')
|
||||
->join('storeProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['search']}%")
|
||||
->when((isset($where['sp.mer_id']) && $where['mer_id'] !== ''), function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->column('order_id');
|
||||
$query->where(function ($query) use ($orderId, $where) {
|
||||
$query->whereIn('order_id', $orderId ? $orderId : '')
|
||||
->whereOr('order_sn', 'like', "%{$where['search']}%")
|
||||
->whereOr('user_phone', 'like', "%{$where['search']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($where['product_id']) && $where['product_id'] !== '', function ($query) use ($where) {
|
||||
$orderId = StoreOrderProduct::alias('op')
|
||||
->join('storeProduct sp', 'op.product_id = sp.product_id')
|
||||
->where('sp.product_id', $where['product_id'])
|
||||
->column('order_id');
|
||||
$query->whereIn('order_id', $orderId ? $orderId : '');
|
||||
})
|
||||
->when(isset($where['group_order_sn']) && $where['group_order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->join('StoreGroupOrder GO', 'StoreOrder.group_order_id = GO.group_order_id')->where('group_order_sn', $where['group_order_sn']);
|
||||
})
|
||||
->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
|
||||
$query->where(function ($query) use ($where) {
|
||||
$query->whereLike('StoreOrder.real_name|StoreOrder.user_phone|order_sn', "%" . $where['keywords'] . "%");
|
||||
});
|
||||
})
|
||||
->order('StoreOrder.create_time DESC');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $uid
|
||||
* @return array|Model|null
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/11
|
||||
*/
|
||||
public function userOrder($id, $uid)
|
||||
{
|
||||
return StoreOrder::getDB()->where('order_id', $id)->where('uid', $uid)->where('is_del', 0)->where('paid', 1)->where('is_system_del', 0)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @param $ids
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/6/26
|
||||
*/
|
||||
public function usersOrderQuery(array $where, $ids, $uid)
|
||||
{
|
||||
return StoreOrder::getDB()->where(function ($query) use ($uid, $ids) {
|
||||
$query->whereIn('uid', $ids)
|
||||
->whereOr(function ($query) use ($uid) {
|
||||
if ($uid) {
|
||||
$query->where('uid', $uid)->where('is_selfbuy', 1);
|
||||
}
|
||||
});
|
||||
})->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'pay_time');
|
||||
})->when(isset($where['create_time']) && $where['create_time'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['create_time'], 'create_time');
|
||||
})->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
|
||||
$_uid = User::where('nickname', 'like', "%{$where['keyword']}%")->column('uid');
|
||||
$orderId = StoreOrderProduct::alias('op')
|
||||
->join('storeProduct sp', 'op.product_id = sp.product_id')
|
||||
->whereLike('store_name', "%{$where['keyword']}%")
|
||||
->column('order_id');
|
||||
$query->where(function ($query) use ($orderId, $where, $_uid) {
|
||||
$query->whereLike('order_id|order_sn', "%{$where['keyword']}%")->whereOr('order_id', 'in', $orderId)->whereOr('uid', 'in', $_uid);
|
||||
});
|
||||
})->where('paid', 1)->order('pay_time DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param int|null $except
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/6/11
|
||||
*/
|
||||
public function fieldExists($field, $value, ?int $except = null): bool
|
||||
{
|
||||
return ($this->getModel()::getDB())->when($except, function ($query) use ($field, $except) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public function getMerId($id)
|
||||
{
|
||||
return StoreOrder::getDB()->where('order_id', $id)->value('mer_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2020-06-12
|
||||
*/
|
||||
public function merFieldExists(array $where)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where($where)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param $reconciliation_id
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-06-15
|
||||
*/
|
||||
public function reconciliationUpdate($reconciliation_id)
|
||||
{
|
||||
return ($this->getModel()::getDB())->whereIn('reconciliation_id', $reconciliation_id)->update(['reconciliation_id' => 0]);
|
||||
}
|
||||
|
||||
public function dayOrderNum($day, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($day, function ($query, $day) {
|
||||
getModelTime($query, $day, 'pay_time');
|
||||
})->count();
|
||||
}
|
||||
|
||||
public function dayOrderPrice($day, $merId = null)
|
||||
{
|
||||
return getModelTime(StoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
}), $day, 'pay_time')->sum('pay_price');
|
||||
}
|
||||
|
||||
public function dateOrderPrice($date, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->sum('pay_price');
|
||||
}
|
||||
|
||||
public function dateOrderNum($date, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->count();
|
||||
}
|
||||
|
||||
public function dayOrderUserNum($day, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($day, function ($query, $day) {
|
||||
getModelTime($query, $day, 'pay_time');
|
||||
})->group('uid')->count();
|
||||
}
|
||||
|
||||
public function orderUserNum($date, $paid = null, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->when($paid, function ($query, $paid) {
|
||||
$query->where('paid', $paid);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) use ($paid) {
|
||||
if (!$paid) {
|
||||
getModelTime($query, $date);
|
||||
} else
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->group('uid')->count();
|
||||
}
|
||||
|
||||
public function orderUserGroup($date, $paid = null, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->when($paid, function ($query, $paid) {
|
||||
$query->where('paid', $paid);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->group('uid')->field(Db::raw('uid,sum(pay_price) as pay_price,count(order_id) as total'))->select();
|
||||
}
|
||||
|
||||
public function oldUserNum(array $ids, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->whereIn('uid', $ids)->where('paid', 1)->group('uid')->count();
|
||||
}
|
||||
|
||||
public function oldUserIds(array $ids, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->whereIn('uid', $ids)->where('paid', 1)->group('uid')->column('uid');
|
||||
}
|
||||
|
||||
public function orderPrice($date, $paid = null, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->when($paid, function ($query, $paid) {
|
||||
$query->where('paid', $paid);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->when($date, function ($query, $date) use ($paid) {
|
||||
if (!$paid) {
|
||||
$query->where(function ($query) use ($date) {
|
||||
$query->where(function ($query) use ($date) {
|
||||
$query->where('paid', 1);
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->whereOr(function ($query) use ($date) {
|
||||
$query->where('paid', 0);
|
||||
getModelTime($query, $date);
|
||||
});
|
||||
});
|
||||
} else
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->sum('pay_price');
|
||||
}
|
||||
|
||||
public function orderGroupNum($date, $merId = null)
|
||||
{
|
||||
$field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`');
|
||||
if ($date == 'year') {
|
||||
$field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m\') as `day`');
|
||||
}
|
||||
$query = StoreOrder::getDB()->field($field)
|
||||
->where('paid', 1)->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
});
|
||||
return $query->order('pay_time ASC')->group('day')->select();
|
||||
}
|
||||
|
||||
public function orderGroupNumPage($where, $page, $limit, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->when(isset($where['dateRange']), function ($query) use ($where) {
|
||||
getModelTime($query, date('Y/m/d 00:00:00', $where['dateRange']['start']) . '-' . date('Y/m/d 00:00:00', $where['dateRange']['stop']), 'pay_time');
|
||||
})->field(Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`'))
|
||||
->where('paid', 1)->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->order('pay_time DESC')->page($page, $limit)->group('day')->select();
|
||||
}
|
||||
|
||||
public function dayOrderPriceGroup($date, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->field(Db::raw('sum(pay_price) as price, from_unixtime(unix_timestamp(pay_time),\'%H:%i\') as time'))
|
||||
->where('paid', 1)->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->group('time')->select();
|
||||
}
|
||||
|
||||
public function dayOrderNumGroup($date, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->field(Db::raw('count(*) as total, from_unixtime(unix_timestamp(pay_time),\'%H:%i\') as time'))
|
||||
->where('paid', 1)->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->group('time')->select();
|
||||
}
|
||||
|
||||
public function dayOrderUserGroup($date, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->field(Db::raw('count(DISTINCT uid) as total, from_unixtime(unix_timestamp(pay_time),\'%H:%i\') as time'))
|
||||
->where('paid', 1)->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->group('time')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间到指定时间的支付金额 管理员
|
||||
* @param string $start 开始时间
|
||||
* @param string $stop 结束时间
|
||||
* @return mixed
|
||||
*/
|
||||
public function chartTimePrice($start, $stop, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->where('paid', 1)
|
||||
->where('pay_time', '>=', $start)
|
||||
->where('pay_time', '<', $stop)
|
||||
->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})
|
||||
->field('sum(pay_price) as num,FROM_UNIXTIME(unix_timestamp(pay_time), \'%Y-%m-%d\') as time')
|
||||
->group('time')
|
||||
->order('pay_time ASC')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
* @param null $merId
|
||||
* @return mixed
|
||||
*/
|
||||
public function chartTimeNum($date, $merId = null)
|
||||
{
|
||||
return StoreOrder::getDB()->where('paid', 1)->when($date, function ($query) use ($date) {
|
||||
getModelTime($query, $date, 'pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->field('count(order_id) as num,FROM_UNIXTIME(unix_timestamp(pay_time), \'%Y-%m-%d\') as time')
|
||||
->group('time')
|
||||
->order('pay_time ASC')->select()->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $end
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/9/16
|
||||
*/
|
||||
public function getFinishTimeoutIds($end)
|
||||
{
|
||||
return StoreOrderStatus::getDB()->alias('A')->leftJoin('StoreOrder B', 'A.order_id = B.order_id')
|
||||
->where('A.change_type', 'take')
|
||||
->where('A.change_time', '<', $end)->where('B.paid', 1)->where('B.status', 2)
|
||||
->column('A.order_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 参与人数
|
||||
* @param array $data
|
||||
* @param int|null $uid
|
||||
* @return BaseQuery
|
||||
* @author Qinii
|
||||
* @day 2020-11-11
|
||||
*/
|
||||
public function getTattendCount(array $data, ?int $uid)
|
||||
{
|
||||
$query = StoreOrder::hasWhere('orderProduct', function ($query) use ($data, $uid) {
|
||||
$query->when(isset($data['activity_id']), function ($query) use ($data) {
|
||||
$query->where('activity_id', $data['activity_id']);
|
||||
})
|
||||
->when(isset($data['product_sku']), function ($query) use ($data) {
|
||||
$query->where('product_sku', $data['product_sku']);
|
||||
})
|
||||
->when(isset($data['product_id']), function ($query) use ($data) {
|
||||
$query->where('product_id', $data['product_id']);
|
||||
})
|
||||
->when(isset($data['exsits_id']), function ($query) use ($data) {
|
||||
switch ($data['product_type']) {
|
||||
case 3:
|
||||
$make = app()->make(ProductAssistSetRepository::class);
|
||||
$id = 'product_assist_id';
|
||||
break;
|
||||
case 4:
|
||||
$make = app()->make(ProductGroupBuyingRepository::class);
|
||||
$id = 'product_group_id';
|
||||
break;
|
||||
}
|
||||
$where = [$id => $data['exsits_id']];
|
||||
$activity_id = $make->getSearch($where)->column($make->getPk());
|
||||
if ($activity_id) {
|
||||
$id = array_unique($activity_id);
|
||||
$query->where('activity_id', 'in', $id);
|
||||
} else {
|
||||
$query->where('activity_id', '<', 0);
|
||||
}
|
||||
})
|
||||
->where('product_type', $data['product_type']);
|
||||
if ($uid) $query->where('uid', $uid);
|
||||
});
|
||||
$query->where('activity_type', $data['product_type']);
|
||||
switch ($data['product_type']) {
|
||||
case 0:
|
||||
$query->where(function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1);
|
||||
})->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 1: //秒杀
|
||||
$query->where(function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1);
|
||||
})->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
});
|
||||
})->when(isset($data['day']), function ($query) use ($data) {
|
||||
$query->whereDay('StoreOrder.create_time', $data['day']);
|
||||
});
|
||||
break;
|
||||
case 2: //预售
|
||||
|
||||
/**
|
||||
* 第一阶段参与人数:所有人
|
||||
* 第二阶段参与人数:支付了第一阶段
|
||||
*/
|
||||
//第二阶段
|
||||
if ($data['type'] == 1) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1)->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
if ($data['type'] == 2) $query->where('paid', 1)->where('status', 'in', [0, 1, 2, 3, -1]);
|
||||
break;
|
||||
case 3: //助力
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1)->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 4: //
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1)->whereOr(function ($query) {
|
||||
$query->where('paid', 0)->where('is_del', 0);
|
||||
})
|
||||
->where('status', '>', -1);
|
||||
});
|
||||
break;
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 未使用
|
||||
* TODO 成功支付人数
|
||||
* @param int $productType
|
||||
* @param int $activityId
|
||||
* @param int|null $uid
|
||||
* @param int|null $status
|
||||
* @author Qinii
|
||||
* @day 2020-10-30
|
||||
*/
|
||||
public function getTattendSuccessCount($data, ?int $uid)
|
||||
{
|
||||
$query = StoreOrder::hasWhere('orderProduct', function ($query) use ($data, $uid) {
|
||||
$query->when(isset($data['activity_id']), function ($query) use ($data) {
|
||||
$query->where('activity_id', $data['activity_id']);
|
||||
})
|
||||
->when(isset($data['product_sku']), function ($query) use ($data) {
|
||||
$query->where('product_sku', $data['product_sku']);
|
||||
})
|
||||
->when(isset($data['product_id']), function ($query) use ($data) {
|
||||
$query->where('product_id', $data['product_id']);
|
||||
})
|
||||
->when(isset($data['exsits_id']), function ($query) use ($data) {
|
||||
switch ($data['product_type']) {
|
||||
case 3:
|
||||
$make = app()->make(ProductAssistSetRepository::class);
|
||||
$id = 'product_assist_id';
|
||||
break;
|
||||
case 4:
|
||||
$make = app()->make(ProductGroupBuyingRepository::class);
|
||||
$id = 'product_group_id';
|
||||
break;
|
||||
}
|
||||
$where = [$id => $data['exsits_id']];
|
||||
$activity_id = $make->getSearch($where)->column($make->getPk());
|
||||
if ($activity_id) {
|
||||
$id = array_unique($activity_id);
|
||||
$query->where('activity_id', 'in', $id);
|
||||
} else {
|
||||
$query->where('activity_id', '<', 0);
|
||||
}
|
||||
})
|
||||
->where('product_type', $data['product_type']);
|
||||
if ($uid) $query->where('uid', $uid);
|
||||
});
|
||||
$query->where('activity_type', $data['product_type'])->where('paid', 1);
|
||||
|
||||
switch ($data['product_type']) {
|
||||
case 1: //秒杀
|
||||
$query->where(function ($query) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('paid', 1);
|
||||
});
|
||||
})->when(isset($data['day']), function ($query) use ($data) {
|
||||
$query->whereDay('StoreOrder.create_time', $data['day']);
|
||||
});
|
||||
break;
|
||||
case 2: //预售
|
||||
if ($data['type'] == 1) { //第一阶段
|
||||
$query->where('status', 'in', [0, 1, 2, 3, 10]);
|
||||
} else { //第二阶段
|
||||
$query->where('status', 'in', [0, 1, 2, 3]);
|
||||
}
|
||||
break;
|
||||
case 3: //助力
|
||||
break;
|
||||
case 4:
|
||||
break;
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 获取退款单数量
|
||||
* @param $where
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 1/4/21
|
||||
*/
|
||||
public function getSeckillRefundCount($where, $type = 1)
|
||||
{
|
||||
$query = StoreOrderProduct::getDB()->alias('P')->join('StoreRefundOrder R', 'P.order_id = R.order_id');
|
||||
$query->join('StoreOrder O', 'O.order_id = P.order_id');
|
||||
$query
|
||||
->when(isset($where['activity_id']), function ($query) use ($where) {
|
||||
$query->where('P.activity_id', $where['activity_id']);
|
||||
})
|
||||
->when(isset($where['product_id']), function ($query) use ($where) {
|
||||
$query->where('P.product_id', $where['product_id']);
|
||||
})
|
||||
->when(isset($where['product_sku']), function ($query) use ($where) {
|
||||
$query->where('P.product_sku', $where['product_sku']);
|
||||
})
|
||||
->when(isset($where['day']), function ($query) use ($where) {
|
||||
$query->whereDay('P.create_time', $where['day']);
|
||||
})
|
||||
->when($type == 1, function ($query) use ($where) {
|
||||
$query->where('O.verify_time', null)->where('O.delivery_type', null);
|
||||
}, function ($query) {
|
||||
$query->where('R.refund_type', 2);
|
||||
})
|
||||
->where('P.product_type', 1)->where('R.status', 3);
|
||||
return $query->sum('R.refund_num');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 用户的某个商品购买数量
|
||||
* @param int $uid
|
||||
* @param int $productId
|
||||
* @return int
|
||||
* @author Qinii
|
||||
* @day 2022/9/26
|
||||
*/
|
||||
public function getMaxCountNumber(int $uid, int $productId)
|
||||
{
|
||||
return (int)StoreOrderProduct::hasWhere('orderInfo', function ($query) use ($uid) {
|
||||
$query->where('uid', $uid)->where(function ($query) {
|
||||
$query->where('is_del', 0)->whereOr(function ($query) {
|
||||
$query->where('is_del', 1)->where('paid', 1);
|
||||
});
|
||||
});
|
||||
})->where('product_id', $productId)->sum('product_num');
|
||||
}
|
||||
|
||||
public function getOrderSn($order_id)
|
||||
{
|
||||
return StoreOrder::getDB()->where($this->getPk(), $order_id)->value('order_sn', '');
|
||||
}
|
||||
|
||||
public function getSubOrderNotSend(int $group_order_id, int $order_id)
|
||||
{
|
||||
return StoreOrder::getDB()->where('group_order_id', $group_order_id)->where('status', 0)->where('order_id', '<>', $order_id)->count();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取商户排行
|
||||
* @param string $date
|
||||
* @param string $type
|
||||
* @param string $sort
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMerchantTop(string $date, string $type = 'sales', string $sort = 'desc')
|
||||
{
|
||||
|
||||
$query = StoreOrder::getDB()->with(['merchant' => function ($query) {
|
||||
$query->field('mer_id,mer_name,mer_avatar');
|
||||
}]);
|
||||
$query = getModelTime($query, $date)->where('paid', 1)->where('mer_id', '>', 0)->field('mer_id,sum(total_num) as sales,sum(pay_price + pay_postage) as price')->group('mer_id');
|
||||
switch ($type) {
|
||||
case 'sales':
|
||||
$query->order('sales ' . $sort);
|
||||
break;
|
||||
case 'price':
|
||||
$query->order('price ' . $sort);
|
||||
break;
|
||||
}
|
||||
|
||||
return $query->limit(0, 10)->select()->toArray();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,197 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\order\StoreOrderProduct;
|
||||
use think\facade\Db;
|
||||
use think\model\Relation;
|
||||
|
||||
/**
|
||||
* Class StoreOrderProductDao
|
||||
* @package app\common\dao\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/6/10
|
||||
*/
|
||||
class StoreOrderProductDao extends BaseDao
|
||||
{
|
||||
const ORDER_VERIFY_STATUS_ = 1;
|
||||
const ORDER_VERIFY_STATUS_SUCCESS = 3;
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/10
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreOrderProduct::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $uid
|
||||
* @return array|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/10
|
||||
*/
|
||||
public function userOrderProduct($id, $uid)
|
||||
{
|
||||
return StoreOrderProduct::getDB()->where('uid', $uid)->where('order_product_id', $id)->with(['orderInfo' => function (Relation $query) {
|
||||
$query->field('order_id,order_sn,mer_id')->where('status', 2);
|
||||
}])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $orderId
|
||||
* @return int
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public function noReplyProductCount($orderId)
|
||||
{
|
||||
return StoreOrderProduct::getDB()->where('order_id', $orderId)->where('is_refund','<>','3')->where('is_reply', 0)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @param $uid
|
||||
* @param null $orderId
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public function userRefundProducts(array $ids, $uid, $orderId = null,$refund_switch = 1)
|
||||
{
|
||||
return StoreOrderProduct::getDB()
|
||||
->when($ids,function($query) use($ids){
|
||||
$query->whereIn('order_product_id', $ids);
|
||||
})
|
||||
->when($orderId, function ($query) use($orderId) {
|
||||
$query->where('order_id', $orderId);
|
||||
})
|
||||
->when($uid, function ($query) use($uid) {
|
||||
$query->where('uid', $uid);
|
||||
})
|
||||
->when($refund_switch, function ($query) use($refund_switch) {
|
||||
$query->where('refund_switch', $refund_switch);
|
||||
})
|
||||
->where('refund_num', '>', 0)->select();
|
||||
}
|
||||
|
||||
public function orderProductGroup($date, $merId = null, $limit = 7)
|
||||
{
|
||||
return StoreOrderProduct::getDB()->alias('A')->leftJoin('StoreOrder B', 'A.order_id = B.order_id')
|
||||
->field(Db::raw('sum(A.product_num) as total,A.product_id,cart_info'))
|
||||
->withAttr('cart_info', function ($val) {
|
||||
return json_decode($val, true);
|
||||
})->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'B.pay_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('B.mer_id', $merId);
|
||||
})->where('B.paid', 1)->group('A.product_id')->limit($limit)->order('total DESC')->select();
|
||||
}
|
||||
|
||||
public function dateProductNum($date)
|
||||
{
|
||||
return StoreOrderProduct::getDB()->alias('A')->leftJoin('StoreOrder B', 'A.order_id = B.order_id')->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'B.pay_time');
|
||||
})->where('B.paid',1)->sum('A.product_num');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 用户购买活动商品数量
|
||||
* @param int $activityId
|
||||
* @param int $uid
|
||||
* @param int $orderType
|
||||
* @return int
|
||||
* @author Qinii
|
||||
* @day 2020-10-23
|
||||
*/
|
||||
public function getUserPayCount(int $activityId,int $uid,int $productType)
|
||||
{
|
||||
$query = StoreOrderProduct::hasWhere('orderInfo',function($query){
|
||||
// 已支付/未支付
|
||||
$query->where('is_del',0)->whereOr(function($query){
|
||||
$query->where('paid',1)->where('is_del',1);
|
||||
});
|
||||
});
|
||||
$query->where('uid',$uid)->where('product_type',$productType)->where('activity_id',$activityId);
|
||||
$count = $query->count();
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
public function getUserPayProduct(?string $keyword, int $uid)
|
||||
{
|
||||
$query = StoreOrderProduct::hasWhere('spu',function($query) use($keyword){
|
||||
$query->when($keyword, function ($query) use($keyword) {
|
||||
$query->whereLike('store_name',"%{$keyword}%");
|
||||
});
|
||||
$query->where('product_type',0);
|
||||
});
|
||||
$query->where('uid', $uid)->where('StoreOrderProduct.product_type',0);
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 统计已支付的订单 商品相关信息
|
||||
* @param int $mer_id
|
||||
* @param $type 统计类型 金额/数量/支付时间
|
||||
* @param $date 统计时间段
|
||||
* @param $limit
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2023/11/28
|
||||
*/
|
||||
public function getProductRate(int $mer_id, $date = '', $type = 'number', $limit = 10, string $group = 'P.product_id')
|
||||
{
|
||||
$query = StoreOrderProduct::getDB()->alias('P')->leftJoin('StoreOrder O', 'O.order_id = P.order_id')
|
||||
->with(['product' => function ($query) {
|
||||
$query->field('product_id,store_name,image');
|
||||
}])->where('O.paid', 1);
|
||||
switch($type){
|
||||
case 'number':
|
||||
$field = "P.product_id,O.pay_price as number,sum(P.product_num) as count,P.create_time, P.order_id,O.mer_id";
|
||||
break;
|
||||
case 'count':
|
||||
$field = "P.product_id,sum(P.product_num) as count,O.pay_price as number,P.create_time, P.order_id,O.mer_id";
|
||||
break;
|
||||
case 'paytime':
|
||||
$field = 'P.product_id,O.pay_time paytime,O.pay_price as number,P.create_time, P.order_id,O.mer_id';
|
||||
break;
|
||||
default:
|
||||
$field = 'P.*';
|
||||
break;
|
||||
}
|
||||
$query->when($mer_id, function ($query) use($mer_id) {
|
||||
$query->where('O.mer_id', $mer_id);
|
||||
})->when($date, function($query) use ($date) {
|
||||
getModelTime($query, $date,'P.create_time');
|
||||
});
|
||||
|
||||
return $query->field($field)->when(!empty($group), function ($query) use ($group) {
|
||||
$query->group($group);
|
||||
})->order("$type DESC")->limit($limit)->select();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreOrderProfitsharing;
|
||||
|
||||
class StoreOrderProfitsharingDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreOrderProfitsharing::class;
|
||||
}
|
||||
|
||||
public function getOrderSn()
|
||||
{
|
||||
list($msec, $sec) = explode(' ', microtime());
|
||||
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
|
||||
$orderId = 'pr' . $msectime . random_int(10000, max(intval($msec * 10000) + 10000, 98369));
|
||||
return $orderId;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
return StoreOrderProfitsharing::getDB()->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_id', $where['order_id']);
|
||||
})->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
|
||||
$query->where('type', $where['type']);
|
||||
})->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
$query->where('status', $where['status']);
|
||||
})->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['date']);
|
||||
})->when(isset($where['profit_date']) && $where['profit_date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['profit_date'], 'profitsharing_time');
|
||||
})->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('keyword', "%{$where['keyword']}%");
|
||||
});
|
||||
}
|
||||
|
||||
public function getAutoProfitsharing($time)
|
||||
{
|
||||
return StoreOrderProfitsharing::getDB()->alias('A')->join('StoreOrder B', 'A.order_id = B.order_id', 'left')
|
||||
->where(function ($query) {
|
||||
$query->where('B.status', '>', 1)->whereOr('B.status', -1);
|
||||
})->where('A.status', 0)->where(function ($query) use ($time) {
|
||||
$query->whereNotNull('B.verify_time')->where('B.verify_time', '<', $time);
|
||||
})->column('A.profitsharing_id');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreOrderReceipt;
|
||||
use app\common\model\user\User;
|
||||
|
||||
class StoreOrderReceiptDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreOrderReceipt::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
if((isset($where['order_type']) && $where['order_type'] !== '') || (isset($where['keyword']) && $where['keyword'] !== '')){
|
||||
$query = StoreOrderReceipt::hasWhere('storeOrder',function($query)use($where){
|
||||
switch ($where['order_type'])
|
||||
{
|
||||
case 1:
|
||||
$query->where('StoreOrder.paid',0)->where('StoreOrder.is_del',0);
|
||||
break; // 未支付
|
||||
case 2:
|
||||
$query->where('StoreOrder.paid',1)->where('StoreOrder.status',0)->where('StoreOrder.is_del',0);
|
||||
break; // 待发货
|
||||
case 3:
|
||||
$query->where('StoreOrder.status',1)->where('StoreOrder.is_del',0);
|
||||
break; // 待收货
|
||||
case 4:
|
||||
$query->where('StoreOrder.status',2)->where('StoreOrder.is_del',0);
|
||||
break; // 待评价
|
||||
case 5:
|
||||
$query->where('StoreOrder.status',3)->where('StoreOrder.is_del',0);
|
||||
break; // 交易完成
|
||||
case 6:
|
||||
$query->where('StoreOrder.status',-1)->where('StoreOrder.is_del',0);
|
||||
break; // 已退款
|
||||
case 7:
|
||||
$query->where('StoreOrder.is_del',1);
|
||||
break; // 已删除
|
||||
case 8:
|
||||
$query->where('StoreOrder.is_del', 0);
|
||||
break; //全部
|
||||
default:
|
||||
$query->where(true);
|
||||
break; //全部
|
||||
}
|
||||
$query->when(isset($where['keyword']) && $where['keyword'] !== '' ,function($query)use($where){
|
||||
$query->whereLike("order_sn|real_name|user_phone","%{$where['keyword']}%");
|
||||
});
|
||||
});
|
||||
}else{
|
||||
$query = StoreOrderReceipt::alias('StoreOrderReceipt');
|
||||
}
|
||||
$query->when(isset($where['status']) && $where['status'] !== '' ,function($query)use($where){
|
||||
$query->where('StoreOrderReceipt.status',$where['status']);
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'] !== '' ,function($query)use($where){
|
||||
getModelTime($query,$where['date'],'StoreOrderReceipt.create_time');
|
||||
})
|
||||
->when(isset($where['receipt_sn']) && $where['receipt_sn'] !== '' ,function($query)use($where){
|
||||
$query->where('StoreOrderReceipt.receipt_sn',$where['receipt_sn']);
|
||||
})
|
||||
->when(isset($where['username']) && $where['username'] !== '' ,function($query)use($where){
|
||||
$uid = User::whereLike('nickname|phone',"%{$where['username']}%")->column('uid');
|
||||
$query->where('StoreOrderReceipt.uid','in',$uid);
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '' ,function($query)use($where){
|
||||
$query->where('StoreOrderReceipt.mer_id',$where['mer_id']);
|
||||
})
|
||||
->when(isset($where['uid']) && $where['uid'] !== '' ,function($query)use($where){
|
||||
$query->where('StoreOrderReceipt.uid',$where['uid']);
|
||||
})
|
||||
;
|
||||
return $query->order('StoreOrderReceipt.create_time DESC');
|
||||
}
|
||||
|
||||
public function updateBySn(string $receipt_sn,$data)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('receipt_sn',$receipt_sn)->update($data);
|
||||
}
|
||||
|
||||
|
||||
public function deleteByOrderId($id)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('order_id',$id)->delete();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\order\StoreOrderStatus;
|
||||
use app\common\repositories\store\order\StoreOrderStatusRepository;
|
||||
|
||||
/**
|
||||
* Class StoreOrderStatusDao
|
||||
* @package app\common\dao\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
class StoreOrderStatusDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreOrderStatus::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public function search($where)
|
||||
{
|
||||
$query = ($this->getModel()::getDB())
|
||||
->when(isset($where['id']) && $where['id'] !== '', function($query) use($where){
|
||||
$query->where('order_id', $where['id']);
|
||||
})
|
||||
->when(isset($where['type']) && $where['type'] !== '', function($query) use($where){
|
||||
$query->where('type', $where['type']);
|
||||
})
|
||||
->when(isset($where['user_type']) && $where['user_type'] !== '', function($query) use($where){
|
||||
$query->where('user_type', $where['user_type']);
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'] !== '', function($query) use($where){
|
||||
getModelTime($query, $where['date'],'change_time');
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getTimeoutDeliveryOrder($start,$end)
|
||||
{
|
||||
return StoreOrderStatus::getDB()->alias('A')->leftJoin('StoreOrder B', 'A.order_id = B.order_id')
|
||||
->whereIn('A.change_type', [StoreOrderStatusRepository::ORDER_DELIVERY_SELF, StoreOrderStatusRepository::ORDER_DELIVERY_NOTHING,StoreOrderStatusRepository::ORDER_DELIVERY_COURIER])
|
||||
->where('A.type','order')
|
||||
->whereBetweenTime('A.change_time',$start,$end)
|
||||
->where('B.paid', 1)->where('B.status', 1)
|
||||
->column('A.order_id');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreRefundOrder;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DbException;
|
||||
|
||||
class StoreRefundOrderDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreRefundOrder::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public function search(array $where)
|
||||
{
|
||||
if(isset($where['is_trader']) && $where['is_trader'] !== ''){
|
||||
$query = StoreRefundOrder::hasWhere('merchant',function($query)use($where){
|
||||
$query->where('is_trader',$where['is_trader']);
|
||||
});
|
||||
}else{
|
||||
$query = (StoreRefundOrder::getDB())->alias('StoreRefundOrder');
|
||||
}
|
||||
$query->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreRefundOrder.mer_id', $where['mer_id']);
|
||||
})->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
|
||||
$ids = StoreOrder::where('order_sn','like','%'.$where['order_sn'].'%')->column('order_id');
|
||||
$query->where('order_id','in',$ids);
|
||||
})->when(isset($where['refund_order_sn']) && $where['refund_order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->where('refund_order_sn', 'like', '%' . $where['refund_order_sn'] . '%');
|
||||
})->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreRefundOrder.status', $where['status']);
|
||||
})->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('uid', $where['uid']);
|
||||
})->when(isset($where['id']) && $where['id'] !== '', function ($query) use ($where) {
|
||||
$query->where('refund_order_id', $where['id']);
|
||||
})->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreRefundOrder.is_del', $where['is_del']);
|
||||
})->when(isset($where['type']) && $where['type'] == 1, function ($query) {
|
||||
$query->whereIn('StoreRefundOrder.status', [0, 1, 2]);
|
||||
})->when(isset($where['type']) && $where['type'] == 2, function ($query) {
|
||||
$query->whereIn('status', [-1, 3,-10]);
|
||||
})->when(isset($where['refund_type']) && $where['refund_type'] !== '',function($query)use($where){
|
||||
$query->where('refund_type',$where['refund_type']);
|
||||
})->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query,$where['date'],'StoreRefundOrder.create_time');
|
||||
})->when(isset($where['order_id']) && $where['order_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('order_id', $where['order_id']);
|
||||
})->when(isset($where['delivery_id']) && $where['delivery_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreRefundOrder.delivery_id', $where['delivery_id']);
|
||||
})->when(isset($where['user_type']) && $where['user_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreRefundOrder.user_type', $where['user_type']);
|
||||
})->when(isset($where['username']) && $where['username'] !== '', function ($query) use ($where) {
|
||||
$uid = User::whereLike('nickname|phone|real_name',"{$where['username']}")->column('uid');
|
||||
$query->whereIn('uid',$uid);
|
||||
});
|
||||
return $query->order('StoreRefundOrder.create_time DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-06-12
|
||||
*/
|
||||
public function getOne($id)
|
||||
{
|
||||
return $this->getModel()::where($this->getPk(),$id)->with([
|
||||
'refundProduct.product',
|
||||
'user' => function($query){
|
||||
$query->field('uid,nickname,phone');
|
||||
},
|
||||
'order.orderProduct'
|
||||
])->find()->append(['create_user']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2020-06-12
|
||||
*/
|
||||
public function getFieldExists($where)
|
||||
{
|
||||
return (($this->getModel()::getDB())->where($where)->count()) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $uid
|
||||
* @param $id
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/12
|
||||
*/
|
||||
public function userDel($uid, $id)
|
||||
{
|
||||
return StoreRefundOrder::getDB()->where('uid', $uid)->where('refund_order_id', $id)->where('status', 3)->update(['is_del' => 1, 'status_time' => date('Y-m-d H:i:s')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO超过期限退款申请
|
||||
* @param $time
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-06-13
|
||||
*/
|
||||
public function getTimeOutIds($time)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where('status_time','<=',$time)
|
||||
->where(function($query){
|
||||
$query->where(function($query){
|
||||
$query->where('refund_type',1)->where('status',0);
|
||||
})->whereOr(function($query){
|
||||
$query->where('refund_type',2)->where('status',2);
|
||||
});
|
||||
})->column('refund_order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param $reconciliation_id
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-06-15
|
||||
*/
|
||||
public function reconciliationUpdate($reconciliation_id)
|
||||
{
|
||||
return ($this->getModel()::getDB())->whereIn('reconciliation_id',$reconciliation_id)->update(['reconciliation_id' => 0]);
|
||||
}
|
||||
|
||||
public function refundPirceByOrder(array $orderIds)
|
||||
{
|
||||
return $this->getModel()::getDB()->whereIn('order_id',$orderIds)->where('status',3)->sum('refund_price');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreRefundProduct;
|
||||
|
||||
class StoreRefundProductDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreRefundProduct::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = $this->getModel()::getDB()
|
||||
->when(isset($where['order_id']) && $where['order_id'] !== '',function($query)use($where){
|
||||
$query->where('order_id',$where['order_id']);
|
||||
});
|
||||
|
||||
return $query->order('create_time');
|
||||
}
|
||||
|
||||
public function userRefundPrice(array $ids)
|
||||
{
|
||||
$lst = $this->getModel()::getDB()->alias('A')->leftJoin('StoreRefundOrder B', 'A.refund_order_id = B.refund_order_id')
|
||||
->where('B.status', '>', -1)
|
||||
->whereIn('A.order_product_id', $ids)->group('A.order_product_id')
|
||||
->field('A.order_product_id, SUM(A.refund_price) as refund_price, SUM(A.platform_refund_price) as platform_refund_price, SUM(A.refund_postage) as refund_postage, SUM(A.refund_integral) as refund_integral')
|
||||
->select()->toArray();
|
||||
$data = [];
|
||||
foreach ($lst as $item) {
|
||||
$data[$item['order_product_id']] = $item;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreRefundStatus;
|
||||
|
||||
class StoreRefundStatusDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return StoreRefundStatus::class;
|
||||
}
|
||||
|
||||
public function search($id)
|
||||
{
|
||||
return $query = StoreRefundStatus::getDB()->where('refund_order_id', $id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\parameter;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\parameter\Parameter;
|
||||
|
||||
class ParameterDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return Parameter::class;
|
||||
}
|
||||
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
}
|
||||
|
||||
public function clear(int $id, string $field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\parameter;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\parameter\ParameterTemplate;
|
||||
|
||||
class ParameterTemplateDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ParameterTemplate::class;
|
||||
}
|
||||
|
||||
public function clear(int $id, string $field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\parameter;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\parameter\ParameterValue;
|
||||
|
||||
class ParameterValueDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ParameterValue::class;
|
||||
}
|
||||
|
||||
public function clear($id,$field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductAssist;
|
||||
use app\common\repositories\store\product\SpuRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
|
||||
class ProductAssistDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductAssist::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = ProductAssist::hasWhere('product',function($query)use($where){
|
||||
$query->when(isset($where['product_show']) && $where['product_show'] !== '',function($query)use($where){
|
||||
$query->where('is_del',0)->where('mer_status',1)->where('product_type',3);
|
||||
})
|
||||
->where('status',1);
|
||||
});
|
||||
$query->Join('StoreSpu U', 'Product.product_id = U.product_id')->where('U.product_type', 3);
|
||||
$query->when(isset($where['product_assist_id']) && $where['product_assist_id'] !== '',function($query)use($where){
|
||||
$query->where('product_assist_id',$where['product_assist_id']);
|
||||
})
|
||||
->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){
|
||||
$query->whereLike('ProductAssist.store_name|ProductAssist.product_id',"%{$where['keyword']}%");
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){
|
||||
$query->where('ProductAssist.mer_id',$where['mer_id']);
|
||||
})
|
||||
->when(isset($where['type']) && $where['type'] !== '',function($query)use($where){
|
||||
switch ($where['type']){
|
||||
case 0: //未开始
|
||||
$query->whereTime('start_time','>',time());
|
||||
break;
|
||||
case 1: //进行中
|
||||
$query->whereTime('start_time','<=',time())->whereTime('end_time','>',time())
|
||||
->where('ProductAssist.product_status',1)->where('ProductAssist.status',1)->where('ProductAssist.is_show',1);
|
||||
break;
|
||||
case 2: //已结束
|
||||
$query->where(function($query){
|
||||
$query->where('action_status',-1)->whereOr('end_time','<= TIME',time());
|
||||
});
|
||||
break;
|
||||
}
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '',function($query)use($where){
|
||||
$query->where('ProductAssist.status',$where['status']);
|
||||
})
|
||||
->when(isset($where['is_show']) && $where['is_show'] !== '',function($query)use($where){
|
||||
$query->where('ProductAssist.is_show',$where['is_show']);
|
||||
})
|
||||
->when(isset($where['is_del']) && $where['is_del'] !== '',function($query)use($where){
|
||||
$query->where('ProductAssist.is_del',$where['is_del']);
|
||||
})
|
||||
->when(isset($where['mer_name']) && $where['mer_name'] !== '',function($query)use($where){
|
||||
$make = app()->make(MerchantRepository::class);
|
||||
$mer_id = $make->search(['keyword' => $where['mer_name']])->column('mer_id');
|
||||
$query->whereIn('ProductAssist.mer_id',$mer_id);
|
||||
})
|
||||
->when(isset($where['product_status']) && $where['product_status'] !== '',function($query)use($where){
|
||||
if($where['product_status'] == -1){
|
||||
$query->where('ProductAssist.product_status','in',[-1,-2]);
|
||||
}else{
|
||||
$query->where('ProductAssist.product_status',$where['product_status']);
|
||||
}
|
||||
})
|
||||
->when(isset($where['is_trader']) && $where['is_trader'] !== '',function($query)use($where){
|
||||
$make = app()->make(MerchantRepository::class);
|
||||
$mer_id = $make->search(['is_trader' => $where['is_trader']])->column('mer_id');
|
||||
$query->whereIn('ProductAssist.mer_id',$mer_id);
|
||||
})
|
||||
->when(isset($where['us_status']) && $where['us_status'] !== '',function($query)use($where){
|
||||
if($where['us_status'] == 0) {
|
||||
$query->where('ProductAssist.is_show',0)->where('ProductAssist.status',1)->where('ProductAssist.product_status',1);
|
||||
}
|
||||
if($where['us_status'] == 1) {
|
||||
$query->where('ProductAssist.is_show',1)->where('ProductAssist.status',1)->where('ProductAssist.product_status',1);
|
||||
}
|
||||
if($where['us_status'] == -1) {
|
||||
$query->where(function($query){
|
||||
$query->where('ProductAssist.status',0)->whereOr('ProductAssist.product_status','<>',1);
|
||||
});
|
||||
}
|
||||
})
|
||||
->when(isset($where['mer_labels']) && $where['mer_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.mer_labels', "%,{$where['mer_labels']},%");
|
||||
})
|
||||
->when(isset($where['sys_labels']) && $where['sys_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.sys_labels', "%,{$where['sys_labels']},%");
|
||||
})
|
||||
->when(isset($where['star']),function($query)use($where){
|
||||
$query->when($where['star'] !== '', function ($query) use ($where) {
|
||||
$query->where('U.star', $where['star']);
|
||||
});
|
||||
$query->order('U.star DESC,U.rank DESC,ProductAssist.create_time DESC');
|
||||
});
|
||||
$query->where('ProductAssist.is_del',0);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 移动端展示 条件
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2020-10-19
|
||||
*/
|
||||
public function assistShow()
|
||||
{
|
||||
return [
|
||||
'product_show' => 1,
|
||||
'product_status' => 1,
|
||||
'status' => 1,
|
||||
'is_show' => 1,
|
||||
'type' => 1,
|
||||
'is_del' => 0
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @author Qinii
|
||||
* @day 1/27/21
|
||||
*/
|
||||
public function valActiveStatus()
|
||||
{
|
||||
$query = $this->getModel()::getDB()->whereTime('end_time','<=',time())->where('action_status',1);
|
||||
$id = $query->column($this->getPk());
|
||||
if($id) {
|
||||
$this->getModel()::getDB()->where($this->getPk(),'in',$id)->update(['action_status' => -1]);
|
||||
$where = [
|
||||
'product_type' => 3,
|
||||
'activity_ids' => $id
|
||||
];
|
||||
app()->make(SpuRepository::class)->getSearch($where)->update(['status' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 软删除商户的所有商品
|
||||
* @param $merId
|
||||
* @author Qinii
|
||||
* @day 5/15/21
|
||||
*/
|
||||
public function clearProduct($merId)
|
||||
{
|
||||
$this->getModel()::getDb()->where('mer_id', $merId)->update(['is_del' => 1]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductAssistSet;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use think\Exception;
|
||||
|
||||
class ProductAssistSetDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductAssistSet::class;
|
||||
}
|
||||
|
||||
|
||||
public function incNum(int $type,int $id,int $inc = 1)
|
||||
{
|
||||
try{
|
||||
$query = $this->getModel()::where($this->getPk(),$id);
|
||||
if($type == 1) $query->inc('share_num',$inc)->update();
|
||||
if($type == 2) $query->inc('view_num',$inc)->update();
|
||||
}catch (Exception $exception){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function userCount()
|
||||
{
|
||||
$count = $this->getModel()::getDB()->count("*");
|
||||
$res = $this->getModel()::getDB()->order('create_time DESC')->with(['user' => function($query){
|
||||
$query->field('uid,avatar avatar_img');
|
||||
}])->limit(10)->group('uid')->select()->toArray();
|
||||
|
||||
$list = [];
|
||||
foreach ($res as $item){
|
||||
if(isset($item['user']['avatar_img']) && $item['user']['avatar_img']){
|
||||
$list[] = $item['user'];
|
||||
}
|
||||
}
|
||||
return compact('count','list');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 更新状态
|
||||
* @param int $id
|
||||
* @author Qinii
|
||||
* @day 2020-11-25
|
||||
*/
|
||||
public function changStatus(int $id)
|
||||
{
|
||||
$this->getModel()::getDB()->where($this->getPk(),$id)->update(['status' => 20]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductAssistSku;
|
||||
use think\facade\Db;
|
||||
|
||||
class ProductAssistSkuDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductAssistSku::class;
|
||||
}
|
||||
|
||||
public function clear($id)
|
||||
{
|
||||
$this->getModel()::getDB()->where('product_assist_id',$id)->delete();
|
||||
}
|
||||
|
||||
public function descStock(int $product_assist_id, string $unique, int $desc)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('product_assist_id', $product_assist_id)->where('unique', $unique)->update([
|
||||
'stock' => Db::raw('stock-' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
public function incStock(int $product_assist_id, string $unique, int $desc)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('product_assist_id', $product_assist_id)->where('unique', $unique)->update([
|
||||
'stock' => Db::raw('stock+' . $desc)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductAssistUser;
|
||||
|
||||
class ProductAssistUserDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductAssistUser::class;
|
||||
}
|
||||
|
||||
|
||||
public function userCount(int $limit = 3)
|
||||
{
|
||||
$count = $this->getModel()::getDB()->count("*");
|
||||
$list = $this->getModel()::getDB()->limit(3)->order('create_time DESC')->select();
|
||||
return compact('count','list');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductAttr as model;
|
||||
|
||||
class ProductAttrDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $productId
|
||||
* @return mixed
|
||||
*/
|
||||
public function clearAttr(int $productId)
|
||||
{
|
||||
return ($this->getModel())::where('product_id',$productId)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/13
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function insert(array $data)
|
||||
{
|
||||
return ($this->getModel()::getDB())->insertAll($data);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,322 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductAttrValue as model;
|
||||
use app\common\repositories\store\product\ProductCdkeyRepository;
|
||||
use app\common\repositories\store\product\ProductRepository;
|
||||
use think\db\exception\DbException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* Class ProductAttrValueDao
|
||||
* @package app\common\dao\store\product
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
class ProductAttrValueDao extends BaseDao
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
public function add($data,$isType)
|
||||
{
|
||||
if ($isType == 2) {
|
||||
foreach ($data as $datum) {
|
||||
if (!isset($datum['cdkey'])){
|
||||
$this->insertAll($data);
|
||||
break;
|
||||
}
|
||||
$cdkey = $datum['cdkey'];
|
||||
unset($datum['cdkey']);
|
||||
$sku = $this->create($datum);
|
||||
$arr = array_chunk($cdkey, 30);
|
||||
foreach ($arr as $item){
|
||||
$sku->productCdkey()->saveAll($item);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->insertAll($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $productId
|
||||
* @return mixed
|
||||
*/
|
||||
public function clearAttr(int $productId)
|
||||
{
|
||||
($this->getModel())::where('product_id', $productId)->delete();
|
||||
app()->make(ProductCdkeyRepository::class)->clearAttr($productId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFieldColumnt($key, $value, $field, $except = null)
|
||||
{
|
||||
return ($this->getModel()::getDB())->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->where($key, $value)->column($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/11
|
||||
* @param $key
|
||||
* @param $value
|
||||
* @param $field
|
||||
* @param null $except
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFieldSum($key, $value, $field, $except = null)
|
||||
{
|
||||
return ($this->getModel()::getDB())->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->where($key, $value)->sum($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/11
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function insert(array $data)
|
||||
{
|
||||
return ($this->getModel()::getDB())->insertAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/11
|
||||
* @param int|null $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return bool
|
||||
*/
|
||||
public function merFieldExists(?int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function getSku($id)
|
||||
{
|
||||
return ($this->getModel())::where('product_id', $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return mixed
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function getFieldExists(?int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->where($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $unique
|
||||
* @param int $desc
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function descStock(int $productId, string $unique, int $desc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('unique', $unique)->update([
|
||||
'stock' => Db::raw('stock-' . $desc),
|
||||
'sales' => Db::raw('sales+' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $sku
|
||||
* @param int $desc
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function descSkuStock(int $productId, string $sku, int $desc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('sku', $sku)->update([
|
||||
'stock' => Db::raw('stock-' . $desc),
|
||||
'sales' => Db::raw('sales+' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $sku
|
||||
* @param int $desc
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
* 特殊需求 秒杀商品需要增加秒杀商品sku的销量
|
||||
*/
|
||||
public function incSales(int $productId, string $sku, int $desc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('sku', $sku)->update([
|
||||
'sales' => Db::raw('sales+' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $unique
|
||||
* @param int $inc
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function incStock(int $productId, string $unique, int $inc)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->where('unique', $unique)->inc('stock', $inc)->update();
|
||||
model::getDB()->where('product_id', $productId)->where('unique', $unique)->where('sales', '>=', $inc)->dec('sales', $inc)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $sku
|
||||
* @param int $inc
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function incSkuStock(int $productId, string $sku, int $inc)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->where('sku', $sku)->inc('stock', $inc)->update();
|
||||
model::getDB()->where('product_id', $productId)->where('sku', $sku)->where('sales', '>', $inc)->dec('sales', $inc)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $unique
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function attrExists(int $productId, string $unique): bool
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('unique', $unique)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $sku
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/6/9
|
||||
*/
|
||||
public function skuExists(int $productId, string $sku): bool
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('sku', $sku)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 商品佣金是否大于设置佣金比例
|
||||
* @param $productId
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
* @day 2020-06-25
|
||||
*/
|
||||
public function checkExtensionById($productId)
|
||||
{
|
||||
$extension_one_rate = systemConfig('extension_one_rate');
|
||||
$extension_two_rate = systemConfig('extension_two_rate');
|
||||
|
||||
$count = ($this->getModel()::getDb())->where(function($query)use($productId,$extension_one_rate){
|
||||
$query->where('product_id',$productId)->whereRaw('price * '.$extension_one_rate.' > extension_one');
|
||||
})->whereOr(function($query)use($productId,$extension_two_rate){
|
||||
$query->where('product_id',$productId)->whereRaw('price * '.$extension_two_rate.' > extension_two');
|
||||
})->count();
|
||||
return $count ? false : true;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = ($this->getModel()::getDb())
|
||||
->when(isset($where['product_id']) && $where['product_id'] !== '',function($query)use($where){
|
||||
$query->where('product_id',$where['product_id']);
|
||||
})
|
||||
->when(isset($where['sku']) && $where['sku'] !== '',function($query)use($where){
|
||||
$query->where('sku',$where['sku']);
|
||||
})
|
||||
->when(isset($where['unique']) && $where['unique'] !== '',function($query)use($where){
|
||||
$query->where('unique',$where['unique']);
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function updates(array $ids, array $data)
|
||||
{
|
||||
$this->getModel()::getDb()->whereIn('product_id',$ids)->update($data);
|
||||
}
|
||||
|
||||
public function updatesExtension(array $ids, array $data)
|
||||
{
|
||||
app()->make(ProductRepository::class)->updates($ids,['extension_type' => 1]);
|
||||
$query = $this->getModel()::getDb()->where('product_id','in',$ids);
|
||||
$query->chunk(100, function($list) use($data){
|
||||
foreach ($list as $item) {
|
||||
$arr['extension_one'] = bcmul($item->price,$data['extension_one'],2);
|
||||
$arr['extension_two'] = bcmul($item->price,$data['extension_two'],2);
|
||||
$this->getModel()::getDb()->where('unique',$item->unique)->update($arr);
|
||||
}
|
||||
},'product_id');
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductCate as model;
|
||||
|
||||
class ProductCateDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $productId
|
||||
* @return mixed
|
||||
*/
|
||||
public function clearAttr(int $productId)
|
||||
{
|
||||
return ($this->getModel())::where('product_id',$productId)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/13
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function insert(array $data)
|
||||
{
|
||||
return ($this->getModel()::getDB())->insertAll($data);
|
||||
}
|
||||
|
||||
public function clear(int $id, string $field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductCdkey as model;
|
||||
|
||||
class ProductCdkeyDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
|
||||
public function clearAttr(int $productId)
|
||||
{
|
||||
return ($this->getModel())::where('product_id',$productId)->delete();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductContent as model;
|
||||
|
||||
class ProductContentDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $productId
|
||||
* @return mixed
|
||||
*/
|
||||
public function clearAttr(int $productId, ?int $type)
|
||||
{
|
||||
$query = ($this->getModel())::where('product_id', $productId);
|
||||
if (!is_null($type)) $query->where('type', $type);
|
||||
return $query->delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductCopy as model;
|
||||
|
||||
class ProductCopyDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
return $this->getModel()::getDB()
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){
|
||||
$query->where('mer_id',$where['mer_id']);
|
||||
})
|
||||
->when(isset($where['type']) && $where['type'] !== '',function($query)use($where){
|
||||
if($where['type'] == 'copy'){
|
||||
$query->where('type','in',['taobao','jd','copy']);
|
||||
} else {
|
||||
$query->where('type',$where['type']);
|
||||
}
|
||||
})
|
||||
->order('create_time DESC');
|
||||
}
|
||||
|
||||
public function get2()
|
||||
{
|
||||
return $data = model::where('store_product_copy_id','>',398)
|
||||
->where('store_product_copy_id','<',467)->field('info')->select();
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,760 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\Product as model;
|
||||
use app\common\repositories\store\product\SpuRepository;
|
||||
use app\common\repositories\store\StoreCategoryRepository;
|
||||
use crmeb\jobs\ChangeSpuStatusJob;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DbException;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
use think\facade\Queue;
|
||||
|
||||
class ProductDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return model::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function createAttr(int $id, array $data)
|
||||
{
|
||||
($this->getModel()::withTrashed()->find($id))->attr()->saveAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function createAttrValue(int $id, array $data)
|
||||
{
|
||||
($this->getModel()::withTrashed()->find($id))->attrValue()->saveAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function createContent(int $id, array $data)
|
||||
{
|
||||
($this->getModel()::withTrashed()->find($id))->content()->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/9
|
||||
* @param int $merId
|
||||
* @param $field
|
||||
* @param $value
|
||||
* @param null $except
|
||||
* @return bool
|
||||
*/
|
||||
public function merFieldExists(?int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return model::withTrashed()->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
public function apiFieldExists(int $merId, $field, $value, $except = null)
|
||||
{
|
||||
return ($this->getModel())::getDB()->when($except, function ($query, $except) use ($field) {
|
||||
$query->where($field, '<>', $except);
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('mer_id', $merId);
|
||||
})->where(['status' => 1])->where($field, $value)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param int $productId
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getDeleteExists(int $merId, int $productId)
|
||||
{
|
||||
return ($this->getModel())::onlyTrashed()->where('mer_id', $merId)->where($this->getPk(), $productId)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/11
|
||||
* @param $merId
|
||||
* @param array $where
|
||||
* @return mixed
|
||||
*/
|
||||
public function search($merId, array $where)
|
||||
{
|
||||
$keyArray = $whereArr = [];
|
||||
$out = ['soft', 'us_status', 'mer_labels', 'sys_labels', 'order', 'hot_type', 'is_action','seckill_active_id','level_one_cate_ids'];
|
||||
foreach ($where as $key => $item) {
|
||||
if ($item !== '' && !in_array($key, $out)) {
|
||||
$keyArray[] = $key;
|
||||
$whereArr[$key] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$query = isset($where['soft']) ? model::onlyTrashed()->alias('Product')->where('delete', 0) : model::alias('Product');
|
||||
if (isset($where['is_trader']) && $where['is_trader'] !== '') {
|
||||
$query->hasWhere('merchant', function ($query) use ($where) {
|
||||
$query->where('is_trader', $where['is_trader']);
|
||||
});
|
||||
}
|
||||
$query->withSearch($keyArray, $whereArr)->Join('StoreSpu U', 'Product.product_id = U.product_id')->where('U.product_type', $where['product_type'] ?? 0);
|
||||
$query->when((isset($where['level_one_cate_ids']) && !empty($where['level_one_cate_ids'])), function ($query) use ($where) {
|
||||
$storeCategoryRepository = app()->make(StoreCategoryRepository::class);
|
||||
$where['level_one_cate_ids'] = explode(',',$where['level_one_cate_ids']);
|
||||
if(!empty($where['level_one_cate_ids'])){
|
||||
$levelTwoCateIds = $storeCategoryRepository->getSearch([])->whereIn('pid',$where['level_one_cate_ids'])->column('store_category_id');//选中的一级分类下的二级分类ID数组
|
||||
if(!empty($levelTwoCateIds)){
|
||||
$levelThreeCateIds = $storeCategoryRepository->getSearch([])->whereIn('pid',$levelTwoCateIds)->column('store_category_id');
|
||||
if(!empty($levelThreeCateIds)){
|
||||
$query->whereIn('cate_id',$levelThreeCateIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
$query->when((isset($where['cate_id']) && !empty($where['cate_id'])), function ($query) use ($where) {
|
||||
$query->where(['cate_id'=>$where['cate_id']]);
|
||||
});
|
||||
$query->when((isset($where['seckill_active_id']) && is_array($where['seckill_active_id']) && !empty($where['seckill_active_id'])), function ($query) use ($where) {
|
||||
$query->whereIn('Product.active_id', $where['seckill_active_id']);
|
||||
});
|
||||
$query->when((isset($where['seckill_active_id']) && !is_array($where['seckill_active_id']) && $where['seckill_active_id']), function ($query) use ($where) {
|
||||
$query->where('Product.active_id', $where['seckill_active_id']);
|
||||
});
|
||||
$query->when($merId, function ($query) use ($merId) {
|
||||
if(is_array($merId)){
|
||||
$query->whereIn('Product.mer_id', $merId);
|
||||
}else if(!is_array($merId)){
|
||||
$query->where('Product.mer_id', $merId);
|
||||
}
|
||||
})
|
||||
->when(isset($where['hot_type']) && $where['hot_type'] !== '', function ($query) use ($where) {
|
||||
if ($where['hot_type'] == 'new')
|
||||
$query->where('is_new', 1);
|
||||
else if ($where['hot_type'] == 'hot')
|
||||
$query->where('is_hot', 1);
|
||||
else if ($where['hot_type'] == 'best')
|
||||
$query->where('is_best', 1);
|
||||
else if ($where['hot_type'] == 'good')
|
||||
$query->where('is_benefit', 1);
|
||||
})
|
||||
->when(isset($where['us_status']) && $where['us_status'] !== '', function ($query) use ($where) {
|
||||
if ($where['us_status'] == 0) {
|
||||
$query->where('Product.is_show', 0)->where('Product.is_used', 1)->where('Product.status', 1);
|
||||
}
|
||||
if ($where['us_status'] == 1) {
|
||||
$query->where('Product.is_show', 1)->where('Product.is_used', 1)->where('Product.status', 1);
|
||||
}
|
||||
if ($where['us_status'] == -1) {
|
||||
$query->where(function ($query) {
|
||||
$query->where('Product.is_used', 0)->whereOr('Product.status', '<>', 1);
|
||||
});
|
||||
}
|
||||
})
|
||||
// ->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
// $query->where('Product.status', $where['status']);
|
||||
// })
|
||||
->when(isset($where['mer_labels']) && $where['mer_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.mer_labels', "%,{$where['mer_labels']},%");
|
||||
})
|
||||
//活动商品列表
|
||||
->when(isset($where['is_action']) && $where['is_action'] !== '', function ($query) use ($where) {
|
||||
$query->where('type', '<>', 2);
|
||||
})
|
||||
->when(isset($where['sys_labels']) && $where['sys_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.sys_labels', "%,{$where['sys_labels']},%");
|
||||
})
|
||||
->when(isset($where['svip_price_type']) && $where['svip_price_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('Product.svip_price_type', $where['svip_price_type']);
|
||||
})
|
||||
->when(isset($where['product_type']) && $where['product_type'] == 1, function ($query) use ($where) {
|
||||
$query->where('active_id','>',0);
|
||||
})
|
||||
->when(isset($where['order']), function ($query) use ($where, $merId) {
|
||||
if (in_array($where['order'], ['is_new', 'price_asc', 'price_desc', 'rate', 'sales'])) {
|
||||
if ($where['order'] == 'price_asc') {
|
||||
$where['order'] = 'price ASC';
|
||||
} else if ($where['order'] == 'price_desc') {
|
||||
$where['order'] = 'price DESC';
|
||||
} else {
|
||||
$where['order'] = $where['order'] . ' DESC';
|
||||
}
|
||||
$query->order($where['order'] . ',rank DESC ,create_time DESC ');
|
||||
} else if ($where['order'] !== '') {
|
||||
$query->order('U.' . $where['order'] . ' DESC,U.create_time DESC');
|
||||
} else {
|
||||
$query->order('U.create_time DESC');
|
||||
}
|
||||
})
|
||||
->when(isset($where['star']), function ($query) use ($where) {
|
||||
$query->when($where['star'] !== '', function ($query) use ($where) {
|
||||
$query->where('U.star', $where['star']);
|
||||
});
|
||||
$query->order('U.star DESC,U.rank DESC,Product.create_time DESC');
|
||||
})
|
||||
->when(isset($where['sort']), function ($query) use ($where) {
|
||||
$query->when($where['sort'] !== '', function ($query) use ($where) {
|
||||
$query->where('U.sort', $where['sort']);
|
||||
});
|
||||
$query->order('Product.sort DESC,Product.create_time DESC');
|
||||
})
|
||||
->when(isset($where['is_good']) && $where['is_good'] !== '', function ($query) use ($where) {
|
||||
$query->where('Product.is_good', $where['is_good']);
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author Qinii
|
||||
* @day 2020-08-04
|
||||
*/
|
||||
public function seckillSearch(array $where)
|
||||
{
|
||||
$query = model::hasWhere('seckillActive', function ($query) use ($where) {
|
||||
$query->where('status', 1);
|
||||
// $query->whereTime('start_day', '<=', $where['day'])->whereTime('end_day', '>=', $where['day']);
|
||||
// $query->where('start_time', '<=', $where['start_time'])
|
||||
// ->where('end_time', '>', $where['start_time'])
|
||||
// ->where('end_time', '<=', $where['end_time']);
|
||||
});
|
||||
$query->Join('StoreSpu U', 'Product.product_id = U.product_id')->where('U.product_type', 1);
|
||||
$query->where([
|
||||
'Product.is_show' => 1,
|
||||
'Product.status' => 1,
|
||||
'Product.is_used' => 1,
|
||||
'Product.mer_status' => 1,
|
||||
'Product.product_type' => 1,
|
||||
'Product.is_gift_bag' => 0,
|
||||
])
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('Product.mer_id', $where['mer_id']);
|
||||
})
|
||||
->when(isset($where['active_id']) && !empty($where['active_id']) && is_array($where['active_id']), function ($query) use ($where) {
|
||||
$query->whereIn('Product.active_id', $where['active_id']);
|
||||
})
|
||||
->when(isset($where['star']), function ($query) use ($where) {
|
||||
$query->when($where['star'] !== '', function ($query) use ($where) {
|
||||
$query->where('U.star', $where['star']);
|
||||
});
|
||||
$query->order('U.star DESC,Product.rank DESC');
|
||||
});
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/18
|
||||
* @param int $id
|
||||
* @param bool $soft
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function delete(int $id, $soft = false)
|
||||
{
|
||||
if ($soft) {
|
||||
(($this->getModel())::onlyTrashed()->find($id))->force()->delete();
|
||||
} else {
|
||||
$this->getModel()::where($this->getPk(), $id)->update(['is_del' => 1]);
|
||||
}
|
||||
app()->make(SpuRepository::class)->getSearch(['product_id' => $id])->update(['is_del' => 1, 'status' => 0]);
|
||||
event('product.delete', compact('id'));
|
||||
}
|
||||
|
||||
public function destory(int $id)
|
||||
{
|
||||
try {
|
||||
$this->getModel()::withTrashed()->where('product_id', $id)->update(['delete' => 1]);
|
||||
app()->make(SpuRepository::class)->getSearch(['product_id' => $id])->delete();
|
||||
event('product.delete', compact('id'));
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-07-03
|
||||
*/
|
||||
public function restore($id)
|
||||
{
|
||||
$res = ($this->getModel())::onlyTrashed()->find($id);
|
||||
app()->make(SpuRepository::class)->delProduct($id, 0);
|
||||
return $res->restore();
|
||||
}
|
||||
|
||||
public function getOnlyTranshed($where)
|
||||
{
|
||||
return ($this->getModel())::onlyTrashed()->where($where)->order('product_id DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/18
|
||||
* @param int $id
|
||||
* @param array $status
|
||||
* @return mixed
|
||||
*/
|
||||
public function switchStatus(int $id, array $status)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where($this->getPk(), $id)->update($status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $merId
|
||||
* @param array $productIds
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/5/26
|
||||
*/
|
||||
public function productIdByImage(int $merId, array $productIds)
|
||||
{
|
||||
return model::getDB()->where('mer_id', $merId)->whereIn('product_id', $productIds)->column('product_id,image');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
* @return array
|
||||
* @author xaboy
|
||||
* @day 2020/5/30
|
||||
*/
|
||||
public function intersectionKey(array $ids): array
|
||||
{
|
||||
return model::getDB()->whereIn('product_id', $ids)->column('product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/30
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function productIdByMerId($id)
|
||||
{
|
||||
return model::getDB()->where('product_id', $id)->value('mer_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param int $desc
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function descStock(int $productId, int $desc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->update([
|
||||
'stock' => Db::raw('stock-' . $desc),
|
||||
'sales' => Db::raw('sales+' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param int $inc
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/6/8
|
||||
*/
|
||||
public function incStock(int $productId, int $inc)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->inc('stock', $inc)->update();
|
||||
model::getDB()->where('product_id', $productId)->where('sales', '>=', $inc)->dec('sales', $inc)->update();
|
||||
}
|
||||
|
||||
public function descSales(int $productId, int $desc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->update([
|
||||
'sales' => Db::raw('sales-' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
public function incSales(int $productId, int $inc)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->update([
|
||||
'sales' => Db::raw('sales+' . $inc)
|
||||
]);
|
||||
}
|
||||
|
||||
public function descIntegral(int $productId, $integral_total, $integral_price_total)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->update([
|
||||
'integral_total' => Db::raw('integral_total-' . $integral_total),
|
||||
'integral_price_total' => Db::raw('integral_price_total-' . $integral_price_total),
|
||||
]);
|
||||
}
|
||||
|
||||
public function incIntegral(int $productId, $integral_total, $integral_price_total)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->inc('integral_total', $integral_total)->inc('integral_price_total', $integral_price_total)->update();
|
||||
}
|
||||
|
||||
public function visitProductGroup($date, $merId = null, $limit = 7)
|
||||
{
|
||||
return model::getDB()->alias('A')->leftJoin('UserRelation B', 'A.product_id = B.type_id')
|
||||
->field(Db::raw('count(B.type_id) as total,A.product_id,A.store_name,A.image'))
|
||||
->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'B.create_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('A.mer_id', $merId);
|
||||
})->where('B.type', 1)->group('A.product_id')->limit($limit)->order('total DESC')->select();
|
||||
}
|
||||
|
||||
public function cartProductGroup($date, $merId = null, $limit = 7)
|
||||
{
|
||||
return model::getDB()->alias('A')->leftJoin('StoreCart B', 'A.product_id = B.product_id')
|
||||
->field(Db::raw('sum(B.cart_num) as total,A.product_id,A.store_name,A.image'))
|
||||
->when($date, function ($query, $date) {
|
||||
getModelTime($query, $date, 'B.create_time');
|
||||
})->when($merId, function ($query, $merId) {
|
||||
$query->where('A.mer_id', $merId);
|
||||
})->where('B.product_type', 0)->where('B.is_pay', 0)->where('B.is_del', 0)
|
||||
->where('B.is_new', 0)->where('B.is_fail', 0)->group('A.product_id')->limit($limit)->order('total DESC')->select();
|
||||
}
|
||||
|
||||
public function changeMerchantProduct($merId, $data)
|
||||
{
|
||||
($this->getModel()::getDB())->where('mer_id', $merId)->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param int $productId
|
||||
* @author Qinii
|
||||
* @day 2020-07-09
|
||||
*/
|
||||
public function incCareCount(int $productId)
|
||||
{
|
||||
($this->getModel()::getDB())->where($this->getPk(), $productId)->inc('care_count', 1)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param int $productId
|
||||
* @author Qinii
|
||||
* @day 2020-07-09
|
||||
*/
|
||||
public function decCareCount(array $productId)
|
||||
{
|
||||
($this->getModel()::getDB())->whereIn($this->getPk(), $productId)->where('care_count', '>', 0)->dec('care_count', 1)->update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO api展示的商品条件
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2020-08-18
|
||||
*/
|
||||
public function productShow()
|
||||
{
|
||||
return [
|
||||
'is_show' => 1, // 上架
|
||||
'status' => 1, // 审核通过
|
||||
'is_used' => 1, // 显示
|
||||
'product_type' => 0, // 普通商品
|
||||
'mer_status' => 1, //商铺状态正常
|
||||
'is_gift_bag' => 0, //不是礼包
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO api展示的礼包商品条件
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2020-08-18
|
||||
*/
|
||||
public function bagShow()
|
||||
{
|
||||
return [
|
||||
'is_show' => 1,
|
||||
'status' => 1,
|
||||
'is_used' => 1,
|
||||
'mer_status' => 1,
|
||||
'product_type' => 0,
|
||||
'is_gift_bag' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO api展示的秒杀商品条件
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2020-08-18
|
||||
*/
|
||||
public function seckillShow()
|
||||
{
|
||||
return [
|
||||
'is_show' => 1,
|
||||
'status' => 1,
|
||||
'is_used' => 1,
|
||||
'mer_status' => 1,
|
||||
'product_type' => 1,
|
||||
'is_gift_bag' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
public function getProductTypeById(int $productId, ?int $exsistType)
|
||||
{
|
||||
$product_type = $this->getModel()::getDB()
|
||||
->when($exsistType, function ($query) use ($exsistType) {
|
||||
$query->where('product_type', $exsistType);
|
||||
})
|
||||
->where($this->getPk(), $productId)->where('is_del', 0)->value('product_type');
|
||||
return $product_type == 0 ? true : false;
|
||||
}
|
||||
|
||||
public function getFailProduct(int $productId)
|
||||
{
|
||||
return $this->getModel()::withTrashed()->field('product_type,product_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,is_used,mer_form_id')->find($productId);
|
||||
}
|
||||
|
||||
public function geTrashedtProduct(int $id)
|
||||
{
|
||||
return model::withTrashed()->where($this->getPk(), $id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TODO 获取各种有效时间内的活动
|
||||
* @param int $productType
|
||||
* @return BaseQuery
|
||||
*
|
||||
* @date 2023/09/22
|
||||
* @author yyw
|
||||
*/
|
||||
public function activitSearch(int $productType)
|
||||
{
|
||||
$query = model::getDB()->alias('P')
|
||||
->where('P.is_del', 0)
|
||||
->where('P.mer_status', 1)
|
||||
->where('P.product_type', $productType);
|
||||
switch ($productType) {
|
||||
case 0:
|
||||
// $query->where('P.is_show',1)
|
||||
// ->where('P.is_used',1)
|
||||
// ->field('product_id,product_type,mer_id,store_name,keyword,price,rank,sort,image,status,temp_id');
|
||||
break;
|
||||
case 1:
|
||||
$query->join('StoreSeckillActive S', 'S.seckill_active_id = P.active_id')
|
||||
->field('P.*,S.status,S.seckill_active_id,S.end_time');
|
||||
break;
|
||||
case 2:
|
||||
$query->join('StoreProductPresell R', 'R.product_id = P.product_id')
|
||||
->where('R.is_del', 0)
|
||||
->field('P.*,R.product_presell_id,R.store_name,R.price,R.status,R.is_show,R.product_status,R.action_status');
|
||||
break;
|
||||
case 3:
|
||||
$query->join('StoreProductAssist A', 'A.product_id = P.product_id')
|
||||
->where('A.is_del', 0)
|
||||
->field('P.*,A.product_assist_id,A.store_name,A.status,A.is_show,A.product_status,A.action_status');
|
||||
break;
|
||||
case 4:
|
||||
$query->join('StoreProductGroup G', 'G.product_id = P.product_id')
|
||||
->where('G.is_del', 0)
|
||||
->field('P.*,G.product_group_id,G.price,G.status,G.is_show,G.product_status,G.action_status');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function commandChangeProductStatus($data)
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
foreach ($data as $item) {
|
||||
$status = 0;
|
||||
switch ($item['product_type']) {
|
||||
case 0:
|
||||
if ($item['is_show'] && $item['is_used']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => 0,
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
case 1:
|
||||
if ($item['is_show'] && $item['is_used'] && $item['status'] && ($item['end_time'] > time())) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => $item['seckill_active_id'],
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
case 2:
|
||||
if ($item['is_show'] && $item['action_status'] && $item['status'] && $item['product_status']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => $item['product_presell_id'],
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
case 3:
|
||||
if ($item['is_show'] && $item['action_status'] && $item['status'] && $item['product_status']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => $item['product_assist_id'],
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
case 4:
|
||||
if ($item['is_show'] && $item['action_status'] && $item['status'] && $item['product_status']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => $item['product_group_id'],
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
default:
|
||||
if ($item['is_show'] && $item['is_used']) $status = 1;
|
||||
$ret[] = [
|
||||
'activity_id' => 0,
|
||||
'product_id' => $item['product_id'],
|
||||
'mer_id' => $item['mer_id'],
|
||||
'keyword' => $item['keyword'],
|
||||
'price' => $item['price'],
|
||||
'rank' => $item['rank'],
|
||||
'sort' => $item['sort'],
|
||||
'image' => $item['image'],
|
||||
'status' => $status,
|
||||
'temp_id' => $item['temp_id'],
|
||||
'store_name' => $item['store_name'],
|
||||
'product_type' => $item['product_type'],
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 软删除商户的所有商品
|
||||
* @param $merId
|
||||
* @author Qinii
|
||||
* @day 5/15/21
|
||||
*/
|
||||
public function clearProduct($merId)
|
||||
{
|
||||
$this->getModel()::withTrashed()->where('mer_id', $merId)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取好物推荐列表
|
||||
* @param array|null $good_ids
|
||||
* @param $is_mer
|
||||
* @return array|mixed
|
||||
*
|
||||
* @date 2023/10/30
|
||||
* @author yyw
|
||||
*/
|
||||
public function getGoodList(array $good_ids, int $merId, $is_show = true)
|
||||
{
|
||||
if (empty($good_ids) && !$is_show) return [];
|
||||
$filed = 'product_id,image,store_name,price,create_time,is_gift_bag,is_good,is_show,mer_id,sales,status';
|
||||
$where = [];
|
||||
$limit = 30;
|
||||
if ($is_show) {
|
||||
$where = $this->productShow();
|
||||
$limit = 18;
|
||||
}
|
||||
$query = $this->getModel()::getDB()->where('mer_id', $merId)->where($where)
|
||||
->when(!empty($good_ids), function ($query) use ($good_ids) {
|
||||
$query->whereIn($this->getPk(), $good_ids);
|
||||
})->field($filed);
|
||||
$list = $query->limit($limit)->select()->toArray();
|
||||
|
||||
if ($is_show && count($list) < 6) {
|
||||
$res = $query->where('is_good', 1)->orderRaw("RAND()")->limit(6 - count($list))->select()->toArray();
|
||||
if ($res) $list = array_merge($list,$res);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function deleteProductFormByFormId(int $form_id, int $mer_id)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('mer_form_id', $form_id)->where('mer_id', $mer_id)->update(['mer_form_id' => 0]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductGroupBuying;
|
||||
|
||||
class ProductGroupBuyingDao extends BaseDao
|
||||
{
|
||||
public function getModel(): string
|
||||
{
|
||||
return ProductGroupBuying::class;
|
||||
}
|
||||
|
||||
|
||||
public function search($where)
|
||||
{
|
||||
$query = ProductGroupBuying::getDb()->alias('B')->join('StoreProductGroup G','B.product_group_id = G.product_group_id');
|
||||
|
||||
$query
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function($query)use($where){
|
||||
$query->where('B.mer_id',$where['mer_id']);
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'] , function($query)use($where){
|
||||
getModelTime($query,$where['date'],'B.create_time');
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '', function($query)use($where){
|
||||
$query->where('B.status',$where['status']);
|
||||
})
|
||||
->when(isset($where['user_name']) && $where['user_name'] !== '', function($query)use($where){
|
||||
$query->join('StoreProductGroupUser U','U.group_buying_id = B.group_buying_id')->where('is_initiator',1)
|
||||
->whereLike('uid|nickname',"%{$where['user_name']}%");
|
||||
})
|
||||
->when(isset($where['keyword']) && $where['keyword'] !== '' , function($query)use($where){
|
||||
$query->join('StoreProduct P','G.product_id = P.product_id')
|
||||
->whereLike('B.group_buying_id|P.product_id|store_name',"%{$where['keyword']}%");
|
||||
})
|
||||
->when(isset($where['is_trader']) && $where['is_trader'] !== '', function($query)use($where){
|
||||
$query->join('Merchant M','M.mer_id = B.mer_id')->where('is_trader',$where['is_trader']);
|
||||
})
|
||||
;
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductGroup;
|
||||
use app\common\repositories\store\product\SpuRepository;
|
||||
|
||||
class ProductGroupDao extends BaseDao
|
||||
{
|
||||
public function getModel(): string
|
||||
{
|
||||
return ProductGroup::class;
|
||||
}
|
||||
|
||||
public function search($where)
|
||||
{
|
||||
$query = ProductGroup::hasWhere('product',function($query)use($where){
|
||||
$query->where('status',1);
|
||||
$query->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){
|
||||
$query->whereLike('store_name',"%{$where['keyword']}%");
|
||||
});
|
||||
});
|
||||
$query->when(isset($where['is_show']) && $where['is_show'] !== '',function($query)use($where){
|
||||
$query->where('ProductGroup.is_show',$where['is_show']);
|
||||
})
|
||||
->when(isset($where['product_status']) && $where['product_status'] !== '',function($query)use($where){
|
||||
if($where['product_status'] == -1){
|
||||
$query->where('ProductGroup.product_status','in',[-1,-2]);
|
||||
}else{
|
||||
$query->where('ProductGroup.product_status',$where['product_status']);
|
||||
}
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '',function($query)use($where){
|
||||
$query->where('ProductGroup.status',$where['status']);
|
||||
})
|
||||
->when(isset($where['end_time']) && $where['end_time'] !== '',function($query)use($where){
|
||||
$query->whereTime('ProductGroup.end_time','>',$where['end_time']);
|
||||
})
|
||||
->when(isset($where['active_type']) && $where['active_type'] !== '',function($query)use($where){
|
||||
$query->where('ProductGroup.action_status',$where['active_type']);
|
||||
})
|
||||
->when(isset($where['is_trader']) && $where['is_trader'] !== '',function($query)use($where){
|
||||
$query->join('Merchant M','M.mer_id = ProductGroup.mer_id')->where('is_trader',$where['is_trader']);
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){
|
||||
$query->where('ProductGroup.mer_id',$where['mer_id']);
|
||||
})
|
||||
->when(isset($where['product_group_id']) && $where['product_group_id'] !== '',function($query)use($where){
|
||||
$query->where('ProductGroup.product_group_id',$where['product_group_id']);
|
||||
})
|
||||
->when(isset($where['store_category_id']) && $where['store_category_id'] !== '',function($query)use($where){
|
||||
$query->join('StoreCategory C','Product.cate_id = C.store_category_id')
|
||||
->whereLike('path',"/{$where['store_category_id']}/%");
|
||||
})
|
||||
->when(isset($where['us_status']) && $where['us_status'] !== '',function($query)use($where){
|
||||
if($where['us_status'] == 0) {
|
||||
$query->where('ProductGroup.is_show',0)->where('ProductGroup.status',1)->where('ProductGroup.product_status',1);
|
||||
}
|
||||
if($where['us_status'] == 1) {
|
||||
$query->where('ProductGroup.is_show',1)->where('ProductGroup.status',1)->where('ProductGroup.product_status',1);
|
||||
}
|
||||
if($where['us_status'] == -1) {
|
||||
$query->where(function($query){
|
||||
$query->where('ProductGroup.status',0)->whereOr('ProductGroup.product_status','<>',1);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$query->join('StoreSpu U','ProductGroup.product_group_id = U.activity_id')->where('U.product_type',4);
|
||||
|
||||
$query->when(isset($where['star']) && $where['star'] !== '',function($query)use($where){
|
||||
$query->where('U.star',$where['star']);
|
||||
})
|
||||
->when(isset($where['level']) && $where['level'] !== '',function($query)use($where) {
|
||||
$query->where('U.star',$where['level']);
|
||||
})
|
||||
->when(isset($where['mer_labels']) && $where['mer_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.mer_labels', "%,{$where['mer_labels']},%");
|
||||
})
|
||||
->when(isset($where['sys_labels']) && $where['sys_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.sys_labels', "%,{$where['sys_labels']},%");
|
||||
});
|
||||
if(isset($where['order'])) {
|
||||
switch ($where['order']) {
|
||||
case 'sort':
|
||||
$order = 'U.sort DESC';
|
||||
break;
|
||||
case 'rank':
|
||||
$order = 'U.rank DESC';
|
||||
break;
|
||||
case 'star':
|
||||
$order = 'U.star DESC,U.rank DESC';
|
||||
break;
|
||||
default:
|
||||
$order = 'U.star DESC,U.rank DESC,U.sort DES';
|
||||
break;
|
||||
}
|
||||
$query->order($order.',ProductGroup.create_time DESC');
|
||||
}
|
||||
|
||||
return $query->where('ProductGroup.is_del',0);
|
||||
}
|
||||
|
||||
public function actionShow()
|
||||
{
|
||||
return [
|
||||
'is_show' => 1,
|
||||
'action_status' => 1,
|
||||
'product_status' => 1,
|
||||
'status' => 1,
|
||||
'end_time' => time(),
|
||||
];
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
$query = ProductGroup::alias('G')->join('StoreProduct P','G.product_id = P.product_id')
|
||||
->join('StoreCategory C','P.cate_id = C.store_category_id');
|
||||
$query->where('G.is_show',1)->where('G.action_status',1)->where('G.product_status',1);
|
||||
$query->group('G.product_id');
|
||||
return $query->column('path');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @author Qinii
|
||||
* @day 1/27/21
|
||||
*/
|
||||
public function valActiveStatus()
|
||||
{
|
||||
$query = $this->getModel()::getDB()->whereTime('end_time','<=',time())->where('action_status',1);
|
||||
$id = $query->column($this->getPk());
|
||||
if($id) {
|
||||
$this->getModel()::getDB()->where($this->getPk(),'in',$id)->update(['action_status' => -1]);
|
||||
$where = [
|
||||
'product_type' => 4,
|
||||
'activity_ids' => $id
|
||||
];
|
||||
app()->make(SpuRepository::class)->getSearch($where)->update(['status' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 软删除商户的所有商品
|
||||
* @param $merId
|
||||
* @author Qinii
|
||||
* @day 5/15/21
|
||||
*/
|
||||
public function clearProduct($merId)
|
||||
{
|
||||
$this->getModel()::getDb()->where('mer_id', $merId)->update(['is_del' => 1]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductGroupSku;
|
||||
|
||||
class ProductGroupSkuDao extends BaseDao
|
||||
{
|
||||
public function getModel(): string
|
||||
{
|
||||
return ProductGroupSku::class;
|
||||
}
|
||||
|
||||
public function clear($id)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('product_group_id', $id)->delete();
|
||||
}
|
||||
|
||||
public function incStock($product_group_id, $unique, $inc)
|
||||
{
|
||||
return ProductGroupSku::getDB()->where('product_group_id', $product_group_id)->where('unique', $unique)->inc('stock', $inc)->update();
|
||||
}
|
||||
|
||||
public function descStock($product_group_id, $unique, $inc)
|
||||
{
|
||||
return ProductGroupSku::getDB()->where('product_group_id', $product_group_id)->where('unique', $unique)->dec('stock', $inc)->update();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductGroupUser;
|
||||
|
||||
class ProductGroupUserDao extends BaseDao
|
||||
{
|
||||
public function getModel(): string
|
||||
{
|
||||
return ProductGroupUser::class;
|
||||
}
|
||||
|
||||
public function successUser($id)
|
||||
{
|
||||
$query = ProductGroupUser::hasWhere('groupBuying',function($query){
|
||||
$query->where('status',10);
|
||||
});
|
||||
$query->where('ProductGroupUser.product_group_id',$id);
|
||||
return $query->setOption('field',[])->field('nickname,avatar')->select();
|
||||
}
|
||||
|
||||
public function updateStatus(int $groupId)
|
||||
{
|
||||
return $this->getModel()::getDb()->where('group_buying_id',$groupId)->update(['status' => 10]);
|
||||
}
|
||||
|
||||
public function groupOrderIds($productGroupId)
|
||||
{
|
||||
return ProductGroupUser::getDB()->where('group_buying_id', $productGroupId)->where('order_id', '>', 0)->select();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductLabel;
|
||||
|
||||
class ProductLabelDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductLabel::class;
|
||||
}
|
||||
|
||||
public function clear($id,$field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductPresell;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\store\product\SpuRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
|
||||
class ProductPresellDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductPresell::class;
|
||||
}
|
||||
|
||||
public function search(array $where)
|
||||
{
|
||||
$query = ProductPresell::hasWhere('product',function($query)use($where){
|
||||
$query->when(isset($where['product_show']) && $where['product_show'] !== '',function($query)use($where){
|
||||
$query->where('is_del',0)->where('mer_status',1);
|
||||
})
|
||||
->when(isset($where['product_type']) && $where['product_type'] !== '',function($query)use($where){
|
||||
$query->where('product_type',2);
|
||||
})
|
||||
->where('status',1);
|
||||
});
|
||||
$query->Join('StoreSpu U', 'ProductPresell.product_presell_id = U.activity_id')->where('U.product_type', 2);
|
||||
$query->when(isset($where['product_presell_id']) && $where['product_presell_id'] !== '',function($query)use($where){
|
||||
$query->where('product_presell_id',$where['product_presell_id']);
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '',function($query)use($where){
|
||||
$query->where('ProductPresell.mer_id',$where['mer_id']);
|
||||
})
|
||||
->when(isset($where['is_del']) && $where['is_del'] !== '',function($query)use($where){
|
||||
$query->where('ProductPresell.is_del',$where['is_del']);
|
||||
})
|
||||
->when(isset($where['action_status']) && $where['action_status'] !== '',function($query)use($where){
|
||||
$query->where('ProductPresell.action_status',$where['action_status']);
|
||||
})
|
||||
->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){
|
||||
$query->whereLike('ProductPresell.store_name|ProductPresell.product_id|ProductPresell.product_presell_id',"%{$where['keyword']}%");
|
||||
})
|
||||
->when(isset($where['product_status']) && $where['product_status'] !== '',function($query)use($where){
|
||||
if($where['product_status'] == -1){
|
||||
$query->where('ProductPresell.product_status','in',[-1,-2]);
|
||||
}else{
|
||||
$query->where('ProductPresell.product_status',$where['product_status']);
|
||||
}
|
||||
})
|
||||
->when(isset($where['presell_type']) && $where['presell_type'] !== '',function($query)use($where){
|
||||
$query->where('ProductPresell.presell_type',$where['presell_type']);
|
||||
})
|
||||
->when(isset($where['type']) && $where['type'] !== '',function($query)use($where){
|
||||
switch ($where['type']){
|
||||
case 0: //未开始
|
||||
if(isset($where['api_type'])){
|
||||
$query->where('product_status',1);
|
||||
}
|
||||
$query->where('action_status',1);
|
||||
$query->where(function($query){
|
||||
$query->whereTime('start_time','>',time())->whereOr(function ($query){
|
||||
$query->whereTime('start_time','<',time())->whereTime('end_time','>',time())->where(function($query){
|
||||
$query->where('ProductPresell.product_status','<>',1)->whereOr('ProductPresell.is_show','<>',1)->whereOr('ProductPresell.status','<>',1);
|
||||
});
|
||||
});
|
||||
});
|
||||
break;
|
||||
case 1: //进行中
|
||||
$query->where('action_status',1)
|
||||
->whereTime('start_time','<=',time())
|
||||
->whereTime('end_time','>',time())
|
||||
->where('product_status',1)
|
||||
->where('ProductPresell.status',1)
|
||||
->where('ProductPresell.is_show',1);
|
||||
break;
|
||||
case 2: //已结束
|
||||
$query->where(function($query){
|
||||
$query->where('action_status',-1)->whereOr('end_time','<= TIME',time());
|
||||
});
|
||||
break;
|
||||
case 3: //已关闭
|
||||
$query->where(function($query){
|
||||
$query->where(function($query){
|
||||
$query->where('ProductPresell.presell_type',1)->whereTime('end_time','<',time());
|
||||
})->whereOr(function($query){
|
||||
$query->where('ProductPresell.presell_type',2)->whereTime('final_end_time','<',time());
|
||||
});
|
||||
});
|
||||
break;
|
||||
default:
|
||||
$query->where(function($query){
|
||||
$query->where(function($query){
|
||||
$query->where('ProductPresell.presell_type',1)->whereTime('end_time','>',time());
|
||||
})->whereOr(function($query){
|
||||
$query->where('ProductPresell.presell_type',2)->whereTime('final_end_time','>',time());
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '',function($query)use($where){
|
||||
$query->where('ProductPresell.status',$where['status']);
|
||||
})
|
||||
->when(isset($where['is_show']) && $where['is_show'] !== '',function($query)use($where){
|
||||
$query->where('ProductPresell.is_show',$where['is_show']);
|
||||
})
|
||||
->when(isset($where['mer_name']) && $where['mer_name'] !== '',function($query)use($where){
|
||||
$make = app()->make(MerchantRepository::class);
|
||||
$mer_id = $make->search(['keyword' => $where['mer_name']])->column('mer_id');
|
||||
$query->whereIn('ProductPresell.mer_id',$mer_id);
|
||||
})
|
||||
->when(isset($where['is_trader']) && $where['is_trader'] !== '',function($query)use($where){
|
||||
$make = app()->make(MerchantRepository::class);
|
||||
$mer_id = $make->search(['is_trader' => $where['is_trader']])->column('mer_id');
|
||||
$query->whereIn('ProductPresell.mer_id',$mer_id);
|
||||
})
|
||||
->when(isset($where['us_status']) && $where['us_status'] !== '',function($query)use($where){
|
||||
if($where['us_status'] == 0) {
|
||||
$query->where('ProductPresell.is_show',0)->where('ProductPresell.status',1)->where('ProductPresell.product_status',1);
|
||||
}
|
||||
if($where['us_status'] == 1) {
|
||||
$query->where('ProductPresell.is_show',1)->where('ProductPresell.status',1)->where('ProductPresell.product_status',1);
|
||||
}
|
||||
if($where['us_status'] == -1) {
|
||||
$query->where(function($query){
|
||||
$query->where('ProductPresell.status',0)->whereOr('ProductPresell.product_status','<>',1);
|
||||
});
|
||||
}
|
||||
});
|
||||
$query->when(isset($where['mer_labels']) && $where['mer_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.mer_labels', "%,{$where['mer_labels']},%");
|
||||
})
|
||||
->when(isset($where['sys_labels']) && $where['sys_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.sys_labels', "%,{$where['sys_labels']},%");
|
||||
})
|
||||
->when(isset($where['star']),function($query)use($where){
|
||||
$query->when($where['star'] !== '', function ($query) use ($where) {
|
||||
$query->where('U.star', $where['star']);
|
||||
});
|
||||
$query->order('U.star DESC,U.rank DESC,ProductPresell.create_time DESC');
|
||||
});
|
||||
$query->where('ProductPresell.is_del',0);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 移动端展示 条件
|
||||
* @return array
|
||||
* @author Qinii
|
||||
* @day 2020-10-19
|
||||
*/
|
||||
public function actionShow()
|
||||
{
|
||||
return [
|
||||
'product_show' => 1,
|
||||
//'product_status' => 1,
|
||||
'status' => 1,
|
||||
'is_show' => 1,
|
||||
'api_type' => 1,
|
||||
'is_del' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @author Qinii
|
||||
* @day 1/27/21
|
||||
*/
|
||||
public function valActiveStatus()
|
||||
{
|
||||
$query = $this->getModel()::getDB()->whereTime('end_time','<=',time())->where('action_status',1);
|
||||
$id = $query->column($this->getPk());
|
||||
if($id){
|
||||
$this->getModel()::getDB()->where($this->getPk(),'in',$id)->update(['action_status' => -1]);
|
||||
$where = [
|
||||
'product_type' => 2,
|
||||
'activity_ids' => $id
|
||||
];
|
||||
app()->make(SpuRepository::class)->getSearch($where)->update(['status' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 软删除商户的所有商品
|
||||
* @param $merId
|
||||
* @author Qinii
|
||||
* @day 5/15/21
|
||||
*/
|
||||
public function clearProduct($merId)
|
||||
{
|
||||
$this->getModel()::getDb()->where('mer_id', $merId)->update(['is_del' => 1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductPresellSku;
|
||||
use think\facade\Db;
|
||||
|
||||
class ProductPresellSkuDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductPresellSku::class;
|
||||
}
|
||||
|
||||
public function clear($id)
|
||||
{
|
||||
$this->getModel()::getDB()->where('product_presell_id', $id)->delete();
|
||||
}
|
||||
|
||||
public function descStock(int $product_presell_id, string $unique, int $desc)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique', $unique)->update([
|
||||
'stock' => Db::raw('stock-' . $desc),
|
||||
'seles' => Db::raw('seles+' . $desc),
|
||||
]);
|
||||
}
|
||||
|
||||
public function incStock(int $product_presell_id, string $unique, int $desc)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique', $unique)->update([
|
||||
'stock' => Db::raw('stock+' . $desc),
|
||||
'seles' => Db::raw('seles-' . $desc),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 增加 参与或支付成功 人数
|
||||
* @param int $product_presell_id
|
||||
* @param string $unique
|
||||
* @param string $field
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-11-27
|
||||
*/
|
||||
public function incCount(int $product_presell_id,string $unique,string $field,$inc = 1)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique', $unique)
|
||||
->update([
|
||||
$field => Db::raw($field.'+' . $inc)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 减少 参与或支付成功 人数
|
||||
* @param int $product_presell_id
|
||||
* @param string $unique
|
||||
* @param string $field
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-11-27
|
||||
*/
|
||||
public function desCount(int $product_presell_id,string $unique,$inc = 1)
|
||||
{
|
||||
$res = $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique',$unique)->find();
|
||||
if($res->presell->presell_type == 1 ){
|
||||
$res->one_pay = ($res->one_pay > 0) ? $res->one_pay - $inc : 0;
|
||||
}else{
|
||||
$res->two_pay = ($res->two_pay > 0) ? $res->two_pay - $inc : 0;
|
||||
}
|
||||
return $res->save();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductReply;
|
||||
use crmeb\jobs\UpdateProductReplyJob;
|
||||
use think\db\BaseQuery;
|
||||
use think\db\exception\DbException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Queue;
|
||||
|
||||
/**
|
||||
* Class ProductReplyDao
|
||||
* @package app\common\dao\store\product
|
||||
* @author xaboy
|
||||
* @day 2020/5/30
|
||||
*/
|
||||
class ProductReplyDao extends BaseDao
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @author xaboy
|
||||
* @day 2020/5/30
|
||||
*/
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductReply::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return BaseQuery
|
||||
* @author xaboy
|
||||
* @day 2020/6/1
|
||||
*/
|
||||
public function search(array $where)
|
||||
{
|
||||
return ProductReply::getDB()->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('mer_id', $where['mer_id']);
|
||||
})->when(isset($where['is_reply']) && $where['is_reply'] !== '', function ($query) use ($where) {
|
||||
$query->where('is_reply', $where['is_reply']);
|
||||
})->when(isset($where['is_virtual']) && $where['is_virtual'] !== '', function ($query) use ($where) {
|
||||
$query->where('is_virtual', $where['is_virtual']);
|
||||
})->when(isset($where['nickname']) && $where['nickname'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('nickname', "%{$where['nickname']}%");
|
||||
})->when(isset($where['product_id']) && $where['product_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('product_id', $where['product_id']);
|
||||
})->when(isset($where['product_type']) && $where['product_type'] !== '', function ($query) use ($where) {
|
||||
$query->where('product_type', 'product_type');
|
||||
})->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
|
||||
$query->where('is_del', $where['is_del']);
|
||||
})->order('sort DESC');
|
||||
}
|
||||
|
||||
public function searchJoinQuery(array $where)
|
||||
{
|
||||
return ProductReply::getDB()->alias('A')
|
||||
->join('StoreProduct B', 'A.product_id = B.product_id')
|
||||
->when(isset($where['is_reply']) && $where['is_reply'] !== '', function ($query) use ($where) {
|
||||
$query->where('A.is_reply', $where['is_reply']);
|
||||
})
|
||||
->when(isset($where['nickname']) && $where['nickname'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('A.nickname', "%{$where['nickname']}%");
|
||||
})
|
||||
->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
|
||||
$query->where(function ($query) use ($where) {
|
||||
$query->where('B.store_name', 'like', "%{$where['keyword']}%")
|
||||
->whereOr('B.product_id', $where['keyword']);
|
||||
});
|
||||
})
|
||||
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
|
||||
getModelTime($query, $where['date'], 'A.create_time');
|
||||
})
|
||||
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('A.mer_id', $where['mer_id']);
|
||||
})
|
||||
->when(isset($where['product_id']) && $where['product_id'] !== '', function ($query) use ($where) {
|
||||
$query->where('A.product_id', $where['product_id']);
|
||||
})
|
||||
->order('A.sort DESC, A.create_time DESC')
|
||||
->where('A.is_del', 0)
|
||||
->field('A.reply_id,A.is_reply,A.uid,A.product_score,A.service_score,A.postage_score,A.comment,A.pics,A.create_time,A.merchant_reply_content,A.nickname,A.avatar,B.store_name,B.image,B.product_id,A.sort');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return int
|
||||
* @author xaboy
|
||||
* @day 2020/5/30
|
||||
*/
|
||||
public function insertAll(array $data)
|
||||
{
|
||||
return ProductReply::getDB()->insertAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/5/30
|
||||
*/
|
||||
public function exists(int $id)
|
||||
{
|
||||
return ProductReply::getDB()->where($this->getPk(), $id)->where('is_del', 0)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $merId
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @author xaboy
|
||||
* @day 2020/6/28
|
||||
*/
|
||||
public function merExists($merId, int $id)
|
||||
{
|
||||
return ProductReply::getDB()->where($this->getPk(), $id)->where('is_del', 0)->where('mer_id', $merId)->count() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @author xaboy
|
||||
* @day 2020/5/30
|
||||
*/
|
||||
public function delete(int $id)
|
||||
{
|
||||
$reply = ProductReply::getDB()->where('reply_id', $id)->find();
|
||||
$reply->is_del = 1;
|
||||
$reply->save();
|
||||
Queue::push(UpdateProductReplyJob::class, $reply['product_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回评论数
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/6/2
|
||||
* @param int $productId
|
||||
* @param array $where
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProductReplay(int $productId, $where = [0, 5])
|
||||
{
|
||||
return $this->getModel()::getDB()->where('product_id', $productId)->whereBetween('rate', $where)->select();
|
||||
}
|
||||
|
||||
public function productTotalRate($productId)
|
||||
{
|
||||
return ProductReply::getDB()->where('product_id', $productId)->where('is_del', 0)->field('sum(rate) as total_rate,count(reply_id) as total_count')->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算商铺平均分
|
||||
* @param $merId
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
* @day 2020-06-11
|
||||
*/
|
||||
public function merchantTotalRate($merId)
|
||||
{
|
||||
return ($this->getModel()::getDB())->where('mer_id', $merId)->field('avg(product_score) product_score ,avg(service_score) service_score,avg(postage_score) postage_score')->find()->toArray();
|
||||
}
|
||||
|
||||
public function clear($id,$field)
|
||||
{
|
||||
$this->getModel()::getDB()->where($field, $id)->delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductSku;
|
||||
use think\facade\Db;
|
||||
|
||||
class ProductSkuDao extends BaseDao
|
||||
{
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductSku::class;
|
||||
}
|
||||
|
||||
public function clear(int $id, int $type)
|
||||
{
|
||||
$this->getModel()::getDB()->where('active_id', $id)->where('active_type', $type)->delete();
|
||||
}
|
||||
|
||||
public function descStock(int $active_id, string $unique, int $desc)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('active_id', $active_id)->where('unique', $unique)->update([
|
||||
'stock' => Db::raw('stock-' . $desc)
|
||||
]);
|
||||
}
|
||||
|
||||
public function incStock(int $active_id, string $unique, int $desc)
|
||||
{
|
||||
return $this->getModel()::getDB()->where('active_id', $active_id)->where('unique', $unique)->update([
|
||||
'stock' => Db::raw('stock+' . $desc)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\dao\store\product;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\ProductTake;
|
||||
use think\facade\Db;
|
||||
|
||||
class ProductTakeDao extends BaseDao
|
||||
{
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
return ProductTake::class;
|
||||
}
|
||||
|
||||
public function changeStatus($id)
|
||||
{
|
||||
$this->getSearch(['product_id' => $id,'status' => 0])->update(['status' => 1]);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue