chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
76
app/dao/activity/coupon/StoreCouponDao.php
Normal file
76
app/dao/activity/coupon/StoreCouponDao.php
Normal 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'));
|
||||
}
|
||||
}
|
||||
424
app/dao/activity/coupon/StoreCouponIssueDao.php
Normal file
424
app/dao/activity/coupon/StoreCouponIssueDao.php
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
49
app/dao/activity/coupon/StoreCouponIssueUserDao.php
Normal file
49
app/dao/activity/coupon/StoreCouponIssueUserDao.php
Normal 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();
|
||||
}
|
||||
}
|
||||
35
app/dao/activity/coupon/StoreCouponProductDao.php
Normal file
35
app/dao/activity/coupon/StoreCouponProductDao.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
120
app/dao/activity/coupon/StoreCouponUserCouponDao.php
Normal file
120
app/dao/activity/coupon/StoreCouponUserCouponDao.php
Normal 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();
|
||||
}
|
||||
}
|
||||
258
app/dao/activity/coupon/StoreCouponUserDao.php
Normal file
258
app/dao/activity/coupon/StoreCouponUserDao.php
Normal 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();
|
||||
}
|
||||
}
|
||||
110
app/dao/activity/coupon/StoreCouponUserUserDao.php
Normal file
110
app/dao/activity/coupon/StoreCouponUserUserDao.php
Normal 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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user