chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
703
app/services/activity/combination/StoreCombinationServices.php
Normal file
703
app/services/activity/combination/StoreCombinationServices.php
Normal file
@@ -0,0 +1,703 @@
|
||||
<?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\combination;
|
||||
|
||||
use app\services\BaseServices;
|
||||
use app\dao\activity\combination\StoreCombinationDao;
|
||||
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\user\UserRelationServices;
|
||||
use app\services\product\product\StoreProductReplyServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use app\services\product\sku\StoreProductAttrServices;
|
||||
use app\services\product\sku\StoreProductAttrValueServices;
|
||||
use app\jobs\product\ProductLogJob;
|
||||
use app\services\user\UserServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\SystemConfigService;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 拼团商品
|
||||
* Class StoreCombinationServices
|
||||
* @package app\services\activity\combination
|
||||
* @mixin StoreCombinationDao
|
||||
*/
|
||||
class StoreCombinationServices extends BaseServices
|
||||
{
|
||||
const THODLCEG = 'ykGUKB';
|
||||
|
||||
/**
|
||||
* 商品活动类型
|
||||
*/
|
||||
const TYPE = 2;
|
||||
|
||||
/**
|
||||
* @var StoreCombinationDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreCombinationDao $dao;
|
||||
|
||||
/**
|
||||
* 获取指定条件下的条数
|
||||
* @param array $where
|
||||
*/
|
||||
public function getCount(array $where)
|
||||
{
|
||||
$this->dao->count($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $productIds
|
||||
* @return mixed
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2022/11/28
|
||||
*/
|
||||
public function getPinkIdsArrayCache(array $productIds)
|
||||
{
|
||||
return $this->dao->cacheTag()->remember(md5('pink_ids_' . json_encode($productIds)), function () use ($productIds) {
|
||||
return $this->dao->getPinkIdsArray($productIds, ['id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取是否有拼团商品
|
||||
* */
|
||||
public function validCombination()
|
||||
{
|
||||
return $this->dao->count([
|
||||
'is_del' => 0,
|
||||
'is_show' => 1,
|
||||
'pinkIngTime' => true
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团商品添加
|
||||
* @param int $id
|
||||
* @param array $data
|
||||
*/
|
||||
public function saveData(int $id, array $data)
|
||||
{
|
||||
/** @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['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;
|
||||
if ($data['product_type'] !== 0) {
|
||||
$data['delivery_type'] = 2;
|
||||
}
|
||||
if (in_array($data['product_type'], [1, 2, 3])) {
|
||||
$data['freight'] = 2;
|
||||
$data['temp_id'] = 0;
|
||||
$data['postage'] = 0;
|
||||
} else {
|
||||
if ($data['freight'] == 1) {
|
||||
$data['temp_id'] = 0;
|
||||
$data['postage'] = 0;
|
||||
} elseif ($data['freight'] == 2) {
|
||||
$data['temp_id'] = 0;
|
||||
} elseif ($data['freight'] == 3) {
|
||||
$data['postage'] = 0;
|
||||
}
|
||||
if ($data['freight'] == 2 && !$data['postage']) {
|
||||
throw new AdminException('请设置运费金额');
|
||||
}
|
||||
if ($data['freight'] == 3 && !$data['temp_id']) {
|
||||
throw new AdminException('请选择运费模版');
|
||||
}
|
||||
}
|
||||
$description = $data['description'];
|
||||
$detail = $data['attrs'];
|
||||
$items = $data['items'];
|
||||
$data['start_time'] = strtotime($data['section_time'][0]);
|
||||
$data['stop_time'] = strtotime($data['section_time'][1]);
|
||||
if ($data['stop_time'] < strtotime(date('Y-m-d', time()))) throw new AdminException('结束时间不能小于今天');
|
||||
$data['image'] = $data['images'][0] ?? '';
|
||||
$data['images'] = json_encode($data['images']);
|
||||
$data['price'] = min(array_column($detail, 'price'));
|
||||
$data['quota'] = $data['quota_show'] = array_sum(array_column($detail, 'quota'));
|
||||
if ($data['quota'] > $productInfo['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) {
|
||||
if ($id) {
|
||||
$res = $this->dao->update($id, $data);
|
||||
if (!$res) throw new AdminException('修改失败');
|
||||
} else {
|
||||
$data['add_time'] = time();
|
||||
$res = $this->dao->save($data);
|
||||
if (!$res) throw new AdminException('添加失败');
|
||||
$id = (int)$res->id;
|
||||
}
|
||||
$storeDescriptionServices->saveDescription((int)$id, $description, 3);
|
||||
$storeProductAttrServices->setItem('store_product_id', $data['product_id']);
|
||||
$skuList = $storeProductAttrServices->validateProductAttr($items, $detail, (int)$id, 3);
|
||||
$storeProductAttrServices->reset();
|
||||
$valueGroup = $storeProductAttrServices->saveProductAttr($skuList, (int)$id, 3);
|
||||
|
||||
$res = true;
|
||||
foreach ($valueGroup as $item) {
|
||||
$res = $res && CacheService::setStock($item['unique'], (int)$item['quota_show'], 3);
|
||||
}
|
||||
if (!$res) {
|
||||
throw new AdminException('占用库存失败');
|
||||
}
|
||||
});
|
||||
|
||||
$this->dao->cacheTag()->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团列表
|
||||
* @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);
|
||||
/** @var StorePinkServices $storePinkServices */
|
||||
$storePinkServices = app()->make(StorePinkServices::class);
|
||||
$countAll = $storePinkServices->getPinkCount([]);
|
||||
$countTeam = $storePinkServices->getPinkCount(['k_id' => 0, 'status' => 2]);
|
||||
$countPeople = $storePinkServices->getPinkCount(['k_id' => 0]);
|
||||
$ids = [];
|
||||
foreach ($list as &$item) {
|
||||
$item['count_people'] = $countPeople[$item['id']] ?? 0;//拼团数量
|
||||
$item['count_people_all'] = $countAll[$item['id']] ?? 0;//参与人数
|
||||
$item['count_people_pink'] = $countTeam[$item['id']] ?? 0;//成团数量
|
||||
$item['stop_status'] = $item['stop_time'] < time() ? 1 : 0;
|
||||
if ($item['is_show']) {
|
||||
if ($item['start_time'] > time()) {
|
||||
$item['start_name'] = '未开始';
|
||||
} else if ($item['stop_time'] < time()) {
|
||||
$item['start_name'] = '已结束';
|
||||
$item['is_show'] = 0;
|
||||
$ids[] = $item['id'];
|
||||
} else if ($item['stop_time'] > time() && $item['start_time'] < time()) {
|
||||
$item['start_name'] = '进行中';
|
||||
}
|
||||
} else {
|
||||
$item['start_name'] = '已结束';
|
||||
}
|
||||
}
|
||||
foreach ($ids as $id) {
|
||||
$this->dao->update($id, ['is_show' => 0]);
|
||||
app()->make(StorePinkServices::class)->update(['cid' => $id, 'status' => 1], ['stop_time' => time()]);
|
||||
}
|
||||
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('您查看的团团商品已被删除!');
|
||||
}
|
||||
if ($info['start_time'])
|
||||
$start_time = date('Y-m-d H:i:s', $info['start_time']);
|
||||
|
||||
if ($info['stop_time'])
|
||||
$stop_time = date('Y-m-d H:i:s', $info['stop_time']);
|
||||
if (isset($start_time) && isset($stop_time))
|
||||
$info['section_time'] = [$start_time, $stop_time];
|
||||
else
|
||||
$info['section_time'] = [];
|
||||
unset($info['start_time'], $info['stop_time']);
|
||||
$info['price'] = floatval($info['price']);
|
||||
$info['postage'] = floatval($info['postage']);
|
||||
$info['weight'] = floatval($info['weight']);
|
||||
$info['volume'] = floatval($info['volume']);
|
||||
if (!$info['delivery_type']) {
|
||||
$info['delivery_type'] = [1];
|
||||
}
|
||||
if ($info['postage']) {
|
||||
$info['freight'] = 2;
|
||||
} elseif ($info['temp_id']) {
|
||||
$info['freight'] = 3;
|
||||
} else {
|
||||
$info['freight'] = 1;
|
||||
}
|
||||
/** @var StoreDescriptionServices $storeDescriptionServices */
|
||||
$storeDescriptionServices = app()->make(StoreDescriptionServices::class);
|
||||
$info['description'] = $storeDescriptionServices->getDescription(['product_id' => $id, 'type' => 3]);
|
||||
/** @var StoreProductAttrValueServices $storeProductAttrValueServices */
|
||||
$storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
|
||||
$info['attrs'] = $storeProductAttrValueServices->attrList($id, $info['product_id'], 3);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取拼团数据列表
|
||||
* @return array
|
||||
* @throws \ReflectionException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getCombinationList()
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
/** @var StoreProductServices $storeProductServices */
|
||||
$storeProductServices = app()->make(StoreProductServices::class);
|
||||
|
||||
$field = 'id,title,image,price,product_id,people,quota,quota_show,stock';
|
||||
$list = $this->dao->combinationList(['is_del' => 0, 'is_show' => 1, 'pinkIngTime' => true, 'storeProductId' => true], $field, $page, $limit);
|
||||
foreach ($list as &$item) {
|
||||
$item['image'] = set_file_url($item['image']);
|
||||
$item['price'] = floatval($item['price']);
|
||||
$item['product_price'] = floatval($item['product_price']);
|
||||
$item['pink_count'] = max((int)bcsub((string)$item['quota_show'], (string)$item['quota'], 0), 0);
|
||||
$item['brand_name'] = $storeProductServices->productIdByBrandName((int)$item['product_id']);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团商品详情
|
||||
* @param int $uid
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \Throwable
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function combinationDetail(int $uid, int $id)
|
||||
{
|
||||
$storeInfo = $this->dao->cacheTag()->remember('' . $id, function () use ($id) {
|
||||
$storeInfo = $this->dao->getOne(['id' => $id], '*,title as store_name', ['descriptions', 'total']);
|
||||
if (!$storeInfo) {
|
||||
throw new ValidateException('商品不存在');
|
||||
} else {
|
||||
$storeInfo = $storeInfo->toArray();
|
||||
}
|
||||
return $storeInfo;
|
||||
}, 600);
|
||||
/** @var DiyServices $diyServices */
|
||||
$diyServices = app()->make(DiyServices::class);
|
||||
$infoDiy = $diyServices->getProductDetailDiy();
|
||||
//diy控制参数
|
||||
if (!isset($infoDiy['showService']) || in_array(3, $infoDiy['showService'])) {
|
||||
$storeInfo['specs'] = [];
|
||||
}
|
||||
$configData = SystemConfigService::more(['site_url', 'routine_contact_type', 'site_name', 'share_qrcode', 'store_self_mention', 'store_func_status', 'product_poster_title']);
|
||||
$siteUrl = $configData['site_url'] ?? '';
|
||||
$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 StoreProductServices $storeProductServices */
|
||||
$storeProductServices = app()->make(StoreProductServices::class);
|
||||
$productInfo = $storeProductServices->getCacheProductInfo((int)$storeInfo['product_id']);
|
||||
$storeInfo['brand_name'] = $storeProductServices->productIdByBrandName((int)$storeInfo['product_id'], $productInfo);
|
||||
$delivery_type = $storeInfo['delivery_type'] ?? $productInfo['delivery_type'];
|
||||
$storeInfo['delivery_type'] = is_string($delivery_type) ? explode(',', $delivery_type) : $delivery_type;
|
||||
$storeInfo['product_show'] = $productInfo['is_show']; // 商品是否上架
|
||||
/**
|
||||
* 判断配送方式
|
||||
*/
|
||||
$storeInfo['delivery_type'] = $storeProductServices->getDeliveryType($storeInfo['type'], $storeInfo['relation_id'], $storeInfo['delivery_type']);
|
||||
$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']);
|
||||
}
|
||||
|
||||
/** @var UserRelationServices $userRelationServices */
|
||||
$userRelationServices = app()->make(UserRelationServices::class);
|
||||
$storeInfo['userCollect'] = $userRelationServices->isProductRelationCache(['uid' => $uid, 'relation_id' => $storeInfo['product_id'], 'type' => 'collect', 'category' => UserRelationServices::CATEGORY_PRODUCT]);
|
||||
$storeInfo['userLike'] = 0;
|
||||
|
||||
|
||||
$storeInfo['small_image'] = get_thumb_water($storeInfo['image']);
|
||||
$data['storeInfo'] = $storeInfo;
|
||||
|
||||
/** @var StorePinkServices $pinkService */
|
||||
$pinkService = app()->make(StorePinkServices::class);
|
||||
[$pink, $pindAll] = $pinkService->getPinkList($id, true, 1);//拼团进行中列表
|
||||
$data['pink_ok_list'] = $pinkService->getPinkOkList($uid);
|
||||
$data['pink_ok_sum'] = $pinkService->getPinkOkSumTotalNum();
|
||||
$data['pink'] = $pink;
|
||||
$data['pindAll'] = $pindAll;
|
||||
|
||||
/** @var StoreOrderServices $storeOrderServices */
|
||||
$storeOrderServices = app()->make(StoreOrderServices::class);
|
||||
$data['buy_num'] = $storeOrderServices->getBuyCount($uid, 3, $id);
|
||||
|
||||
$data['reply'] = [];
|
||||
$data['replyChance'] = $data['replyCount'] = 0;
|
||||
if (isset($infoDiy['showReply']) && $infoDiy['showReply']) {
|
||||
/** @var StoreProductReplyServices $storeProductReplyService */
|
||||
$storeProductReplyService = app()->make(StoreProductReplyServices::class);
|
||||
$reply = $storeProductReplyService->getRecProductReplyCache($storeInfo['product_id'], (int)($infoDiy['replyNum'] ?? 1));
|
||||
$data['reply'] = $reply ? get_thumb_water($reply, 'small', ['pics']) : [];
|
||||
[$replyCount, $goodReply, $replyChance] = $storeProductReplyService->getProductReplyData((int)$storeInfo['product_id']);
|
||||
$data['replyChance'] = $replyChance;
|
||||
$data['replyCount'] = $replyCount;
|
||||
}
|
||||
/** @var StoreProductAttrServices $storeProductAttrServices */
|
||||
$storeProductAttrServices = app()->make(StoreProductAttrServices::class);
|
||||
[$productAttr, $productValue] = $storeProductAttrServices->getProductAttrDetailCache($id, $uid, 0, 3, $storeInfo['product_id'], $productInfo);
|
||||
$data['productAttr'] = $productAttr;
|
||||
$data['productValue'] = $productValue;
|
||||
$data['routine_contact_type'] = sys_config('routine_contact_type', 0);
|
||||
$data['store_func_status'] = (int)($configData['store_func_status'] ?? 1);//门店是否开启
|
||||
$data['store_self_mention'] = $data['store_func_status'] ? (int)($configData['store_self_mention'] ?? 0) : 0;//门店自提是否开启
|
||||
$data['site_name'] = sys_config('site_name');
|
||||
$data['share_qrcode'] = sys_config('share_qrcode', 0);
|
||||
$data['product_poster_title'] = $configData['product_poster_title'] ?? '';
|
||||
//浏览记录
|
||||
ProductLogJob::dispatch(['visit', ['uid' => $uid, 'id' => $id, 'product_id' => $storeInfo['product_id']], 'combination']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改销量和库存
|
||||
* @param int $num
|
||||
* @param int $CombinationId
|
||||
* @param string $unique
|
||||
* @param int $store_id
|
||||
* @return bool
|
||||
*/
|
||||
public function decCombinationStock(int $num, int $CombinationId, string $unique, int $store_id = 0)
|
||||
{
|
||||
$product_id = $this->dao->value(['id' => $CombinationId], 'product_id');
|
||||
$res = false;
|
||||
if ($product_id) {
|
||||
if ($unique) {
|
||||
/** @var StoreProductAttrValueServices $skuValueServices */
|
||||
$skuValueServices = app()->make(StoreProductAttrValueServices::class);
|
||||
//减去拼团商品的sku库存增加销量
|
||||
$res = false !== $skuValueServices->decProductAttrStock($CombinationId, $unique, $num, 3);
|
||||
|
||||
//拼团商品sku
|
||||
$sku = $skuValueServices->value(['product_id' => $CombinationId, 'unique' => $unique, 'type' => 3], 'suk');
|
||||
//平台普通商品sku unique
|
||||
$productUnique = $skuValueServices->value(['suk' => $sku, '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' => $CombinationId, 'type' => 3], $num);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加库存减销量
|
||||
* @param int $num
|
||||
* @param int $CombinationId
|
||||
* @param string $unique
|
||||
* @param int $store_id
|
||||
* @return bool
|
||||
*/
|
||||
public function incCombinationStock(int $num, int $CombinationId, string $unique, int $store_id = 0)
|
||||
{
|
||||
$product_id = $this->dao->value(['id' => $CombinationId], 'product_id');
|
||||
$res = false;
|
||||
if ($product_id) {
|
||||
if ($unique) {
|
||||
/** @var StoreProductAttrValueServices $skuValueServices */
|
||||
$skuValueServices = app()->make(StoreProductAttrValueServices::class);
|
||||
//增加拼团商品的sku库存,减去销量
|
||||
$res = false !== $skuValueServices->incProductAttrStock($CombinationId, $unique, $num, 3);
|
||||
|
||||
//拼团商品sku
|
||||
$suk = $skuValueServices->value(['unique' => $unique, 'product_id' => $CombinationId, 'type' => 3], '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' => $CombinationId, 'type' => 3], $num);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条拼团数据
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCombinationOne($id, $field = '*')
|
||||
{
|
||||
return $this->dao->validProduct($id, $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取拼团详情
|
||||
* @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 getPinkInfo(int $uid, int $id)
|
||||
{
|
||||
$is_ok = 0;//判断拼团是否完成
|
||||
$userBool = 0;//判断当前用户是否在团内 0未在 1在
|
||||
$pinkBool = 0;//判断拼团是否成功 0未在 1在
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$user = $userServices->getUserCacheInfo($uid);
|
||||
if (!$user) {
|
||||
throw new ValidateException('用户不存在');
|
||||
}
|
||||
/** @var StorePinkServices $pinkService */
|
||||
$pinkService = app()->make(StorePinkServices::class);
|
||||
$pink = $pinkService->getPinkUserOne($id);
|
||||
if (!$pink) throw new ValidateException('参数错误');
|
||||
$pink = $pink->toArray();
|
||||
if (isset($pink['is_refund']) && $pink['is_refund']) {
|
||||
if ($pink['is_refund'] != $pink['id']) {
|
||||
$id = $pink['is_refund'];
|
||||
return $this->getPinkInfo($uid, $id);
|
||||
} else {
|
||||
throw new ValidateException('订单已退款');
|
||||
}
|
||||
}
|
||||
[$pinkAll, $pinkT, $count, $idAll, $uidAll] = $pinkService->getPinkMemberAndPinkK($pink);
|
||||
if ($pinkT['status'] == 2) {
|
||||
$pinkBool = 1;
|
||||
$is_ok = 1;
|
||||
} else if ($pinkT['status'] == 3) {
|
||||
$pinkBool = -1;
|
||||
$is_ok = 0;
|
||||
} else {
|
||||
if ($count < 1) {//组团完成
|
||||
$is_ok = 1;
|
||||
$pinkBool = $pinkService->pinkComplete($uidAll, $idAll, $user['uid'], $pinkT);
|
||||
} else {
|
||||
$pinkBool = $pinkService->pinkFail($pinkAll, $pinkT, $pinkBool);
|
||||
}
|
||||
//更新pinkT 数据 可能成功或失败
|
||||
$pinkT = $pinkService->getPinkUserOne($pinkT['id']);
|
||||
}
|
||||
if (!empty($pinkAll)) {
|
||||
foreach ($pinkAll as $v) {
|
||||
if ($v['uid'] == $user['uid']) $userBool = 1;
|
||||
}
|
||||
}
|
||||
if ($pinkT['uid'] == $user['uid']) $userBool = 1;
|
||||
$combinationOne = $this->getCombinationOne($pink['cid']);
|
||||
if (!$combinationOne) {
|
||||
throw new ValidateException('拼团不存在或已下架,请手动申请退款!');
|
||||
}
|
||||
$combinationOne = $combinationOne->hidden(['mer_id', 'images', 'attr', 'info', 'sort', 'sales', 'stock', 'add_time', 'is_host', 'is_show', 'is_del', 'combination', 'mer_use', 'is_postage', 'postage', 'start_time', 'stop_time', 'cost', 'browse'])->toArray();
|
||||
$combinationOne['pink_count'] = max((int)bcsub((string)$combinationOne['quota_show'], (string)$combinationOne['quota'], 0), 0);
|
||||
|
||||
$data['userInfo']['uid'] = $user['uid'];
|
||||
$data['userInfo']['nickname'] = $user['nickname'];
|
||||
$data['userInfo']['avatar'] = $user['avatar'];
|
||||
$data['is_ok'] = $is_ok;
|
||||
$data['userBool'] = $userBool;
|
||||
$data['pinkBool'] = $pinkBool;
|
||||
$delivery_type = $combinationOne['delivery_type'] ?? [];
|
||||
$combinationOne['delivery_type'] = is_string($delivery_type) ? explode(',', $delivery_type) : $delivery_type;
|
||||
$data['store_combination'] = $combinationOne;
|
||||
$data['pinkT'] = $pinkT;
|
||||
$data['pinkAll'] = $pinkAll;
|
||||
$data['count'] = $count <= 0 ? 0 : $count;
|
||||
$data['store_combination_host'] = $this->dao->getCombinationHost();
|
||||
foreach ($data['store_combination_host'] as &$item) {
|
||||
$item['pink_count'] = max((int)bcsub((string)$item['quota_show'], (string)$item['quota'], 0), 0);
|
||||
}
|
||||
$data['current_pink_order'] = $pinkService->getCurrentPink($id, $user['uid']);
|
||||
|
||||
/** @var StoreProductAttrServices $storeProductAttrServices */
|
||||
$storeProductAttrServices = app()->make(StoreProductAttrServices::class);
|
||||
/** @var StoreProductAttrValueServices $storeProductAttrValueServices */
|
||||
$storeProductAttrValueServices = app()->make(StoreProductAttrValueServices::class);
|
||||
|
||||
[$productAttr, $productValue] = $storeProductAttrServices->getProductAttrDetail($combinationOne['id'], $user['uid'], 0, 3, $combinationOne['product_id']);
|
||||
foreach ($productValue as $k => $v) {
|
||||
$productValue[$k]['product_stock'] = $storeProductAttrValueServices->value(['product_id' => $combinationOne['product_id'], 'suk' => $v['suk'], 'type' => 0], 'stock');
|
||||
}
|
||||
$data['store_combination']['productAttr'] = $productAttr;
|
||||
$data['store_combination']['productValue'] = $productValue;
|
||||
$data['store_func_status'] = (int)(sys_config('store_func_status', 1));
|
||||
$data['store_self_mention'] = $data['store_func_status'] ? (int)(sys_config('store_self_mention', 0)) : 0;//门店自提是否开启
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证拼团下单库存限量
|
||||
* @param int $uid
|
||||
* @param int $combinationId
|
||||
* @param int $cartNum
|
||||
* @param string $unique
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function checkCombinationStock(int $uid, int $combinationId, int $cartNum = 1, string $unique = '')
|
||||
{
|
||||
/** @var StoreProductAttrValueServices $attrValueServices */
|
||||
$attrValueServices = app()->make(StoreProductAttrValueServices::class);
|
||||
if ($unique == '') {
|
||||
$unique = $attrValueServices->value(['product_id' => $combinationId, 'type' => 3], 'unique');
|
||||
}
|
||||
$attrInfo = $attrValueServices->getOne(['product_id' => $combinationId, 'unique' => $unique, 'type' => 3]);
|
||||
if (!$attrInfo || $attrInfo['product_id'] != $combinationId) {
|
||||
throw new ValidateException('请选择有效的商品属性');
|
||||
}
|
||||
$StoreCombinationInfo = $productInfo = $this->getCombinationOne($combinationId, '*,title as store_name');
|
||||
if (!$StoreCombinationInfo) {
|
||||
throw new ValidateException('该商品已下架或删除');
|
||||
}
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
$userBuyCount = $orderServices->getBuyCount($uid, 3, $combinationId);
|
||||
if ($StoreCombinationInfo['once_num'] < $cartNum) {
|
||||
throw new ValidateException('每个订单限购' . $StoreCombinationInfo['once_num'] . '件');
|
||||
}
|
||||
if ($StoreCombinationInfo['num'] < ($userBuyCount + $cartNum)) {
|
||||
throw new ValidateException('每人总共限购' . $StoreCombinationInfo['num'] . '件');
|
||||
}
|
||||
|
||||
if ($cartNum > $attrInfo['quota']) {
|
||||
throw new ValidateException('该商品库存不足' . $cartNum);
|
||||
}
|
||||
return [$attrInfo, $unique, $productInfo];
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团统计
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public function combinationStatistics(int $id)
|
||||
{
|
||||
/** @var StorePinkServices $pinkServices */
|
||||
$pinkServices = app()->make(StorePinkServices::class);
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
$people_count = $pinkServices->getDistinctCount([['cid', '=', $id]], 'uid', false);
|
||||
$spread_count = $pinkServices->getDistinctCount([['cid', '=', $id], ['k_id', '>', 0]], 'uid', false);
|
||||
$start_count = $pinkServices->count(['cid' => $id, 'k_id' => 0]);
|
||||
$success_count = $pinkServices->count(['cid' => $id, 'k_id' => 0, 'status' => 2]);
|
||||
$pay_price = $orderServices->sum(['type' => 3, 'activity_id' => $id, 'paid' => 1, 'pid' => [0, -1]], 'pay_price', true);
|
||||
$pay_count = $orderServices->getDistinctCount(['type' => 3, 'activity_id' => $id, 'paid' => 1, 'pid' => [0, -1]], 'uid');
|
||||
return compact('people_count', 'spread_count', 'start_count', 'success_count', 'pay_price', 'pay_count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团订单
|
||||
* @param $id
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function combinationStatisticsOrder(int $id, array $where = [])
|
||||
{
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $orderServices->activityStatisticsOrder($id, 3, $where, $page, $limit);
|
||||
$where['type'] = 3;
|
||||
$where['activity_id'] = $id;
|
||||
$count = $orderServices->count($where);
|
||||
foreach ($list as &$item) {
|
||||
if ($item['is_del'] || $item['is_system_del']) {
|
||||
$item['status'] = '已删除';
|
||||
} else if ($item['paid'] == 0 && $item['status'] == 0) {
|
||||
$item['status'] = '待付款';
|
||||
} else if ($item['paid'] == 1 && $item['status'] == 4 && in_array($item['shipping_type'], [1, 3]) && $item['refund_status'] == 0) {
|
||||
$item['status'] = '部分发货';
|
||||
} else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
|
||||
$item['status'] = '已退款';
|
||||
} else if ($item['paid'] == 1 && $item['status'] == 5 && $item['refund_status'] == 0) {
|
||||
$item['status'] = $item['shipping_type'] == 2 ? '部分核销' : '部分收货';
|
||||
$item['_status'] = 12;//已支付 部分核销
|
||||
} else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
|
||||
$item['status'] = '申请退款';
|
||||
} else if ($item['paid'] == 1 && $item['refund_status'] == 4) {
|
||||
$item['status'] = '退款中';
|
||||
} else if ($item['paid'] == 1 && $item['status'] == 0 && in_array($item['shipping_type'], [1, 3]) && $item['refund_status'] == 0) {
|
||||
$item['status'] = '未发货';
|
||||
$item['_status'] = 2;//已支付 未发货
|
||||
} else if ($item['paid'] == 1 && in_array($item['status'], [0, 1]) && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
|
||||
$item['status'] = '未核销';
|
||||
} else if ($item['paid'] == 1 && in_array($item['status'], [1, 5]) && in_array($item['shipping_type'], [1, 3]) && $item['refund_status'] == 0) {
|
||||
$item['status'] = '待收货';
|
||||
} else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
|
||||
$item['status'] = '待评价';
|
||||
} else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
|
||||
$item['status'] = '已完成';
|
||||
} else if ($item['paid'] == 1 && $item['refund_status'] == 3) {
|
||||
$item['status'] = '部分退款';
|
||||
} else {
|
||||
$item['status'] = '未知';
|
||||
}
|
||||
$item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
|
||||
$item['pay_time'] = $item['pay_time'] ? date('Y-m-d H:i:s', $item['pay_time']) : '';
|
||||
}
|
||||
return compact('list', 'count');
|
||||
}
|
||||
}
|
||||
806
app/services/activity/combination/StorePinkServices.php
Normal file
806
app/services/activity/combination/StorePinkServices.php
Normal file
@@ -0,0 +1,806 @@
|
||||
<?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\combination;
|
||||
|
||||
use app\jobs\activity\pink\AuthPinkFail;
|
||||
use app\services\BaseServices;
|
||||
use app\dao\activity\combination\StorePinkDao;
|
||||
use app\services\order\StoreOrderRefundServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use app\services\other\QrcodeServices;
|
||||
use app\services\user\UserServices;
|
||||
use app\jobs\activity\pink\PinkJob;
|
||||
use app\jobs\notice\template\RoutineTemplateJob;
|
||||
use crmeb\services\CacheService;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 拼团
|
||||
* Class StorePinkServices
|
||||
* @package app\services\activity\combination
|
||||
* @mixin StorePinkDao
|
||||
*/
|
||||
class StorePinkServices extends BaseServices
|
||||
{
|
||||
|
||||
const OXPJOHRW = '/G6B.Z';
|
||||
|
||||
/**
|
||||
* @var StorePinkDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StorePinkDao $dao;
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function systemPage(array $where)
|
||||
{
|
||||
$where['k_id'] = 0;
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getList($where, $page, $limit);
|
||||
$time = time();
|
||||
foreach ($list as &$item) {
|
||||
$item['count_people'] = $this->dao->count(['k_id' => $item['id']]) + 1;
|
||||
//状态为进行中,实际已经结束的
|
||||
if ($item['status'] == 1 && $item['stop_time'] < $time) {
|
||||
$item['status'] = $item['count_people'] >= $item['people'] ? 2 : 3;
|
||||
}
|
||||
$item['_add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', (int)$item['add_time']) : '';
|
||||
$item['_stop_time'] = $item['stop_time'] ? date('Y-m-d H:i:s', (int)$item['stop_time']) : '';
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团列表头部
|
||||
* @return array
|
||||
*/
|
||||
public function getStatistics()
|
||||
{
|
||||
$res = [
|
||||
['col' => 6, 'count' => $this->dao->count(), 'name' => '参与人数(人)', 'className' => 'ios-speedometer-outline'],
|
||||
['col' => 6, 'count' => $this->dao->count(['k_id' => 0, 'status' => 2]), 'name' => '成团数量(个)', 'className' => 'md-rose'],
|
||||
];
|
||||
return compact('res');
|
||||
}
|
||||
|
||||
/**
|
||||
* 参团人员
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function getPinkMember(int $id)
|
||||
{
|
||||
return $this->dao->getList(['k_id' => $id, 'is_refund' => 0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团退款
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public function setRefundPink($order)
|
||||
{
|
||||
$res = true;
|
||||
if ($order['pink_id']) {
|
||||
$id = $order['pink_id'];
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
//正在拼团 团长
|
||||
$count = $this->dao->getOne(['id' => $id, 'uid' => $order['uid']]);
|
||||
//正在拼团 团员
|
||||
$countY = $this->dao->getOne(['k_id' => $id, 'uid' => $order['uid']]);
|
||||
if (!$count && !$countY) {
|
||||
return $res;
|
||||
}
|
||||
if ($count) {//团长
|
||||
//判断团内是否还有其他人 如果有 团长为第二个进团的人
|
||||
$kCount = $this->dao->getPinking(['k_id' => $id]);
|
||||
if ($kCount) {
|
||||
$res11 = $this->dao->update($id, ['k_id' => $kCount['id']], 'k_id');
|
||||
$res12 = $this->dao->update($kCount['id'], ['stop_time' => $count['add_time'] + 86400]);
|
||||
$res1 = $res11 && $res12;
|
||||
$res2 = $this->dao->update($id, ['stop_time' => time() - 1, 'is_refund' => $kCount['id'], 'status' => 3]);
|
||||
} else {
|
||||
$res1 = true;
|
||||
$res2 = $this->dao->update($id, ['stop_time' => time() - 1, 'is_refund' => $id, 'status' => 3]);
|
||||
}
|
||||
//修改结束时间为前一秒
|
||||
$res = $res1 && $res2;
|
||||
} else if ($countY) {//团员
|
||||
$res = $this->dao->update($countY['id'], ['stop_time' => time() - 1, 'is_refund' => $id, 'status' => 3]);
|
||||
}
|
||||
if ($res) {
|
||||
CacheService::setStock(md5((string)$id), 1, 3, false);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团详情查看拼团列表
|
||||
* @param int $id
|
||||
* @param bool $type
|
||||
* @param int $status
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getPinkList(int $id, bool $type, int $status = -1)
|
||||
{
|
||||
$where['cid'] = $id;
|
||||
$where['k_id'] = 0;
|
||||
$where['is_refund'] = 0;
|
||||
if ($status !== -1) {
|
||||
$where['status'] = $status;
|
||||
}
|
||||
$list = $this->dao->pinkList($where);
|
||||
$ids = array_column($list, 'id');
|
||||
$counts = $this->dao->getPinkPeopleCount($ids);
|
||||
if ($type) {
|
||||
$pinkAll = [];
|
||||
foreach ($list as &$v) {
|
||||
$v['count'] = $v['people'] - $counts[$v['id']];
|
||||
$v['h'] = date('H', (int)$v['stop_time']);
|
||||
$v['i'] = date('i', (int)$v['stop_time']);
|
||||
$v['s'] = date('s', (int)$v['stop_time']);
|
||||
$pinkAll[] = $v['id'];//开团团长ID
|
||||
$v['stop_time'] = (int)$v['stop_time'];
|
||||
}
|
||||
return [$list, $pinkAll];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取成团列表信息
|
||||
* @param int $uid
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getPinkOkList(int $uid)
|
||||
{
|
||||
$list = $this->dao->successList($uid, 'id,nickname', 0, 100);
|
||||
$msg = [];
|
||||
foreach ($list as &$item) {
|
||||
if (isset($item['nickname'])) $msg[] = $item['nickname'] .= '拼团成功';
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找拼团信息
|
||||
* @param $pink
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getPinkMemberAndPinkK($pink)
|
||||
{
|
||||
//查找拼团团员和团长
|
||||
if ($pink['k_id']) {
|
||||
$pinkAll = $this->dao->getPinkUserList(['k_id' => $pink['k_id'], 'is_refund' => 0]);
|
||||
$pinkT = $this->dao->getPinkUserOne($pink['k_id']);
|
||||
} else {
|
||||
$pinkAll = $this->dao->getPinkUserList(['k_id' => $pink['id'], 'is_refund' => 0]);
|
||||
$pinkT = $pink;
|
||||
}
|
||||
$count = count($pinkAll) + 1;
|
||||
$count = $pinkT['people'] - $count;
|
||||
$idAll = [];
|
||||
$uidAll = [];
|
||||
//收集拼团用户id和拼团id
|
||||
foreach ($pinkAll as $k => $v) {
|
||||
$idAll[$k] = $v['id'];
|
||||
$uidAll[$k] = $v['uid'];
|
||||
}
|
||||
$idAll[] = $pinkT['id'];
|
||||
$uidAll[] = $pinkT['uid'];
|
||||
return [$pinkAll, $pinkT, $count, $idAll, $uidAll];
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团失败
|
||||
* @param $pinkAll
|
||||
* @param $pinkT
|
||||
* @param $pinkBool
|
||||
* @param bool $isRunErr
|
||||
* @param bool $isIds
|
||||
* @return array|int
|
||||
*/
|
||||
public function pinkFail($pinkAll, $pinkT, $pinkBool, $isRunErr = true, $isIds = false)
|
||||
{
|
||||
/** @var StoreOrderServices $orderService */
|
||||
$orderService = app()->make(StoreOrderServices::class);
|
||||
/** @var StoreOrderRefundServices $orderRefundService */
|
||||
$orderRefundService = app()->make(StoreOrderRefundServices::class);
|
||||
$pinkIds = [];
|
||||
try {
|
||||
if ($pinkT['stop_time'] < time()) {//拼团时间超时 退款
|
||||
$virtual = $this->virtualCombination($pinkT['id']);
|
||||
if ($virtual) return 1;
|
||||
$pinkBool = -1;
|
||||
$pinkAll[] = $pinkT;
|
||||
$oids = array_column($pinkAll, 'order_id_key');
|
||||
$orders = $orderService->getColumn([['id', 'in', $oids]], '*', 'id');
|
||||
$refundData = [
|
||||
'refund_reason' => '拼团时间超时',
|
||||
'refund_explain' => '拼团时间超时',
|
||||
'refund_img' => json_encode([]),
|
||||
];
|
||||
$refundeOrder = $orderRefundService->getColumn([
|
||||
['store_order_id', 'IN', $oids],
|
||||
['refund_type', 'in', [0, 1, 2, 4, 5]],
|
||||
['is_cancel', '=', 0],
|
||||
['is_del', '=', 0]
|
||||
], 'id,store_order_id', 'store_order_id');
|
||||
foreach ($pinkAll as $v) {
|
||||
if (isset($orders[$v['order_id_key']]) && $order = $orders[$v['order_id_key']]) {
|
||||
if (in_array($v['order_id_key'], $refundeOrder)) {
|
||||
continue;
|
||||
}
|
||||
$res1 = $res2 = true;
|
||||
try {
|
||||
//申请退款
|
||||
$refundId = $orderRefundService->applyRefund((int)$order['id'], (int)$order['uid'], $order, [], 1, (float)$order['pay_price'], $refundData);
|
||||
if ($refundId) {//申请退款成功,自动退款
|
||||
$refund_data = ['pay_price' => $order['pay_price'], 'refund_price' => $order['pay_price']];
|
||||
$res1 = $orderRefundService->agreeRefund((int)$refundId, $refund_data);
|
||||
|
||||
//修改退款单状态
|
||||
$res1 = $res1 && $orderRefundService->update((int)$refundId, ['refund_type' => 6, 'refunded_price' => $order['pay_price'], 'refunded_time' => time()]);
|
||||
//修改订单状态
|
||||
$res1 = $res1 && $orderService->update((int)$order['id'], ['refund_status' => 2, 'refund_type' => 6]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
}
|
||||
|
||||
$res2 = $this->dao->getCount([['uid', '=', $v['uid']], ['is_tpl', '=', 0], ['k_id|id', '=', $pinkT['id']]]);
|
||||
if ($res1 && $res2) {
|
||||
if ($isIds) $pinkIds[] = $v['id'];
|
||||
$this->orderPinkAfterNo($pinkT['uid'], $pinkT['id'], false, $orders[$v['order_id_key']]['is_channel']);
|
||||
} else {
|
||||
if ($isRunErr) return $pinkBool;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($isIds) return $pinkIds;
|
||||
} catch (\Exception $e) {
|
||||
\think\facade\Log::error('拼团超时处理失败,原因:' . $e->getMessage());
|
||||
}
|
||||
return $pinkBool;
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败发送消息和修改状态
|
||||
* @param $uid
|
||||
* @param $pid
|
||||
* @param bool $isRemove
|
||||
* @param $channel
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function orderPinkAfterNo($uid, $pid, $isRemove = false, $channel = '')
|
||||
{
|
||||
$this->dao->update([['id|k_id', '=', $pid]], ['status' => 3, 'stop_time' => time()]);
|
||||
$pink = $this->dao->getOne([['id|k_id', '=', $pid], ['uid', '=', $uid]], '*', ['getProduct']);
|
||||
if ($isRemove) {
|
||||
event('notice.notice', [['uid' => $uid, 'pink' => $pink, 'user_type' => $channel], 'send_order_pink_clone']);
|
||||
} else {
|
||||
event('notice.notice', [['uid' => $uid, 'pink' => $pink, 'user_type' => $channel], 'send_order_pink_fial']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断拼团状态
|
||||
* @param $pinkId
|
||||
* @return bool
|
||||
*/
|
||||
public function isPinkStatus($pinkId)
|
||||
{
|
||||
if (!$pinkId) return false;
|
||||
$stopTime = $this->dao->value(['id' => $pinkId], 'stop_time');
|
||||
if ($stopTime < time()) return true; //拼团结束
|
||||
else return false;//拼团未结束
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取拼团order_id
|
||||
* @param int $id
|
||||
* @param int $uid
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCurrentPink(int $id, int $uid)
|
||||
{
|
||||
$oid = $this->dao->value(['id' => $id, 'uid' => $uid], 'order_id_key');
|
||||
if (!$oid) $oid = $this->dao->value(['k_id' => $id, 'uid' => $uid], 'order_id_key');
|
||||
/** @var StoreOrderServices $orderService */
|
||||
$orderService = app()->make(StoreOrderServices::class);
|
||||
return $orderService->value(['id' => $oid], 'order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团成功
|
||||
* @param $uidAll
|
||||
* @param $idAll
|
||||
* @param $uid
|
||||
* @param $pinkT
|
||||
* @return int
|
||||
*/
|
||||
public function pinkComplete($uidAll, $idAll, $uid, $pinkT)
|
||||
{
|
||||
$pinkBool = 6;
|
||||
try {
|
||||
if (!$this->dao->getCount([['id', 'in', $idAll], ['is_refund', '=', 1]])) {
|
||||
$this->dao->update([['id', 'in', $idAll]], ['stop_time' => time(), 'status' => 2]);
|
||||
if (in_array($uid, $uidAll)) {
|
||||
if ($this->dao->getCount([['uid', 'in', $uidAll], ['is_tpl', '=', 0], ['k_id|id', '=', $pinkT['id']]]))
|
||||
$this->orderPinkAfter($uidAll, $pinkT['id']);
|
||||
$pinkBool = 1;
|
||||
} else $pinkBool = 3;
|
||||
}
|
||||
return $pinkBool;
|
||||
} catch (\Exception $e) {
|
||||
return $pinkBool;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团成功修改
|
||||
* @param $uidAll
|
||||
* @param $pid
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function orderPinkAfter($uidAll, $pid)
|
||||
{
|
||||
//发送消息之前去除虚拟用户
|
||||
foreach ($uidAll as $key => $uid) {
|
||||
if ($uid == 0) unset($uidAll[$key]);
|
||||
}
|
||||
/** @var StoreCombinationServices $storeCombinationServices */
|
||||
$storeCombinationServices = app()->make(StoreCombinationServices::class);
|
||||
$pinkInfo = $this->dao->get((int)$pid, ['cid', 'nickname', 'uid']);
|
||||
$title = $storeCombinationServices->value(['id' => $pinkInfo['cid']], 'title');
|
||||
$pinkList = $this->dao->getColumn([['id|k_id', '=', $pid], ['uid', '<>', 0]], '*', 'uid');
|
||||
$order_ids = array_column($pinkList, 'order_id');
|
||||
/** @var StoreOrderServices $orderService */
|
||||
$orderService = app()->make(StoreOrderServices::class);
|
||||
$order_channels = $orderService->getColumn([['order_id', 'in', $order_ids]], 'is_channel', 'order_id');
|
||||
if (!$pinkList) return false;
|
||||
foreach ($pinkList as $item) {
|
||||
//用户发送消息
|
||||
event('notice.notice', [
|
||||
[
|
||||
'list' => $item,
|
||||
'nickname' => $pinkInfo['nickname'],
|
||||
'title' => $title,
|
||||
'user_type' => $order_channels[$item['order_id']],
|
||||
'url' => '/pages/users/order_details/index?order_id=' . $item['order_id']
|
||||
], 'order_user_groups_success']);
|
||||
}
|
||||
$this->dao->update([['uid', 'in', $uidAll], ['id|k_id', '=', $pid]], ['is_tpl' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建拼团
|
||||
* @param $order
|
||||
* @return mixed
|
||||
*/
|
||||
public function createPink(array $orderInfo)
|
||||
{
|
||||
/** @var StoreCombinationServices $services */
|
||||
$services = app()->make(StoreCombinationServices::class);
|
||||
$product = $services->getOne(['id' => $orderInfo['activity_id']], 'effective_time,title,people');
|
||||
if (!$product) {
|
||||
return false;
|
||||
}
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$userInfo = $userServices->get($orderInfo['uid']);
|
||||
if ($orderInfo['pink_id']) {
|
||||
//拼团存在
|
||||
$res = false;
|
||||
$pink['uid'] = $orderInfo['uid'];//用户id
|
||||
$pink['nickname'] = $userInfo['nickname'];
|
||||
$pink['avatar'] = $userInfo['avatar'];
|
||||
if ($this->isPinkBe($pink, $orderInfo['pink_id'])) return false;
|
||||
$pink['order_id'] = $orderInfo['order_id'];//订单id 生成
|
||||
$pink['order_id_key'] = $orderInfo['id'];//订单id 数据库id
|
||||
$pink['total_num'] = $orderInfo['total_num'];//购买个数
|
||||
$pink['total_price'] = $orderInfo['pay_price'];//总金额
|
||||
$pink['k_id'] = $orderInfo['pink_id'];//拼团id
|
||||
foreach ($orderInfo['cartInfo'] as $v) {
|
||||
$pink['cid'] = $v['activity_id'];//拼团商品id
|
||||
$pink['pid'] = $v['product_id'];//商品id
|
||||
$pink['people'] = $product['people'];//几人拼团
|
||||
$pink['price'] = $v['productInfo']['price'];//单价
|
||||
$pink['stop_time'] = 0;//结束时间
|
||||
$pink['add_time'] = time();//开团时间
|
||||
$res = $this->save($pink);
|
||||
}
|
||||
// 拼团团成功发送模板消息
|
||||
event('notice.notice', [['orderInfo' => $orderInfo, 'title' => $product['title'], 'pink' => $pink], 'can_pink_success']);
|
||||
//处理拼团完成
|
||||
[$pinkAll, $pinkT, $count, $idAll, $uidAll] = $this->getPinkMemberAndPinkK($pink);
|
||||
if ($pinkT['status'] == 1) {
|
||||
if (!$count)//组团完成
|
||||
$this->pinkComplete($uidAll, $idAll, $pink['uid'], $pinkT);
|
||||
else
|
||||
$this->pinkFail($pinkAll, $pinkT, 0);
|
||||
}
|
||||
|
||||
if ($res) return true;
|
||||
else return false;
|
||||
} else {
|
||||
//创建拼团
|
||||
$res = false;
|
||||
$pink['uid'] = $orderInfo['uid'];//用户id
|
||||
$pink['nickname'] = $userInfo['nickname'];
|
||||
$pink['avatar'] = $userInfo['avatar'];
|
||||
$pink['order_id'] = $orderInfo['order_id'];//订单id 生成
|
||||
$pink['order_id_key'] = $orderInfo['id'];//订单id 数据库id
|
||||
$pink['total_num'] = $orderInfo['total_num'];//购买个数
|
||||
$pink['total_price'] = $orderInfo['pay_price'];//总金额
|
||||
$pink['k_id'] = 0;//拼团id
|
||||
/** @var StoreOrderServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderServices::class);
|
||||
foreach ($orderInfo['cartInfo'] as $v) {
|
||||
$pink['cid'] = $v['activity_id'];//拼团商品id
|
||||
$pink['pid'] = $v['product_id'];//商品id
|
||||
$pink['people'] = $product['people'];//几人拼团
|
||||
$pink['price'] = $v['productInfo']['price'];//单价
|
||||
$pink['stop_time'] = time() + $product->effective_time * 3600;//结束时间
|
||||
$pink['add_time'] = time();//开团时间
|
||||
$res1 = $this->dao->save($pink);
|
||||
$res2 = $orderServices->update($orderInfo['id'], ['pink_id' => $res1['id']]);
|
||||
$res = $res1 && $res2;
|
||||
$pink['id'] = $res1['id'];
|
||||
}
|
||||
$number = (int)bcsub((string)$product['people'], '1', 0);
|
||||
if ($number) CacheService::setStock(md5((string)$pink['id']), $number, 3);
|
||||
|
||||
PinkJob::dispatchSece(($product->effective_time * 3600) + 60, [$pink['id']]);
|
||||
event('notice.notice', [['orderInfo' => $orderInfo, 'title' => $product['title'], 'pink' => $pink], 'open_pink_success']);
|
||||
if ($res) return true;
|
||||
else return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否拼团
|
||||
* @param array $data
|
||||
* @param int $id
|
||||
* @return int
|
||||
*/
|
||||
public function isPinkBe(array $data, int $id)
|
||||
{
|
||||
$data['id'] = $id;
|
||||
$count = $this->dao->getCount($data);
|
||||
if ($count) return $count;
|
||||
$data['k_id'] = $id;
|
||||
$count = $this->dao->getCount($data);
|
||||
if ($count) return $count;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参加拼团成功发送模板消息
|
||||
* @param array $order
|
||||
* @param string $openid
|
||||
* @param string $title
|
||||
* @param $pink
|
||||
* @return mixed
|
||||
*/
|
||||
public function joinPinkSuccessSend(array $order, string $openid, string $title, $pink)
|
||||
{
|
||||
if ($order['is_channel'] == 1) {
|
||||
/** @var UserServices $services */
|
||||
$services = app()->make(UserServices::class);
|
||||
$nickname = $services->value(['uid' => $order['uid']], 'nickname');
|
||||
RoutineTemplateJob::dispatchDo('sendPinkSuccess', [$openid, $title, $nickname, $pink['add_time'], $pink['people'], '/pages/users/order_details/index?order_id=' . $pink['order_id']]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开团发送模板消息
|
||||
* @param array $order
|
||||
* @param string $openid
|
||||
* @param string $title
|
||||
* @param $pink
|
||||
* @return mixed
|
||||
*/
|
||||
public function pinkSuccessSend(array $order, string $openid, string $title, $pink)
|
||||
{
|
||||
if ($order['is_channel'] == 1) {
|
||||
/** @var UserServices $services */
|
||||
$services = app()->make(UserServices::class);
|
||||
$nickname = $services->value(['uid' => $order['uid']], 'nickname');
|
||||
RoutineTemplateJob::dispatchDo('sendPinkSuccess', [$openid, $title, $nickname, $pink['add_time'], $pink['people'], '/pages/users/order_details/index?order_id=' . $pink['order_id']]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消拼团
|
||||
* @param int $uid
|
||||
* @param int $cid
|
||||
* @param int $pink_id
|
||||
* @param null $nextPinkT
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function removePink(int $uid, int $cid, int $pink_id, $nextPinkT = null)
|
||||
{
|
||||
$pinkT = $this->dao->getOne([
|
||||
['uid', '=', $uid],
|
||||
['id', '=', $pink_id],
|
||||
['cid', '=', $cid],
|
||||
['k_id', '=', 0],
|
||||
['is_refund', '=', 0],
|
||||
['status', '=', 1],
|
||||
['stop_time', '>', time()],
|
||||
]);
|
||||
if (!$pinkT) throw new ValidateException('未查到拼团信息,无法取消');
|
||||
[$pinkAll, $pinkT, $count, $idAll, $uidAll] = $this->getPinkMemberAndPinkK($pinkT);
|
||||
if (count($pinkAll)) {
|
||||
$count = $pinkT['people'] - ($this->dao->count(['k_id' => $pink_id, 'is_refund' => 0]) + 1);
|
||||
if ($count) {
|
||||
//拼团未完成,拼团有成员取消开团取 紧跟团长后拼团的人
|
||||
if (isset($pinkAll[0])) $nextPinkT = $pinkAll[0];
|
||||
} else {
|
||||
//拼团完成
|
||||
$this->PinkComplete($uidAll, $idAll, $uid, $pinkT);
|
||||
throw new ValidateException('拼团已完成,无法取消');
|
||||
}
|
||||
}
|
||||
/** @var StoreOrderServices $orderService */
|
||||
$orderService = app()->make(StoreOrderServices::class);
|
||||
/** @var StoreOrderRefundServices $orderRefundService */
|
||||
$orderRefundService = app()->make(StoreOrderRefundServices::class);
|
||||
//取消开团
|
||||
$order = $orderService->get($pinkT['order_id_key']);
|
||||
$refundData = [
|
||||
'refund_reason' => '用户手动取消拼团',
|
||||
'refund_explain' => '用户手动取消拼团',
|
||||
'refund_img' => json_encode([]),
|
||||
];
|
||||
try {
|
||||
$res1 = $orderRefundService->applyRefund((int)$order['id'], (int)$order['uid'], $order, [], 1, (float)$order['pay_price'], $refundData);
|
||||
} catch (\Throwable $e) {
|
||||
$res1 = true;
|
||||
}
|
||||
$res2 = $this->dao->getCount([['uid', '=', $pinkT['uid']], ['k_id|id', '=', $pinkT['id']]]);
|
||||
if ($res1 && $res2) {
|
||||
$this->orderPinkAfterNo($pinkT['uid'], $pinkT['id'], true, $order->is_channel);
|
||||
}
|
||||
//当前团有人的时候
|
||||
if (is_array($nextPinkT)) {
|
||||
$this->dao->update($nextPinkT['id'], ['k_id' => 0, 'status' => 1, 'stop_time' => $pinkT['stop_time']]);
|
||||
$this->dao->update($pinkT['id'], ['k_id' => $nextPinkT['id']], 'k_id');
|
||||
$orderService->update($nextPinkT['order_id'], ['pink_id' => $nextPinkT['id']], 'order_id');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改到期的拼团状态
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function statusPink(int $page, int $limit)
|
||||
{
|
||||
$pinkListEnd = $this->dao->pinkListEnd()->page($page, $limit)->select()->toArray();
|
||||
foreach ($pinkListEnd as $key => $pink) {
|
||||
[$pinkAll, $pinkT, $count, $idAll, $uidAll] = $this->getPinkMemberAndPinkK($pink);
|
||||
$this->pinkFail($pinkAll, $pinkT, 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 放入自动取消拼团队列
|
||||
*/
|
||||
public function useStatusPink()
|
||||
{
|
||||
$pinkEndCount = $this->dao->pinkListEnd()->count();
|
||||
if (!$pinkEndCount) {
|
||||
return;
|
||||
}
|
||||
$pages = ceil($pinkEndCount / 100);
|
||||
for ($i = 1; $i <= $pages; $i++) {
|
||||
AuthPinkFail::dispatch([$i, 100]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 拼团成功
|
||||
* @param array $pinkRegimental 成功的团长编号
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function successPinkEdit(array $pinkRegimental)
|
||||
{
|
||||
if (!count($pinkRegimental)) return true;
|
||||
foreach ($pinkRegimental as $key => &$item) {
|
||||
$pinkList = $this->dao->getColumn(['k_id' => $item], 'id', 'id');
|
||||
$pinkList[] = $item;
|
||||
$pinkList = implode(',', $pinkList);
|
||||
$this->dao->update([['id', 'in', $pinkList]], ['stop_time' => time(), 'status' => 2]);
|
||||
$pinkUidList = $this->dao->getColumn([['id', 'in', $pinkList], ['is_tpl', '=', 0]], 'uid', 'uid');
|
||||
if (count($pinkUidList)) $this->orderPinkAfter($pinkUidList, $item);//发送模板消息
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼团失败
|
||||
* @param array $pinkRegimental 失败的团长编号
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function failPinkEdit(array $pinkRegimental)
|
||||
{
|
||||
if (!count($pinkRegimental)) return true;
|
||||
foreach ($pinkRegimental as $key => &$item) {
|
||||
$pinkList = $this->dao->getColumn(['k_id' => $item], 'id', 'id');
|
||||
$pinkList[] = $item;
|
||||
$pinkList = implode(',', $pinkList);
|
||||
$refundPinkList = $this->dao->getColumn([['id', 'in', $pinkList]], 'order_id,uid', 'id');
|
||||
if ($refundPinkList) {
|
||||
/** @var StoreOrderRefundServices $orderRefundService */
|
||||
$orderRefundService = app()->make(StoreOrderRefundServices::class);
|
||||
$refundData = [
|
||||
'refund_reason' => '拼团时间超时',
|
||||
'refund_explain' => '拼团时间超时',
|
||||
'refund_img' => json_encode([]),
|
||||
];
|
||||
foreach ($refundPinkList as $key => &$order) {
|
||||
try {
|
||||
$orderRefundService->applyRefund((int)$order['id'], (int)$order['uid'], $order, [], 1, (float)$order['pay_price'], $refundData);//申请退款
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->dao->update([['id', 'in', $pinkList]], ['status' => 3]);
|
||||
// $pinkUidList = $this->dao->getColumn([['id', 'in', $pinkList], ['is_tpl', '=', 0]], 'uid', 'uid');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 虚拟拼团
|
||||
* @param $pinkId
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function virtualCombination($pinkId)
|
||||
{
|
||||
$pinkInfo = $this->dao->get($pinkId);
|
||||
$people = $pinkInfo['people'];
|
||||
$count = $this->dao->count(['k_id' => $pinkId]) + 1;
|
||||
$percent1 = bcdiv((string)$count, (string)$people, 2) * 100;
|
||||
/** @var StoreCombinationServices $services */
|
||||
$services = app()->make(StoreCombinationServices::class);
|
||||
$percent2 = $services->value(['id' => $pinkInfo['cid']], 'virtual');
|
||||
if ($percent1 >= $percent2) {
|
||||
$time = time();
|
||||
$num = $people - $count;
|
||||
$data = [];
|
||||
mt_srand();
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
$data[$i]['uid'] = 0;
|
||||
$data[$i]['nickname'] = substr(md5(time() . rand(1000, 9999)), 0, 12);
|
||||
$data[$i]['avatar'] = sys_config('h5_avatar');
|
||||
$data[$i]['order_id'] = 0;
|
||||
$data[$i]['order_id_key'] = 0;
|
||||
$data[$i]['total_num'] = 0;
|
||||
$data[$i]['total_price'] = 0;
|
||||
$data[$i]['cid'] = $pinkInfo['cid'];
|
||||
$data[$i]['pid'] = $pinkInfo['pid'];
|
||||
$data[$i]['people'] = $people;
|
||||
$data[$i]['price'] = 0;
|
||||
$data[$i]['add_time'] = $time;
|
||||
$data[$i]['stop_time'] = $time;
|
||||
$data[$i]['k_id'] = $pinkInfo['id'];
|
||||
$data[$i]['is_tpl'] = 1;
|
||||
$data[$i]['is_refund'] = 0;
|
||||
$data[$i]['status'] = 2;
|
||||
$data[$i]['is_virtual'] = 1;
|
||||
}
|
||||
//添加虚拟团员
|
||||
$this->dao->saveAll($data);
|
||||
//更改团员状态为拼团成功
|
||||
$this->dao->update($pinkId, ['stop_time' => $time, 'status' => 2], 'k_id');
|
||||
//更改团长为拼团成功
|
||||
$this->dao->update($pinkId, ['stop_time' => $time, 'status' => 2]);
|
||||
$uidAll = $this->dao->getColumn([['id|k_id', '=', $pinkId]], 'uid');
|
||||
$this->orderPinkAfter($uidAll, $pinkId);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取拼团海报详情信息
|
||||
* @param int $id
|
||||
* @param $user
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function posterInfo(int $id, $user)
|
||||
{
|
||||
$pinkInfo = $this->dao->get($id);
|
||||
/** @var StoreCombinationServices $combinationService */
|
||||
$combinationService = app()->make(StoreCombinationServices::class);
|
||||
$storeCombinationInfo = $combinationService->getOne(['id' => $pinkInfo['cid']], '*', ['getPrice']);
|
||||
$data['title'] = $storeCombinationInfo['title'];
|
||||
$data['url'] = '';
|
||||
$data['image'] = $storeCombinationInfo['image'];
|
||||
$data['price'] = $pinkInfo['price'];
|
||||
$data['label'] = $pinkInfo['people'] . '人团';
|
||||
if ($pinkInfo['k_id']) $pinkAll = $this->getPinkMember($pinkInfo['k_id']);
|
||||
else $pinkAll = $this->getPinkMember($pinkInfo['id']);
|
||||
$count = count($pinkAll);
|
||||
$data['msg'] = '划线价¥' . $storeCombinationInfo['product_price'] . ' 还差' . ($pinkInfo['people'] - $count) . '人拼团成功';
|
||||
|
||||
try {
|
||||
$uid = (int)$user['uid'];
|
||||
if (request()->isRoutine()) {
|
||||
//小程序
|
||||
$name = $id . '_' . $uid . '_' . $user['is_promoter'] . '_pink_share_routine.jpg';
|
||||
/** @var QrcodeServices $QrcodeService */
|
||||
$QrcodeService = app()->make(QrcodeServices::class);
|
||||
//生成小程序地址
|
||||
$urlCode = $QrcodeService->getRoutineQrcodePath($id, $uid, 31, $name);
|
||||
$data['url'] = $urlCode;
|
||||
} else {
|
||||
if (sys_config('share_qrcode', 0) && request()->isWechat()) {
|
||||
/** @var QrcodeServices $qrcodeService */
|
||||
$qrcodeService = app()->make(QrcodeServices::class);
|
||||
$data['url'] = $qrcodeService->getTemporaryQrcode('pink-' . $id . '-' . $uid, $uid)->url;
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user