Files
huangjingfen/pro_v3.5.1_副本/app/services/activity/coupon/StoreCouponService.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

198 lines
8.9 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>
// +----------------------------------------------------------------------
namespace app\services\activity\coupon;
use app\dao\activity\coupon\StoreCouponDao;
use app\services\BaseServices;
use app\services\product\category\StoreProductCategoryServices;
use crmeb\exceptions\AdminException;
use crmeb\services\FormBuilder as Form;
use think\annotation\Inject;
use think\facade\Route as Url;
/**
* Class StoreCouponService
* @package app\services\activity\coupon
* @mixin StoreCouponDao
*/
class StoreCouponService extends BaseServices
{
/**
* @var StoreCouponDao
*/
#[Inject]
protected StoreCouponDao $dao;
/**
* 获取列表
* @param array $where
* @return array
*/
public function getList(array $where)
{
[$page, $limit] = $this->getPageValue();
$where['is_del'] = 0;
$list = $this->dao->getList($where, $page, $limit);
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 添加优惠券表单
* @param int $type
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function createForm(int $type)
{
$f[] = Form::input('title', '优惠券名称');
switch ($type) {
case 1://品类券
$options = function () {
/** @var StoreProductCategoryServices $storeCategoryService */
$storeCategoryService = app()->make(StoreProductCategoryServices::class);
$list = $storeCategoryService->getTierList(1, 1);
$menus = [];
foreach (sort_list_tier($list) as $menu) {
$menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['cate_name'], 'disabled' => false];
}
return $menus;
};
$f[] = Form::select('category_id', '选择品类')->setOptions(Form::setOptions($options))->filterable(1)->col(12);
break;
case 2://商品券
$f[] = Form::frameImages('image', '商品', Url::buildUrl('admin/store.StoreProduct/index', array('fodder' => 'image', 'type' => 'many')))->icon('ios-add')->width('960px')->height('430px')->modal(['footer-hide' => true])->props(['srcKey' => 'image']);
$f[] = Form::hidden('product_id', '');
break;
}
$f[] = Form::number('coupon_price', '优惠券面值', 0)->min(0);
$f[] = Form::number('use_min_price', '优惠券最低消费', 0)->min(0);
$f[] = Form::number('coupon_time', '优惠券有效期限', 0)->min(0);
$f[] = Form::number('sort', '排序', 1)->min(0);
$f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
$f[] = Form::hidden('type', $type);
return create_form('添加优惠券', $f, Url::buildUrl('/marketing/coupon/save'), 'POST');
}
/**
* 优惠卷模板修改表单
* @param int $id
* @return array
* @throws \FormBuilder\Exception\FormBuilderException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function createIssue(int $id)
{
$res = $this->dao->getOne(['id' => $id, 'status' => 1, 'is_del' => 0]);
if (!$res) throw new AdminException('发布的优惠劵已失效或不存在!');
$f = [];
$f[] = Form::input('id', '优惠劵ID', $id)->disabled(1);
$f[] = Form::input('coupon_title', '优惠劵名称', $res['title'])->disabled(1);
$f[] = Form::dateTimeRange('range_date', '领取时间')->placeholder('不填为永久有效');
$f[] = Form::radio('is_permanent', '是否限量', 1)->options([['label' => '不限量', 'value' => 1], ['label' => '限量', 'value' => 0]]);
$f[] = Form::number('count', '发布数量', 0)->min(0)->placeholder('不填或填0,为不限量');
$f[] = Form::radio('is_type', '优惠券类型', 0)->options([['label' => '普通券', 'value' => 0], ['label' => '赠送券', 'value' => 1], ['label' => '新人券', 'value' => 2]]);
$f[] = Form::number('full_reduction', '满赠金额', 0)->min(0)->placeholder('赠送优惠券的最低消费金额');
$f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
return create_form('发布优惠券', $f, $this->url('/marketing/coupon/issue/' . $id), 'POST');
}
/**
* 发布优惠券
* @param int $id
* @param int $_id
* @param string $coupon_title
* @param array $rangeTime
* @param int $count
* @param int $status
* @param int $is_permanent
* @param float $full_reduction
* @param int $is_give_subscribe
* @param int $is_full_give
* @param int $is_type
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function upIssue(int $id, int $_id, string $coupon_title, array $rangeTime, int $count, int $status, int $is_permanent, float $full_reduction, int $is_give_subscribe, int $is_full_give, int $is_type)
{
if ($is_type == 1) {
$is_full_give = 1;
} elseif ($is_type == 2) {
$is_give_subscribe = 1;
}
if ($_id != $id) throw new AdminException('操作失败,信息不对称');
if (!$count) $count = 0;
$couponInfo = $this->dao->getOne(['id' => $id, 'status' => 1, 'is_del' => 0]);
if (!$couponInfo) throw new AdminException('发布的优惠劵已失效或不存在!');
if (count($rangeTime) != 2) throw new AdminException('请选择正确的时间区间');
[$startTime, $endTime] = $rangeTime;
if (!$startTime) $startTime = 0;
if (!$endTime) $endTime = 0;
if (!$startTime && $endTime) throw new AdminException('请选择正确的开始时间');
if ($startTime && !$endTime) throw new AdminException('请选择正确的结束时间');
$data['cid'] = $id;
$data['coupon_title'] = $coupon_title;
$data['start_time'] = strtotime($startTime);
$data['end_time'] = strtotime($endTime);
$data['total_count'] = $count;
$data['remain_count'] = $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['is_del'] = 0;
$data['add_time'] = time();
$data['title'] = $couponInfo['title'];
$data['integral'] = $couponInfo['integral'];
$data['coupon_price'] = $couponInfo['coupon_price'];
$data['use_min_price'] = $couponInfo['use_min_price'];
$data['coupon_time'] = $couponInfo['coupon_time'];
$data['product_id'] = $couponInfo['product_id'];
$data['category_id'] = $couponInfo['category_id'];
$data['type'] = $couponInfo->getData('type');
/** @var StoreCouponIssueServices $storeCouponIssueService */
$storeCouponIssueService = app()->make(StoreCouponIssueServices::class);
$res = $storeCouponIssueService->save($data);
$productIds = explode(',', $data['product_id']);
if (count($productIds)) {
$couponData = [];
foreach ($productIds as $product_id) {
$couponData[] = ['product_id' => $product_id, 'coupon_id' => $res->id];
}
/** @var StoreCouponProductServices $storeCouponProductService */
$storeCouponProductService = app()->make(StoreCouponProductServices::class);
$storeCouponProductService->saveAll($couponData);
}
if (!$res) throw new AdminException('发布优惠劵失败!');
}
/**
* 优惠券失效
* @param int $id
*/
public function invalid(int $id)
{
$res = $this->dao->update($id, ['status' => 0]);
if (!$res) throw new AdminException('操作失败');
/** @var StoreCouponIssueServices $storeCouponIssueService */
$storeCouponIssueService = app()->make(StoreCouponIssueServices::class);
$storeCouponIssueService->update($id, ['status' => -1], 'cid');
}
}