Files
huangjingfen/pro_v3.5.1_副本/app/dao/activity/coupon/StoreCouponIssueDao.php
apple 434aa8c69d feat(fsgx): 完成全部24项开发任务 Phase1-7
Phase1 后端核心:
- 新增 fsgx_v1.sql 迁移脚本(is_queue_goods/frozen_points/available_points/no_assess)
- SystemConfigServices 返佣设置扩展(周期人数/分档比例/范围/时机)
- StoreOrderCreateServices 周期循环佣金计算
- StoreOrderTakeServices 佣金发放后同步冻结积分
- StoreProductServices/StoreProduct 保存 is_queue_goods

Phase2 后端接口:
- GET /api/hjf/brokerage/progress 佣金周期进度
- GET /api/hjf/assets/overview 资产总览
- HjfPointsServices 每日 frozen_points 0.4‰ 释放定时任务
- PUT /adminapi/hjf/member/{uid}/no_assess 不考核接口
- GET /adminapi/hjf/points/release_log 积分日志接口

Phase3 前端清理:
- hjfCustom.js 路由精简(仅保留 points/log)
- hjfQueue.js/hjfMember.js API 清理/重定向至 CRMEB 原生接口
- pages.json 公排→推荐佣金/佣金记录/佣金规则

Phase4-5 前端改造:
- queue/status.vue 推荐佣金进度页整体重写
- 商品详情/订单确认/支付结果页文案与逻辑改造
- 个人中心/资产页/引导页/规则页文案改造
- HjfQueueProgress/HjfRefundNotice/HjfAssetCard 组件改造
- 推广中心嵌入佣金进度摘要
- hjfMockData.js 全量更新(公排字段→佣金字段)

Phase6 Admin 增强:
- 用户列表新增 frozen_points/available_points 列及不考核操作按钮
- hjfPoints.js USE_MOCK=false 对接真实积分日志接口

Phase7 配置文档:
- docs/fsgx-phase7-config-checklist.md 后台配置与全链路验收清单

Made-with: Cursor
2026-03-23 22:32:19 +08:00

425 lines
17 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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();
}
}