Files
huangjingfen/pro_v3.5.1_副本/app/controller/admin/v1/diy/Diy.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

726 lines
28 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\controller\admin\v1\diy;
use app\controller\admin\AuthController;
use app\services\activity\newcomer\StoreNewcomerServices;
use app\services\activity\video\VideoServices;
use app\services\article\ArticleServices;
use app\services\diy\DiyServices;
use app\services\other\CacheServices;
use app\services\product\category\StoreProductCategoryServices;
use app\services\product\product\StoreProductServices;
use crmeb\exceptions\AdminException;
use think\annotation\Inject;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* Class Diy
* @package app\controller\admin\v1\diy
*/
class Diy extends AuthController
{
/**
* @var DiyServices
*/
#[Inject]
protected DiyServices $services;
/**
* DIY列表
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getList()
{
$where = $this->request->getMore([
['status', ''],
['type', 1],
['name', ''],
['version', ''],
]);
$data = $this->services->getDiyList($where);
return $this->success($data);
}
/**
* 修改模版名称
* @param int $id
* @return \think\Response
* User: liusl
* DateTime: 2023/12/27 14:43
*/
public function updateName(int $id)
{
[$name] = $this->request->postMore([
['name', '']
], true);
$info = $this->services->get($id);
if (!$info) {
return $this->fail('数据不存在');
}
if ($info['name'] == $name) {
return $this->fail('模版名称无任何修改');
}
$info->name = $name;
$info->save();
return $this->success('修改成功');
}
/**
* 保存资源
* @param int $id
* @return mixed
*/
public function saveData(int $id = 0)
{
$data = $this->request->postMore([
['name', ''],
['title', ''],
['value', ''],
['type', 1],
['cover_image', ''],
['is_show', 0],
['is_bg_color', 0],
['is_bg_pic', 0],
['bg_tab_val', 0],
['color_picker', ''],
['bg_pic', ''],
]);
$value = is_string($data['value']) ? json_decode($data['value'], true) : $data['value'];
$infoDiy = $id ? $this->services->get($id, ['is_diy']) : [];
// if ($infoDiy && $infoDiy['is_diy']) {
foreach ($value as $key => &$item) {
if ($item['name'] === 'goodList') {
if (isset($item['selectConfig']['list'])) {
unset($item['selectConfig']['list']);
}
if (isset($item['goodsList']['list']) && is_array($item['goodsList']['list'])) {
$limitMax = config('database.page.limitMax', 50);
if (isset($item['numConfig']['val']) && isset($item['tabConfig']['tabVal']) && $item['tabConfig']['tabVal'] == 0 && $item['numConfig']['val'] > $limitMax) {
return $this->fail('您设置得商品个数超出系统限制,最大限制' . $limitMax . '个商品');
}
$item['goodsList']['ids'] = array_column($item['goodsList']['list'], 'id');
unset($item['goodsList']['list'], $item['productList']['list']);
}
} elseif ($item['name'] === 'articleList') {
if (isset($item['selectList']['list']) && is_array($item['selectList']['list'])) {
unset($item['selectList']['list']);
}
} elseif ($item['name'] === 'promotionList') {
if (isset($item['tabConfig']['list']) && $item['tabConfig']['list']) {
$list = $item['tabConfig']['list'];
foreach ($list as &$tabValue) {
if (isset($tabValue['goodsList']['list']) && is_array($tabValue['goodsList']['list'])) {
$limitMax = config('database.page.limitMax', 50);
if (isset($tabValue['numConfig']['val']) && isset($tabValue['tabConfig']['tabVal']) && $tabValue['tabConfig']['tabVal'] == 0 && $tabValue['numConfig']['val'] > $limitMax) {
return $this->fail('您设置得商品个数超出系统限制,最大限制' . $limitMax . '个商品');
}
$tabValue['goodsList']['ids'] = array_column($tabValue['goodsList']['list'], 'id');
}
unset($tabValue['goodsList']['list'], $item['productList']['list']);
}
$item['tabConfig']['list'] = $list;
}
} elseif ($item['name'] === 'newVip') {
unset($item['newVipList']['list']);
} elseif ($item['name'] === 'shortVideo') {
unset($item['videoList']);
}
}
$data['value'] = json_encode($value);
$data['version'] = uniqid();
return $this->success($id ? '修改成功' : '保存成功', ['id' => $this->services->saveData($id, $data)]);
}
/**
* 删除模板
* @param $id
* @return mixed
*/
public function del($id)
{
$this->services->del($id);
return $this->success('删除成功');
}
/**
* 使用模板
* @param $id
* @return mixed
*/
public function setStatus($id)
{
return $this->success($this->services->setStatus($id));
}
/**
* 获取一条数据
* @param int $id
* @return mixed
*/
public function getInfo($id, StoreProductServices $services, StoreNewcomerServices $newcomerServices, VideoServices $videoServices)
{
if (!(int)$id) return $this->fail('参数错误');
$info = $this->services->get((int)$id);
if ($info) {
$info = $info->toArray();
} else {
return $this->fail('模板不存在');
}
$info['value'] = json_decode($info['value'], true);
if ($info['value']) {
/** @var ArticleServices $articleServices */
$articleServices = app()->make(ArticleServices::class);
/** @var StoreProductCategoryServices $storeCategoryServices */
$storeCategoryServices = app()->make(StoreProductCategoryServices::class);
if ($info['is_diy']) {
$limitMax = config('database.page.limitMax', 50);
foreach ($info['value'] as &$item) {
switch ($item['name']) {
case 'goodList'://商品列表
$typeConfig = $item['typeConfig']['activeValue'] ?? 0;
$where = [];
$num = $item['numberConfig']['val'] ?? $limitMax;
$sort = $item['goodsSort']['type'] ?? 0;
if ($sort == 1) {
$where['salesOrder'] = 'desc';
} elseif ($sort == 2) {
$where['priceOrder'] = 'desc';
}
$item['goodsList']['list'] = [];
// $where['type'] = [0, 2];
$where['is_show'] = 1;
$where['is_del'] = 0;
$where['is_verify'] = 1;
switch ($typeConfig) {
case 1://指定商品
$where['ids'] = $item['goodsList']['ids'] ?? [];
$item['goodsList']['list'] = $services->getSearchList($where, 0, 0, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
break;
case 2://指定品牌
$where['brand_id'] = $item['brandList']['brandVal'] ?? [];
$item['productList']['list'] = $services->getSearchList($where, 0, $num, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
break;
case 3://指定分类
$cateIds = $item['classList']['classVal'] ?? [];
if ($cateIds) {
// $ids = $storeCategoryServices->getColumn(['pid' => $cateIds], 'id');
// if ($ids) {
// $cateIds = array_unique(array_merge($cateIds, $ids));
$where['cate_id'] = $cateIds;
// }
}
$item['productList']['list'] = $services->getSearchList($where, 0, $num, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
break;
case 4://商品标签
$storeLabelIds = $item['goodsLabel']['activeValue'] ?? [];
if ($storeLabelIds) {
$where['store_label_id'] = $storeLabelIds;
}
$item['productList']['list'] = $services->getSearchList($where, 0, $num, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
break;
}
break;
case 'articleList'://文章
$data = [];
if ($item['selectConfig']['activeValue'] ?? 0) {
$data = $articleServices->getList(['cid' => $item['selectConfig']['activeValue'] ?? 0], 0, $item['numConfig']['val'] ?? 0);
}
$item['selectList']['list'] = $data['list'] ?? [];
break;
case 'promotionList'://促销列表
if (isset($item['tabConfig']['list']) && $item['tabConfig']['list']) {
$list = $item['tabConfig']['list'];
if ($list) {
foreach ($list as &$tabValue) {
$where = [];
//选择方式
$selectValue = $tabValue['tabVal'] ?? 0;
$num = $tabValue['numConfig']['val'] ?? $limitMax;
$sort = $tabValue['goodsSort'] ?? 0;
if ($sort == 1) {
$where['salesOrder'] = 'desc';
} elseif ($sort == 2) {
$where['priceOrder'] = 'desc';
}
$tabValue['goodsList']['list'] = [];
if ($selectValue == 1 && isset($tabValue['goodsList']['ids']) && count($tabValue['goodsList']['ids'])) {//手动选商品
$where['ids'] = $tabValue['goodsList']['ids'];
$tabValue['goodsList']['list'] = $services->getSearchList($where, 0, 0, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
} elseif ((isset($tabValue['selectConfig']['activeValue']) && $tabValue['selectConfig']['activeValue']) || (isset($tabValue['goodsLabel']['activeValue']) && $tabValue['goodsLabel']['activeValue'])) {//选分类 、标签
$cateIds = $tabValue['selectConfig']['activeValue'] ?? [];
if ($cateIds) {
$ids = $storeCategoryServices->getColumn(['pid' => $cateIds], 'id');
if ($ids) {
$cateIds = array_unique(array_merge($cateIds, $ids));
$where['cate_id'] = $cateIds;
}
}
$storeLabelIds = $tabValue['goodsLabel']['activeValue'] ?? [];
if ($storeLabelIds) {
$where['store_label_id'] = $storeLabelIds;
}
$where['type'] = [0, 2];
$where['is_show'] = 1;
$where['is_del'] = 0;
$where['is_verify'] = 1;
$where['ids'] = '';
$tabValue['productList']['list'] = $services->getSearchList($where, 0, $num, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
}
}
$item['tabConfig']['list'] = $list;
}
}
break;
case 'newVip'://新人专享
$item['newVipList']['list'] = $newcomerServices->getDiyNewcomerList();
break;
// case 'shortVideo'://短视频
// $item['videoList'] = $videoServices->getDiyVideoList(0);
// break;
}
}
} else {
if ($info['value']) {
if (isset($info['value']['d_goodList']['goodsList'])) {
$info['value']['d_goodList']['goodsList']['list'] = [];
}
if (isset($info['value']['d_goodList']['goodsList']['ids']) && count($info['value']['d_goodList']['goodsList']['ids'])) {
$info['value']['d_goodList']['goodsList']['list'] = $services->getSearchList(['ids' => $info['value']['d_goodList']['goodsList']['ids']]);
}
}
}
}
return $this->success(compact('info'));
}
/**
* 获取uni-app路径
* @return mixed
*/
public function getUrl()
{
$url = sys_data('uni_app_link');
if ($url) {
foreach ($url as &$link) {
$link['url'] = $link['link'];
$link['parameter'] = trim($link['param']);
}
} else {
/** @var CacheServices $cache */
$cache = app()->make(CacheServices::class);
$url = $cache->getDbCache('uni_app_url', null);
}
return $this->success(compact('url'));
}
/**
* 获取商品分类
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getCategory()
{
/** @var StoreProductCategoryServices $categoryService */
$categoryService = app()->make(StoreProductCategoryServices::class);
return $this->success($categoryService->cascaderList());
}
/**
* 获取商品
* @return mixed
*/
public function getProduct()
{
$where = $this->request->getMore([
['id', ''],//搜索分类
['salesOrder', ''],//销量排序
['priceOrder', ''],//价格排序
['supplier_id', 0],//供应商ID
['store_id', 0],//门店ID
['store_label_id', ''],//标签ID
['ids', ''],//商品ID
['brand_id', ''],//品牌ID
]);
$cateId = $where['id'];
$where['is_show'] = 1;
$where['is_del'] = 0;
$where['is_verify'] = 1;
$where['type'] = [0, 2];
$where['show_type'] = [0, 1];
if ($where['supplier_id']) {
$where['relation_id'] = $where['supplier_id'];
$where['type'] = 2;
} elseif ($where['store_id']) {
$where['relation_id'] = $where['store_id'];
$where['type'] = 1;
} else {
$where['pid'] = 0;
}
unset($where['supplier_id'], $where['store_id']);
unset($where['id']);
/** @var StoreProductCategoryServices $storeCategoryServices */
$storeCategoryServices = app()->make(StoreProductCategoryServices::class);
if ($cateId) {
$cateId = is_string($cateId) ? [$cateId] : $cateId;
// $cateId = array_merge($cateId, $storeCategoryServices->getColumn(['pid' => $cateId], 'id'));
$cateId = array_unique(array_diff($cateId, [0]));
}
$where['cate_id'] = $cateId;
// if ($storeCategoryServices->value(['id' => $id], 'pid')) {
// $where['sid'] = $id;
// } else {
// $where['cid'] = $id;
// }
[$page, $limit] = $this->services->getPageValue();
/** @var StoreProductServices $productService */
$productService = app()->make(StoreProductServices::class);
$list = $productService->getSearchList($where, $page, $limit, ['id,store_name,cate_id,image,IFNULL(sales, 0) + IFNULL(ficti, 0) as sales,price,stock,activity,ot_price,spec_type,recommend_image,unit_name,is_vip,vip_price'], '', []);
return $this->success($list);
}
/**
* 获取提货点自提开启状态
* @return mixed
*/
public function getStoreStatus()
{
$data['store_status'] = 0;
if (sys_config('store_func_status', 1)) {
$data['store_status'] = sys_config('store_self_mention', 0);
}
return $this->success($data);
}
/**
* 设置模版默认数据
* @param $id
* @return mixed
*/
public function setDefaultData($id)
{
if (!$id) return $this->fail('参数错误');
$info = $this->services->get($id);
if ($info) {
$info->default_value = $info->value;
$info->update_time = time();
$info->save();
event('diy.update');
return $this->success('设置成功');
} else {
return $this->fail('模板不存在');
}
}
/**
* 还原模板数据
* @param $id
* @return mixed
*/
public function Recovery($id)
{
if (!$id) return $this->fail('参数错误');
$info = $this->services->get($id);
if ($info) {
$info->value = $info->default_value;
$info->update_time = time();
$info->save();
event('diy.update');
return $this->success('还原成功');
} else {
return $this->fail('模板不存在');
}
}
/**
* 获取二级分类
* @return mixed
*/
public function getByCategory()
{
$where = $this->request->getMore([
['pid', -1],
['name', '']
]);
/** @var StoreProductCategoryServices $categoryServices */
$categoryServices = app()->make(StoreProductCategoryServices::class);
return $this->success($categoryServices->getALlByIndex($where));
}
/**
* 获取首页推荐不同类型商品的轮播图和商品
* @param $type
* @return mixed
*/
public function groom_list($type)
{
$info['list'] = $this->get_groom_list($type);
return $this->success($info);
}
/**
* 实际获取方法
* @param $type
* @return array
*/
protected function get_groom_list($type, int $num = 0)
{
$where = [];
if ($type == 1) {// 精品推荐
$where['is_best'] = 1;
// 精品推荐个数
} else if ($type == 2) {// 热门榜单
$where['is_hot'] = 1;
} else if ($type == 3) {// 首发新品
$where['is_new'] = 1;
} else if ($type == 4) {// 促销单品
$where['is_benefit'] = 1;
} else if ($type == 5) {// 会员商品
$where['is_vip'] = 1;
}
/** @var StoreProductServices $services */
$services = app()->make(StoreProductServices::class);
return $services->getRecommendProduct(0, $where, $num);
}
/**
* 一键换色
* @param $status
* @return mixed
*/
public function colorChange($status, $type)
{
$colorData = $this->request->postMore([
['aux_color', ''],
['gradient_color', ''],
['light_color', ''],
['theme_color', ''],
['theme_type', '']
]);
if (!$status) return $this->fail('参数错误');
$info = $this->services->get(['template_name' => $type, 'type' => 3]);
if ($info) {
$info->value = $status;
$info->color_data = json_encode($colorData);
$info->update_time = time();
$info->save();
event('diy.update');
$this->services->cacheStrUpdate('color_change_' . $type . '_3', $status);
return $this->success('设置成功');
} else {
return $this->fail('模板不存在');
}
}
/**
* 获取颜色选择和分类模板选择
* @param $type
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getColorChange($type)
{
$colorData = $this->services->getColorChange((string)$type);
$status = (int)$colorData['value'];
$color_data = json_decode($colorData['color_data'], true);
return $this->success(compact('status', 'color_data'));
}
/**
* 获取单个diy小程序预览二维码
* @param $id
* @return mixed
*/
public function getRoutineCode($id)
{
$image = $this->services->getRoutineCode((int)$id);
return $this->success(compact('image'));
}
/**
* 获取会员中心数据
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getMember()
{
$data = $this->services->getMemberData();
return $this->success($data);
}
/**
* 保存个人中心数据
* @return mixed
*/
public function memberSaveData()
{
$data = $this->request->postMore([
['member', []],
['routine_my_banner', []],
['routine_my_menus', []]
]);
$this->services->memberSaveData($data);
event('diy.update');
return $this->success('保存成功');
}
/**
* 获取开屏广告
* @return mixed
*/
public function getOpenAdv()
{
/** @var CacheServices $cacheServices */
$cacheServices = app()->make(CacheServices::class);
$data = $cacheServices->getDbCache('open_adv', '');
$data = $data ?: [];
$data['time'] = (float)($data['time'] ?? 3);
$data['interval_time'] = (float)($data['interval_time'] ?? 24);
return app('json')->success($data);
}
/**
* 保存开屏广告
* @return mixed
*/
public function openAdvAdd()
{
$data = $this->request->postMore([
['status', 0],//状态
['time', 0],//广告时间
['interval_time', 24],//再次出现间隔时间
['type', 'pic'],//类型
['value', []],
['video_link', '']
]);
if (!$data['type']) {
$data['type'] = 'pic';
}
/** @var CacheServices $cacheServices */
$cacheServices = app()->make(CacheServices::class);
$cacheServices->setDbCache('open_adv', $data);
event('diy.update');
return app('json')->success('保存成功');
}
/**
* 获取商品详情数据
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getProductDetailDiy()
{
$data = $this->services->getProductDetailDiy();
return $this->success($data);
}
/**
* 保存商品详情数据
* @return mixed
*/
public function saveProductDetailDiy()
{
[$content] = $this->request->postMore([
['product_detail_diy', []],
], true);
$this->services->saveProductDetailDiy($content);
event('diy.update');
return $this->success('保存成功');
}
/**
* 获取商品分类数据
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function getProductCategoryDiy()
{
$data = $this->services->getProductCategoryDiy();
return $this->success($data);
}
/**
* 保存商品分类数据
* @return mixed
*/
public function saveProductCategoryDiy()
{
[$content] = $this->request->postMore([
['product_category_diy', []],
], true);
$this->services->saveProductCategoryDiy($content);
event('diy.update');
return $this->success('保存成功');
}
/**
* 获取新人礼商品
* @param StoreNewcomerServices $newcomerServices
* @return mixed
*/
public function newcomerList(StoreNewcomerServices $newcomerServices)
{
$where = $this->request->getMore([
['priceOrder', ''],
['salesOrder', ''],
]);
return app('json')->success($newcomerServices->getDiyNewcomerList(0, $where));
}
/**
* 获取悬浮窗数据
* @return \think\Response
* User: liusl
* DateTime: 2024/9/6 10:11
*/
public function getSuspendedDiy()
{
$data = $this->services->getSuspendedDiy();
return $this->success($data);
}
/**
* 保存悬浮窗数据
* @return \think\Response
* User: liusl
* DateTime: 2024/9/6 10:11
*/
public function saveSuspendedDiy()
{
[$content] = $this->request->postMore([
['suspended_window_diy', []],
], true);
$this->services->saveSuspendedDiy($content);
event('diy.update');
return $this->success('保存成功');
}
}