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

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();
}
}