chore: 添加静态资源文件和版本配置文件

添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材
添加系统版本配置文件(.version)和常量定义文件(.constant)
更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件
添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
2026-03-06 20:14:23 +08:00
commit c9a98f342c
4485 changed files with 490986 additions and 0 deletions

611
app/dao/BaseDao.php Normal file
View File

@@ -0,0 +1,611 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao;
use think\helper\Str;
use think\Model;
use think\Collection;
use think\db\BaseQuery;
use crmeb\basic\BaseAuth;
use crmeb\basic\BaseModel;
use think\db\exception\DbException;
use crmeb\traits\dao\CacheDaoTrait;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
/**
* Class BaseDao
* @package app\dao
*/
abstract class BaseDao
{
use CacheDaoTrait;
/**
* 当前表名别名
* @var string
*/
protected string $alias;
/**
* join表别名
* @var string
*/
protected string $joinAlis;
/**
* 过滤字段
* @var array
*/
protected array $filterateField = [];
/**
* 获取当前模型
* @return string
*/
abstract protected function setModel(): string;
/**
* 设置join链表模型
* @return string
*/
protected function setJoinModel(): string
{
}
/**
* 读取数据条数
* @param array $where
* @return int
* @throws DbException
*/
public function count(array $where = []): int
{
return $this->search($where)->count();
}
/**
* 获取某些条件总数
* @param array $where
* @return int
* @throws DbException
*/
public function getCount(array $where): int
{
return $this->getModel()->where($where)->count();
}
/**
* 获取某些条件去重总数
* @param array $where
* @param $field
* @param bool $search
* @return int|mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getDistinctCount(array $where, $field, bool $search = true)
{
if ($search) {
return $this->search($where)->field('COUNT(distinct(' . $field . ')) as count')->select()->toArray()[0]['count'] ?? 0;
} else {
return $this->getModel()->where($where)->field('COUNT(distinct(' . $field . ')) as count')->select()->toArray()[0]['count'] ?? 0;
}
}
/**
* 获取模型
* @return BaseModel
*/
protected function getModel()
{
return app()->make($this->setModel());
}
/**
* 获取主键
* @return mixed
*/
protected function getPk()
{
return $this->getModel()->getPk();
}
/**
* 获取一条数据
* @param int|array $id
* @param array|null $field
* @param array|null $with
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function get($id, ?array $field = [], ?array $with = [])
{
if (is_array($id)) {
$where = $id;
} else {
$where = [$this->getPk() => $id];
}
return $this->getModel()::where($where)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->field($field ?? ['*'])->find();
}
/**
* 查询一条数据是否存在
* @param $map
* @param string $field
* @return bool 是否存在
* @throws DbException
*/
public function be($map, string $field = '')
{
if (!is_array($map) && empty($field)) $field = $this->getPk();
$map = !is_array($map) ? [$field => $map] : $map;
return 0 < $this->getModel()->where($map)->count();
}
/**
* 根据条件获取一条数据
* @param array $where
* @param string|null $field
* @param array $with
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getOne(array $where, ?string $field = '*', array $with = [])
{
$field = explode(',', $field);
return $this->get($where, $field, $with);
}
/**
* 获取单个字段值
* @param array $where
* @param string|null $field
* @return mixed
*/
public function value(array $where, ?string $field = '')
{
$pk = $this->getPk();
return $this->getModel()::where($where)->value($field ?: $pk);
}
/**
* 获取某个字段数组
* @param array $where
* @param string $field
* @param string $key
* @param bool $search
* @return array
*/
public function getColumn(array $where, string $field, string $key = '', bool $search = false)
{
if ($search) {
return $this->search($where)->column($field, $key);
} else {
return $this->getModel()::where($where)->column($field, $key);
}
}
/**
* 删除
* @param int|string|array $id
* @return bool
*/
public function delete($id, ?string $key = null)
{
if (is_array($id)) {
$where = $id;
} else {
$where = [is_null($key) ? $this->getPk() : $key => $id];
}
return $this->getModel()::where($where)->delete();
}
/**
* 更新数据
* @param int|string|array $id
* @param array $data
* @param string|null $key
* @return BaseModel
*/
public function update($id, array $data, ?string $key = null)
{
if (is_array($id)) {
$where = $id;
} else {
$where = [is_null($key) ? $this->getPk() : $key => $id];
}
return $this->getModel()::update($data, $where);
}
/**
* 批量更新数据
* @param array $ids
* @param array $data
* @param string|null $key
* @return BaseModel
*/
public function batchUpdate(array $ids, array $data, ?string $key = null)
{
return $this->getModel()::whereIn(is_null($key) ? $this->getPk() : $key, $ids)->update($data);
}
/**
* 批量更新数据,增加条件
* @param array $ids
* @param array $data
* @param array $where
* @param string|null $key
* @return BaseModel
*/
public function batchUpdateAppendWhere(array $ids, array $data, array $where, ?string $key = null)
{
return $this->getModel()::whereIn(is_null($key) ? $this->getPk() : $key, $ids)->where($where)->update($data);
}
/**
* 插入数据
* @param array $data
* @return BaseModel|Model
*/
public function save(array $data)
{
return $this->getModel()::create($data);
}
/**
* 插入数据
* @param array $data
* @return int
*/
public function saveAll(array $data)
{
return $this->getModel()::insertAll($data);
}
/**
* 获取某个字段内的值
* @param $value
* @param string $filed
* @param string|null $valueKey
* @param array|string[] $where
* @return mixed
*/
public function getFieldValue($value, string $filed, ?string $valueKey = '', ?array $where = [])
{
return $this->getModel()->getFieldValue($value, $filed, $valueKey, $where);
}
/**
* 根据搜索器获取搜索内容
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
protected function withSearchSelect(array $where, bool $search = true)
{
[$with, $otherWhere] = $this->getSearchData($where);
return $this->getModel()
->withSearch($with, $where)
->when($search, fn($query) => $query->where($this->filterWhere($otherWhere)));
}
/**
* 过滤字段
* @param array $where
* @return array
* @author 等风来
* @email 136327134@qq.com
* @date 2023/10/7
*/
protected function filterWhere(array $where = [])
{
$fields = $this->getModel()->getTableFields();
foreach ($where as $key => $item) {
if (isset($item[0]) && !in_array($item[0], $fields)) {
unset($where[$key]);
}
}
return $where;
}
/**
* 获取搜索器和其他搜索条件
* @param array $where
* @return array[]
* @throws \ReflectionException
* @author 等风来
* @email 136327134@qq.com
* @date 2023/10/7
*/
private function getSearchData(array $where)
{
$with = [];
$otherWhere = [];
$responses = new \ReflectionClass($this->setModel());
foreach ($where as $key => $value) {
$method = 'search' . Str::studly($key) . 'Attr';
if ($responses->hasMethod($method)) {
$with[] = $key;
} else {
if (!in_array($key, array_merge(['timeKey'], $this->filterateField))) {
if (!is_array($value)) {
$otherWhere[] = [$key, '=', $value];
} else if (count($value) === 3) {
$otherWhere[] = $value;
}
}
}
}
return [$with, $otherWhere];
}
/**
* 设置过滤不进入普通搜索条件的字段
* @param array $keys
* @return $this
* @author 等风来
* @email 136327134@qq.com
* @date 2023/10/7
*/
public function setFilterateField(array $keys)
{
$this->filterateField = $keys;
return $this;
}
/**
* 搜索
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = true)
{
if ($where) {
return $this->withSearchSelect($where, $search);
} else {
return $this->getModel();
}
}
/**
* 求和
* @param array $where
* @param string $field
* @param bool $search
* @return float
*/
public function sum(array $where, string $field, bool $search = false)
{
if ($search) {
return $this->search($where)->sum($field);
} else {
return $this->getModel()::where($where)->sum($field);
}
}
/**
* 高精度加法
* @param int|string $key
* @param string $incField
* @param string $inc
* @param string|null $keyField
* @param int $acc
* @return bool
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function bcInc($key, string $incField, string $inc, string $keyField = null, int $acc = 2)
{
return $this->bc($key, $incField, $inc, $keyField, 1, $acc);
}
/**
* 高精度 减法
* @param $key
* @param string $decField 相减的字段
* @param string $dec 减的值
* @param string|null $keyField id的字段
* @param int $acc 精度
* @param bool $dec_return_false 减法 不够减是否返回false || 减为0
* @return bool
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function bcDec($key, string $decField, string $dec, string $keyField = null, int $acc = 2, bool $dec_return_false = true)
{
return $this->bc($key, $decField, $dec, $keyField, 2, $acc, $dec_return_false);
}
/**
* 高精度计算并保存
* @param $key
* @param string $incField
* @param string $inc
* @param string|null $keyField
* @param int $type
* @param int $acc
* @param bool $dec_return_false 减法 不够减是否返回false || 减为0
* @return bool
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function bc($key, string $incField, string $inc, string $keyField = null, int $type = 1, int $acc = 2, bool $dec_return_false = true)
{
if ($keyField === null) {
$result = $this->get($key);
} else {
$result = $this->getOne([$keyField => $key]);
}
if (!$result) return false;
if ($type === 1) {
$new = bcadd($result[$incField], $inc, $acc);
} else if ($type === 2) {
if ($result[$incField] < $inc) {
if ($dec_return_false) return false;
$new = 0;
} else {
$new = bcsub($result[$incField], $inc, $acc);
}
}
$result->{$incField} = $new;
return false !== $result->save();
}
/**
* 减库存加销量
* @param array $where
* @param int $num
* @param string $stock
* @param string $sales
* @return mixed
*/
public function decStockIncSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
{
return app()->make(BaseAuth::class)->_____($this->getModel(), $where, $num, $stock, $sales) !== false;
}
/**
* 加库存减销量
* @param array $where
* @param int $num
* @param string $stock
* @param string $sales
* @return mixed
*/
public function incStockDecSales(array $where, int $num, string $stock = 'stock', string $sales = 'sales')
{
return app()->make(BaseAuth::class)->___($this->getModel(), $where, $num, $stock, $sales) !== false;
}
/**
* 软删除
* @param $id
* @param string|null $key
* @param bool $force
* @return bool
*/
public function destroy($id, ?string $key = null, bool $force = false)
{
if (is_array($id)) {
$where = $id;
} else {
$where = [is_null($key) ? $this->getPk() : $key => $id];
}
return $this->getModel()::destroy($where, $force);
}
/**
* 自增单个数据
* @param $where
* @param string $field
* @param int $number
* @return mixed
*/
public function incUpdate($where, string $field, int $number = 1)
{
return $this->getModel()->where(is_array($where) ? $where : [$this->getPk() => $where])->inc($field, $number)->update();
}
/**
* 自减单个数据
* @param $where
* @param string $field
* @param int $number
* @return mixed
*/
public function decUpdate($where, string $field, int $number = 1)
{
return $this->getModel()->where(is_array($where) ? $where : [$this->getPk() => $where])->dec($field, $number)->update();
}
/**
* 条件查询
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param string $order
* @param bool $search
* @return Collection
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function selectList(array $where, string $field = '*', int $page = 0, int $limit = 0, string $order = '', bool $search = false)
{
if ($search) {
$model = $this->search($where);
} else {
$model = $this->getModel()->where($where);
}
return $model->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($order !== '', function ($query) use ($order) {
$query->order($order);
})->select();
}
/**
* 获取分页请求 兼容大量数据查询
* @param BaseQuery $query
* @param int $page
* @param int $limit
* @param int $id
* @param string $op
* @param string $key
* @author 等风来
* @email 136327134@qq.com
* @date 2023/9/20
*/
protected function pageQueryModel(BaseQuery $query, int $page = 1, int $limit = 10, int $id = 0, string $op = '<', string $key = '')
{
if ($id && $page && $limit) {
$query->where($key ?: $this->getPk(), $op, $id)->limit($limit);
} else {
$query->page($page, $limit);
}
}
/**
* 判断字段是否存在
* @param $field
* @param $value
* @param int|null $except
* @return bool
* User: liusl
* DateTime: 2025/7/2 10:49
*/
public function fieldExists($field, $value, int $except = 0): bool
{
$query = $this->getModel()->where($field, $value);
if ($except != 0) $query->where($this->getPk(), '<>', $except);
return !!$query->value($this->getPk());
}
}

View File

@@ -0,0 +1,102 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity;
use app\dao\BaseDao;
use app\model\activity\StoreActivity;
/**
* 活动
* Class StoreActivityDao
* @package app\dao\activity
*/
class StoreActivityDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreActivity::class;
}
/**
* @param array $where
* @return \crmeb\basic\BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = true)
{
return parent::search($where)->when(isset($where['activityTime']), function ($query) use ($where) {
[$startTime, $stopTime] = is_array($where['activityTime']) ? $where['activityTime'] : [time(), time() - 86400];
$query->where('start_day', '<=', $startTime)->where('end_day', '>=', $stopTime);
})->when(isset($where['store_name']) && $where['store_name'] !== '', function ($query) use ($where) {
$query->where('name|id', 'like', '%' . $where['store_name'] . '%');
})->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where(function ($q) use ($time) {
$q->where('end_day', '<', $time - 86400)->whereOr('status', '0');
});
break;
case 0:
$query->where('start_day', '>', $time)->where('status', 1);
break;
case 1:
$query->where('start_day', '<=', $time)->where('end_day', '>=', $time - 86400)->where('status', 1);
break;
}
});
}
/**
* 获取活动列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @param string $order
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [], string $order = 'start_time asc, id desc')
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
/**
* 验证是否有活动
* @param array $where
* @return bool
* @throws \think\db\exception\DbException
*/
public function checkActivity(array $where)
{
return !!$this->getModel()->where($where)->find();
}
}

View File

@@ -0,0 +1,175 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\bargain;
use app\dao\BaseDao;
use app\model\activity\bargain\StoreBargain;
use crmeb\basic\BaseModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 砍价商品
* Class StoreBargainDao
* @package app\dao\activity\bargain
*/
class StoreBargainDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreBargain::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = true)
{
return parent::search($where, false)
->when(isset($where['pinkIngTime']), function ($query) use ($where) {
$time = time();
[$startTime, $stopTime] = is_array($where['pinkIngTime']) ? $where['pinkIngTime'] : [$time, $time];
$query->where('start_time', '<=', $startTime)->where('stop_time', '>=', $stopTime);
})->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where('stop_time', '<', $time);
break;
case 0:
$query->where('start_time', '>', $time);
break;
case 1:
$query->where('start_time', '<=', $time)->where('stop_time', '>=', $time);
break;
}
});
}
/**
* 获取砍价列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException|\ReflectionException
*/
public function getList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取活动开启中的砍价id以数组形式返回
* @param array $ids
* @param array $field
* @return array
*/
public function getBargainIdsArray(array $ids, array $field = [])
{
return $this->search(['is_del' => 0, 'status' => 1])->where('start_time', '<=', time())
->where('stop_time', '>=', time())->whereIn('product_id', $ids)->column(implode(',', $field), 'product_id');
}
/**
* 根据id获取砍价数据
* @param array $ids
* @param string $field
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function idByBargainList(array $ids, string $field)
{
return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
}
/**
* 获取一条有效的砍价商品
* @param int $id
* @param string $field
* @return array|mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \ReflectionException
*/
public function validProduct(int $id, string $field = '*')
{
$where = ['is_show' => 1, 'is_del' => 0, 'status' => 1,'pinkIngTime' => true];
return $this->search($where)->where('id', $id)->where('quota', '>', 0)->field($field)->order('sort DESC,id DES')->find();
}
/**
* 正在开启的砍价活动
* @param int $status
* @return BaseModel
*/
public function validWhere(int $status = 1)
{
return $this->getModel()->where('is_del', 0)->where('status', $status)->where('start_time', '<', time())->where('stop_time', '>', time());
}
/**
* 砍价列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws \ReflectionException
*/
public function bargainList(array $where = [],string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search(['is_del' => 0, 'status' => 1])->where($where)->field($field)
->where('start_time', '<=', time())
->where('stop_time', '>=', time())
->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_del', 0)->field('id');
})->with('product')
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort DESC,id DESC')->select()->toArray();
}
/**
* 修改砍价状态
* @param int $id
* @param string $field
* @return mixed
*/
public function addBargain(int $id, string $field = 'look')
{
return $this->getModel()->where('id', $id)->inc($field, 1)->update();
}
}

View File

@@ -0,0 +1,116 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\bargain;
use app\dao\BaseDao;
use app\model\activity\bargain\StoreBargainUser;
use crmeb\basic\BaseModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 参与砍价
* Class StoreBargainUserDao
* @package app\dao\activity\bargain
*/
class StoreBargainUserDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreBargainUser::class;
}
/**
* 获取帮砍数量
* @param array $where
* @return array
*/
public function getAllCount(array $where = [])
{
return $this->getModel()->where($where)->group('bargain_id')->column('count(*)', 'bargain_id');
}
/**
* 获取砍价表ID
* @param int $bargainId $bargainId 砍价商品
* @param int $bargainUserUid $bargainUserUid 开启砍价用户编号
* @return mixed
*/
public function getBargainUserTableId(int $bargainId = 0, int $bargainUserUid = 0)
{
return $this->value(['bargain_id' => $bargainId, 'uid' => $bargainUserUid, 'is_del' => 0, 'status' => 1], 'id') ?? 0;
}
/**
* 获取用户砍价列表
* @param int $bargainUserUid
* @param int $page
* @param int $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function userAll(int $bargainUserUid, int $page = 0, int $limit = 0)
{
return $this->search(['uid' => $bargainUserUid, 'is_del' => 0])->with('getBargain')->order('add_time DESC,id DESC')->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取砍价状态
* @param $bargainId
* @param $uid
* @return mixed
*/
public function getBargainUserStatus($bargainId, $uid)
{
return $this->search(['bargain_id' => $bargainId, 'uid' => $uid])->order('add_time DESC')->value('status');
}
/**
* 修改砍价状态
* @param int $id
* @param int $status
* @return BaseModel
*/
public function updateBargainStatus(int $id, int $status = 3)
{
return $this->getModel()->where('id', $id)->where('status', 1)->update(['status' => $status]);
}
/**
* 砍价列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function bargainUserList(array $where, int $page = 0, int $limit = 0): array
{
return $this->search($where)->with(['getBargain', 'getUser'])->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,81 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\bargain;
use app\dao\BaseDao;
use app\model\activity\bargain\StoreBargainUserHelp;
/**
* 帮助砍价
* Class StoreBargainUserHelpDao
* @package app\dao\activity\bargain
*/
class StoreBargainUserHelpDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreBargainUserHelp::class;
}
/**
* 获取帮砍人数
* @return array
*/
public function getHelpAllCount(array $where = [])
{
return $this->getModel()->where($where)->group('bargain_id')->column('count(*)', 'bargain_id');
}
/**
* 获取帮砍列表
* @param int $bid
* @param int $page
* @param int $limit
* @return array
*/
public function getHelpList(int $bid, int $page = 0, int $limit = 0)
{
return $this->getModel()->with('getUser')
->where('bargain_user_id', $bid)
->order('add_time desc')
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->field("uid,price,from_unixtime(add_time,'%Y-%m-%d %H:%i:%s') as add_time")->select()->toArray();
}
/**
* 获取砍价商品已砍人数
* @return array
*/
public function getNums()
{
return $this->getModel()->field('count(id) as num,bargain_user_id')->group('bargain_user_id')->select()->toArray();
}
/**
* 获取每个商品参与砍价人数
* @param array $where
* @param string $field
* @param string $key
* @return mixed
*/
public function getBargainPeople(array $where, string $field = '*', string $key = 'bargain_id')
{
return $this->getModel()->where($where)->group($key)->column($field, $key);
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\card;
use app\dao\BaseDao;
use app\model\activity\card\CardBatch;
/**
* 卡次表
* Class CardBatchDao
* @package app\dao\activity\card
*/
class CardBatchDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CardBatch::class;
}
}

View File

@@ -0,0 +1,67 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\card;
use app\dao\BaseDao;
use app\model\activity\card\CardCode;
use app\services\user\UserServices;
/**
* 卡密
* Class CardCodeDao
* @package app\dao\activity\card
*/
class CardCodeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CardCode::class;
}
/**
* 获取卡密列表
* @param array $where 查询条件
* @param int $page 页码
* @param int $limit 每页数量
* @param string $order 排序
* @return array
*/
public function getList($where = [], $page = 0, $limit = 0, $order = 'id desc')
{
return $this->search($where)
->when(isset($where['field_key']) && $where['field_key'] && isset($where['keyword']) && $where['keyword'], function ($query) use ($where) {
switch ($where['field_key']) {
case 'card_number':
$query->whereLike('card_number', "%{$where['keyword']}%");
break;
case 'nickname':
$query->whereIn('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname', '%' . $where['keyword'] . '%')->field(['uid'])->select();
});
case 'uid':
$query->where('uid', $where['keyword']);
break;
}
})
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})
->order($order)->select()->toArray();
}
}

View File

@@ -0,0 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\card;
use app\dao\BaseDao;
use app\model\activity\card\CardGift;
use app\model\activity\card\CardGiftAuxiliary;
/**
* 礼品卡
* Class CardGiftAuxiliaryDao
* @package app\dao\activity\card
*/
class CardGiftAuxiliaryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CardGiftAuxiliary::class;
}
}

View File

@@ -0,0 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\card;
use app\dao\BaseDao;
use app\model\activity\card\CardGift;
/**
* 礼品卡
* Class CardGiftDao
* @package app\dao\activity\card
*/
class CardGiftDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CardGift::class;
}
/**
* 获取礼品卡列表
* @param array $where 查询条件
* @param string $field 查询字段
* @param int $page 页码
* @param int $limit 每页数量
* @param string $order 排序
* @return array
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, string $order = '')
{
return $this->search($where)
->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})
->when($order, function ($query) use ($order) {
$query->order($order);
})
->select()
->toArray();
}
}

View File

@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\card;
use app\dao\BaseDao;
use app\model\activity\card\CardGift;
use app\model\activity\card\CardGiftRecord;
/**
* 礼品卡
* Class CardGiftDao
* @package app\dao\activity\card
*/
class CardGiftRecordDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CardGiftRecord::class;
}
/**
* 获取礼品卡记录列表
* @param array $where 查询条件
* @param string $field 查询字段
* @param int $page 页码
* @param int $limit 每页数量
* @param string $order 排序
* @return array
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, string $order = '')
{
return $this->search($where)
->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})
->when($order, function ($query) use ($order) {
$query->order($order);
})
->select()
->toArray();
}
}

View File

@@ -0,0 +1,164 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\combination;
use app\dao\BaseDao;
use app\model\activity\combination\StoreCombination;
use crmeb\basic\BaseModel;
/**
* 拼团商品
* Class StoreCombinationDao
* @package app\dao\activity\combination
*/
class StoreCombinationDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCombination::class;
}
/**
* 搜索
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['pinkIngTime']), function ($query) use ($where) {
$time = time();
[$startTime, $stopTime] = is_array($where['pinkIngTime']) ? $where['pinkIngTime'] : [$time, $time];
$query->where('start_time', '<=', $startTime)->where('stop_time', '>=', $stopTime);
})->when(isset($where['storeProductId']), function ($query) {
$query->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_del', 0)->field('id');
});
})->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where(function ($query) use ($time) {
$query->where('stop_time', '<', $time)->whereOr('is_show', 0);
});
break;
case 0:
$query->where('start_time', '>', $time)->where('is_show', 1);
break;
case 1:
$query->where('start_time', '<=', $time)->where('stop_time', '>=', $time)->where('is_show', 1);
break;
}
});
}
/**
* 拼团商品列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->with('getPrice')
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取正在进行拼团的商品以数组形式返回
* @param array $ids
* @param array $field
* @return array
*/
public function getPinkIdsArray(array $ids, array $field = [])
{
return $this->search(['is_del' => 0, 'is_show' => 1, 'pinkIngTime' => 1])->whereIn('product_id', $ids)->column(implode(',', $field), 'product_id');
}
/**
* 获取拼团列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function combinationList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->with('getPrice')
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 根据id获取拼团数据
* @param array $ids
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function idCombinationList(array $ids, string $field)
{
return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
}
/**
* 获取一条拼团数据
* @param int $id
* @param string $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function validProduct(int $id, string $field)
{
$where = ['is_show' => 1, 'is_del' => 0, 'pinkIngTime' => true];
return $this->search($where)->where('id', $id)->with(['total'])->field($field)->order('add_time desc')->find();
}
/**
* 获取推荐拼团
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCombinationHost()
{
$where = ['is_del' => 0, 'is_host' => 1, 'is_show' => 1, 'pinkIngTime' => true];
return $this->search($where)->with(['total'])->order('id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,203 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\combination;
use app\dao\BaseDao;
use app\model\activity\combination\StorePink;
/**
* 拼团
* Class StorePinkDao
* @package app\dao\activity\combination
*/
class StorePinkDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StorePink::class;
}
/**
* 获取拼团数量集合
* @param array $where
* @return array
*/
public function getPinkCount(array $where = [])
{
return $this->getModel()->where($where)->group('cid')->column('count(*)', 'cid');
}
/**
* 获取列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->when($where['k_id'] != 0, function ($query) use ($where) {
$query->whereOr('id', $where['k_id']);
})->with(['getProduct', 'getUser'])->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
}
/**
* 获取正在拼团中的人,取最早写入的一条
* @param array $where
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPinking(array $where)
{
return $this->search($where)->order('add_time asc')->find();
}
/**
* 获取拼团列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function pinkList(array $where)
{
return $this->search($where)
->where('stop_time', '>', time())
->order('add_time desc')
->select()->toArray();
}
/**
* 获取正在拼团的人数
* @param int $kid
* @return int
*/
public function getPinkPeople(int $kid)
{
return $this->count(['k_id' => $kid, 'is_refund' => 0]) + 1;
}
/**
* 获取正在拼团的人数
* @param array $kids
* @return int
*/
public function getPinkPeopleCount(array $kids)
{
$count = $this->getModel()->whereIn('k_id', $kids)->where('is_refund', 0)->group('k_id')->column('COUNT(id) as count', 'k_id');
$counts = [];
foreach ($kids as &$item) {
if (isset($count[$item])) {
$counts[$item] = $count[$item] + 1;
} else {
$counts[$item] = 1;
}
}
return $counts;
}
/**
* 获取拼团成功的列表
* @param int $uid
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function successList(int $uid, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search(['status' => 2, 'is_refund' => 0])->field($field)
->where('uid', '>', 0)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取拼团完成的个数
* @return float
*/
public function getPinkOkSumTotalNum()
{
return $this->sum(['status' => 2, 'is_refund' => 0], 'total_num');
}
/**
* 是否能继续拼团
* @param int $id
* @param int $uid
* @return int
*/
public function isPink(int $id, int $uid)
{
return $this->getModel()->where('k_id|id', $id)->where('uid', $uid)->where('is_refund', 0)->count();
}
/**
* 获取一条拼团信息
* @param int $id
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPinkUserOne(int $id)
{
return $this->search()->with('getProduct')->find($id);
}
/**
* 获取拼团信息
* @param array $where
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPinkUserList(array $where)
{
return $this->getModel()->where($where)->with('getProduct')->select()->toArray();
}
/**
* 获取拼团结束的列表
* @return \crmeb\basic\BaseModel
*/
public function pinkListEnd()
{
return $this->getModel()->where('stop_time', '<=', time())
->where('status', 1)
->where('k_id', 0)
->where('is_refund', 0)
->field('id,people,k_id,order_id_key,uid,stop_time');
}
}

View File

@@ -0,0 +1,76 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\coupon;
use app\dao\BaseDao;
use app\model\activity\coupon\StoreCoupon;
/**
* 优惠卷
* Class StoreCouponDao
* @package app\dao\activity\coupon
*/
class StoreCouponDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCoupon::class;
}
/**
* 获取文章列表
* @param array $where
* @param int $page
* @param int $limit
* @return mixed
*/
public function getList(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->order('sort desc,id desc')->select()->toArray();
}
/**
* 写入优惠卷
* @param $cid
* @param int $total_count
* @param int $start_time
* @param int $end_time
* @param int $remain_count
* @param int $status
* @param int $is_permanent
* @param int $full_reduction
* @param int $is_give_subscribe
* @param int $is_full_give
* @return \crmeb\basic\BaseModel|\think\Model
*/
public function setIssue($cid, $total_count = 0, $start_time = 0, $end_time = 0, $remain_count = 0, $status = 0, $is_permanent = 0, $full_reduction = 0, $is_give_subscribe = 0, $is_full_give = 0)
{
$add_time = time();
$data['cid'] = $cid;
$data['start_time'] = $start_time;
$data['end_time'] = $end_time;
$data['total_count'] = $total_count;
$data['remain_count'] = $remain_count;
$data['is_permanent'] = $is_permanent;
$data['status'] = $status;
$data['is_give_subscribe'] = $is_give_subscribe;
$data['is_full_give'] = $is_full_give;
$data['full_reduction'] = $full_reduction;
$data['add_time'] = $add_time;
return $this->getModel()->create(compact('cid', 'start_time', 'end_time', 'total_count', 'remain_count', 'is_permanent', 'status', 'is_give_subscribe', 'is_full_give', 'full_reduction', 'add_time'));
}
}

View File

@@ -0,0 +1,424 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\coupon;
use app\dao\BaseDao;
use app\model\activity\coupon\StoreCouponIssue;
use app\services\activity\coupon\StoreCouponUserServices;
use crmeb\basic\BaseModel;
/**
* 优惠卷
* Class StoreCouponIssueDao
* @package app\dao\activity\coupon
*/
class StoreCouponIssueDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCouponIssue::class;
}
/**
* @param array $where
* @return BaseModel
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['receive']) && $where['receive'] != '', function ($query) use ($where) {
if ($where['receive'] == 'send') {
$query->where('receive_type', 3)
->where('status', 1)
->where('is_del', 0)
->where('remain_count > 0 OR is_permanent = 1')
->where(function ($query1) {
$query1->where(function ($query2) {
$query2->where('start_time', '<=', time())->where('end_time', '>=', time());
})->whereOr(function ($query3) {
$query3->where('start_time', 0)->where('end_time', 0);
});
})->where(function ($query4) {
$query4->where(function ($query5) {
$query5->where('coupon_time', 0)->where('end_use_time', '>=', time());
})->whereOr('coupon_time', '>', 0);
});
}
})->when(isset($where['receive_type']) && $where['receive_type'], function ($query) use ($where) {
$query->where('receive_type', $where['receive_type']);
});
}
/**
* 有效优惠券搜索
* @param array $where
* @return BaseModel|mixed|\think\Model
*/
public function validSearch(array $where = [])
{
return parent::search($where)
->where('status', 1)
->where('is_del', 0)
->where('remain_count > 0 OR is_permanent = 1')
->where(function ($query) {
$query->where(function ($query) {
$query->where('start_time', '<=', time())->where('end_time', '>=', time());
})->whereOr(function ($query) {
$query->where('start_time', 0)->where('end_time', 0);
});
})->where(function ($query4) {
$query4->where(function ($query5) {
$query5->where('coupon_time', 0)->where('end_use_time', '>=', time());
})->whereOr('coupon_time', '>', 0);
});
}
/**
* 获取列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('id desc')->select()->toArray();
}
/**
* 获取有效的优惠券列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getValidList(array $where = [], string $field = '*', int $page = 0, int $limit = 0, array $with = [])
{
return $this->validSearch($where)->field($field)
->when(isset($where['not_id']) && $where['not_id'], function ($query) use ($where) {
$query->whereNotIn('id', $where['not_id']);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->when($with, function ($query) use ($with) {
$query->with($with);
})->order('id desc')->select()->toArray();
}
/**
* 获取有效的赠送券
* @param array $ids
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getValidGiveCoupons(array $ids, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->validSearch()->field($field)
->where('receive_type', 3)
->when(count($ids), function ($query) use ($ids) {
$query->whereIn('id', $ids);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取商品优惠券
* @param int $uid
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param string $sort
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIssueCouponListNew(int $uid, array $where = [], string $field = '*', int $page = 0, int $limit = 0, string $sort = 'sort desc,id desc')
{
return $this->validSearch()->field($field)
->when($uid, function ($query) use ($uid) {
$userAll = app()->make(StoreCouponUserServices::class)->getUserAllCoupon($uid);
$ids = array_column($userAll, 'cid');
if (!$ids || !count($ids)) {
$query->where('receive_type', 1);
return;
}
$query->where(function ($query) use ($ids) {
$query->whereIn('id', $ids)->whereOr('receive_type', 1);
});
})
->with(['used' => function ($query) use ($uid) {
$query->where('uid', $uid);
}])
->when(isset($where['type']) && in_array($where['type'], [-1, 0, 1, 2, 3]), function ($query) use ($where) {
if ($where['type'] == -1) {//即将过期的
$query->where('end_time', '<>', 0)->whereTime('end_time', 'between', [time(), time() + 24 * 3600]);
} else {
$query->where('type', $where['type']);
}
})
->when(isset($where['type']) && $where['type'] == 1 && isset($where['cate_id']) && $where['cate_id'], function ($query) use ($where) {
$query->where('category_id', 'in', $where['cate_id']);
})
->when(isset($where['type']) && $where['type'] == 2 && isset($where['product_id']) && $where['product_id'], function ($query) use ($where) {
$query->whereFindinSet('product_id', $where['product_id']);
})
->when(isset($where['type']) && $where['type'] == 3 && isset($where['brand_id']) && $where['brand_id'], function ($query) use ($where) {
$query->where('brand_id', 'in', $where['brand_id']);
})
->when((isset($where['product_id']) && $where['product_id']) || (isset($where['cate_id']) && $where['cate_id']) || isset($where['brand_id']) && $where['brand_id'], function ($query) use ($where) {
$query->where(function ($z) use ($where) {
$z->whereOr('type', 0)
->when(isset($where['product_id']) && $where['product_id'], function ($p) use ($where) {
$p->whereOr(function ($c) use ($where) {
$c->whereFindinSet('product_id', $where['product_id']);
});
})->when(isset($where['cate_id']) && $where['cate_id'], function ($c) use ($where) {
$c->whereOr('category_id', 'in', $where['cate_id']);
})->when(isset($where['brand_id']) && $where['brand_id'], function ($b) use ($where) {
$b->whereOr('brand_id', 'in', $where['brand_id']);
});
});
})->when(isset($where['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
if ($where['priceOrder'] === 'desc') {
$query->field('if(coupon_type <= 1, `coupon_price`, 100-coupon_price) as true_coupon_price')->order("true_coupon_price desc");
} else {
$query->field('if(coupon_type <= 1, `coupon_price`, 100-coupon_price) as true_coupon_price')->order("true_coupon_price asc");
}
})->when(isset($where['timeOrder']) && $where['timeOrder'] != '', function ($query) use ($where) {
if ($where['timeOrder'] === 'desc') {
$query->order("add_time desc");
} else {
$query->order("add_time asc");
}
})->when(isset($where['defaultOrder']) && $where['defaultOrder'], function ($query) use ($where) {
$query->order('sort desc,id desc');
})
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($sort)->select()->toArray();
}
/**
* 获取优惠券列表
* @param int $uid 用户ID
* @param int $type 0通用,1分类,2商品
* @param int $typeId 分类ID或商品ID
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIssueCouponList(int $uid, int $type, $typeId, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->validSearch()->field($field)
->where('receive_type', 1)
->with(['used' => function ($query) use ($uid) {
$query->where('uid', $uid);
}])
->where('type', $type)
->when($type == 1, function ($query) use ($typeId) {
if ($typeId) $query->where('category_id', 'in', $typeId);
})
->when($type == 2, function ($query) use ($typeId) {
if ($typeId) $query->whereFindinSet('product_id', $typeId);
})
->when($type == 3, function ($query) use ($typeId) {
if ($typeId) $query->where('brand_id', 'in', $typeId);
})
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* PC端获取优惠券
* @param int $uid
* @param array $cate_ids
* @param int $product_id
* @param string $filed
* @param int $page
* @param int $limit
* @param string $sort
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPcIssueCouponList(int $uid, array $cate_ids = [], int $product_id = 0, string $filed = '*', int $page = 0, int $limit = 0, string $sort = 'sort desc,id desc')
{
return $this->validSearch()->field($filed)
->where('receive_type', 1)
->with(['used' => function ($query) use ($uid) {
$query->where('uid', $uid);
}])->where(function ($query) use ($product_id, $cate_ids) {
if ($product_id != 0 && $cate_ids != []) {
$query->whereFindinSet('product_id', $product_id)->whereOr('category_id', 'in', $cate_ids)->whereOr('type', 0);
}
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order($sort)->select()->toArray();
}
/**
* 获取优惠券数量
* @param $productId
* @param $cateId
* @param $brandId
* @return array
* @throws \think\db\exception\DbException
*/
public function getIssueCouponCount($productId = 0, $cateId = 0, $brandId = 0)
{
$count[0] = $this->validSearch()->where('receive_type', 1)->where('type', 0)->count();
$count[1] = $this->validSearch()->where('receive_type', 1)->where('type', 1)->when($cateId != 0, function ($query) use ($cateId) {
if ($cateId) $query->where('category_id', 'in', $cateId);
})->count();
$count[2] = $this->validSearch()->where('receive_type', 1)->where('type', 2)->when($productId != 0, function ($query) use ($productId) {
if ($productId) $query->whereFindinSet('product_id', $productId);
})->count();
$count[3] = $this->validSearch()->where('receive_type', 1)->where('type', 3)->when($productId != 0, function ($query) use ($brandId) {
if ($brandId) $query->where('brand_id', 'in', $brandId);
})->count();
return $count;
}
/**
* 获取优惠卷详情
* @param int $id
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getInfo(int $id)
{
return $this->validSearch()->where('id', $id)->find();
}
/**
* 获取金大于额的优惠卷金额
* @param string $totalPrice
* @return float
*/
public function getUserIssuePrice(string $totalPrice)
{
return $this->search(['status' => 1, 'is_full_give' => 1, 'is_del' => 0])
->where('full_reduction', '<=', $totalPrice)
->sum('coupon_price');
}
/**
* 获取新人券
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getNewCoupon()
{
return $this->validSearch()->where('receive_type', 2)->select()->toArray();
}
/**
* 获取一条优惠券信息
* @param int $id
* @return mixed
*/
public function getCouponInfo(int $id)
{
return $this->getModel()->where('id', $id)->where('status', 1)->where('is_del', 0)->find();
}
/**
* 获取满赠、下单、关注赠送优惠券
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGiveCoupon(array $where, string $field = '*')
{
return $this->validSearch()->field($field)->where($where)->select()->toArray();
}
/**
* 获取商品优惠卷列表
* @param $where
* @param $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function productCouponList($where, $field)
{
return $this->getModel()->where($where)->field($field)->select()->toArray();
}
/**
* 获取优惠券弹窗列表
* @param array $receive_type
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTodayCoupon(array $receive_type = [1, 4], int $limit = 10)
{
return $this->getModel()
->where('status', 1)
->where('is_del', 0)
->whereIn('receive_type', $receive_type)
->whereDay('add_time')
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort desc,id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,49 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\coupon;
use app\dao\BaseDao;
use app\model\activity\coupon\StoreCouponIssueUser;
/**
* 领取优惠券
* Class StoreCouponIssueUserDao
* @package app\dao\activity\coupon
*/
class StoreCouponIssueUserDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCouponIssueUser::class;
}
/**
* 获取领取的优惠卷列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, int $page, int $limit)
{
return $this->search($where)->with('userInfo')->page($page, $limit)->order('add_time desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\coupon;
use app\dao\BaseDao;
use app\model\activity\coupon\StoreCouponProduct;
/**
* 商品关联优惠券
* Class StoreCouponProductDao
* @package app\dao\activity\coupon
*/
class StoreCouponProductDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCouponProduct::class;
}
}

View File

@@ -0,0 +1,120 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\coupon;
use app\dao\BaseDao;
use app\model\activity\coupon\StoreCoupon;
use app\model\activity\coupon\StoreCouponUser;
/**
*
* Class StoreCouponUserCouponDao
* @package app\dao\activity\coupon
*/
class StoreCouponUserCouponDao extends BaseDao
{
/**
* 主表别名
* @var string
*/
protected string $alias = 'a';
/**
* 连表别名
* @var string
*/
protected string $joinAlis = 'b';
/**
* 主表模型
* @return string
*/
public function setModel(): string
{
return StoreCouponUser::class;
}
/**
* 连表表明
* @return string
*/
public function setJoinModel(): string
{
return StoreCoupon::class;
}
/**
* 设置模型
* @return \crmeb\basic\BaseModel
*/
public function getModel()
{
/** @var StoreCoupon $joinModel */
$joinModel = app()->make($this->setJoinModel());
$name = $joinModel->getName();
return parent::getModel()->alias($this->alias)->join($name . ' ' . $this->joinAlis, $this->joinAlis . '.id=' . $this->alias . '.cid');
}
/**
* 根据下单金额获取用户能使用的优惠卷
* @param int $uid
* @param string $truePrice
* @param int $productId
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUidCouponList(int $uid, string $truePrice, int $productId)
{
return $this->getModel()
->where($this->alias . '.uid', $uid)
->where($this->alias . '.is_fail', 0)
->where($this->alias . '.status', 0)
->where($this->alias . '.use_min_price', '<=', $truePrice)
->whereFindinSet($this->joinAlis . '.product_id', $productId)
->where($this->joinAlis . '.type', 2)
->field($this->alias . '.*,' . $this->joinAlis . '.type')
->order($this->alias . '.coupon_price', 'DESC')
->select()
->hidden(['status', 'is_fail'])
->toArray();
}
/**
* 获取购买金额最小使用范围内的优惠卷
* @param $uid
* @param $price
* @param $value
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUidCouponMinList($uid, $price, $value = '', int $type = 1)
{
return $this->getModel()->where($this->alias . '.uid', $uid)
->where($this->alias . '.is_fail', 0)
->where($this->alias . '.status', 0)
->where($this->alias . '.use_min_price', '<=', $price)
->when($value, function ($query) use ($value) {
$query->whereFindinSet($this->joinAlis . '.category_id', $value);
})
->where($this->joinAlis . '.type', $type)
->field($this->alias . '.*,' . $this->joinAlis . '.type')
->order($this->alias . '.coupon_price', 'DESC')
->select()
->hidden(['status', 'is_fail'])
->toArray();
}
}

View File

@@ -0,0 +1,258 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\coupon;
use app\dao\BaseDao;
use app\model\activity\coupon\StoreCouponUser;
use app\model\activity\coupon\StoreCouponIssue;
use crmeb\basic\BaseModel;
/**
* Class StoreCouponUserDao
* @package app\dao\activity\coupon
*/
class StoreCouponUserDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCouponUser::class;
}
/**
* 搜索
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['nickname']) && $where['nickname'] != '', function ($query) use ($where) {
$query->where('uid', 'IN', function ($q) use ($where) {
$q->name('user')->where('uid|real_name|nickname|account|phone', 'like', '%' . $where['nickname'] . '%')->field('uid');
});
})->when(isset($where['coupon_title']) && $where['coupon_title'] != '', function ($query) use ($where) {
$query->where('coupon_title', 'like', '%' . $where['coupon_title'] . '%');
})->when(isset($where['issue_type']) && $where['issue_type'] != '', function ($query) use ($where) {
if($where['issue_type'] == -1) {
$time = time() + 24 * 60 * 60;
$query->where('end_time', '>=', $time);
} else {
$query->whereIn('cid', function ($query) use ($where) {
$query->name('store_coupon_issue')->where('type', $where['issue_type'])->field(['id'])->select();
});
}
});
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = ['issue'], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->with($with)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('id desc')->select()->toArray();
}
/**
* 使用优惠券修改优惠券状态
* @param $id
* @return \think\Model|null
*/
public function useCoupon(int $id)
{
return $this->getModel()->where('id', $id)->update(['status' => 1, 'use_time' => time()]);
}
/**
* 获取指定商品id下的优惠卷
* @param array $productIds
* @param int $uid
* @param string $price
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function productIdsByCoupon(array $productIds, int $uid, string $price)
{
return $this->getModel()->whereIn('cid', function ($query) use ($productIds) {
$query->name('store_coupon_issue')->whereIn('id', function ($q) use ($productIds) {
$q->name('store_coupon_product')->whereIn('product_id', $productIds)->field('coupon_id')->select();
})->field(['id'])->select();
})->with('issue')->where(['uid' => $uid, 'status' => 0])->order('coupon_price DESC')
->where('use_min_price', '<=', $price)->select()
->where('start_time', '<=', time())->where('end_time', '>=', time())
->hidden(['status', 'is_fail'])->toArray();
}
/**
* 根据商品id获取
* @param array $cateIds
* @param int $uid
* @param string $price
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function cateIdsByCoupon(array $cateIds, int $uid, string $price)
{
return $this->getModel()->whereIn('cid', function ($query) use ($cateIds) {
$query->name('store_coupon_issue')->whereIn('category_id', $cateIds)->where('type', 1)->field('id')->select();
})->where(['uid' => $uid, 'status' => 0])->where('use_min_price', '<=', $price)
->where('start_time', '<=', time())->where('end_time', '>=', time())
->order('coupon_price DESC')->with('issue')->select()->hidden(['status', 'is_fail'])->toArray();
}
/**
* 获取当前用户可用的优惠卷
* @param array $ids
* @param int $uid
* @param string $price
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserCouponV1(int $uid, string $price = '0', array $ids = [])
{
return $this->getModel()->where(['uid' => $uid, 'status' => 0])->when(count($ids) != 0, function ($query) use ($ids) {
$query->whereNotIn('id', $ids);
})->whereIn('cid', function ($query) {
$query->name('store_coupon_issue')->where('type', 0)->field(['id'])->select();
})->when($price, function ($query, $price) {
$query->where('use_min_price', '<=', $price);
})
->where('start_time', '<=', time())->where('end_time', '>=', time())
->order('coupon_price DESC')->with('issue')->select()->hidden(['status', 'is_fail'])->toArray();
}
/**
* 获取当前用户可用的优惠卷
* @param array $ids
* @param int $uid
* @param string $price
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserCoupon(array $ids, int $uid, string $price)
{
return $this->getModel()->where(['uid' => $uid, 'status' => 0])->when(count($ids) != 0, function ($query) use ($ids) {
$query->whereNotIn('id', $ids);
})->whereIn('cid', function ($query) {
$query->name('store_coupon_issue')->where('type', 0)->field(['id'])->select();
})->where('use_min_price', '<=', $price)
->where('start_time', '<=', time())->where('end_time', '>=', time())
->order('coupon_price DESC')->with('issue')->select()->hidden(['status', 'is_fail'])->toArray();
}
/**
* 获取当前用户所有可用的优惠卷
* @param int $uid
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserAllCoupon(int $uid)
{
return $this->getModel()->where(['uid' => $uid, 'status' => 0, 'is_fail' => 0])
->where('start_time', '<=', time())->where('end_time', '>=', time())
->order('coupon_price DESC')->with('issue')->select()->hidden(['status', 'is_fail'])->toArray();
}
/**
* 获取列表带排序
* @param array $where
* @param $order
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCouponListByOrder(array $where, $order, int $page = 0, int $limit = 0)
{
return $this->search($where)->with('issue')->when($page > 0 && $limit > 0, function ($qeury) use ($page, $limit) {
$qeury->page($page, $limit);
})->when($order != '', function ($query) use ($order) {
$query->order($order);
})->when(isset($where['coupon_ids']), function ($qeury) use ($where) {
$qeury->whereIn('cid', $where['coupon_ids']);
})->select()->toArray();
}
/**
* 根据月份查询用户获得的优惠券
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function memberCouponUserGroupBymonth(array $where)
{
return $this->search($where)
->whereMonth('add_time')
->whereIn('cid', $where['couponIds'])
->field('count(id) as num,FROM_UNIXTIME(add_time, \'%Y-%m\') as time')
->group("FROM_UNIXTIME(add_time, '%Y-%m')")
->select()->toArray();
}
/**
* 根据时间查询
* @param array $where
* @return int
* @throws \ReflectionException
* @throws \think\db\exception\DbException
*/
public function getUserCounponByMonth(array $where)
{
return $this->search($where)->whereMonth('add_time')->count();
}
/**
* 获取本月领取的优惠券
* @param $uid
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getVipCouponList($uid)
{
return $this->getModel()->where('uid', $uid)->whereMonth('add_time')->select()->toArray();
}
}

View File

@@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\coupon;
use app\dao\BaseDao;
use app\model\activity\coupon\StoreCouponUser;
use app\model\user\User;
/**
* Class StoreCouponUserUserDao
* @package app\dao\activity\coupon
*/
class StoreCouponUserUserDao extends BaseDao
{
/**
* @var string
*/
protected string $alias = '';
/**
* @var string
*/
protected string $join_alis = '';
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCouponUser::class;
}
/**
* 连表模型
* @return string
*/
public function joinModel(): string
{
return User::class;
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
public function getModel(string $alias = 'c', string $join_alias = 'u', $join = 'left')
{
$this->alias = $alias;
$this->join_alis = $join_alias;
/** @var User $user */
$user = app()->make($this->joinModel());
$table = $user->getName();
return parent::getModel()->join($table . ' ' . $join_alias, $alias . '.uid = ' . $join_alias . '.uid', $join)->alias($alias);
}
/**
* 列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function sysPage(array $where, int $page, int $limit)
{
return $this->searchWhere($where)->page($page, $limit)->order('id desc')->select()->toArray();
}
/**
* 总数
* @param array $where
* @return int
*/
public function sysCount(array $where)
{
return $this->searchWhere($where)->count();
}
/**
* 筛选条件
* @param array $where
* @return \crmeb\basic\BaseModel
*/
public function searchWhere(array $where = [])
{
return $this->getModel()
->when($where['nickname'] != '', function ($query) use ($where) {
$query->where('u.nickname', 'like', '%' . $where['nickname'] . '%');
})->when($where['status'] != '', function ($query) use ($where) {
$query->where('c.status', $where['status']);
})->when($where['coupon_title'] != '', function ($query) use ($where) {
$query->where('c.coupon_title', 'like', '%' . $where['coupon_title'] . '%');
})->field('c.*,u.nickname');
}
}

View File

@@ -0,0 +1,151 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\discounts;
use app\dao\BaseDao;
use app\model\activity\discounts\StoreDiscounts;
/**
* 优惠套餐
* Class StoreDiscountsDao
* @package app\dao\activity\discounts
*/
class StoreDiscountsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreDiscounts::class;
}
/**
* 搜索查询
* @param array $where 查询条件
* @param bool $search 是否调用父类搜索
* @return \think\db\BaseQuery
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)
->when(isset($where['is_time']) && $where['is_time'] == 1, function ($query) {
$query->where(function ($q) {
$q->where(function ($query) {
$query->where('start_time', '<=', time())->where('stop_time', '>=', time());
})->whereOr(function ($query) {
$query->where('start_time', 0)->where('stop_time', 0);
});
});
});
}
/**
* 获取列表
* @param $where
* @param array $with
* @param $page
* @param $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList($where, array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->where('is_del', 0)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($with, function ($query) use ($with) {
$query->with($with);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 优惠套餐列表
* @param int $product_id
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getDiscounts(int $product_id, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search(['product_ids' => $product_id])->field($field)
->where('is_del', 0)->where('status', 1)
->with(['products' => function ($query) {
$query->field('*,title as store_name')->with(['product']);
}])->where(function ($query) {
$query->where(function ($query) {
$query->where('start_time', '<=', time())->where('stop_time', '>=', time());
})->whereOr(function ($query) {
$query->where('start_time', 0)->where('stop_time', 0);
});
})->where(function ($query) {
$query->where(function ($query) {
$query->where('is_limit', 0);
})->whereOr(function ($query) {
$query->where('is_limit', 1)->where('limit_num', '>', 0);
});
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 优惠套餐数量
* @return int
*/
public function getDiscountsCount()
{
return $this->getModel()
->where('is_del', 0)->where('status', 1)
->where(function ($query) {
$query->where(function ($query) {
$query->where('start_time', '<=', time())->where('stop_time', '>=', time());
})->whereOr(function ($query) {
$query->where('start_time', 0)->where('stop_time', 0);
});
})->count();
}
/**
* 减少限购数量
* @param int $id 套餐ID
* @param int $num 减少数量
* @return int
*/
public function decLimitNum($id, $num = 1)
{
return $this->getModel()->where('id', $id)->dec('limit_num', $num)->update();
}
/**
* 增加限购数量
* @param int $id 套餐ID
* @param int $num 增加数量
* @return int
*/
public function incLimitNum(int $id, $num = 1)
{
return $this->getModel()->where('id', $id)->inc('limit_num', $num)->update();
}
}

View File

@@ -0,0 +1,62 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\discounts;
use app\dao\BaseDao;
use app\model\activity\discounts\StoreDiscountsProducts;
/**
* 优惠套餐商品
* Class StoreDiscountsProductsDao
* @package app\dao\activity\discounts
*/
class StoreDiscountsProductsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreDiscountsProducts::class;
}
/**
* 获取商品列表
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList($where)
{
return $this->search($where)->select()->toArray();
}
/**
* 获取套餐商品
* @param int $id
* @param string $field
* @param array $with
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getDiscountProductInfo(int $id, string $field, array $with = [])
{
return $this->getModel()->where('id', $id)->when($with, function ($query) use ($with) {
$query->with($with);
})->field($field)->find();
}
}

View File

@@ -0,0 +1,194 @@
<?php
declare (strict_types=1);
namespace app\dao\activity\holiday;
use app\dao\BaseDao;
use app\model\activity\holiday\HolidayGift;
/**
* 节日有礼数据层
* Class HolidayGiftDao
* @package app\dao\activity
*/
class HolidayGiftDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return HolidayGift::class;
}
/**
* 获取节日有礼列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getHolidayGiftList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})
->order('id desc')
->select()
->toArray();
}
/**
* 获取正在进行中的节日有礼活动
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getActiveHolidayGift(array $where = [], string $field = '*')
{
$time = time();
return $this->getModel()->where($where)
->where('status', 1)
->where('is_del', 0)
->where(function ($query) use ($time) {
$query->whereOr([
['is_permanent', '=', 1], // 永久活动
[['start_time', '<=', $time], ['end_time', '>=', $time]] // 时间范围内的活动
]);
})
->field($field)
->select()
->toArray();
}
/**
* 获取用户生日相关的节日有礼活动
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getBirthdayHolidayGift(array $where = [], string $field = '*')
{
$time = time();
return $this->getModel()->where($where)
->where('status', 1)
->where('is_del', 0)
->where('task_type', 1) // 用户生日类型
->where(function ($query) use ($time) {
$query->whereOr([
['is_permanent', '=', 1], // 永久活动
[['start_time', '<=', $time], ['end_time', '>=', $time]] // 时间范围内的活动
]);
})
->field($field)
->select()
->toArray();
}
/**
* 获取活动日期相关的节日有礼活动
* @param string $date 日期,格式:MM-DD
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCustomDateHolidayGift(string $date, array $where = [], string $field = '*')
{
$time = time();
return $this->getModel()->where($where)
->where('status', 1)
->where('is_del', 0)
->where('task_type', 2) // 活动日期类型
->where('activity_date_type', 1) // 自定义日期
->where(function ($query) use ($date) {
$query->where('activity_start_date', '<=', $date)
->where('activity_end_date', '>=', $date);
})
->where(function ($query) use ($time) {
$query->whereOr([
['is_permanent', '=', 1], // 永久活动
[['start_time', '<=', $time], ['end_time', '>=', $time]] // 时间范围内的活动
]);
})
->field($field)
->select()
->toArray();
}
/**
* 获取每月活动日期相关的节日有礼活动
* @param int $day 日期,1-31
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getMonthlyHolidayGift(int $day, array $where = [], string $field = '*')
{
$time = time();
return $this->getModel()->where($where)
->where('status', 1)
->where('is_del', 0)
->where('task_type', 2) // 活动日期类型
->where('activity_date_type', 2) // 每月
->whereRaw("FIND_IN_SET(?, activity_month_days)", [$day])
->where(function ($query) use ($time) {
$query->whereOr([
['is_permanent', '=', 1], // 永久活动
[['start_time', '<=', $time], ['end_time', '>=', $time]] // 时间范围内的活动
]);
})
->field($field)
->select()
->toArray();
}
/**
* 获取每周活动日期相关的节日有礼活动
* @param int $weekDay 周几,1-7表示周一到周日
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getWeeklyHolidayGift(int $weekDay, array $where = [], string $field = '*')
{
$time = time();
return $this->getModel()->where($where)
->where('status', 1)
->where('is_del', 0)
->where('task_type', 2) // 活动日期类型
->where('activity_date_type', 3) // 每周
->whereRaw("FIND_IN_SET(?, activity_week_days)", [$weekDay])
->where(function ($query) use ($time) {
$query->whereOr([
['is_permanent', '=', 1], // 永久活动
[['start_time', '<=', $time], ['end_time', '>=', $time]] // 时间范围内的活动
]);
})
->field($field)
->select()
->toArray();
}
}

View File

@@ -0,0 +1,138 @@
<?php
declare (strict_types=1);
namespace app\dao\activity\holiday;
use app\dao\BaseDao;
use app\model\activity\holiday\HolidayGiftPush;
/**
* 节日有礼推送记录数据层
* Class HolidayGiftPushDao
* @package app\dao\activity
*/
class HolidayGiftPushDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return HolidayGiftPush::class;
}
/**
* 获取节日有礼推送记录列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getHolidayGiftPushList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->getModel()->where($where)->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})
->order('id desc')
->select()
->toArray();
}
/**
* 获取节日有礼推送记录数量
* @param array $where
* @return int
*/
public function count(array $where = []): int
{
return $this->getModel()->where($where)->count();
}
/**
* 获取用户今日推送记录
* @param int $uid 用户ID
* @param int $giftId 节日有礼活动ID
* @param int $pushType 推送类型
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserTodayPushRecord(int $uid, int $giftId, int $pushType = 0, string $field = '*')
{
$today = strtotime(date('Y-m-d'));
$tomorrow = $today + 86400;
return $this->getModel()->where('uid', $uid)
->where('gift_id', $giftId)
->when($pushType, function ($query) use ($pushType) {
$query->where('push_type', $pushType);
})
->where('push_time', '>=', $today)
->where('push_time', '<', $tomorrow)
->field($field)
->find();
}
/**
* 获取用户本周推送记录
* @param int $uid 用户ID
* @param int $giftId 节日有礼活动ID
* @param int $pushType 推送类型
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserWeekPushRecord(int $uid, int $giftId, int $pushType = 0, string $field = '*')
{
$weekStart = strtotime(date('Y-m-d', strtotime('this week Monday')));
$weekEnd = $weekStart + 7 * 86400;
return $this->getModel()->where('uid', $uid)
->where('gift_id', $giftId)
->when($pushType, function ($query) use ($pushType) {
$query->where('push_type', $pushType);
})
->where('push_time', '>=', $weekStart)
->where('push_time', '<', $weekEnd)
->field($field)
->find();
}
/**
* 获取用户本月推送记录
* @param int $uid 用户ID
* @param int $giftId 节日有礼活动ID
* @param int $pushType 推送类型
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserMonthPushRecord(int $uid, int $giftId, int $pushType = 0, string $field = '*')
{
$monthStart = strtotime(date('Y-m-01'));
$monthEnd = strtotime(date('Y-m-01', strtotime('+1 month')));
return $this->getModel()->where('uid', $uid)
->where('gift_id', $giftId)
->when($pushType, function ($query) use ($pushType) {
$query->where('push_type', $pushType);
})
->where('push_time', '>=', $monthStart)
->where('push_time', '<', $monthEnd)
->field($field)
->find();
}
}

View File

@@ -0,0 +1,159 @@
<?php
declare (strict_types=1);
namespace app\dao\activity\holiday;
use app\dao\BaseDao;
use app\model\activity\holiday\HolidayGiftRecord;
/**
* 节日有礼领取记录数据层
* Class HolidayGiftRecordDao
* @package app\dao\activity
*/
class HolidayGiftRecordDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return HolidayGiftRecord::class;
}
/**
* 获取节日有礼领取记录列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getHolidayGiftRecordList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->getModel()->where($where)->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})
->order('id desc')
->select()
->toArray();
}
/**
* 获取节日有礼领取记录数量
* @param array $where
* @return int
*/
public function count(array $where = []): int
{
return $this->getModel()->where($where)->count();
}
/**
* 获取用户领取的节日有礼记录
* @param int $uid 用户ID
* @param int $giftId 节日有礼活动ID
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserGiftRecord(int $uid, int $giftId, string $field = '*')
{
return $this->getModel()->where('uid', $uid)
->where('gift_id', $giftId)
->field($field)
->find();
}
/**
* 获取用户今日领取的节日有礼记录
* @param int $uid 用户ID
* @param int $giftId 节日有礼活动ID
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserTodayGiftRecord(int $uid, int $giftId, string $field = '*')
{
$today = strtotime(date('Y-m-d'));
$tomorrow = $today + 86400;
return $this->getModel()->where('uid', $uid)
->where('gift_id', $giftId)
->where('receive_time', '>=', $today)
->where('receive_time', '<', $tomorrow)
->field($field)
->find();
}
/**
* 获取用户本周领取的节日有礼记录
* @param int $uid 用户ID
* @param int $giftId 节日有礼活动ID
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserWeekGiftRecord(int $uid, int $giftId, string $field = '*')
{
$weekStart = strtotime(date('Y-m-d', strtotime('this week Monday')));
$weekEnd = $weekStart + 7 * 86400;
return $this->getModel()->where('uid', $uid)
->where('gift_id', $giftId)
->where('receive_time', '>=', $weekStart)
->where('receive_time', '<', $weekEnd)
->field($field)
->find();
}
/**
* 获取用户本月领取的节日有礼记录
* @param int $uid 用户ID
* @param int $giftId 节日有礼活动ID
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserMonthGiftRecord(int $uid, int $giftId, string $field = '*')
{
$monthStart = strtotime(date('Y-m-01'));
$monthEnd = strtotime(date('Y-m-01', strtotime('+1 month')));
return $this->getModel()->where('uid', $uid)
->where('gift_id', $giftId)
->where('receive_time', '>=', $monthStart)
->where('receive_time', '<', $monthEnd)
->field($field)
->find();
}
/**
* 检查用户是否可以推送礼物
* @param int $uid 用户ID
* @param int $gifId 礼物ID
* @return bool
*/
public function checkUserCanPush(int $uid, int $gifId)
{
$where = [
'uid' => $uid,
'gift_id' => $gifId,
];
return !!$this->search($where)->find();
}
}

View File

@@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\integral;
use app\dao\BaseDao;
use app\model\activity\integral\StoreIntegral;
/**
* 积分商品
* Class StoreIntegralDao
* @package app\dao\activity\integral
*/
class StoreIntegralDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreIntegral::class;
}
/**
* 搜索查询
* @param array $where 查询条件
* @param bool $search 是否调用父类搜索
* @return \think\db\BaseQuery
*/
public function search($where = [], bool $search = true)
{
return parent::search($where)
->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_del', 0)->field('id');
})
->when(isset($where['integral_time']) && $where['integral_time'] !== '', function ($query) use ($where) {
[$startTime, $endTime] = explode('-', $where['integral_time']);
$query->where('add_time', '>', strtotime($startTime))
->where('add_time', '<', strtotime($endTime) + 24 * 3600);
})->when(isset($where['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
if ($where['priceOrder'] === 'desc') {
$query->order("integral,price desc");
} else {
$query->order("integral,price asc");
}
})->when(isset($where['salesOrder']) && $where['salesOrder'] != '', function ($query) use ($where) {
if ($where['salesOrder'] === 'desc') {
$query->order("sales desc");
} else {
$query->order("sales asc");
}
})->when(isset($where['range']) && $where['range'] != '', function ($query) use ($where) {
$data = explode('-', $where['range']);
if (count($data) > 1) {
$query->where('integral', '>=', $data[0])->where('integral', '<=', $data[1]);
}
});
}
/**
* 积分商品列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, int $page = 0, int $limit = 0, string $field = '*')
{
return $this->search($where)->where('is_del', 0)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->field($field)->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取一条积分商品数据
* @param int $id
* @param string $field
* @param array $with
* @return array|mixed
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function validProduct(int $id, string $field, array $with = [])
{
$where = ['is_show' => 1, 'is_del' => 0];
return $this->search($where)->where('id', $id)->when($with, function ($query) use ($with) {
$query->with($with);
})->field($field)->order('add_time desc')->find();
}
}

View File

@@ -0,0 +1,183 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\integral;
use app\dao\BaseDao;
use app\model\activity\integral\StoreIntegralOrder;
use crmeb\basic\BaseModel;
/**
* 积分订单
* Class StoreIntegralOrderDao
* @package app\dao\activity\integral
*/
class StoreIntegralOrderDao extends BaseDao
{
/**
* 限制精确查询字段
* @var string[]
*/
protected array $withField = ['uid', 'order_id', 'real_name', 'user_phone', 'store_name'];
/**
* @return string
*/
protected function setModel(): string
{
return StoreIntegralOrder::class;
}
/**
* 订单搜索
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
$isDel = isset($where['is_del']) && $where['is_del'] !== '' && $where['is_del'] != -1;
$realName = $where['real_name'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
return parent::search($where, $search)->when($isDel, function ($query) use ($where) {
$query->where('is_del', $where['is_del']);
})->when(isset($where['is_system_del']), function ($query) {
$query->where('is_system_del', 0);
})->when(isset($where['paid']), function ($query) {
$query->where('paid', 1);
})->when(isset($where['is_price']) && $where['is_price'] == 1, function ($query) {
$query->where('price', '>', 0);
})->when(isset($where['is_integral']) && $where['is_integral'] == 1, function ($query) {
$query->where('integral', '>', 0);
})->when($realName && $fieldKey && in_array($fieldKey, $this->withField), function ($query) use ($where, $realName, $fieldKey) {
if ($fieldKey !== 'store_name') {
$query->where(trim($fieldKey), trim($realName));
} else {
$query->whereLike('store_name', '%' . $realName . '%');
}
})->when($realName && !$fieldKey, function ($query) use ($where) {
$query->where(function ($que) use ($where) {
$que->whereLike('order_id|real_name|store_name', '%' . $where['real_name'] . '%')->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid|phone', '%' . $where['real_name'] . '%')->field(['uid'])->select();
});
});
});
}
/**
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field, int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)->field($field)->with($with)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 订单搜索列表
* @param array $where
* @param array $field
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOrderList(array $where, array $field, int $page, int $limit, array $with = [])
{
return $this->search($where)->field($field)->with(array_merge(['user'], $with))->page($page, $limit)->order('add_time DESC,id DESC')->select()->toArray();
}
/**
* 根据条件获取订单列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getIntegralOrderList(array $where)
{
return $this->search($where)->order('id asc')->select()->toArray();
}
/**
* 获取订单总数
* @param array $where
* @return int
*/
public function count(array $where = []): int
{
return $this->search($where)->count();
}
/**
* 查找指定条件下的订单数据以数组形式返回
* @param array $where
* @param string $field
* @param string $key
* @param string $group
* @return array
*/
public function column(array $where, string $field, string $key = '', string $group = '')
{
return $this->search($where)->when($group, function ($query) use ($group) {
$query->group($group);
})->column($field, $key);
}
/**
* 获取订单详情
* @param $uid
* @param $key
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserOrderDetail(string $key, int $uid)
{
return $this->getOne(['order_id' => $key, 'uid' => $uid, 'is_del' => 0]);
}
/**
* 获取用户已购买此活动商品的个数
* @param $uid
* @param $productId
* @return int
*/
public function getBuyCount($uid, $productId): int
{
return $this->getModel()
->where('uid', $uid)
->where('is_del', 0)
->where('product_id', $productId)
->value('sum(total_num)') ?? 0;
}
}

View File

@@ -0,0 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\integral;
use app\dao\BaseDao;
use app\model\activity\integral\StoreIntegralOrderStatus;
/**
* 积分订单状态
* Class StoreIntegralOrderStatusDao
* @package app\dao\activity\integral
*/
class StoreIntegralOrderStatusDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreIntegralOrderStatus::class;
}
/**
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)->field($field)->with($with)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取订单状态列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStatusList(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->select()->toArray();
}
}

View File

@@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\live;
use app\dao\BaseDao;
use app\model\activity\live\LiveAnchor;
/**
* 主播
* Class LiveAnchorDao
* @package app\dao\activity\live
*/
class LiveAnchorDao extends BaseDao
{
protected function setModel(): string
{
return LiveAnchor::class;
}
/**
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,71 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\live;
use app\dao\BaseDao;
use app\model\activity\live\LiveGoods;
/**
* 直播商品
* Class LiveGoodsDao
* @package app\dao\activity\live
*/
class LiveGoodsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return LiveGoods::class;
}
/**
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->with($with)->page($page, $limit)->order('sort desc,add_time desc')->select()->toArray();
}
/**
* 获取所有商品审核状态
* @return array
*/
public function goodsStatusAll()
{
return $this->getModel()->where('goods_id', '>', 0)->whereIn('audit_status', [0, 1])->column('id,audit_status', 'goods_id');
}
/**
* @param array $ids
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function goodsList(array $ids)
{
return $this->getModel()->whereIn('id', $ids)->where('is_del', 0)->where('audit_status', 2)->select()->toArray();
}
}

View File

@@ -0,0 +1,80 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\live;
use app\dao\BaseDao;
use app\model\activity\live\LiveRoom;
/**
* 直播间
* Class LiveRoomDao
* @package app\dao\activity\live
*/
class LiveRoomDao extends BaseDao
{
/**
* @return string
* @author xaboy
* @day 2020/7/29
*/
protected function setModel(): string
{
return LiveRoom::class;
}
/**
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->with($with)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($page, $limit) {
$query->limit($limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* @param $roomId
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function validRoom($roomId)
{
return $this->getModel()->where('id', $roomId)->where('status', 'IN', [0, 2])->where('is_del', 0)->find();
}
/**
* 根据房间ID数组获取直播状态
* @param array $roomIds 房间ID数组
* @return array
*/
public function getRooms(array $roomIds)
{
return $this->search(['room_id' => $roomIds])->column('live_status,id', 'room_id');
}
}

View File

@@ -0,0 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\live;
use app\dao\BaseDao;
use app\model\activity\live\LiveRoomGoods;
/**
* 直播间关联商品
* Class LiveRoomGoodsDao
* @package app\dao\activity\live
*/
class LiveRoomGoodsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return LiveRoomGoods::class;
}
/**
* 清除直播间关联商品
* @param int $id 直播间ID
* @return bool
*/
public function clear($id)
{
return $this->getModel()->where('live_room_id', $id)->delete();
}
}

View File

@@ -0,0 +1,150 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\lottery;
use app\dao\BaseDao;
use app\model\activity\lottery\LuckLottery;
/**
* 抽奖活动
* Class LuckLotteryDao
* @package app\dao\activity\lottery
*/
class LuckLotteryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return LuckLottery::class;
}
/**
* 搜索查询
* @param array $data 查询条件
* @param bool $search 是否调用父类搜索
* @return \think\db\BaseQuery
*/
public function search(array $data = [], bool $search = false)
{
return parent::search($data, $search)->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
$query->where('id', $data['id']);
})->when(isset($data['start']) && $data['start'] !== '', function ($query) use ($data) {
$time = time();
switch ($data['start']) {
case 0:
$query->where('start_time', '>', $time)->where('status', 1);
break;
case 1:
$query->where('status', 1)->where(function ($query1) use ($time) {
$query1->where(function ($query2) use ($time) {
$query2->where('start_time', '<=', $time)->where('end_time', '>=', $time);
})->whereOr(function ($query3) {
$query3->where('start_time', 0)->where('end_time', 0);
});
});
break;
case 2:
$query->where(function ($query1) use ($time) {
$query1->where('end_time', '<', $time)->whereOr('status', 0);
});
break;
}
})->when(isset($data['time_ranges']) && $data['time_ranges'] !== '', function ($query) use ($data) {
$time_ranges = explode('-', $data['time_ranges']);
$query->where(function ($query) use ($time_ranges) {
$time_range1 = strtotime($time_ranges[0]);
$time_range2 = strtotime($time_ranges[1]);
$query->where(function ($query1) use ($time_range1) {
$query1->where('start_time', '<=', $time_range1)->where('end_time', '>=',$time_range1);
})->whereOr(function ($query2) use ($time_range2) {
$query2->where('start_time', '<=', $time_range2)->where('end_time', '>=', $time_range2);
});
});
});
}
/**
* 抽奖活动列表
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->with(['records' => function ($query) {
$query->field([
'lottery_id',
'COUNT(DISTINCT uid) AS total_user', // 总参与人数
'COUNT(DISTINCT CASE WHEN type != 1 THEN uid END) AS wins_user', // 中奖人数
'COUNT(*) AS total_num', // 总参与次数
'SUM(type != 1) AS wins_num', // 中奖次数
])->group('lottery_id');
}])->order('add_time desc')->select()->toArray();
}
/**
* 获取单个活动
* @param int $id
* @param string $field
* @param array|string[] $with
* @param bool $is_doing
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLottery(int $id, string $field = '*', array $with = ['prize'], bool $is_doing = false)
{
$where = ['id' => $id];
$where['is_del'] = 0;
if ($is_doing) $where['start'] = 1;
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with($with);
})->find();
}
/**
* 获取某个抽奖类型的一条抽奖数据
* @param int $factor
* @param string $field
* @param array|string[] $with
* @param bool $is_doing
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFactorLottery(int $factor = 1, string $field = '*', array $with = ['prize'], bool $is_doing = true)
{
$where = ['factor' => $factor, 'is_del' => 0, 'is_use' => 1];
if ($is_doing) $where['start'] = 1;
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with($with);
})->order('id desc')->find();
}
}

View File

@@ -0,0 +1,74 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\lottery;
use app\dao\BaseDao;
use app\model\activity\lottery\LuckLotteryRecord;
/**
* 中奖记录
* Class LuckLotteryRecordDao
* @package app\dao\activity\lottery
*/
class LuckLotteryRecordDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return LuckLotteryRecord::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, $field = '*', array $with = [], int $page = 0, int $limit = 10)
{
return $this->search($where)->when($with, function ($query) use ($with) {
$query->with($with);
})->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
}
/**
* @param array $where
* @param string $group
* @return int
*/
public function getCount(array $where, string $group = ''):int
{
$add_time = 0;
if (isset($where['add_time']) && $where['add_time']) {
$add_time = $where['add_time'];
unset($where['add_time']);
}
return $this->search($where)->when($add_time > 0, function ($query) use ($where, $add_time) {
$query->where('add_time', '>=', $add_time);
})->when($group, function ($query) use ($group) {
$query->group($group);
})->count();
}
}

View File

@@ -0,0 +1,49 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\lottery;
use app\dao\BaseDao;
use app\model\activity\lottery\LuckPrize;
/**
* 抽奖奖品
* Class LuckPrizeDao
* @package app\dao\activity\lottery
*/
class LuckPrizeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return LuckPrize::class;
}
/**
* 获取某个活动所有奖品
* @param int $lottery_id
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPrizeList(int $lottery_id, string $field = '*')
{
$where = ['is_del' => 0, 'status' => 1];
return $this->search($where + ['lottery_id' => $lottery_id])->field($field)->order('sort desc,id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,90 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\newcomer;
use app\dao\BaseDao;
use app\model\activity\newcomer\StoreNewcomer;
use crmeb\basic\BaseModel;
/**
* 新人礼商品
* Class StoreNewcomerDao
* @package app\dao\activity\newcomer
*/
class StoreNewcomerDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreNewcomer::class;
}
/**
* 搜索
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['storeProductId']), function ($query) {
$query->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_del', 0)->field('id');
});
});
}
/**
* 新人专享商品列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when(isset($where['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
if ($where['priceOrder'] === 'desc') {
$query->order("price desc");
} else {
$query->order("price asc");
}
})->when(isset($where['salesOrder']) && $where['salesOrder'] != '', function ($query) use ($where) {
if ($where['salesOrder'] === 'desc') {
$query->order("sales desc");
} else {
$query->order("sales asc");
}
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,134 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\activity\promotions;
use app\dao\BaseDao;
use app\model\activity\promotions\StorePromotions;
use app\model\activity\promotions\StorePromotionsAuxiliary;
/**
* 优惠活动辅助表
*/
class StorePromotionsAuxiliaryDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return StorePromotionsAuxiliary::class;
}
/**
* 设置关联模型
* @return string
*/
public function joinModel(): string
{
return StorePromotions::class;
}
/**
* 获取所有的分销员等级
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where = [], string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 关联模型
* @param string $alias
* @param string $join_alias
* @return \crmeb\basic\BaseModel
*/
public function getJoinModel(string $alias = 'a', string $join_alias = 'p', $join = 'left')
{
$this->alias = $alias;
$this->joinAlis = $join_alias;
/** @var StorePromotions $storePromotions */
$storePromotions = app()->make($this->joinModel());
$table = $storePromotions->getName();
return parent::getModel()->alias($alias)->join($table . ' ' . $join_alias, $alias . '.promotions_id = ' . $join_alias . '.id', $join);
}
/**
* 获取ids
* @param array $product_id
* @param int $product_partake_type
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getProductsPromotionsIds(array $product_id, int $product_partake_type = 2, string $field = '')
{
$time = time();
return $this->getJoinModel()->field($field)
->where($this->joinAlis . '.type', 1)
->where($this->joinAlis . '.status', 1)
->where($this->joinAlis . '.is_del', 0)
->where($this->joinAlis . '.start_time', '<=', $time)
->where($this->joinAlis . '.stop_time', '>=', $time)
->where($this->alias . '.type', 1)
->when(in_array($product_partake_type, [2, 3]), function ($query) use ($product_partake_type, $product_id) {
if ($product_partake_type == 2) {
$query->where(function ($q) use ($product_id) {
$q->whereOr( $this->joinAlis.'.product_partake_type', 1)
->whereOr(function ($w) use ($product_id) {
$w->where($this->joinAlis.'.product_partake_type', 2)->where(function ($p) use ($product_id) {
if (is_array($product_id)) {
$p->whereIn($this->alias.'.product_id', $product_id);
} else {
$p->where($this->alias.'.product_id', $product_id);
}
});
})->whereOr(function ($e) use ($product_id) {
$e->where($this->joinAlis.'.product_partake_type', 3)->where($this->alias.'.is_all', 1)->where(function ($p) use ($product_id) {
if (is_array($product_id)) {
$p->whereNotIn($this->alias.'.product_id', $product_id);
} else {
$p->where($this->alias.'.product_id', '<>', $product_id);
}
});
});
});
} else {
$query->where($this->alias.'.product_partake_type', 3)->where($this->alias.'.is_all', 1)->where(function ($p) use ($product_id){
if(is_array($product_id)){
$p->whereNotIn($this->alias.'.product_id', $product_id);
}else{
$p->where($this->alias.'.product_id', $product_id);
}
});
}
})->select()->toArray();
}
}

View File

@@ -0,0 +1,156 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\promotions;
use app\dao\BaseDao;
use app\model\activity\promotions\StorePromotions;
use crmeb\basic\BaseModel;
/**
* 促销活动
* Class StorePromotionsDao
* @package app\dao\activity\promotions
*/
class StorePromotionsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StorePromotions::class;
}
/**
* 搜索
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['promotionsTime']), function ($query) use ($where) {
[$startTime, $stopTime] = is_array($where['promotionsTime']) ? $where['promotionsTime'] : [time(), time()];
$query->where('start_time', '<=', $startTime)->where('stop_time', '>=', $stopTime);
})->when(isset($where['ids']) && $where['ids'], function ($query) use ($where) {
$query->whereIn('id', $where['ids']);
})->when(isset($where['not_ids']) && $where['not_ids'], function ($query) use ($where) {
$query->whereNotIn('id', $where['not_ids']);
})->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where(function ($q) use ($time) {
$q->where('stop_time', '<', $time)->whereOr('status', '0');
});
break;
case 0:
$query->where('start_time', '>', $time)->where('status', 1);
break;
case 1:
$query->where('start_time', '<=', $time)->where('stop_time', '>=', $time)->where('status', 1);
break;
}
})->when(isset($where['product_id']) && $where['product_id'], function ($query) use ($where) {
$query->where(function ($q) use ($where) {
$q->whereOr('product_partake_type', 1)
->whereOr(function ($w) use ($where) {
$w->where('product_partake_type', 2)->whereIn('id', function ($a) use ($where) {
$a->name('store_promotions_auxiliary')->field('promotions_id')->where('type', 1)->where('product_partake_type', 2)->where(function ($p) use ($where) {
if (is_array($where['product_id'])) {
$p->whereIn('product_id', $where['product_id']);
} else {
$p->where('product_id', $where['product_id']);
}
});
});
})->whereOr(function ($b) use ($where) {
$b->where('product_partake_type', 4)->whereIn('id', function ($a) use ($where) {
$a->name('store_promotions_auxiliary')->field('promotions_id')->where('type', 1)->where('product_partake_type', 2)->where(function ($p) use ($where) {
if (is_array($where['product_id'])) {
$p->whereIn('product_id', $where['product_id']);
} else {
$p->where('product_id', $where['product_id']);
}
});
});
});
});
});
}
/**
* 获取促销活动列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @param string $order
* @param string $group
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [], string $order = 'update_time desc,id desc', string $group = '')
{
return $this->search($where)->field($field)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($with, function ($query) use ($with) {
$query->with($with);
})->order($order)->when($group, function ($query) use ($group) {
$query->group($group);
})->select()->toArray();
}
/**
* 获取一条活动
* @param int $id
* @param string $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function validPromotions(int $id, string $field = '*')
{
$where = ['status' => 1, 'is_del' => 0];
$time = time();
return $this->search($where)
->where('id', $id)
->where('start_time', '<=', $time)
->where('stop_time', '>=', $time)
->field($field)->find();
}
/**
* 获取一个活动包含子集的所有ID
* @param int $id
* @return array
*/
public function getOnePromotionsIds(int $id)
{
$result = $this->getModel()->where('id|pid', $id)->column('id');
$res = [];
if ($result) {
$res = array_column($result, 'id');
}
return $res;
}
}

View File

@@ -0,0 +1,226 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\seckill;
use app\dao\BaseDao;
use app\model\activity\seckill\StoreSeckill;
use crmeb\basic\BaseModel;
/**
* 秒杀商品
* Class StoreSeckillDao
* @package app\dao\activity\seckill
*/
class StoreSeckillDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreSeckill::class;
}
/**
* 搜索
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['seckllTime']), function ($query) use ($where) {
[$startTime, $stopTime] = is_array($where['seckllTime']) ? $where['seckllTime'] : [time(), time() - 86400];
$query->where('start_time', '<=', $startTime)->where('stop_time', '>=', $stopTime);
})->when(isset($where['storeProductId']), function ($query) {
$query->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_del', 0)->field('id');
});
})->when(isset($where['time_id']) && $where['time_id'], function ($query) use ($where) {
$query->where('time_id', $where['time_id']);
})->when(isset($where['start_status']) && $where['start_status'] !== '', function ($query) use ($where) {
$time = time();
switch ($where['start_status']) {
case -1:
$query->where(function ($q) use ($time) {
$q->where('stop_time', '<', $time - 86400)->whereOr('status', '0');
});
break;
case 0:
$query->where('start_time', '>', $time)->where('status', 1);
break;
case 1:
$query->where('start_time', '<=', $time)->where('stop_time', '>=', $time - 86400)->where('status', 1);
break;
}
});
}
/**
* 获取某个活动下的秒杀商品ids
* @param array $where
* @return array
*/
public function getActivitySeckillIds(array $where)
{
return $this->search($where)->column('id');
}
/**
* 获取秒杀列表
* @param array $where
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 根据商品id获取当前正在开启秒杀产品的列表以数组返回
* @param array $ids
* @param array $field
* @return array
*/
public function getSeckillIdsArray(array $ids, array $field = [])
{
return $this->search(['is_del' => 0, 'status' => 1])
->where('start_time', '<=', time())
->where('stop_time', '>=', time() - 86400)
->whereIn('product_id', $ids)
->field($field)->select()->toArray();
}
/**
* 获取某个时间段的秒杀列表
* @param array $activity_id
* @param array $ids
* @param string $field
* @param int $page
* @param int $limit
* @param bool $isStore
* @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getListByTime(array $activity_id, array $ids = [], string $field = '*', int $page = 0, int $limit = 0, bool $isStore = false)
{
if ($activity_id == 0) return [];
return $this->search(['is_del' => 0, 'status' => 1])->field($field)
->where('start_time', '<=', time())
->where('stop_time', '>=', time() - 86400)
->when($activity_id, function ($query) use ($activity_id) {
$query->whereIn('activity_id', $activity_id);
})->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_del', 0)->field('id');
})->when($ids, function($query) use($ids) {
$query->whereIn('product_id', $ids);
})->when($isStore, function($query) {
$query->where(function ($q) {
$q->whereOr(function ($c) {
$c->whereFindInSet('delivery_type', 2);
})->whereOr(function ($d) {
$d->whereFindInSet('delivery_type', 3);
});
});
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取正在开启的秒杀总数
* @param array $activity_id
* @param $ids
* @param $not_ids
* @param bool $isStore
* @return int
* @throws \think\db\exception\DbException
*/
public function getTimeCount(array $activity_id, $ids = [], $not_ids = [], bool $isStore = true)
{
if ($activity_id == 0) return 0;
return $this->search(['is_del' => 0, 'status' => 1])
->where('start_time', '<=', time())
->where('stop_time', '>=', time() - 86400)
->when($activity_id, function ($query) use ($activity_id) {
$query->whereIn('activity_id', $activity_id);
})->where('product_id', 'IN', function ($query) {
$query->name('store_product')->where('is_del', 0)->field('id');
})->when($ids, function($query) use($ids) {
$query->whereIn('product_id', $ids);
})->when($not_ids, function($query) use($not_ids) {
$query->whereNotIn('product_id', $not_ids);
})->when($isStore, function($query) {
$query->where(function ($q) {
$q->whereOr(function ($c) {
$c->whereFindInSet('delivery_type', 2);
})->whereOr(function ($d) {
$d->whereFindInSet('delivery_type', 3);
});
});
})->count();
}
/**
* 根据id获取秒杀数据
* @param array $ids
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function idSeckillList(array $ids, string $field)
{
return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
}
/**获取一条秒杀商品
* @param $id
* @param $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function validProduct($id, $field)
{
$where = ['status' => 1, 'is_del' => 0];
$time = time();
return $this->search($where)
->where('id', $id)
->where('start_time', '<', $time)
->where('stop_time', '>', $time - 86400)
->field($field)->with(['product'])->find();
}
}

View File

@@ -0,0 +1,121 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\seckill;
use app\dao\BaseDao;
use app\model\activity\seckill\StoreSeckillTime;
/**
* 秒杀时间
* Class StoreSeckillTimeDao
* @package app\dao\activity\seckill
*/
class StoreSeckillTimeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreSeckillTime::class;
}
/**
* @param array $where
* @param bool $search
* @return \crmeb\basic\BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = true)
{
return parent::search($where)
->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']));
});
}
/**
* 获取秒杀时间列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, string $order = 'start_time asc,id desc')
{
return $this->search($where)->field($field)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
/**
* 开始时间 在别的时间段中
* @param $time
* @param $id
* @return int
* @throws \think\db\exception\DbException
*/
public function valStartTime($time, $id)
{
return $this->getModel()
->when($id, function ($query) use ($id) {
$query->where('id', '<>', $id);
})->where('start_time', '<=', $time)->where('end_time', '>', $time)->count();
}
/**
* 结束时间在别的时间段中
* @param $time
* @param $id
* @return int
* @throws \think\db\exception\DbException
*/
public function valEndTime($time, $id)
{
return $this->getModel()
->when($id, function ($query) use ($id) {
$query->where('id', '<>', $id);
})->where('start_time', '<', $time)->where('end_time', '>=', $time)->count();
}
/**
* 时间段包含了别的时间段
* @param array $data
* @param $id
* @return int
* @throws \think\db\exception\DbException
*/
public function valAllTime(array $data, $id)
{
return $this->getModel()
->when($id, function ($query) use ($id) {
$query->where('id', '<>', $id);
})->where('start_time', '>', $data['start_time'])->where('end_time', '<=', $data['end_time'])->count();
}
}

View File

@@ -0,0 +1,77 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\video;
use app\dao\BaseDao;
use app\model\activity\video\VideoComment;
use crmeb\basic\BaseModel;
/**
* 视频评论
* Class VideoCommentDao
* @package app\dao\activity\video
*/
class VideoCommentDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return VideoComment::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['keyword']) && $where['keyword'], function ($query) use ($where) {
$keyword = $where['keyword'];
$query->where(function ($q) use ($keyword) {
$q->whereOr('video_id|uid|content', 'like', '%' . $keyword . '%')->whereOr('video_id', 'in', function ($c) use ($keyword) {
$c->name('video')->field('id')->whereLike('id|desc', '%' . $keyword . '%');
});
});
});
}
/**
* 视频评论列表
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,86 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\activity\video;
use app\dao\BaseDao;
use app\model\activity\video\Video;
use crmeb\basic\BaseModel;
/**
* 视频
* Class VideoDao
* @package app\dao\activity\video
*/
class VideoDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Video::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where)->when(isset($where['keyword']) && $where['keyword'], function ($query) use ($where) {
$keyword = $where['keyword'];
$query->where(function ($q) use ($keyword) {
$q->whereOr('id|desc', 'like', '%' . $keyword . '%')->whereOr('id', 'in', function ($c) use ($keyword) {
$c->name('video_comment')->field('video_id')->whereLike('video_id|uid|content', '%' . $keyword . '%');
});
});
})->when(isset($where['order_by_id']) && $where['order_by_id'], function ($query) use ($where) {
$query->where('id', 'in', $where['order_by_id'])->orderField('id', $where['order_by_id']);
})->when(isset($where['notId']), function ($query) use ($where) {
$query->where('id', '<>', $where['notId']);
});
}
/**
* 视频列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, string $order = 'sort desc,id desc')
{
return $this->search($where)->field($field)
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($order, function ($query) use ($order) {
if ($order == 'rand') {
$query->orderRand();
} else if ($order) {
$query->order($order);
} else {
$query->order('sort desc,id desc');
}
})->select()->toArray();
}
}

View File

@@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\agent;
use app\dao\BaseDao;
use app\model\agent\AgentLevel;
/**
* Class AgentLevelDao
* @package app\dao\agent
*/
class AgentLevelDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return AgentLevel::class;
}
/**
* 获取所有的分销员等级
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where = [], string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('grade asc,id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,68 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\agent;
use app\dao\BaseDao;
use app\model\agent\AgentLevelTask;
/**
* Class AgentLevelTaskDao
* @package app\dao\agent
*/
class AgentLevelTaskDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return AgentLevelTask::class;
}
/**
* 获取等级任务
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTaskList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->when($with, function ($query) use ($with) {
$query->with($with);
})->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 获得所有同类型任务
* @param int $type
* @param int $grade
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTypTaskList(int $type)
{
return $this->getModel()->with(['levelGrade'])->where('type', $type)->where('is_del', 0)->where('status', 1)->order('number desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\agent;
use app\dao\BaseDao;
use app\model\agent\AgentLevelTaskRecord;
/**
* Class AgentLevelTaskRecordDao
* @package app\dao\agent
*/
class AgentLevelTaskRecordDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return AgentLevelTaskRecord::class;
}
/**
* 获取所有的分销员等级
* @param array $where
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where = [], string $field = '*')
{
return $this->search($where + ['is_del' => 0, 'status' => 1])->field($field)->order('sort desc,id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace app\dao\agent;
use app\dao\BaseDao;
use app\model\agent\DivisionApply;
class DivisionApplyDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return DivisionApply::class;
}
/**
* 条件查询
* @param $where
* @return \crmeb\basic\BaseModel
* @author wuhaotian
* @email 442384644@qq.com
* @date 2024/8/21
*/
public function getConditionModel($where)
{
return $this->getModel()->where('is_del', 0)
->when($where['division_id'] != 0, function ($query) use ($where) {
$query->where('division_id', $where['division_id']);
})->when($where['status'] !== '' && $where['status'] !== 'all', function ($query) use ($where) {
$query->where('status', $where['status']);
})->when($where['keyword'] !== '', function ($query) use ($where) {
$query->whereLike('uid|agent_name|name|phone', $where['keyword']);
});
}
/**
* 获取申请列表
* @param $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author wuhaotian
* @email 442384644@qq.com
* @date 2024/8/21
*/
public function applyList($where, $page = 0, $limit = 0)
{
return $this->getConditionModel($where)->order('id desc')->when($page != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取申请数量
* @param $where
* @return int
* @throws \think\db\exception\DbException
* @author wuhaotian
* @email 442384644@qq.com
* @date 2024/8/21
*/
public function applyCount($where)
{
return $this->getConditionModel($where)->count();
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace app\dao\agent;
use app\dao\BaseDao;
use app\model\agent\PromoterApply;
class PromoterApplyDao extends BaseDao
{
/**
* @return string
* @author wuhaotian
* @email 442384644@qq.com
* @date 2024/8/30
*/
protected function setModel(): string
{
return PromoterApply::class;
}
/**
* 条件查询
* @param $where
* @return \crmeb\basic\BaseModel
* @author wuhaotian
* @email 442384644@qq.com
* @date 2024/8/21
*/
public function getConditionModel($where)
{
return $this->getModel()->where('is_del', 0)
->when($where['status'] !== '' && $where['status'] !== 'all', function ($query) use ($where) {
$query->where('status', $where['status']);
})->when($where['keyword'] !== '', function ($query) use ($where) {
$query->whereLike('uid|nickname|real_name|phone', $where['keyword']);
});
}
/**
* 获取申请列表
* @param $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author wuhaotian
* @email 442384644@qq.com
* @date 2024/8/21
*/
public function applyList($where, $page = 0, $limit = 0)
{
return $this->getConditionModel($where)->order('id desc')->when($page != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 获取申请数量
* @param $where
* @return int
* @throws \think\db\exception\DbException
* @author wuhaotian
* @email 442384644@qq.com
* @date 2024/8/21
*/
public function applyCount($where)
{
return $this->getConditionModel($where)->count();
}
}

View File

@@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\article;
use app\dao\BaseDao;
use app\model\article\ArticleCategory;
/**
* 文章分类
* Class ArticleCategoryDao
* @package app\dao\article
*/
class ArticleCategoryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ArticleCategory::class;
}
/**
* 获取文章列表
* @param array $where
* @param int $page
* @param int $limit
* @return mixed
*/
public function getList(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->order('sort desc,id desc')->select()->toArray();
}
/**
* 前台获取文章分类
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getArticleCategory()
{
return $this->search(['hidden' => 0, 'is_del' => 0, 'status' => 1])
->order('sort DESC')
->field('id,title')
->select()->toArray();
}
}

View File

@@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\article;
use app\dao\BaseDao;
use app\model\article\ArticleContent;
/**
* 文章详情
* Class ArticleContentDao
* @package app\dao\article
*/
class ArticleContentDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return ArticleContent::class;
}
/**
* 根据id删除数据
* @param int $id
* @return bool
* @throws \Exception
*/
public function del(int $id)
{
return $this->getModel()->where('nid',$id)->delete();
}
}

View File

@@ -0,0 +1,116 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\article;
use app\dao\BaseDao;
use app\model\article\Article;
use crmeb\basic\BaseModel;
/**
* 文章dao
* Class ArticleDao
* @package app\dao\article
*/
class ArticleDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Article::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
* @author 等风来
* @email 136327134@qq.com
* @date 2023/10/7
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, false)->when(isset($where['ids']) && count($where['ids']), function ($query) use ($where) {
$query->whereNotIn('id', $where['ids']);
})->when(isset($where['cid']) && $where['cid'], function ($query) use ($where) {
$query->where('cid', $where['cid']);
})->when(isset($where['is_hot']) && $where['is_hot'], function ($query) use ($where) {
$query->where('is_hot', $where['is_hot']);
})->when(isset($where['is_banner']) && $where['is_banner'], function ($query) use ($where) {
$query->where('is_banner', $where['is_banner']);
});
}
/**
* 获取文章列表
* @param array $where
* @param int $page
* @param int $limit
* @return mixed
*/
public function getList(array $where, int $page, int $limit)
{
return $this->search($where)->with(['contents', 'storeInfo', 'cateName'])->page($page, $limit)->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取一条数据
* @param $id
* @return mixed
*/
public function read($id)
{
$data = $this->search()->with(['contents', 'storeInfo', 'cateName'])->find($id);
if ($data) {
$data['store_info'] = $data['storeInfo'];
}
return $data;
}
/**
* @param array $where
* @param int $page
* @param int $limit
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function cidByArticleList(array $where, int $page, int $limit, string $field = '*')
{
return $this->search($where + ['status' => 1, 'hide' => 0])
->when($page != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->field($field)->select()->toArray();
}
/**新闻分类下的文章
* @param $new_id
* @return mixed
*/
public function articleLists($new_id)
{
return $this->getModel()->where('hide', 0)->where('id', 'in', $new_id)->select();
}
/**图文详情
* @param $new_id
* @return mixed
*/
public function articleContentList($new_id)
{
return $this->getModel()->where('hide', 0)->where('id', 'in', $new_id)->with('contents')->select();
}
}

View File

@@ -0,0 +1,134 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\community;
use app\dao\BaseDao;
use app\model\community\CommunityComment;
use crmeb\basic\BaseModel;
/**
* 社区评论
* Class CommunityCommentDao
* @package app\dao\community
*/
class CommunityCommentDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CommunityComment::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
$keyword = $where['keyword'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = in_array($fieldKey, ['user', 'community', 'comment', 'id']) ? $fieldKey : '';
/** field_key
* user
* community
* comment
* id
*/
return parent::search($where, $search)
->when(isset($where['author_uid']), function ($query) use ($where) {
if ($where['author_uid'] == 0) {
$query->where('is_show', 1);
}
})
->when($keyword !== '' && $fieldKey !== '', function ($query) use ($fieldKey, $keyword) {
switch ($fieldKey) {
case 'user':
$query->whereIn('uid', function ($query) use ($keyword) {
$query->name('user')->whereLike('nickname', '%' . $keyword . '%')->field('uid');
});
break;
case 'community':
$query->whereIn('community_id', function ($query) use ($keyword) {
$query->name('community')->whereLike('title|content', '%' . $keyword . '%')->field('id');
});
break;
case 'comment':
$query->whereLike('content', '%' . $keyword . '%');
break;
case 'id':
$query->where('id', $keyword);
}
})->when(isset($where['is_verify']) && $where['is_verify'] !== '', function ($query) use ($where) {
if (isset($where['author_uid'])) {
$query->where(function ($query) use ($where) {
if ($where['author_uid'] == 0) {
$query->where('is_verify', 1);
} else {
$query->where(function ($query) use ($where) {
// 条件一:uid 等于 author_uid,且 is_verify 为 0 或 1
$query->where('uid', $where['author_uid'])
->whereIn('is_verify', [0, 1]);
})->whereOr(function ($query) use ($where) {
// 条件二:uid 不等于 author_uid,且 is_verify 为 1
$query->where('uid', '<>', $where['author_uid'])
->where('is_verify', 1);
});
}
});
} else {
$query->where('is_verify', $where['is_verify']);
}
});
}
/**
* 获取评论数量
* @param array $where 查询条件
* @return int
*/
public function count($where = []): int
{
return $this->search($where)->count();
}
/**
* 评论列表
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0, $order = 'add_time DESC')
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
}

View File

@@ -0,0 +1,135 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\community;
use app\dao\BaseDao;
use app\model\community\Community;
use app\services\community\CommunityRelevanceServices;
use crmeb\basic\BaseModel;
/**
* 社区
* Class CommunityDao
* @package app\dao\community
*/
class CommunityDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Community::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)
->when(isset($where['keyword']) && $where['keyword'], function ($query) use ($where) {
$query->where(function ($query) use ($where) {
$query->whereLike('title|id', "%{$where['keyword']}%");
});
// ->whereOr(function ($query) use ($where) {
// //商品
// $query->whereIn('id', function ($product) use ($where) {
// $product->name('community_relevance')->where('type', CommunityRelevanceServices::TYPE_COMMUNITY_PRODUCT)->whereIn('right_id',
// function ($q) use ($where) {
// $q->name('store_product')->whereLike('store_name|keyword', "%{$where['keyword']}%")->field('id');
// }
// )->field('left_id');
// });
// })->whereOr(function ($query) use ($where) {
// //用户
// $query->whereIn('relation_id', function ($user) use ($where) {
// $user->name('user')->whereLike('nickname', "%{$where['keyword']}%")->field('uid');
// });
// });
})
->when(isset($where['topic_id']) && $where['topic_id'], function ($query) use ($where) {
$topicIds = is_array($where['topic_id']) ? $where['topic_id'] : [$where['topic_id']];
$query->whereIn('id', function ($topic) use ($topicIds) {
$topic->name('community_relevance')->where('type', CommunityRelevanceServices::TYPE_COMMUNITY_TOPIC)->whereIn('right_id', $topicIds)->field('left_id');
});
})
->when(isset($where['product_id']) && $where['product_id'], function ($query) use ($where) {
$productIds = is_array($where['product_id']) ? $where['product_id'] : [$where['product_id']];
$query->whereIn('id', function ($product) use ($productIds) {
$product->name('community_relevance')->where('type', CommunityRelevanceServices::TYPE_COMMUNITY_PRODUCT)->whereIn('right_id', $productIds)->field('left_id');
});
})
->when(isset($where['is_follow']) && $where['is_follow'], function ($query) use ($where) {
$query->whereIn('relation_id', function ($product) use ($where) {
$product->name('community_relevance')->where('type', CommunityRelevanceServices::TYPE_COMMUNITY_INTEREST)->where('left_id', $where['is_follow'])->field('right_id');
});
})
// ->when(isset($where['order_by_id']) && $where['order_by_id'], function ($query) use ($where) {
// $query->where('id', 'in', $where['order_by_id'])->orderField('id', $where['order_by_id']);
// })
->when(isset($where['notId']), function ($query) use ($where) {
$query->where('id', '<>', $where['notId']);
});
}
/**
* 社区列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [], string $order = 'sort desc,id desc')
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($order, function ($query) use ($order) {
if ($order == 'rand') {
$query->orderRand();
} else if ($order) {
$query->order($order);
} else {
$query->order('sort desc,id desc');
}
})->select()->toArray();
}
/**
* @param array $where
* @param string $field
* @param int $limit
* @return array
* @throws \ReflectionException
* User: liusl
* DateTime: 2024/8/27 10:40
*/
public function getIdColumn(array $where, string $field, int $limit = 5): array
{
return $this->search($where)->limit($limit)->column($field);
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\community;
use app\dao\BaseDao;
use app\model\community\CommunityRecord;
/**
* 社区记录
* Class CommunityRecordDao
* @package app\dao\community
*/
class CommunityRecordDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CommunityRecord::class;
}
}

View File

@@ -0,0 +1,221 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\community;
use app\dao\BaseDao;
use app\model\community\CommunityRelevance;
use app\services\community\CommunityRelevanceServices;
use crmeb\basic\BaseModel;
use think\exception\ValidateException;
/**
* 社区关联
* Class CommunityTopicDao
* @package app\dao\community
*/
class CommunityRelevanceDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CommunityRelevance::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search);
}
/**
* 关联社区列表查询
* @param array $where 查询条件
* @param int $page 页码
* @param int $limit 每页数量
* @param string $condition 关联条件字段
* @param string $order 排序
* @return array
*/
public function joinCommunityList(array $where = [], $page = 0, $limit = 0, $condition = 'right_id', $order = 'r.id DESC')
{
return $this->joinCommunity($where, $condition)
->field('r.*,c.id as c_id,c.type as c_type,c.title,c.image,c.relation_id,c.content_type,c.like_num,c.slider_image')
->when($limit, function ($query) use ($page, $limit) {
if ($page) {
$query->page($page, $limit);
} else {
$query->limit($limit);
}
})
->order($order)
->select()
->toArray();
}
/**
* 关联社区查询
* @param array $where 查询条件
* @param string $condition 关联条件字段
* @return \think\db\BaseQuery
*/
public function joinCommunity(array $where = [], $condition = 'right_id')
{
return $this->getModel()->alias('r')
->join('community c', "r.{$condition}=c.id")
->when(isset($where['keyword']) && $where['keyword'], function ($query) use ($where) {
$query->where(function ($query) use ($where) {
$query->whereLike('c.title|c.content', "%{$where['keyword']}%");
})->whereOr(function ($query) use ($where) {
//商品
$query->whereIn('c.id', function ($product) use ($where) {
$productIds = name('product')->where('store_name|keyword', "%{$where['keyword']}%")->column('id');
$product->name('community_relevance')->where('type', CommunityRelevanceServices::TYPE_COMMUNITY_PRODUCT)->whereIn('right_id', $productIds)->field('left_id');
});
})->whereOr(function ($query) use ($where) {
//用户
$query->whereIn('c.relation_id', function ($user) use ($where) {
$user->name('user')->where('nickname', "%{$where['keyword']}%")->field('uid');
});
});
})
->where('c.is_verify', 1)->where('c.is_del', 0)->where('c.status', 1)
//用户
->when(isset($where['uid']) && $where['uid'], function ($query) use ($where) {
$query->where('r.left_id', $where['uid'])->where('r.type', CommunityRelevanceServices::TYPE_COMMUNITY_LIKE);
})
//商品
->when(isset($where['product_id']) && $where['product_id'], function ($query) use ($where) {
$query->where('r.right_id', $where['product_id'])->where('r.type', CommunityRelevanceServices::TYPE_COMMUNITY_PRODUCT);
})
//话题
->when(isset($where['topic_id']) && $where['topic_id'], function ($query) use ($where) {
$query->where('r.right_id', $where['topic_id'])->where('r.type', CommunityRelevanceServices::TYPE_COMMUNITY_TOPIC);
});
}
/**
* 添加
* @param int $leftId
* @param int $rightId
* @param string $type
* @param bool $check
* @return bool
* User: liusl
* DateTime: 2024/8/7 14:41
*/
public function create(int $leftId, int $rightId, string $type, bool $check = false)
{
if ($check && $this->checkHas($leftId, $rightId, $type)) {
return false;
}
$data = [
'left_id' => $leftId,
'right_id' => $rightId,
'type' => $type,
];
try {
$this->save($data);
return true;
} catch (\Exception $exception) {
throw new ValidateException('创建失败');
}
}
/**
* 检测是否存在
* @param int $leftId
* @param int $rightId
* @param string $type
* @return mixed
* User: liusl
* DateTime: 2024/8/7 14:42
*/
public function checkHas(int $leftId, int $rightId, string $type)
{
return $this->search([
'left_id' => $leftId,
'right_id' => $rightId,
'type' => $type,
])->find();
}
/**
* 根据左键批量删除
* @param $leftId
* @param $type
* @return mixed
* User: liusl
* DateTime: 2024/8/7 14:43
*/
public function batchDelete($leftId, $type)
{
return $this->search([
'left_id' => $leftId,
'type' => $type,
])->delete();
}
/**
* 条件删除
* @param int $leftId
* @param int $rightId
* @param string $type
* @return mixed
* User: liusl
* DateTime: 2024/8/13 14:22
*/
public function destory(int $leftId, int $rightId, string $type)
{
return $this->search([
'left_id' => $leftId,
'right_id' => $rightId,
'type' => $type,
])->delete();
}
/**
* 批量插入
* @param int $leftId
* @param array $rightId
* @param string $type
* @return void
* User: liusl
* DateTime: 2024/8/7 14:44
*/
public function createMany(int $leftId, array $rightId, string $type)
{
if (!empty($rightId)) {
$res = [];
foreach ($rightId as $value) {
$res[] = [
'left_id' => $leftId,
'right_id' => $value,
'type' => $type,
];
}
if (count($res) > 0) {
$this->saveAll($res);
}
}
}
}

View File

@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\community;
use app\dao\BaseDao;
use app\model\community\CommunityTopic;
use crmeb\basic\BaseModel;
/**
* 社区话题
* Class CommunityTopicDao
* @package app\dao\community
*/
class CommunityTopicDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CommunityTopic::class;
}
/**
* 话题列表
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,102 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\community;
use app\dao\BaseDao;
use app\model\community\CommunityUser;
use crmeb\basic\BaseModel;
/**
* 社区用户
* Class CommunityUserDao
* @package app\dao\community
*/
class CommunityUserDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return CommunityUser::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['name']) && $where['name'], function ($query) use ($where) {
$query->whereLike('id|nickname', '%' . $where['name'] . '%');
});
}
/**
*
* @param array $where
* @param string $field
* @param array $with
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = [], int $page = 0, int $limit = 0, string $order = 'id DESC')
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})
->when(isset($where['is_community_num']), function ($query) {
$query->where('community_num', '>', 0);
})
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
/**
* 获取用户信息
* @param int $uid
* @return array|mixed
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* User: liusl
* DateTime: 2024/8/26 15:44
*/
public function getUserInfo(int $uid)
{
$where = [
'is_del' => 0
];
if ($uid == 0) {
$where['type'] = 0;
$where['uid'] = 0;
} else {
$where['type'] = 2;
$where['relation_id'] = $uid;
}
return $this->search($where)->find();
}
}

50
app/dao/diy/DiyDao.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\diy;
use app\dao\BaseDao;
use app\model\diy\Diy;
/**
*
* Class DiyDao
* @package app\dao\diy
*/
class DiyDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Diy::class;
}
/**
* 获取DIY列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getDiyList(array $where, int $page, int $limit, array $field = ['*'])
{
return $this->search($where)->field($field)->page($page, $limit)->order('status desc,id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\diy;
use app\dao\BaseDao;
use app\model\diy\PageCategory;
/**
* Class PageCategoryDao
* @package app\dao\diy
*/
class PageCategoryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return PageCategory::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\diy;
use app\dao\BaseDao;
use app\model\diy\PageLink;
/**
* 页面链接
* Class PageLinkDao
* @package app\dao\diy
*/
class PageLinkDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return PageLink::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page();
})->order('sort desc,id asc')->select()->toArray();
}
}

View File

@@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\message;
use app\dao\BaseDao;
use app\model\message\SystemMessage;
/**
* 站内信
* Class SystemMessageDao
* @package app\dao\message
*/
class SystemMessageDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemMessage::class;
}
/**
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getMessageList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->getModel()->where($where)->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(!$page && $limit, function ($query) use ($limit) {
$query->limit($limit);
})->order('add_time desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,54 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\message;
use app\dao\BaseDao;
use app\model\message\SystemNotification;
/**
* 消息设置
* Class SystemNotificationDao
* @package app\dao\message
*/
class SystemNotificationDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemNotification::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, $limit = 0)
{
return $this->getModel()->where($where)->field($field)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id asc')->select()->toArray();
}
}

View File

@@ -0,0 +1,73 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message;
use app\dao\BaseDao;
use app\model\message\TemplateMessage;
/**
* 模板消息
* Class TemplateMessageDao
* @package app\dao\message
*/
class TemplateMessageDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return TemplateMessage::class;
}
/**
* 获取一条数据
* @param array $where
* @param string $filed
* @param bool $is_search
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTemplateOne(array $where, string $filed = '*', bool $is_search = true)
{
if ($is_search) {
return $this->search($where)->field($filed)->find();
} else {
return $this->getModel()->where($where)->find();
}
}
/**
* 获取模板消息列表
* @param array $where
* @param int $page
* @param int $limit
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTemplateList(array $where, int $page, int $limit)
{
return $this->getModel()->when(isset($where['name']) && $where['name'] != '', function ($query) use ($where) {
$query->where('name', 'LIKE', "%$where[name]%");
})->when(isset($where['status']) && $where['status'] != '', function ($query) use ($where) {
$query->where('status', $where['status']);
})->where('type', $where['type'])->page($page, $limit)->select()->toArray();
}
}

View File

@@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\other\queue\QueueAuxiliaryDao;
use crmeb\basic\BaseModel;
/**
* 客服辅助表
* Class StoreServiceAuxiliaryDao
* @package app\dao\message\service
*/
class StoreServiceAuxiliaryDao extends QueueAuxiliaryDao
{
/**
* 搜索
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = true)
{
return parent::search($where, $search)->where('type', 0);
}
}

View File

@@ -0,0 +1,96 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\BaseDao;
use app\model\message\service\StoreService;
/**
* 客服dao
* Class StoreServiceDao
* @package app\dao\message\service
*/
class StoreServiceDao extends BaseDao
{
/**
* 不存在的用户直接禁止掉
* @param array $uids
* @return bool
*/
public function deleteNonExistentService(array $uids = [])
{
if ($uids) {
return $this->getModel()->whereIn('uid', $uids)->update(['status' => 0]);
} else {
return true;
}
}
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreService::class;
}
/**
* 获取客服列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getServiceList(array $where, int $page, int $limit)
{
return $this->search($where)->with('user')->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(isset($where['noId']), function ($query) use ($where) {
$query->whereNotIn('uid', $where['noId']);
})->with(['workMember' => function ($query) {
$query->field(['uid', 'name', 'position', 'qr_code', 'external_position']);
}])->order('id DESC')->field('id,uid,avatar,nickname as wx_name,status,add_time,phone,account_status')->select()->toArray();
}
/**
* 获取接受通知的客服
* @param int $customer
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStoreServiceOrderNotice(int $customer = 0, string $field = 'nickname,phone,uid,customer')
{
return $this->getModel()->where(['account_status' => 1, 'status' => 1, 'notify' => 1])->when($customer, function ($query) use ($customer) {
$query->where('customer', $customer);
})->field($field)->select()->toArray();
}
/**
*
* @param array $where
* @param array $data
* @return \crmeb\basic\BaseModel
*/
public function updateOnline(array $where, array $data)
{
return $this->getModel()->whereNotIn('uid', $where['notUid'])->update($data);
}
}

View File

@@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\BaseDao;
use app\model\message\service\StoreServiceFeedback;
/**
* Class StoreServiceFeedbackDao
* @package app\dao\message\service
*/
class StoreServiceFeedbackDao extends BaseDao
{
protected function setModel(): string
{
return StoreServiceFeedback::class;
}
/**
* 获取用户反馈信息列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFeedback(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->order('id DESC')->select()->toArray();
}
}

View File

@@ -0,0 +1,142 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\BaseDao;
use app\model\message\service\StoreServiceLog;
/**
*
* Class StoreServiceLogDao
* @package app\dao\service
*/
class StoreServiceLogDao extends BaseDao
{
/**
* StoreServiceLogDao constructor.
*/
public function __construct()
{
//清楚去年的聊天记录
// $this->removeChat();
$this->removeYesterDayChat();
}
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreServiceLog::class;
}
/**
* 获取聊天记录下的uid和to_uid
* @param int $uid
* @return mixed
*/
public function getServiceUserUids(int $uid)
{
return $this->search(['uid' => $uid])->group('uid,to_uid')->field(['uid', 'to_uid'])->select()->toArray();
}
/**
* 获取聊天记录并分页
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getServiceList(array $where, int $page, int $limit, array $field = ['*'])
{
return $this->search($where)->with('user')->field($field)->order('add_time DESC')->page($page, $limit)->select()->toArray();
}
/**
* 获取聊天记录上翻页
* @param array $where
* @param int $limit
* @param int $upperId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getChatList(array $where, int $limit = 20, int $upperId = 0)
{
return $this->search($where)->when($upperId, function ($query) use ($upperId, $limit) {
$query->where('id', '<', $upperId)->limit($limit)->order('id DESC');
})->when(!$upperId, function ($query) use ($limit) {
$query->limit($limit)->order('id DESC');
})->with(['user', 'service'])->select()->toArray();
}
/**
* 清楚去年的聊天记录
* @return bool
*/
public function removeChat()
{
return $this->search(['time' => 'last year'])->delete();
}
/**
* 清楚上周的游客用户聊天记录
* @return bool
*/
public function removeYesterDayChat()
{
return $this->search(['time' => 'last week', 'is_tourist' => 1])->delete();
}
/**
* 根据条件获取条数
* @param array $where
* @return int
*/
public function whereByCount(array $where)
{
return $this->search(['uid' => $where['uid']])->order('id DESC')->where('add_time', '<', time() - 300)->count();
}
/**
* 获取未读消息条数
* @param array $where
* @return int
*/
public function getMessageNum(array $where)
{
return $this->getModel()->where($where)->count();
}
/**
* 搜索聊天记录
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getMessageList(array $where)
{
return $this->search(['chat' => $where['chat']])->when(isset($where['add_time']) && $where['add_time'], function ($query) use ($where) {
$query->where('add_time', '>', $where['add_time']);
})->select()->toArray();
}
}

View File

@@ -0,0 +1,92 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\BaseDao;
use app\model\message\service\StoreServiceRecord;
/**
* Class StoreServiceRecordDao
* @package app\dao\message\service
*/
class StoreServiceRecordDao extends BaseDao
{
/**
* StoreServiceRecordDao constructor.
*/
public function __construct()
{
$this->deleteWeekRecord();
}
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreServiceRecord::class;
}
/**
* 删除上周游客记录
*/
protected function deleteWeekRecord()
{
$this->search(['time' => 'last week', 'timeKey' => 'update_time', 'is_tourist' => 1])->delete();
}
/**
*
* @param array $where
* @param array $data
* @return \crmeb\basic\BaseModel
*/
public function updateOnline(array $where, array $data)
{
return $this->getModel()->whereNotIn('to_uid', $where['notUid'])->update($data);
}
/**
* 获取客服聊天用户列表
* @param array $where
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getServiceList(array $where, int $page, int $limit, array $with = [])
{
return $this->search($where)->page($page, $limit)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->order('update_time desc')->select()->toArray();
}
/**
* 查询最近和用户聊天的uid用户
* @param array $where
* @param string $key
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getLatelyMsgUid(array $where, string $key)
{
return $this->search($where)->order('update_time DESC')->value($key);
}
}

View File

@@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\service;
use app\dao\BaseDao;
use app\model\message\service\StoreServiceSpeechcraft;
/**
* 客服话术dao
* Class StoreServiceSpeechcraftDao
* @package app\dao\message\service
*/
class StoreServiceSpeechcraftDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreServiceSpeechcraft::class;
}
/**
* 获取话术列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSpeechcraftList(array $where, int $page, int $limit)
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort DESC')->select()->toArray();
}
}

View File

@@ -0,0 +1,33 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\sms;
use app\dao\BaseDao;
use app\model\system\config\SystemConfig;
/**
* 短信dao
* Class SmsAdminDao
* @package app\dao\message\sms
*/
class SmsAdminDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemConfig::class;
}
}

View File

@@ -0,0 +1,61 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\message\sms;
use app\dao\BaseDao;
use app\model\message\sms\SmsRecord;
/**
* 短信发送记录
* Class SmsRecordDao
* @package app\dao\message\sms
*/
class SmsRecordDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
public function setModel(): string
{
return SmsRecord::class;
}
/**
* 短信发送记录
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getRecordList(array $where, int $page, int $limit)
{
return $this->search($where)->page($page, $limit)->order('add_time DESC')->select()->toArray();
}
/**
* 获取10分钟前20条无状态的短信记录
* @return array
*/
public function getCodeNull()
{
return $this->getModel()->where([
['resultcode', '=', null],
['add_time', '<=', time() - 600],
['record_id', '>', 0]
])->limit(20)->column('record_id');
}
}

View File

@@ -0,0 +1,211 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\OtherOrder;
use crmeb\basic\BaseModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;
class OtherOrderDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return OtherOrder::class;
}
/**
* 重写搜索器
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['name']) && $where['name'], function ($query) use ($where) {
$query->where('uid', 'in', function ($que) use ($where) {
$que->name('user')->where('nickname|real_name|phone', 'like', '%' . trim($where['name']) . '%')->field(['uid'])->select();
});
});
}
/**
* 获取某个时间点一共有多少用户是付费会员状态
* @param int $time
* @param string $channel_type
* @return array
*/
public function getPayUserCount(int $time, string $channel_type = ''): array
{
return $this->getModel()->when($channel_type != '', function ($query) use ($channel_type) {
$query->where('channel_type', $channel_type);
})->field('distinct(uid),add_time')
->group('uid')->having('add_time < ' . $time)
->order('add_time desc')
->select()->toArray();
}
/**
* 获取VIP曲线
* @param $time
* @param $type
* @param $timeType
* @param string $str
* @return array
*/
public function getTrendData($time, $type, $timeType, string $str = 'count(uid)'): array
{
return $this->getModel()->where("member_type", "<>", 0)->when($type != '', function ($query) use ($type) {
$query->where('channel_type', $type);
})->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime('add_time', 'between', $time);
}
})->field("FROM_UNIXTIME(add_time,'$timeType') as days," . $str . " as num")
->group('days')->select()->toArray();
}
/**
* 合计某字段值
* @param array $where
* @param string $sumField
* @return float
*/
public function getWhereSumField(array $where, string $sumField): float
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where) {
$query->whereBetweenTime('pay_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
})
->sum($sumField);
}
/**
* 根据某字段分组查询
* @param array $where
* @param string $field
* @param string $group
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getGroupField(array $where, string $field, string $group): array
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where, $field, $group) {
$query->whereBetweenTime('pay_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
if ($where['timeKey']['days'] == 1) {
$timeUinx = "%H";
} elseif ($where['timeKey']['days'] == 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] == 365) {
$timeUinx = "%Y-%m";
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
$timeUinx = "%Y-%m";
} else {
$timeUinx = "%Y-%m";
}
$query->field("sum($field) as number,FROM_UNIXTIME($group, '$timeUinx') as time");
$query->group("FROM_UNIXTIME($group, '$timeUinx')");
})
->order('add_time ASC')->select()->toArray();
}
/**
* 根据条件获取单条信息
* @param array $where
* @return Model
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getOneByWhere(array $where)
{
return $this->getModel()->where($where)->find();
}
/**
* 收银订单
* @param array $where
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getScanOrderList(array $where = [], int $page = 0, int $limit = 0, string $order = ''): array
{
foreach ($where as $k => $v) {
if ($v == "") unset($where[$k]);
}
return $this->search($where)
->order(($order ? $order . ' ,' : '') . 'id desc')
->page($page, $limit)->select()->toArray();
}
/**
* 获取会员记录
* @param array $where
* @param string $field
* @param array|string[] $with
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getMemberRecord(array $where = [], string $field = '*', array $with = ['user'], int $page = 0, int $limit = 0, string $order = ''): array
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->order(($order ? $order . ' ,' : '') . 'id desc')
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 店员统计
* @param array $where
* @param string $countField
* @param string $sumField
* @param string $groupField
* @return array
*/
public function preStaffTotal(array $where, string $countField = 'uid', string $sumField = 'pay_price', string $groupField = 'staff_id'): array
{
return $this->search($where)
->field($groupField . ",count(" . $countField . ") as count,sum(`" . $sumField . "`) as price")
->group($groupField)
->select()->toArray();
}
}

View File

@@ -0,0 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\OtherOrderStatus;
/**订单状态
* Class OtherOrderStatusDao
* @package app\dao\order
*/
class OtherOrderStatusDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return OtherOrderStatus::class;
}
/**
* 获取订单状态列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStatusList(array $where, int $page, int $limit)
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
}

View File

@@ -0,0 +1,180 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreCart;
use crmeb\basic\BaseModel;
/**
*
* Class StoreCartDao
* @package app\dao\order
*/
class StoreCartDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreCart::class;
}
/**
* 搜索
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['id']) && $where['id'], function ($query) use ($where) {
$query->whereIn('id', $where['id']);
})->when(isset($where['status']), function ($query) use ($where) {
$query->where('status', $where['status']);
});
}
/**
* @param array $where
* @param array $unique
* @return array
*/
public function getUserCartNums(array $where, array $unique)
{
return $this->search($where)->whereIn('product_attr_unique', $unique)->column('cart_num', 'product_attr_unique');
}
/**
* 根据商品id获取购物车数量
* @param array $ids
* @param int $uid
* @return mixed
*/
public function productIdByCartNum(array $ids, int $uid)
{
return $this->search([
'product_id' => $ids,
'is_pay' => 0,
'is_del' => 0,
'is_new' => 0,
'uid' => $uid,
])->group('product_attr_unique')->column('id,cart_num,product_id', 'product_attr_unique');
}
/**
* 获取购物车列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCartList(array $where, int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when(count($with), function ($query) use ($with, $where) {
$query->with($with);
})->when(isset($where['is_cashier']), function ($query) use ($where) {
$query->where('is_cashier', $where['is_cashier']);
})->order('add_time DESC')->select()->toArray();
}
/**
* 修改购物车数据未已删除
* @param array $id
* @param array $data
* @return BaseModel
*/
public function updateDel(array $id)
{
return $this->getModel()->whereIn('id', $id)->update(['is_del' => 1]);
}
/**
* 删除购物车
* @param int $uid
* @param array $ids
* @return bool
*/
public function removeUserCart(int $uid, array $ids)
{
return $this->getModel()->where('uid', $uid)->whereIn('id', $ids)->delete();
}
/**
* 用户购物车统计数据
* @param int $uid
* @param string $field
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getUserCartList(array $where, string $field = '*', array $with = [])
{
return $this->getModel()->where(array_merge($where, ['is_pay' => 0, 'is_new' => 0, 'is_del' => 0]))
->when(count($with), function ($query) use ($with) {
$query->with($with);
})->order('add_time DESC')->field($field)->select()->toArray();
}
/**
* 修改购物车数量
* @param $cartId
* @param $cartNum
* @param $uid
*/
public function changeUserCartNum(array $where, int $carNum)
{
return $this->getModel()->update(['cart_num' => $carNum], $where);
}
/**
* 修改购物车状态
* @param $cartIds
* @return bool
*/
public function deleteCartStatus($cartIds)
{
return $this->getModel()->where('id', 'IN', $cartIds)->delete();
}
/**
* 购物车趋势
* @param $time
* @param $timeType
* @param $str
* @return mixed
*/
public function getProductTrend($time, $timeType, $str)
{
return $this->getModel()->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime('add_time', 'between', $time);
}
})->field("FROM_UNIXTIME(add_time,'$timeType') as days,$str as num")->group('days')->select()->toArray();
}
}

View File

@@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreDeliveryOrder;
/**
* 发货订单
* Class StoreDeliveryOrderDao
* @package app\dao\order
*/
class StoreDeliveryOrderDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return StoreDeliveryOrder::class;
}
/**
* 获取列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [])
{
return $this->search($where)->field($field)->when($with, function($query) use ($with) {
$query->with($with);
})->when($page && $limit, function($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,66 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreHangOrder;
/**
* Class StoreHangOrderDao
* @package app\dao\order
*/
class StoreHangOrderDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return StoreHangOrder::class;
}
/**
* @param array $where
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getHang(array $where, int $limit = 50)
{
return $this->search($where)->with('user')->limit($limit)->order('add_time desc')->select()->toArray();
}
/**
* 获取挂单分页
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getHangPage(array $where, int $page, int $limit)
{
return $this->search($where)->when(isset($where['search']) && $where['search'] !== '', function ($query) use ($where) {
$query->whereIn('uid', function ($query) use ($where) {
$query->name('user')->whereIn('uid', function ($query) use ($where) {
$query->name('store_user')->where('store_id', $where['store_id'])->field('uid');
})->where('phone|nickname', 'like', "%" . $where['search'] . "%")->field('uid');
});
})->with('user')->page($page, $limit)->order('add_time desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrderCartInfo;
/**
* 订单详情
* Class StoreOrderCartInfoDao
* @package app\dao\order
* @method saveAll(array $data)
*/
class StoreOrderCartInfoDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreOrderCartInfo::class;
}
/**
* 获取购物车详情列表
* @param array $where
* @param array $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCartInfoList(array $where, array $field = ['*'])
{
return $this->search($where)->field($field)->select()->toArray();
}
/**
* 获取购物车信息以数组返回
* @param array $where
* @param string $field
* @param string $key
*/
public function getCartColunm(array $where, string $field, string $key = '')
{
return $this->search($where)->order('id asc')->column($field, $key);
}
/**
* @param $cart_ids
* @return array
*/
public function getSplitCartNum($cart_ids)
{
$res = $this->getModel()->whereIn('old_cart_id', $cart_ids)->field('sum(cart_num) as num,old_cart_id')->group('old_cart_id')->select()->toArray();
$data = [];
foreach ($res as $value) {
$data[$value['old_cart_id']] = $value['num'];
}
return $data;
}
/**
* 临期 卡次
* @param int $writeEndTime
* @param int $writeTime
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAdventCartInfoList(int $time = 0, int $writeTime = 0)
{
$list = $this->getModel()->where(['is_writeoff' => 0, 'is_advent_sms' => 0])->where('write_start', '>', 0)->where('write_end', '>', 0)
->where('write_end', '>', $time)->where('write_end', '<=', $writeTime)
->field('id,oid,product_id,write_times,write_surplus_times,write_start,write_end,cart_info')->select();
$list = count($list) > 0 ? $list->toArray() : [];
return $list;
}
/**
* 过期 卡次
* @param int $writeTime
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getExpireCartInfoList(int $writeTime = 0)
{
$list = $this->getModel()->where(['is_writeoff' => 0, 'is_expire_sms' => 0])->where('write_start', '>', 0)->where('write_end', '>', 0)
->where('write_end', '<', $writeTime)
->field('id,oid,product_id,write_times,write_surplus_times,write_start,write_end,cart_info')->select();
$list = count($list) > 0 ? $list->toArray() : [];
return $list;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrderEconomize;
/**
* Class StoreOrderEconomizeDao
* @package app\dao\order
*/
class StoreOrderEconomizeDao extends BaseDao
{
protected function setModel(): string
{
return StoreOrderEconomize::class;
}
/**
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where)
{
return $this->getModel()->where($where)->select()->toArray();
}
}

View File

@@ -0,0 +1,107 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrderInvoice;
use crmeb\basic\BaseModel;
/**
* Class StoreOrderInvoiceDao
* @package app\dao\order
*/
class StoreOrderInvoiceDao extends BaseDao
{
/**
* 限制精确查询字段
* @var string[]
*/
protected array $withField = ['uid', 'order_id', 'real_name', 'user_phone'];
protected function setModel(): string
{
return StoreOrderInvoice::class;
}
/**
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
* @author 等风来
* @email 136327134@qq.com
* @date 2023/10/7
*/
public function search(array $where = [], bool $search = false)
{
$realName = $where['real_name'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
$type = $where['type'] ?? '';
unset($where['type']);
return parent::search($where, $search)->when($type, function ($query) use ($type) {
switch ($type) {
case 1://待开
$query->where('is_invoice', 0)->where('invoice_time', 0)->where('is_refund', 0);
break;
case 2://已开
$query->where('is_invoice', 1)->where('is_refund', 0);
break;
case 3://退款
$query->where('is_refund', 1);
break;
case 4://未开
$query->where('is_invoice', 0)->where('invoice_time', 0)->where('is_refund', 0);
break;
}
})->when($realName && $fieldKey && in_array($fieldKey, $this->withField), function ($query) use ($realName, $fieldKey) {
$query->where('order_id', 'IN', function ($que) use ($fieldKey, $realName) {
$que->name('store_order')->where(trim($fieldKey), trim($realName))->field(['id'])->select();
});
})->when($realName && !$fieldKey, function ($query) use ($where) {
$query->where(function ($que) use ($where) {
$que->whereLike('order_id|invoice_id|name|drawer_phone|email|tell|address|bank', "%{$where['real_name']}%")
->whereOr('order_id', 'IN', function ($order) use ($where) {
$order->name('store_order')->where('uid|real_name|order_id', 'LIKE', "%{$where['real_name']}%")->field('id')->select();
})
->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid|phone', '%' . $where['real_name'] . '%')->field(['uid'])->select();
});
});
});
}
/**
* @param array $where
* @param string $field
* @param array|string[] $with
* @param string $order
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', array $with = ['order'], string $order = '', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->when($order != '', function ($query) use ($order) {
$query->order($order);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
}

View File

@@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrderPromotions;
/**
* 订单详情
* Class StoreOrderPtomotionsDao
* @package app\dao\order
* @method saveAll(array $data)
*/
class StoreOrderPromotionsDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreOrderPromotions::class;
}
/**
* 获取购物车详情列表
* @param array $where
* @param string $field
* @param array $with
* @param string $group
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getPromotionsDetailList(array $where, string $field = '*', array $with = [], string $group = '')
{
return $this->search($where)->field($field)->when($with, function($query) use($with) {
$query->with($with);
})->when($group, function($query) use($group) {
$query->group($group);
})->select()->toArray();
}
}

View File

@@ -0,0 +1,224 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrderRefund;
use crmeb\basic\BaseModel;
use think\Model;
/**
* 退款订单
* Class StoreOrderInvoiceDao
* @package app\dao\order
*/
class StoreOrderRefundDao extends BaseDao
{
protected function setModel(): string
{
return StoreOrderRefund::class;
}
/**
* 搜索器
* @param array $where
* @param bool $search
* @return BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
$realName = $where['real_name'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
return parent::search($where, $search)
// ->when(isset($where['refund_type']) && $where['refund_type'] !== '', function ($query) use ($where) {
// if ($where['refund_type'] == 0) {
// $query->where('refund_type', '>', 0);
// } else {
// if (is_array($where['refund_type'])) {
// $query->whereIn('refund_type', $where['refund_type']);
// } else {
// $query->where('refund_type', $where['refund_type']);
// }
// }
// })
->when(isset($where['refund_type']) && $where['refund_type'] !== '', function ($query) use ($where) {
if (is_array($where['refund_type'])) {
$query->whereIn('refund_type', $where['refund_type']);
} else {
$query->where('refund_type', $where['refund_type']);
}
})->when(isset($where['apply_type']) && $where['apply_type'] !== '', function ($query) use ($where) {
$query->where('apply_type', $where['apply_type']);
})->when(isset($where['order_id']) && $where['order_id'] != '', function ($query) use ($where) {
$query->where(function ($q) use ($where) {
$q->whereLike('order_id|refund_express', '%' . $where['order_id'] . '%')->whereOr(function ($q) use ($where) {
$q->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid|phone', '%' . $where['order_id'] . '%')->field(['uid'])->select();
})->whereOr('store_order_id', 'in', function ($que) use ($where) {
$que->name('store_order_cart_info')->whereIn('product_id', function ($q) use ($where) {
$q->name('store_product')->whereLike('store_name|keyword', '%' . $where['order_id'] . '%')->field(['id'])->select();
})->field(['oid'])->select();
})->whereOr('store_order_id', 'in', function ($orderModel) use ($where) {
$orderModel->name('store_order')->field('id')->whereLike('order_id|uid|user_phone', '%' . $where['order_id'] . '%');
});
});
});
})->when($realName && !$fieldKey, function ($query) use ($where) {
$query->where(function ($que) use ($where) {
$que->whereLike('order_id|refund_express', '%' . $where['real_name'] . '%')->whereOr(function ($q) use ($where) {
$q->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid|phone', '%' . $where['real_name'] . '%')->field(['uid'])->select();
})->whereOr('store_order_id', 'in', function ($que) use ($where) {
$que->name('store_order_cart_info')->whereIn('product_id', function ($q) use ($where) {
$q->name('store_product')->whereLike('store_name|keyword', '%' . $where['real_name'] . '%')->field(['id'])->select();
})->field(['oid'])->select();
})->whereOr('store_order_id', 'in', function ($orderModel) use ($where) {
$orderModel->name('store_order')->field('id')->whereLike('order_id', '%' . $where['real_name'] . '%');
});
});
});
})->when(isset($where['refundTypes']) && $where['refundTypes'] !== '', function ($query) use ($where) {
switch ((int)$where['refundTypes']) {
case 0://未处理
$query->where('refund_type', 1);
break;
case 1://申请中
$query->whereIn('refund_type', [1, 2]);
break;
case 2://待退货
$query->whereIn('refund_type', [4, 5]);
break;
case 3://退款中
$query->where('refund_type', 5);
break;
case 4://已退款
$query->where('refund_type', 6);
break;
case 5://处理中
$query->whereIn('refund_type', [0, 1, 2, 4, 5]);
break;
case 6://已完成
$query->whereIn('refund_type', [3, 6]);
break;
}
})->when(isset($where['supplier']) && $where['supplier'] !== '', function ($query) use ($where) {
$query->where('supplier_id', '>', 0);
})->when(isset($where['refund_reason']) && $where['refund_reason'] != '', function ($query) use ($where) {
$query->whereLike('refund_reason', '%' .$where['refund_reason']. '%');
});
}
/**
* 查询退款订单
* @param $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getRefundList($where, string $file = '*', array $with = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($file)->with(array_merge(['user'], $with))
->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time desc')->select()->toArray();
}
/**
* 获取退款金额按照时间分组
* @param array $time
* @param string $timeType
* @param string $field
* @param string $str
* @return mixed
*/
public function getUserRefundPriceList(array $time, string $timeType, string $str, string $field = 'add_time')
{
return $this->getModel()->where('is_cancel', 0)->where(function ($query) use ($time, $field) {
if ($time[0] == $time[1]) {
$query->whereDay($field, $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime($field, 'between', $time);
}
})->field("FROM_UNIXTIME($field,'$timeType') as days,$str as num,GROUP_CONCAT(store_order_id) as link_ids")->group('days')->select()->toArray();
}
/**
* 根据时间获取
* @param array $where
* @return float|int
*/
public function getOrderRefundMoneyByWhere(array $where, string $sum_field, string $selectType, string $group = "")
{
switch ($selectType) {
case "sum" :
return $this->getDayTotalMoney($where, $sum_field);
case "group" :
return $this->getDayGroupMoney($where, $sum_field, $group);
}
}
/**
* 按照支付时间统计支付金额
* @param array $where
* @param string $sumField
* @return mixed
*/
public function getDayTotalMoney(array $where, string $sumField)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where) {
$query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
})
->sum($sumField);
}
/**
* 时间分组订单付款金额统计
* @param array $where
* @param string $sumField
* @return mixed
*/
public function getDayGroupMoney(array $where, string $sumField, string $group)
{
return $this->search($where)
->when(isset($where['timeKey']), function ($query) use ($where, $sumField, $group) {
$query->whereBetweenTime('add_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
if ($where['timeKey']['days'] == 1) {
$timeUinx = "%H";
} elseif ($where['timeKey']['days'] == 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] == 365) {
$timeUinx = "%Y-%m";
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
$timeUinx = "%Y-%m-%d";
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
$timeUinx = "%Y-%m";
} else {
$timeUinx = "%Y-%m";
}
$query->field("sum($sumField) as number,FROM_UNIXTIME($group, '$timeUinx') as time");
$query->group("FROM_UNIXTIME($group, '$timeUinx')");
})
->order('add_time ASC')->select()->toArray();
}
}

View File

@@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrderStatus;
/**
* 订单状态
* Class StoreOrderStatusDao
* @package app\dao\order
*/
class StoreOrderStatusDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreOrderStatus::class;
}
/**
* 获取订单状态列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getStatusList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('change_time desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,70 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrder;
use app\model\order\StoreOrderCartInfo;
/**
*
* Class StoreOrderStoreOrderCartInfoDao
* @package app\dao\order
*/
class StoreOrderStoreOrderCartInfoDao extends BaseDao
{
protected string $alias = 'a';
protected string $joinAlis = 'c';
/**
* 设置主表模型
* @return string
*/
protected function setModel(): string
{
return StoreOrder::class;
}
/**
* 设置链表模型
* @return string
*/
protected function setJoinModel(): string
{
return StoreOrderCartInfo::class;
}
/**
* 设置模型
* @return \crmeb\basic\BaseModel
*/
public function getModel()
{
$name = app()->make($this->setJoinModel())->getName();
return parent::getModel()->alias($this->alias)->join($name . ' ' . $this->joinAlis, $this->alias . '.id =' . $this->joinAlis . '.oid');
}
/**
* 获取用户购买过的商品id
* @param array $where
* @return array
*/
public function getUserCartProductIds(array $where)
{
return $this->getModel()->when(isset($where['uid']), function ($query) use ($where) {
$query->where($this->alias . '.uid', $where['uid']);
})->column($this->joinAlis . '.product_id');
}
}

View File

@@ -0,0 +1,107 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrder;
use app\model\order\StoreOrderStatus;
use crmeb\basic\BaseModel;
/**
* Class StoreOrderStoreOrderStatusDao
* @package app\dao\order
*/
class StoreOrderStoreOrderStatusDao extends BaseDao
{
protected string $alias = 'o';
protected string $joinAlis = 's';
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreOrder::class;
}
/**
* 设置链表模型
* @return string
*/
protected function setJoinModel(): string
{
return StoreOrderStatus::class;
}
/**
* 设置模型
* @return BaseModel
*/
protected function getModel()
{
$name = app()->make($this->setJoinModel())->getName();
return parent::getModel()->join($name . ' ' . $this->joinAlis, $this->joinAlis . '.oid = ' . $this->alias . '.id')->alias($this->alias);
}
/**
* 搜索
* @param array $where
* @return BaseModel
*/
public function search(array $where = [], bool $search = false)
{
return $this->getModel()->when(isset($where['paid']), function ($query) use ($where) {
$query->where($this->alias . '.paid', $where['paid']);
})->when(isset($where['status']), function ($query) use ($where) {
$query->where($this->alias . '.status', $where['status']);
})->when(isset($where['refund_status']), function ($query) use ($where) {
$query->where($this->alias . '.refund_status', $where['refund_status']);
})->when(isset($where['is_del']), function ($query) use ($where) {
$query->where($this->alias . '.is_del', $where['is_del']);
})->when(isset($where['change_type']), function ($query) use ($where) {
$query->whereIn($this->joinAlis . '.change_type', $where['change_type']);
})->when(isset($where['change_time']), function ($query) use ($where) {
$query->where($this->joinAlis . '.change_time', '<', $where['change_time']);
});
}
/**
* 根据条件获取订单
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOrderIds(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->whereIn('refund_type', [0, 3])->where('pid', '<>', -1)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->field([$this->alias . '.*'])->group($this->alias . '.id')->select()->toArray();
}
/**
* 根据条件获取订单数量
* @param array $where
* @return int
*/
public function getOrderCount(array $where)
{
return $this->search($where)->whereIn('refund_type', [0, 3])->where('pid', '<>', -1)->field([$this->alias . '.*'])->count();
}
}

View File

@@ -0,0 +1,79 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\order;
use app\dao\BaseDao;
use app\model\order\StoreOrderWriteoff;
/**
* 订单核销
* Class StoreOrderWriteoffDao
* @package app\dao\order
* @method saveAll(array $data)
*/
class StoreOrderWriteoffDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreOrderWriteoff::class;
}
/**搜索器
* @param array $where
* @param bool $search
* @return \crmeb\basic\BaseModel
* @throws \ReflectionException
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where)
->when(isset($where['keyword']) && $where['keyword'] , function($query) use ($where) {
$query->where(function ($q) use ($where) {
$q->whereLike('uid|oid|relation_id|staff_id|product_id', '%' . $where['keyword'] . '%')
->whereOr('uid', 'IN', function ($user) use ($where) {
$user->name('user')->field('id')->whereLike('uid|phone|nickname', '%' . $where['keyword'] . '%');
})->whereOr('product_id', 'IN', function ($product) use ($where) {
$product->name('store_product')->field('id')->whereLike('store_name|keyword', '%' . $where['keyword'] . '%');
})->whereOr('oid', 'IN', function ($order) use ($where) {
$order->name('store_order')->field('id')->whereLike('order_id|uid|user_phone|staff_id', '%' . $where['keyword'] . '%');
});
});
});
}
/**
* 获取核销列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [], $order = 'id desc')
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order($order)->select()->toArray();
}
}

View File

@@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\model\other\Agreement;
/**
* Class AgreementDao
* @package app\dao\other
*/
class AgreementDao extends BaseDao
{
/**
* @return string
*/
public function setModel(): string
{
return Agreement::class;
}
}

View File

@@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\model\other\Cache;
/**
* Class CacheDao
* @package app\dao\other
*/
class CacheDao extends BaseDao
{
/**
* @return string
*/
public function setModel(): string
{
return Cache::class;
}
/**
* 清除过期缓存
* @throws \Exception
*/
public function delectDeOverdueDbCache()
{
$this->getModel()->where('expire_time', '<>', 0)->where('expire_time', '<', time())->delete();
}
}

View File

@@ -0,0 +1,100 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\model\other\Category;
/**
* 分类
* Class CategoryDao
* @package app\dao\other
*/
class CategoryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Category::class;
}
/**
* @param array $where
* @param bool $search
* @return \crmeb\basic\BaseModel
* @throws \ReflectionException
* @author 等风来
* @email 136327134@qq.com
* @date 2023/10/7
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->when(isset($where['name']) && $where['name'], function ($query) use ($where) {
$query->where(function ($q) use ($where) {
$q->whereOr('id|name', 'like', '%' . $where['name'] . '%')
->when(!empty($where['product_label']), function ($query) use ($where) {
$query->whereOr('id', 'IN', function ($l) use ($where) {
$l->name('store_product_label')->whereLike('id|label_name', '%' . $where['name'] . '%')->field('label_cate');
});
});
});
})->when(!empty($where['nowName']), function ($query) use ($where) {
$query->where('name', $where['nowName']);
});
}
/**
* 获取分类
* @param array $where
* @param int $page
* @param int $limit
* @param array|string[] $field
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCateList(array $where, int $page = 0, int $limit = 0, array $field = ['*'], array $with = [])
{
$other = false;
if (isset($where['other'])) {
$other = true;
unset($where['other']);
}
return $this->search($where)->field($field)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->when($other, function ($query) {
$query->where('other', '<>', '');
})->order('sort DESC,id DESC')->select()->toArray();
}
/**
* 获取全部标签分类
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAll(array $where = [], array $with = [])
{
return $this->search($where)->when(count($with), function ($query) use ($with) {
$query->with($with);
})->order('sort DESC,id DESC')->select()->toArray();
}
}

View File

@@ -0,0 +1,119 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\model\other\CityArea;
/**
* Class CityAreaDao
* @package app\dao\other
*/
class CityAreaDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return CityArea::class;
}
/**
* @param array $where
* @param bool $search
* @return \crmeb\basic\BaseModel
* @throws \ReflectionException
* @author 等风来
* @email 136327134@qq.com
* @date 2023/10/7
*/
public function search(array $where = [], bool $search = false)
{
return parent::search($where, $search)->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'], '/'));
if (isset($address[0]) && isset($address[1]) && $address[0] == $address[1]) {//直辖市:北京市北京市朝阳区
array_shift($address);
}
$p = array_shift($address);
// 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);
// $p = str_replace(['壮族', '回族', '维吾尔'], '', $p);
// }
$pcity = $this->getModel()->where('name', $p)->value('id');
$path = ['', $pcity];
$street = $p;
$i = 0;
foreach ($address as $item) {
//县级市,只有三级地址;市和县相同
if ($item == ($address[$i - 1] ?? '')) continue;
$pcity = $this->getModel()->whereLike('path', implode('/', $path) . '/%')->where('name', $item)->value('id');
if (!$pcity) {
break;
}
$path[] = $pcity;
$street = $item;
$i++;
}
array_pop($path);
$query->whereLike('path', implode('/', $path) . '/%')->where('name', $street);
});
}
/**
* 搜索某个地址
* @param array $where
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function searchCity(array $where)
{
return $this->search($where)->order('id DESC')->find();
}
/**
* 获取地址
* @param array $where
* @param string $field
* @param array $with
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCityList(array $where, string $field = '*', array $with = [])
{
return $this->getModel()->where($where)->field($field)->with($with)->order('id asc')->select()->toArray();
}
/**
* 删除上级城市和当前城市id
* @param int $cityId
* @return bool
* @throws \Exception
*/
public function deleteCity(int $cityId)
{
return $this->getModel()->where('id', $cityId)->whereOr('parent_id', $cityId)->delete();
}
}

View File

@@ -0,0 +1,76 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\model\other\Express;
/**
* 物流信息
* Class ExpressDao
* @package app\dao\other
*/
class ExpressDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Express::class;
}
/**
* 获取物流列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getExpressList(array $where, string $field, int $page, int $limit)
{
return $this->search($where)->field($field)->order('sort DESC,id asc')
->when($page > 0 && $limit > 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
/**
* 指定的条件获取物流信息以数组返回
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getExpress(array $where, string $field, string $key)
{
return $this->search($where)->order('id DESC')->column($field, $key);
}
/**
* 通过code获取一条信息
* @param string $code
* @param string $field
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getExpressByCode(string $code, string $field = '*')
{
return $this->getModel()->field($field)->where('code', $code)->find();
}
}

View File

@@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other\Import;
use app\dao\BaseDao;
use app\model\other\import\ImportRecord;
/**
* 导入数据
* Class ImportRecordDao
* @package app\dao\other
*/
class ImportRecordDao extends BaseDao
{
/**
* @return string
*/
public function setModel(): string
{
return ImportRecord::class;
}
}

View File

@@ -0,0 +1,34 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other\Import;
use app\dao\BaseDao;
use app\model\other\import\ImportRecordError;
/**
* 导入数据错误
* Class ImportRecordDao
* @package app\dao\other
*/
class ImportRecordErrorDao extends BaseDao
{
/**
* @return string
*/
public function setModel(): string
{
return ImportRecordError::class;
}
}

View File

@@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\other;
use app\dao\BaseDao;
use app\model\other\Qrcode;
/**
*
* Class QrcodeDao
* @package app\dao\other
*/
class QrcodeDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return Qrcode::class;
}
/**
* 获取一条二维码
* @param $id
* @param string $type
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getQrcode($id, $type = 'id')
{
return $this->getModel()->where($type, $id)->find();
}
/**
* 修改二维码使用状态
* @param $id
* @param string $type
* @return mixed
*/
public function scanQrcode($id, $type = 'id')
{
return $this->getModel()->where($type, $id)->inc('scan')->update();
}
}

View File

@@ -0,0 +1,90 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other;
use app\dao\BaseDao;
use app\model\other\SystemCity;
/**
* 城市数据
* Class SystemCityDao
* @package app\dao\other
*/
class SystemCityDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return SystemCity::class;
}
/**
* 获取城市数据列表
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCityList(array $where, string $field = '*')
{
return $this->search($where)->field($field)->select()->toArray();
}
/**
* 获取城市数据以数组形式返回
* @param array $where
* @param string $field
* @param string $key
* @return array
*/
public function getCityArray(array $where, string $field, string $key)
{
return $this->search($where)->column($field, $key);
}
/**
* 删除上级城市和当前城市id
* @param int $cityId
* @return bool
* @throws \Exception
*/
public function deleteCity(int $cityId)
{
return $this->getModel()->where('city_id', $cityId)->whereOr('parent_id', $cityId)->delete();
}
/**
* 获取city_id的最大值
* @return mixed
*/
public function getCityIdMax()
{
return $this->getModel()->max('city_id');
}
/**
* 获取运费模板城市选择
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getShippingCity()
{
return $this->getModel()->with('children')->where('parent_id', 0)->order('id asc')->select()->toArray();
}
}

View File

@@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other\queue;
use app\dao\BaseDao;
use app\model\other\queue\QueueAuxiliary;
/**
* 队列辅助
* Class QueueAuxiliaryDao
* @package app\dao\other\queue
*/
class QueueAuxiliaryDao extends BaseDao
{
/**
* @return string
*/
protected function setModel(): string
{
return QueueAuxiliary::class;
}
/**
* 添加订单缓存记录
* @param array $data
* @return int|string
*/
public function saveOrderCacheLog(array $data)
{
return $this->getModel()->insertGetId($data);
}
/**
* 获取发货缓存数据列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOrderExpreList(array $where, int $page = 0, int $limit = 0)
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('add_time asc')->select()->toArray();
}
/**
* 查询单条订单缓存数据
* @param array $where
* @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getOrderCacheOne(array $where)
{
return $this->search($where)->find();
}
/**
* 获取发货记录
* @param array $where
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function deliveryLogList(array $where, int $page = 0, int $limit = 0, string $order = '')
{
foreach ($where as $k => $v) {
if ($v == "") unset($where[$k]);
}
return $this->search($where)
->order(($order ? $order . ' ,' : '') . 'add_time desc')
->page($page, $limit)->select()->toArray();
}
/**
* 获取某个队列的数据缓存
* @param $bindingId
* @param $type
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCacheOidList($bindingId, $type)
{
return $this->search(['binding_id' => $bindingId, 'type' => $type])->select()->toArray();
}
}

View File

@@ -0,0 +1,128 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\other\queue;
use app\dao\BaseDao;
use app\model\other\queue\Queue;
/**
* 队列
* Class QueueDao
* @package app\dao\other
*/
class QueueDao extends BaseDao
{
/**
* @return string
*/
public function setModel(): string
{
return Queue::class;
}
/**
* 队列任务列表
* @param array $where
* @param int $page
* @param int $limit
* @param string $order
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, int $page = 0, int $limit = 0, string $order = '')
{
foreach ($where as $k => $v) {
if ($v == "") unset($where[$k]);
}
return $this->search($where)
->order(($order ? $order . ' ,' : '') . 'add_time desc')
->page($page, $limit)->select()->toArray();
}
/**
* 获取单个队列详情
* @param array $where
* @return array|bool|\think\Model|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getQueueOne(array $where)
{
if (!$where) return false;
return $this->search($where)->order('id desc')->find();
}
/**
* 加入队列数据表
* @param string $queueName
* @param int $queueDataNum
* @param int $type
* @param string $redisKey
* @param string $source
* @return mixed
*/
public function addQueueList(string $queueName, int $queueDataNum, int $type, string $redisKey, string $source = "admin")
{
$data = [
'type' => $type,
'source' => $source,
'execute_key' => $redisKey ? $redisKey : '',
'title' => $queueName,
'status' => 0,
'surplus_num' => $queueDataNum,
'total_num' => $queueDataNum,
'add_time' => time(),
];
return $this->getModel()->insertGetId($data);
}
/**
* 将队列置为正在执行状态
* @param $queueInValue
* @param $queueId
* @return bool|mixed
*/
public function setQueueDoing($queueInValue, $queueId, bool $is_again = false)
{
$saveData['queue_in_value'] = is_array($queueInValue) ? json_encode($queueInValue) : $queueInValue;
$saveData['status'] = 1;
if ($is_again) {
$saveData['again_time'] = time();
} else {
$saveData['first_time'] = time();
}
return $this->getModel()->update($saveData, ['id' => $queueId]);
}
/**
* 停止队列
* @param $queueId
* @return \crmeb\basic\BaseModel
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function stopWrongQueue($queueId)
{
$queueInfo = $this->getModel()->where(['id' => $queueId])->find();
if (!$queueInfo) return false;
return $this->getModel()->update(['id' => $queueId], ['status' => 3]);
}
}

View File

@@ -0,0 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\out;
use app\dao\BaseDao;
use app\model\out\OutAccount;
/**
* 对外接口dao
* Class StoreServiceDao
* @package app\dao\service
*/
class OutAccountDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return OutAccount::class;
}
/**
* 列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where = [], int $page = 0, int $limit = 0)
{
return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->select()->toArray();
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace app\dao\out;
use app\dao\BaseDao;
use app\model\out\OutInterface;
class OutInterfaceDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return OutInterface::class;
}
/**
* 获取接口列表
* @param array $where 查询条件
* @param string|array $field 查询字段
* @return array
*/
public function getInterfaceList($where, $field)
{
return $this->getModel()->where($where)->field($field)->select()->toArray();
}
}

View File

@@ -0,0 +1,101 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\brand;
use app\dao\BaseDao;
use app\model\product\brand\StoreBrand;
/**
* Class StoreBrandDao
* @package app\dao\product\brand
*/
class StoreBrandDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreBrand::class;
}
/**
* 获取品牌列表
* @param array $where
* @param array $with
* @param array $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, array $with = [], array $field = ['*'], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when(in_array('product', $with), function ($query) use ($with) {
$with = array_merge(array_diff($with, ['product']), ['product' => function ($que) {
$que->field(['pid', 'brand_id', "count(`brand_id`) as brand_num"])->where('pid', 0)->where('is_del', 0)->group('brand_id');
}]);
$query->with($with);
})->when($page && $limit, function ($query) use($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* 获取品牌列表
* @param array $where
* @param array $with
* @param array $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function searchList(array $where, array $with = [], array $field = ['*'], int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when(in_array('product', $with), function ($query) use ($with) {
$with = array_merge(array_diff($with, ['product']), ['product' => function ($que) {
$que->field(['pid', 'brand_id', "count(`brand_id`) as brand_num"])->where('pid', 0)->where('is_del', 0)->group('brand_id');
}]);
$query->with($with);
})->when($page && $limit, function ($query) use($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
* @param int $id
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllById(int $id, string $field = 'id')
{
if (!$id) return [];
return $this->getModel()->where(function ($query) use ($id) {
$query->where(function ($q) use ($id) {
$q->where('id', $id)->whereOr('pid', $id);
});
})->where('is_show', 1)->field($field)->select()->toArray();
}
}

View File

@@ -0,0 +1,234 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\category;
use app\dao\BaseDao;
use app\model\product\category\StoreProductCategory;
/**
* Class StoreProductCategoryDao
* @package app\dao\product\product
*/
class StoreProductCategoryDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductCategory::class;
}
/**
* 获取分类列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @param array $with
* @return array
* @throws \ReflectionException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = ['children'])
{
return $this->search($where)->field($field)
->when($with, function ($query) use ($with) {
$query->with($with);
})->when($page && $limit, function ($query) use($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
/**
*
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTierList(array $where = [], array $field = ['*'])
{
return $this->search($where)->field($field)->order('sort desc,id desc')->select()->toArray();
}
/**
* 添加修改选择上级分类列表
* @param array $where
* @return array
*/
public function getMenus(array $where)
{
return $this->search($where)->order('sort desc,id desc')->column('cate_name,id');
}
/**
* 根据id获取分类
* @param string $cateIds
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCateArray(string $cateIds)
{
return $this->search(['id' => $cateIds])->field('cate_name,id')->select()->toArray();
}
/**
* 前端分类页面分离列表
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getCategory(string $field = '*')
{
return $this->getModel()->field($field)->with('children')->where('is_show', 1)->where('pid', 0)->order('sort desc,id desc')->hidden(['add_time', 'is_show', 'sort', 'children.sort', 'children.add_time', 'children.pid', 'children.is_show'])->select()->toArray();
}
/**
* 根据分类id获取上级id
* @param array $cateId
* @return array
*/
public function cateIdByPid(array $cateId)
{
return $this->getModel()->whereIn('id', $cateId)->column('pid');
}
/**
* 获取首页展示的二级分类 排序默认降序
* @param int $limit
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function byIndexList($limit = 4, $field = 'id,cate_name,pid,pic')
{
return $this->getModel()->where('pid', '>', 0)->where('is_show', 1)->field($field)->order('sort DESC')->limit($limit)->select()->toArray();
}
/**
* 获取一级分类和二级分类组成的集合
* @param $cateId
* @return mixed
*/
public function getCateParentAndChildName(string $cateId)
{
return $this->getModel()->where('id', 'IN', $cateId)->field('cate_name as two,id,pid')
->with(['parentCateName'])->select()->toArray();
}
/**
* 按照个数获取一级分类下有商品的分类ID
* @param $page
* @param $limit
* @return array
*/
public function getCid($page, $limit)
{
return $this->getModel()
->where('is_show', 1)
->where('pid', 0)
->where('id', 'in', function ($query) {
$query->name('store_product_relation')->where('type', 1)->where('status', 1)->group('relation_pid')->field('relation_pid')->select()->toArray();
})
->page($page, $limit)
->order('sort DESC,id DESC')
->select()->toArray();
}
/**
* 按照个数获取一级分类下有商品的分类个数
* @param $page
* @param $limit
* @return int
*/
public function getCidCount()
{
return $this->getModel()
->where('is_show', 1)
->where('pid', 0)
->where('id', 'in', function ($query) {
$query->name('store_product_relation')->where('type', 1)->where('status', 1)->group('relation_pid')->field('relation_pid')->select()->toArray();
})
->count();
}
/**
* 通过分类id 获取(自己以及下级)的所有分类
* @param int $id
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllById(int $id, string $field = 'id')
{
return $this->getModel()->where(function ($query) use ($id) {
$query->where(function ($q) use ($id) {
$q->where('id', $id)->whereOr('pid', $id);
});
})->where('is_show', 1)->field($field)->select()->toArray();
}
/**
* 通过分类ids 获取(自己以及下级)的所有分类
* @param int $ids
* @param string $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAllByIds(array $ids, string $field = 'id')
{
return $this->getModel()->where(function ($query) use ($ids) {
$query->where(function ($q) use ($ids) {
$q->where('id', 'in', $ids)->whereOr('pid', 'in', $ids);
});
})->where('is_show', 1)->field($field)->select()->toArray();
}
/**
* 可以搜索的获取所有二级分类
* @param array $where
* @param string $field
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getALlByIndex(array $where, string $field = 'id,cate_name,pid,pic', int $limit = 0)
{
$pid = $where['pid'] ?? -1;
$where['is_show'] = 1;
return $this->search($where)->field($field)
->when((int)$pid > -1, function ($query) use ($pid) {
$query->where('pid', $pid);
})->when(isset($where['name']) && $where['name'], function ($query) use ($where) {
$query->whereLike('id|cate_name', '%' . $where['name'] . '%');
})->when($limit > 0, function ($query) use ($limit) {
$query->limit($limit);
})->order('sort desc,id desc')->select()->toArray();
}
}

View File

@@ -0,0 +1,55 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\dao\product\ensure;
use app\dao\BaseDao;
use app\model\product\ensure\StoreProductEnsure;
/**
* 商品保障服务
* Class StoreProductEnsureDao
* @package app\dao\product\label
*/
class StoreProductEnsureDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return StoreProductEnsure::class;
}
/**
* 获取保障服务列表
* @param array $where
* @param string $field
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0)
{
return $this->search($where)->field($field)
->when($page && $limit, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})->order('sort desc,id desc')->select()->toArray();
}
}

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