chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
120
app/services/activity/integral/StoreIntegralCategoryServices.php
Normal file
120
app/services/activity/integral/StoreIntegralCategoryServices.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>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\activity\integral;
|
||||
|
||||
use app\dao\other\CategoryDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\other\CategoryServices;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use think\annotation\Inject;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
/**
|
||||
* 积分商品
|
||||
* Class StoreIntegralServices
|
||||
* @package app\services\activity\integral
|
||||
* @mixin CategoryDao
|
||||
*/
|
||||
class StoreIntegralCategoryServices extends BaseServices
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var CategoryDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected CategoryDao $dao;
|
||||
|
||||
/**
|
||||
* 分类类型
|
||||
* @var int
|
||||
*/
|
||||
protected int $group = CategoryServices::INTEGRAL_CATEGORY_GROUP;
|
||||
|
||||
/**
|
||||
* 获取积分分类列表
|
||||
* @param array $where 查询条件
|
||||
* @return array
|
||||
*/
|
||||
public function getList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$count = $this->dao->count($where);
|
||||
$list = $this->dao->getCateList($where, $page, $limit);
|
||||
if ($list) {
|
||||
foreach ($list as &$item) {
|
||||
$item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
|
||||
}
|
||||
}
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新增表单
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createForm()
|
||||
{
|
||||
return create_form('添加分类', $this->form(), Url::buildUrl('/marketing/integral/category'), 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建编辑表单
|
||||
* @param $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function editForm(int $id)
|
||||
{
|
||||
$info = $this->dao->get($id);
|
||||
return create_form('编辑分类', $this->form($info), $this->url('/marketing/integral/category/' . $id), 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成表单参数
|
||||
* @param array $info
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function form($info = [])
|
||||
{
|
||||
$f[] = Form::input('name', '分类名称:', $info['name'] ?? '')->maxlength(30)->required();
|
||||
$f[] = Form::number('integral_min', '最低积分:', (int)($info['integral_min'] ?? 0))->min(0);
|
||||
$f[] = Form::number('integral_max', '最高积分:', (int)($info['integral_max'] ?? 0))->min(0);
|
||||
$f[] = Form::radio('is_show', '状态:', $info['is_show'] ?? 1)->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]]);
|
||||
$f[] = Form::number('sort', '排序:', (int)($info['sort'] ?? 0))->min(0);
|
||||
return $f;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取积分分类树形结构列表
|
||||
* @return array
|
||||
*/
|
||||
public function getTreeList()
|
||||
{
|
||||
$where = [
|
||||
'is_show' => 1,
|
||||
'group' => CategoryServices::INTEGRAL_CATEGORY_GROUP,
|
||||
];
|
||||
$list = $this->dao->search($where)->field(['name', 'integral_min', 'integral_max'])->order('sort DESC')->select()->toArray();
|
||||
$data = [];
|
||||
foreach ($list as $item) {
|
||||
$data[] = [
|
||||
'label' => $item['name'],
|
||||
'value' => "{$item['integral_min']}-{$item['integral_max']}"
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
213
app/services/activity/integral/StoreIntegralOrderServices.php
Normal file
213
app/services/activity/integral/StoreIntegralOrderServices.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?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\integral;
|
||||
|
||||
|
||||
use app\dao\activity\integral\StoreIntegralOrderDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\user\UserServices;
|
||||
use app\services\user\UserBillServices;
|
||||
use crmeb\services\SystemConfigService;
|
||||
use crmeb\utils\Arr;
|
||||
use think\annotation\Inject;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* Class StoreIntegralOrderServices
|
||||
* @package app\services\activity\integral
|
||||
* @mixin StoreIntegralOrderDao
|
||||
*/
|
||||
class StoreIntegralOrderServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var StoreIntegralOrderDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreIntegralOrderDao $dao;
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $where
|
||||
* @param array $field
|
||||
* @param array $with
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function getOrderList(array $where, array $field = ['*'], array $with = [])
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$data = $this->dao->getOrderList($where, $field, $page, $limit, $with);
|
||||
$count = $this->dao->count($where);
|
||||
$data = $this->tidyOrderList($data);
|
||||
$batch_url = "file/upload/1";
|
||||
return compact('data', 'count', 'batch_url');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导出数据
|
||||
* @param array $where
|
||||
* @param int $limit
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function getExportList(array $where, int $limit = 0)
|
||||
{
|
||||
if ($limit) {
|
||||
[$page] = $this->getPageValue();
|
||||
} else {
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
}
|
||||
$data = $this->dao->getOrderList($where, ['*'], $page, $limit);
|
||||
$data = $this->tidyOrderList($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端订单列表
|
||||
* @param array $where
|
||||
* @param array|string[] $field
|
||||
* @param array $with
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function getOrderApiList(array $where, array $field = ['*'], array $with = [])
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$data = $this->dao->getOrderList($where, $field, $page, $limit, $with);
|
||||
$data = $this->tidyOrderList($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情数据格式化
|
||||
* @param $order
|
||||
* @return mixed
|
||||
*/
|
||||
public function tidyOrder($order)
|
||||
{
|
||||
$order['_add_time'] = $order['add_time'] = date('Y-m-d H:i:s', $order['add_time']);
|
||||
if ($order['status'] == 1) {
|
||||
$order['status_name'] = '未发货';
|
||||
} else if ($order['status'] == 2) {
|
||||
$order['status_name'] = '待收货';
|
||||
} else if ($order['status'] == 3) {
|
||||
$order['status_name'] = '已完成';
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据转换
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function tidyOrderList(array $data)
|
||||
{
|
||||
foreach ($data as &$item) {
|
||||
$item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
|
||||
if (!$item['paid']) {
|
||||
$item['status_name'] = '待付款';
|
||||
} else if ($item['status'] == 1) {
|
||||
$item['status_name'] = '未发货';
|
||||
} else if ($item['status'] == 2) {
|
||||
$item['status_name'] = '待收货';
|
||||
} else if ($item['status'] == 3) {
|
||||
$item['status_name'] = '已完成';
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 未支付积分订单退积分
|
||||
* @return bool|void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function rebatePointsOrders()
|
||||
{
|
||||
//废弃 积分订单合并入统一下单流程
|
||||
//先完成支付 后在支付积分
|
||||
return true;
|
||||
$where['is_del'] = 0;
|
||||
$where['is_system_del'] = 0;
|
||||
$where['paid'] = 0;
|
||||
$where['is_price'] = 1;
|
||||
$where['is_integral'] = 1;
|
||||
$list = $this->dao->getIntegralOrderList($where);
|
||||
//系统预设取消订单时间段
|
||||
$keyValue = ['rebate_points_orders_time', 'order_cancel_time'];
|
||||
//获取配置
|
||||
$systemValue = SystemConfigService::more($keyValue);
|
||||
//格式化数据
|
||||
$systemValue = Arr::setValeTime($keyValue, is_array($systemValue) ? $systemValue : []);
|
||||
$order_cancel_time = $systemValue['rebate_points_orders_time'] ?: $systemValue['order_cancel_time'];
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
/** @var UserBillServices $userBillServices */
|
||||
$userBillServices = app()->make(UserBillServices::class);
|
||||
$order_cancel_time = (int)bcmul((string)$order_cancel_time, '3600', 0);
|
||||
foreach ($list as $key => $item) {
|
||||
if (($item['add_time'] + $order_cancel_time) < time()) {
|
||||
try {
|
||||
$this->transaction(function () use ($item, $userServices, $userBillServices) {
|
||||
$user_integral = $userServices->value(['uid' => $item['uid']], 'integral');
|
||||
$res = $userServices->incUpdate(['uid' => $item['uid']], 'integral', (int)$item['integral']);
|
||||
$integral = bcadd((string)$user_integral, (string)$item['integral']);
|
||||
$res1 = $userBillServices->income('integral_refund', $item['uid'], (int)$item['integral'], (int)$integral, $item['id']);
|
||||
//修改订单状态
|
||||
$res = $res && $res1 && $this->dao->update($item['id'], ['is_del' => 1, 'is_system_del' => 1, 'mark' => '积分订单未支付已超过系统预设时间']);
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('未支付积分订单退积分失败,失败原因:' . $e->getMessage(), $e->getTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*获取订单数量
|
||||
* @param array $where
|
||||
* @return mixed
|
||||
*/
|
||||
public function orderCount(array $where)
|
||||
{
|
||||
$where['type'] = 4;
|
||||
//全部订单
|
||||
$data['statusAll'] = (string)$this->dao->count($where + ['is_system_del' => 0]);
|
||||
//未发货
|
||||
$data['unshipped'] = (string)$this->dao->count($where + ['status' => 1, 'is_system_del' => 0]);
|
||||
//待收货
|
||||
$data['untake'] = (string)$this->dao->count($where + ['status' => 2, 'is_system_del' => 0]);
|
||||
//待评价
|
||||
// $data['unevaluate'] = (string)$this->dao->count(['status' => 3, 'time' => $where['time'], 'is_system_del' => 0]);
|
||||
//交易完成
|
||||
$data['complete'] = (string)$this->dao->count($where + ['status' => 3, 'is_system_del' => 0]);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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\integral;
|
||||
|
||||
|
||||
use app\dao\activity\integral\StoreIntegralOrderStatusDao;
|
||||
use app\services\BaseServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 订单状态
|
||||
* Class StoreIntegralOrderStatusServices
|
||||
* @package app\services\activity\integral
|
||||
* @mixin StoreIntegralOrderStatusDao
|
||||
*/
|
||||
class StoreIntegralOrderStatusServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var StoreIntegralOrderStatusDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreIntegralOrderStatusDao $dao;
|
||||
|
||||
/**
|
||||
* 订单状态分页
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getStatusList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getStatusList($where, $page, $limit);
|
||||
foreach ($list as &$item) {
|
||||
if (is_int($item['change_time'])) $item['change_time'] = date('Y-m-d H:i:s', $item['change_time']);
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
}
|
||||
453
app/services/activity/integral/StoreIntegralServices.php
Normal file
453
app/services/activity/integral/StoreIntegralServices.php
Normal file
@@ -0,0 +1,453 @@
|
||||
<?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\services\activity\integral;
|
||||
|
||||
use app\services\BaseServices;
|
||||
use app\dao\activity\integral\StoreIntegralDao;
|
||||
use app\services\diy\DiyServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use app\services\product\ensure\StoreProductEnsureServices;
|
||||
use app\services\product\label\StoreProductLabelServices;
|
||||
use app\services\product\product\StoreDescriptionServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use app\services\product\sku\StoreProductAttrResultServices;
|
||||
use app\services\product\sku\StoreProductAttrServices;
|
||||
use app\services\product\sku\StoreProductAttrValueServices;
|
||||
use app\jobs\product\ProductLogJob;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\CacheService;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 积分商品
|
||||
* Class StoreIntegralServices
|
||||
* @package app\services\activity\integral
|
||||
* @mixin StoreIntegralDao
|
||||
*/
|
||||
class StoreIntegralServices extends BaseServices
|
||||
{
|
||||
const THODLCEG = 'ykGUKB';
|
||||
|
||||
/**
|
||||
* 商品活动类型
|
||||
*/
|
||||
const TYPE = 4;
|
||||
|
||||
/**
|
||||
* @var StoreIntegralDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreIntegralDao $dao;
|
||||
|
||||
/**
|
||||
* 获取指定条件下的条数
|
||||
* @param array $where
|
||||
*/
|
||||
public function getCount(array $where)
|
||||
{
|
||||
$this->dao->count($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分商品添加
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function saveData(int $id, array $data)
|
||||
{
|
||||
if ($data['freight'] == 2 && !$data['postage']) {
|
||||
throw new AdminException('请设置运费金额');
|
||||
}
|
||||
if ($data['freight'] == 3 && !$data['temp_id']) {
|
||||
throw new AdminException('请选择运费模版');
|
||||
}
|
||||
/** @var StoreProductServices $storeProductServices */
|
||||
$storeProductServices = app()->make(StoreProductServices::class);
|
||||
$productInfo = $storeProductServices->getOne(['is_del' => 0, 'is_verify' => 1, 'id' => $data['product_id']]);
|
||||
if (!$productInfo) {
|
||||
throw new AdminException('原商品已移入回收站');
|
||||
}
|
||||
if ($productInfo['is_vip_product']) {
|
||||
throw new AdminException("【{$productInfo["store_name"]}】是svip专享");
|
||||
}
|
||||
if ($productInfo['is_presale_product']) {
|
||||
throw new AdminException("【{$productInfo["store_name"]}】是预售商品");
|
||||
}
|
||||
$data['delivery_type'] = $productInfo['delivery_type'];
|
||||
$data['product_type'] = $productInfo['product_type'];
|
||||
$data['type'] = $productInfo['type'] ?? 0;
|
||||
$data['relation_id'] = $productInfo['relation_id'] ?? 0;
|
||||
$custom_form = $productInfo['custom_form'] ?? [];
|
||||
$data['custom_form'] = is_array($custom_form) ? json_encode($custom_form) : $custom_form;
|
||||
$data['system_form_id'] = $productInfo['system_form_id'] ?? 0;
|
||||
$store_label_id = $productInfo['store_label_id'] ?? [];
|
||||
$data['store_label_id'] = is_array($store_label_id) ? implode(',', $store_label_id) : $store_label_id;
|
||||
$ensure_id = $productInfo['ensure_id'] ?? [];
|
||||
$data['ensure_id'] = is_array($ensure_id) ? implode(',', $ensure_id) : $ensure_id;
|
||||
$specs = $productInfo['specs'] ?? [];
|
||||
$data['specs'] = is_array($specs) ? json_encode($specs) : $specs;
|
||||
$description = $data['description'];
|
||||
$detail = $data['attrs'];
|
||||
if ($detail) {
|
||||
foreach ($detail as $attr) {
|
||||
if ($attr['quota'] > $attr['stock']) {
|
||||
throw new AdminException('限量超过了商品库存');
|
||||
}
|
||||
}
|
||||
}
|
||||
$items = $data['items'];
|
||||
if (!$data['image'] && count($data['images']) > 0) {
|
||||
$data['image'] = $data['images'][0];
|
||||
}
|
||||
$data['images'] = json_encode($data['images']);
|
||||
$integral_data = array_column($detail, 'integral', 'price');
|
||||
$data['integral'] = $integral_data ? (int)min($integral_data) : 0;
|
||||
$data['price'] = array_search($data['integral'], $integral_data);
|
||||
$data['quota'] = $data['quota_show'] = array_sum(array_column($detail, 'quota'));
|
||||
if ($data['quota'] > $storeProductServices->value(['id' => $data['product_id']], 'stock')) {
|
||||
throw new ValidateException('限量不能超过商品库存');
|
||||
}
|
||||
$data['stock'] = array_sum(array_column($detail, 'stock'));
|
||||
unset($data['section_time'], $data['description'], $data['attrs'], $data['items']);
|
||||
/** @var StoreDescriptionServices $storeDescriptionServices */
|
||||
$storeDescriptionServices = app()->make(StoreDescriptionServices::class);
|
||||
/** @var StoreProductAttrServices $storeProductAttrServices */
|
||||
$storeProductAttrServices = app()->make(StoreProductAttrServices::class);
|
||||
$this->transaction(function () use ($id, $data, $description, $detail, $items, $storeDescriptionServices, $storeProductAttrServices, $storeProductServices) {
|
||||
if ($id) {
|
||||
$res = $this->dao->update($id, $data);
|
||||
if (!$res) throw new AdminException('修改失败');
|
||||
} else {
|
||||
if (!$storeProductServices->getOne(['is_del' => 0, 'is_verify' => 1, 'id' => $data['product_id']])) {
|
||||
throw new AdminException('原商品已移入回收站');
|
||||
}
|
||||
$data['add_time'] = time();
|
||||
$res = $this->dao->save($data);
|
||||
if (!$res) throw new AdminException('添加失败');
|
||||
$id = (int)$res->id;
|
||||
}
|
||||
$storeDescriptionServices->saveDescription((int)$id, $description, 4);
|
||||
$storeProductAttrServices->setItem('store_product_id', $data['product_id']);
|
||||
$skuList = $storeProductAttrServices->validateProductAttr($items, $detail, (int)$id, 4);
|
||||
$storeProductAttrServices->reset();
|
||||
$valueGroup = $storeProductAttrServices->saveProductAttr($skuList, (int)$id, 4);
|
||||
|
||||
$res = true;
|
||||
foreach ($valueGroup as $item) {
|
||||
$res = $res && CacheService::setStock($item['unique'], (int)$item['quota_show'], 4);
|
||||
}
|
||||
if (!$res) {
|
||||
throw new AdminException('占用库存失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加商品
|
||||
* @param array $data
|
||||
*/
|
||||
public function saveBatchData(array $data)
|
||||
{
|
||||
/** @var StoreProductServices $service */
|
||||
$service = app()->make(StoreProductServices::class);
|
||||
/** @var StoreDescriptionServices $storeDescriptionServices */
|
||||
$storeDescriptionServices = app()->make(StoreDescriptionServices::class);
|
||||
/** @var StoreProductAttrResultServices $storeProductAttrResultServices */
|
||||
$storeProductAttrResultServices = app()->make(StoreProductAttrResultServices::class);
|
||||
if (!$data) {
|
||||
throw new ValidateException('请先添加产品!');
|
||||
}
|
||||
$attrs = [];
|
||||
foreach ($data['attrs'] as $k => $v) {
|
||||
$attrs[$v['product_id']][] = $v;
|
||||
}
|
||||
foreach ($attrs as $k => $v) {
|
||||
$productInfo = $service->getOne(['id' => $k]);
|
||||
$productInfo = is_object($productInfo) ? $productInfo->toArray() : [];
|
||||
if ($productInfo) {
|
||||
$product = [];
|
||||
$result = $storeProductAttrResultServices->getResult(['product_id' => $productInfo['id'], 'type' => 0]);
|
||||
$product['product_id'] = $productInfo['id'];
|
||||
$product['description'] = $storeDescriptionServices->getDescription(['product_id' => $productInfo['id'], 'type' => 0]);
|
||||
$product['attrs'] = $v;
|
||||
$product['items'] = $result['attr'];
|
||||
$product['is_show'] = isset($data['is_show']) ? $data['is_show'] : 0;
|
||||
$product['title'] = $productInfo['store_name'];
|
||||
$product['unit_name'] = $productInfo['unit_name'];
|
||||
$product['image'] = $productInfo['image'];
|
||||
$product['images'] = $productInfo['slider_image'];
|
||||
$product['num'] = 0;
|
||||
$product['is_host'] = 0;
|
||||
$product['once_num'] = 0;
|
||||
$product['sort'] = 0;
|
||||
$this->saveData(0, $product);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分商品列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function systemPage(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
* @param int $id
|
||||
* @return array|\think\Model|null
|
||||
*/
|
||||
public function getInfo(int $id)
|
||||
{
|
||||
$info = $this->dao->get($id);
|
||||
if (!$info) {
|
||||
throw new ValidateException('查看的商品不存在!');
|
||||
}
|
||||
if ($info->is_del) {
|
||||
throw new ValidateException('您查看的积分商品已被删除!');
|
||||
}
|
||||
$info['price'] = floatval($info['price']);
|
||||
/** @var StoreDescriptionServices $storeDescriptionServices */
|
||||
$storeDescriptionServices = app()->make(StoreDescriptionServices::class);
|
||||
$info['description'] = $storeDescriptionServices->getDescription(['product_id' => $id, 'type' => 4]);
|
||||
/** @var StoreProductAttrValueServices $storeProductAttrValueServices */
|
||||
$storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
|
||||
$info['attrs'] = $storeProductAttrValueServices->attrList($id, $info['product_id'], 4);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分商品详情
|
||||
* @param int $uid
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function integralDetail(int $uid, int $id)
|
||||
{
|
||||
$storeInfo = $this->dao->getOne(['id' => $id], '*,title as store_name', ['getPrice']);
|
||||
if (!$storeInfo) {
|
||||
throw new ValidateException('商品不存在');
|
||||
} else {
|
||||
$storeInfo = $storeInfo->toArray();
|
||||
}
|
||||
/** @var DiyServices $diyServices */
|
||||
$diyServices = app()->make(DiyServices::class);
|
||||
$infoDiy = $diyServices->getProductDetailDiy();
|
||||
//diy控制参数
|
||||
if (!isset($infoDiy['showService']) || in_array(3, $infoDiy['showService'])) {
|
||||
$storeInfo['specs'] = [];
|
||||
}
|
||||
$siteUrl = sys_config('site_url');
|
||||
$storeInfo['store_name'] = $storeInfo['title'];
|
||||
$storeInfo['image'] = set_file_url($storeInfo['image'], $siteUrl);
|
||||
$storeInfo['image_base'] = set_file_url($storeInfo['image'], $siteUrl);
|
||||
$storeInfo['sale_stock'] = 0;
|
||||
if ($storeInfo['stock'] > 0) $storeInfo['sale_stock'] = 1;
|
||||
/** @var StoreDescriptionServices $storeDescriptionService */
|
||||
$storeDescriptionService = app()->make(StoreDescriptionServices::class);
|
||||
$storeInfo['description'] = $storeDescriptionService->getDescription(['product_id' => $id, 'type' => 4]);
|
||||
$storeInfo['store_label'] = $storeInfo['ensure'] = [];
|
||||
if ($storeInfo['store_label_id']) {
|
||||
/** @var StoreProductLabelServices $storeProductLabelServices */
|
||||
$storeProductLabelServices = app()->make(StoreProductLabelServices::class);
|
||||
$storeInfo['store_label'] = $storeProductLabelServices->getLabelCache($storeInfo['store_label_id'], ['id', 'label_name', 'style_type', 'color', 'bg_color', 'border_color', 'icon']);
|
||||
}
|
||||
if ($storeInfo['ensure_id'] && isset($infoDiy['showService']) && in_array(2, $infoDiy['showService'])) {
|
||||
/** @var StoreProductEnsureServices $storeProductEnsureServices */
|
||||
$storeProductEnsureServices = app()->make(StoreProductEnsureServices::class);
|
||||
$storeInfo['ensure'] = $storeProductEnsureServices->getEnsurCache($storeInfo['ensure_id'], ['id', 'name', 'image', 'desc']);
|
||||
}
|
||||
$storeInfo['small_image'] = get_thumb_water($storeInfo['image']);
|
||||
|
||||
/** @var StoreProductServices $storeProductServices */
|
||||
$storeProductServices = app()->make(StoreProductServices::class);
|
||||
$storeInfo['brand_name'] = $storeProductServices->productIdByBrandName((int)$storeInfo['product_id']);
|
||||
|
||||
$data['storeInfo'] = $storeInfo;
|
||||
|
||||
/** @var StoreProductAttrServices $storeProductAttrServices */
|
||||
$storeProductAttrServices = app()->make(StoreProductAttrServices::class);
|
||||
[$productAttr, $productValue] = $storeProductAttrServices->getProductAttrDetail($id, $uid, 0, 4, $storeInfo['product_id']);
|
||||
$data['productAttr'] = $productAttr;
|
||||
$data['productValue'] = $productValue;
|
||||
$data['site_name'] = sys_config('site_name');
|
||||
$data['share_qrcode'] = sys_config('share_qrcode', 0);
|
||||
$data['product_poster_title'] = sys_config('product_poster_title', '');
|
||||
|
||||
//浏览记录
|
||||
ProductLogJob::dispatch(['visit', ['uid' => $uid, 'id' => $id, 'product_id' => $storeInfo['product_id']], 'integral']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改销量和库存
|
||||
* @param $num
|
||||
* @param $integralId
|
||||
* @return bool
|
||||
*/
|
||||
public function decIntegralStock(int $num, int $integralId, string $unique)
|
||||
{
|
||||
$product_id = $this->dao->value(['id' => $integralId], 'product_id');
|
||||
if ($unique) {
|
||||
/** @var StoreProductAttrValueServices $skuValueServices */
|
||||
$skuValueServices = app()->make(StoreProductAttrValueServices::class);
|
||||
//减去积分商品的sku库存增加销量
|
||||
$res = false !== $skuValueServices->decProductAttrStock($integralId, $unique, $num, 4);
|
||||
|
||||
//积分商品sku
|
||||
$suk = $skuValueServices->value(['unique' => $unique, 'product_id' => $integralId, 'type' => 4], 'suk');
|
||||
//平台商品sku unique
|
||||
$productUnique = $skuValueServices->value(['suk' => $suk, 'product_id' => $product_id, 'type' => 0], 'unique');
|
||||
/** @var StoreProductServices $services */
|
||||
$services = app()->make(StoreProductServices::class);
|
||||
//减去普通商品库存
|
||||
$res = $res && $services->decProductStock($num, $product_id, (string)$productUnique);
|
||||
}
|
||||
//减去积分商品库存
|
||||
$res = $res && false !== $this->dao->decStockIncSales(['id' => $integralId, 'type' => 4], $num);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加库存减销量
|
||||
* @param int $num
|
||||
* @param int $integralId
|
||||
* @param string $unique
|
||||
* @param int $store_id
|
||||
* @return bool
|
||||
*/
|
||||
public function incIntegralStock(int $num, int $integralId, string $unique, int $store_id = 0)
|
||||
{
|
||||
$product_id = $this->dao->value(['id' => $integralId], 'product_id');
|
||||
$res = false;
|
||||
if ($product_id) {
|
||||
if ($unique) {
|
||||
/** @var StoreProductAttrValueServices $skuValueServices */
|
||||
$skuValueServices = app()->make(StoreProductAttrValueServices::class);
|
||||
//增加积分商品的sku库存,减去销量
|
||||
$res = false !== $skuValueServices->incProductAttrStock($integralId, $unique, $num, 4);
|
||||
|
||||
//积分商品sku
|
||||
$suk = $skuValueServices->value(['unique' => $unique, 'product_id' => $integralId, 'type' => 4], 'suk');
|
||||
//平台商品sku unique
|
||||
$productUnique = $skuValueServices->value(['suk' => $suk, 'product_id' => $product_id, 'type' => 0], 'unique');
|
||||
/** @var StoreProductServices $services */
|
||||
$services = app()->make(StoreProductServices::class);
|
||||
//增加普通商品库存
|
||||
$res = $res && $services->incProductStock($num, $product_id, (string)$productUnique);
|
||||
}
|
||||
//增加积分库存
|
||||
$res = $res && false !== $this->dao->incStockDecSales(['id' => $integralId, 'type' => 4], $num);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条积分商品
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIntegralOne($id)
|
||||
{
|
||||
return $this->dao->validProduct($id, '*');
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证积分商品下单库存限量
|
||||
* @param int $uid
|
||||
* @param int $integralId
|
||||
* @param int $num
|
||||
* @param string $unique
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function checkoutProductStock(int $uid, int $integralId, int $num = 1, string $unique = '')
|
||||
{
|
||||
/** @var StoreProductAttrValueServices $attrValueServices */
|
||||
$attrValueServices = app()->make(StoreProductAttrValueServices::class);
|
||||
if ($unique == '') {
|
||||
$unique = $attrValueServices->value(['product_id' => $integralId, 'type' => 4], 'unique');
|
||||
}
|
||||
$StoreIntegralInfo = $this->dao->validProduct($integralId, '*,title as store_name');
|
||||
if (!$StoreIntegralInfo) {
|
||||
throw new ValidateException('该商品已下架或删除');
|
||||
}
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
$userBuyCount = $orderServices->getBuyCount($uid, 4, $integralId);
|
||||
if ($StoreIntegralInfo['once_num'] < $num && $StoreIntegralInfo['once_num'] != -1) {
|
||||
throw new ValidateException('每个订单限购' . $StoreIntegralInfo['once_num'] . '件');
|
||||
}
|
||||
if ($StoreIntegralInfo['num'] < ($userBuyCount + $num) && $StoreIntegralInfo['num'] != -1) {
|
||||
throw new ValidateException('每人总共限购' . $StoreIntegralInfo['num'] . '件');
|
||||
}
|
||||
$attrInfo = $attrValueServices->getOne(['product_id' => $integralId, 'unique' => $unique, 'type' => 4]);
|
||||
if ($num > $attrInfo['quota']) {
|
||||
throw new ValidateException('该商品库存不足' . $num);
|
||||
}
|
||||
$product_stock = $attrValueServices->value(['product_id' => $StoreIntegralInfo['product_id'], 'suk' => $attrInfo['suk'], 'type' => 0], 'stock');
|
||||
if ($product_stock < $num) {
|
||||
throw new ValidateException('该商品库存不足' . $num);
|
||||
}
|
||||
if (!CacheService::checkStock($unique, $num, 4)) {
|
||||
throw new ValidateException('该商品库存不足' . $num);
|
||||
}
|
||||
return [$attrInfo, $unique, $StoreIntegralInfo];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推荐积分商品
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getIntegralList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getList($where, $page, $limit, 'id,product_id,image,title,integral,price,sales,stock');
|
||||
foreach ($list as &$item) {
|
||||
/** @var StoreProductServices $storeProductServices */
|
||||
$storeProductServices = app()->make(StoreProductServices::class);
|
||||
$item['brand_name'] = $storeProductServices->productIdByBrandName((int)$item['product_id']);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部积分商品
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getAllIntegralList(array $where)
|
||||
{
|
||||
$list = $this->dao->getList($where, 0, 0, 'id,image,title,integral,price,sales');
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
230
app/services/activity/integral/UserPointServices.php
Normal file
230
app/services/activity/integral/UserPointServices.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace app\services\activity\integral;
|
||||
|
||||
use app\dao\user\UserBillDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use app\services\user\UserServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use think\annotation\Inject;
|
||||
|
||||
class UserPointServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* UserBillServices constructor.
|
||||
* @param UserBillDao $dao
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserBillDao $dao;
|
||||
|
||||
/**
|
||||
* 积分记录
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public function pointRecord($where)
|
||||
{
|
||||
$where['category'] = 'integral';
|
||||
$status = [
|
||||
'invite_user' => '邀新奖励',
|
||||
'system_add' => '系统增加积分',
|
||||
'system_sub' => '系统减少积分',
|
||||
'gain' => '下单赠送积分',
|
||||
'product_gain' => '购买商品赠送积分',
|
||||
'deduction' => '下单积分抵扣',
|
||||
'lottery_use' => '参与抽奖使用积分',
|
||||
'lottery_add' => '抽奖中奖赠送积分',
|
||||
'order_deduction' => '扣除订单下单赠送积分',
|
||||
'storeIntegral_use' => '积分兑换商品',
|
||||
'pay_product_integral_back' => '返还下单使用积分',
|
||||
'sign' => '签到获得积分',
|
||||
];
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getList($where, '*', $page, $limit);
|
||||
//关联用户
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$uids = array_column($list, 'uid');
|
||||
$nicknameArr = $userServices->getColumn([['uid', 'in', $uids]], 'nickname', 'uid');
|
||||
//关联订单
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
/** @var StoreIntegralOrderServices $integralOrderServices */
|
||||
$integralOrderServices = app()->make(StoreIntegralOrderServices::class);
|
||||
foreach ($list as &$item) {
|
||||
$item['nickname'] = $nicknameArr[$item['uid']] ?? '未知用户';
|
||||
if ($item['type'] == 'gain' || $item['type'] == 'deduction' || $item['type'] == 'product_deduction' || $item['type'] == 'pay_product_integral_back') {
|
||||
$item['relation'] = $orderServices->value(['id' => $item['link_id']], 'order_id');
|
||||
} elseif ($item['type'] == 'storeIntegral_use') {
|
||||
$item['relation'] = $integralOrderServices->value(['id' => $item['link_id']], 'order_id');
|
||||
} else {
|
||||
$item['relation'] = $status[$item['type']];
|
||||
}
|
||||
$item['type_name'] = $status[$item['type']];
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count', 'status');
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分记录备注
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function recordRemark($id, $mark)
|
||||
{
|
||||
if (!$id) throw new AdminException('缺少参数');
|
||||
if ($mark === '') throw new AdminException('请填写备注');
|
||||
if ($this->dao->update($id, ['mark' => $mark])) {
|
||||
return true;
|
||||
} else {
|
||||
throw new AdminException('备注失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单统计基础
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public function getBasic($where)
|
||||
{
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$data['now_point'] = $userServices->sum(['status' => 1], 'integral', true);
|
||||
$data['all_point'] = $this->dao->sum(['category' => 'integral', 'pm' => 1, 'time' => $where['time']], 'number', true);
|
||||
$data['pay_point'] = $this->dao->sum(['category' => 'integral', 'pm' => 0, 'time' => $where['time']], 'number', true);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单趋势
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public function getTrend($where)
|
||||
{
|
||||
$time = explode('-', $where['time']);
|
||||
if (count($time) != 2) throw new AdminException('数据错误');
|
||||
$dayCount = (strtotime($time[1]) - strtotime($time[0])) / 86400 + 1;
|
||||
$data = [];
|
||||
if ($dayCount == 1) {
|
||||
$data = $this->trend($time, 0);
|
||||
} elseif ($dayCount > 1 && $dayCount <= 31) {
|
||||
$data = $this->trend($time, 1);
|
||||
} elseif ($dayCount > 31 && $dayCount <= 92) {
|
||||
$data = $this->trend($time, 3);
|
||||
} elseif ($dayCount > 92) {
|
||||
$data = $this->trend($time, 30);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单趋势
|
||||
* @param $time
|
||||
* @param $num
|
||||
* @param false $excel
|
||||
* @return array
|
||||
*/
|
||||
public function trend($time, $num, $excel = false)
|
||||
{
|
||||
if ($num == 0) {
|
||||
$xAxis = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'];
|
||||
$timeType = '%H';
|
||||
} elseif ($num != 0) {
|
||||
$dt_start = strtotime($time[0]);
|
||||
$dt_end = strtotime($time[1]);
|
||||
while ($dt_start <= $dt_end) {
|
||||
if ($num == 30) {
|
||||
$xAxis[] = date('Y-m', $dt_start);
|
||||
$dt_start = strtotime("+1 month", $dt_start);
|
||||
$timeType = '%Y-%m';
|
||||
} else {
|
||||
$xAxis[] = date('m-d', $dt_start);
|
||||
$dt_start = strtotime("+$num day", $dt_start);
|
||||
$timeType = '%m-%d';
|
||||
}
|
||||
}
|
||||
}
|
||||
$point_add = array_column($this->dao->getPointTrend($time, $timeType, 'add_time', 'sum(number)', 'add'), 'num', 'days');
|
||||
$point_sub = array_column($this->dao->getPointTrend($time, $timeType, 'add_time', 'sum(number)', 'sub'), 'num', 'days');
|
||||
$data = $series = [];
|
||||
foreach ($xAxis as $item) {
|
||||
$data['积分积累'][] = isset($point_add[$item]) ? floatval($point_add[$item]) : 0;
|
||||
$data['积分消耗'][] = isset($point_sub[$item]) ? floatval($point_sub[$item]) : 0;
|
||||
}
|
||||
foreach ($data as $key => $item) {
|
||||
$series[] = [
|
||||
'name' => $key,
|
||||
'data' => $item,
|
||||
'type' => 'line',
|
||||
];
|
||||
}
|
||||
return compact('xAxis', 'series');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单来源
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public function getChannel($where)
|
||||
{
|
||||
$bing_xdata = ['订单赠送', '商品赠送', '后台赠送', '签到获得', '九宫格抽奖'];
|
||||
$color = ['#64a1f4', '#3edeb5', '#70869f', '#ffc653', '#fc7d6a'];
|
||||
$data = ['gain', 'gain', 'system_add', 'sign', 'lottery_add'];
|
||||
$bing_data = [];
|
||||
foreach ($data as $key => $item) {
|
||||
$bing_data[] = [
|
||||
'name' => $bing_xdata[$key],
|
||||
'value' => $this->dao->sum(['pm' => 1, 'type' => $item, 'category' => 'integral', 'time' => $where['time']], 'number', true),
|
||||
'itemStyle' => ['color' => $color[$key]]
|
||||
];
|
||||
}
|
||||
$list = [];
|
||||
$count = array_sum(array_column($bing_data, 'value'));
|
||||
foreach ($bing_data as $key => $item) {
|
||||
$list[] = [
|
||||
'name' => $item['name'],
|
||||
'value' => $item['value'],
|
||||
'percent' => $count != 0 ? bcmul((string)bcdiv((string)$item['value'], (string)$count, 4), '100', 1) : 0,
|
||||
];
|
||||
}
|
||||
array_multisort(array_column($list, 'value'), SORT_DESC, $list);
|
||||
return compact('bing_xdata', 'bing_data', 'list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单类型
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public function getType($where)
|
||||
{
|
||||
$bing_xdata = ['订单抵扣', '九宫格抽奖', '后台减少', '退款退回', '兑换商品'];
|
||||
$color = ['#64a1f4', '#3edeb5', '#70869f', '#ffc653', '#fc7d6a'];
|
||||
$data = ['deduction', 'lottery_use', 'system_sub', 'pay_product_integral_back', 'storeIntegral_use'];
|
||||
$bing_data = [];
|
||||
foreach ($data as $key => $item) {
|
||||
$bing_data[] = [
|
||||
'name' => $bing_xdata[$key],
|
||||
'value' => $this->dao->sum(['type' => $item, 'category' => 'integral', 'time' => $where['time']], 'number', true),
|
||||
'itemStyle' => ['color' => $color[$key]]
|
||||
];
|
||||
}
|
||||
|
||||
$list = [];
|
||||
$count = array_sum(array_column($bing_data, 'value'));
|
||||
foreach ($bing_data as $key => $item) {
|
||||
$list[] = [
|
||||
'name' => $item['name'],
|
||||
'value' => $item['value'],
|
||||
'percent' => $count != 0 ? bcmul((string)bcdiv((string)$item['value'], (string)$count, 4), '100', 1) : 0,
|
||||
];
|
||||
}
|
||||
array_multisort(array_column($list, 'value'), SORT_DESC, $list);
|
||||
return compact('bing_xdata', 'bing_data', 'list');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user