Initial commit: queue workspace

Made-with: Cursor
This commit is contained in:
apple
2026-03-21 02:55:24 +08:00
commit 78de918c37
12388 changed files with 1840126 additions and 0 deletions

View File

@@ -0,0 +1,165 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\api\v2\activity;
use app\Request;
use app\services\activity\lottery\LuckLotteryRecordServices;
use app\services\activity\lottery\LuckLotteryServices;
use app\services\other\QrcodeServices;
use app\services\wechat\WechatServices;
use crmeb\services\CacheService;
use think\annotation\Inject;
/**
*
* Class LuckLottery
* @package app\controller\api\v1\activity
*/
class LuckLottery
{
/**
* @var LuckLotteryServices
*/
#[Inject]
protected LuckLotteryServices $services;
/**
* 抽奖活动信息
* @param Request $request
* @param $factor
* @return mixed
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function LotteryInfo(Request $request, $factor)
{
if (!$factor) $factor = 1;
$lottery = $this->services->getFactorLotteryCache((int)$factor);
if (!$lottery) {
return app('json')->fail('抽奖活动不存在');
}
$uid = (int)$request->uid();
$prizeArr = isset($lottery['prize']) && $lottery['prize'] ? $lottery['prize'] : [];
$prize = [];
if ($prizeArr) {
foreach ($prizeArr as &$item) {
$prize[] = [
'id' => $item['id'],
'type' => $item['type'],
'name' => $item['name'],
'image' => $item['image'],
'prompt' => $item['prompt'],
];
}
}
$lottery['prize'] = $prize;
$lotteryData = ['lottery' => $lottery];
$this->services->checkoutUserAuth($uid, (int)$lottery['id'], [], $lottery);
$lotteryData['lottery_num'] = $this->services->getLotteryNum($uid, (int)$lottery['id'], [], $lottery);
if ($factor == 3 && $lotteryData['lottery_num'] < 1) {
return app('json')->successful('ok', []);
}
$all_record = $user_record = [];
/** @var LuckLotteryRecordServices $lotteryRecordServices */
$lotteryRecordServices = app()->make(LuckLotteryRecordServices::class);
if ($lottery['is_all_record'] || $lottery['is_personal_record']) {
if ($lottery['is_all_record']) {
$all_record = $lotteryRecordServices->getWinList(['lottery_id' => $lottery['id']]);
}
if ($lottery['is_personal_record']) {
$user_record = $lotteryRecordServices->getWinList(['lottery_id' => $lottery['id'], 'uid' => $uid]);
}
}
if ($lottery['factor'] == 1) {//积分抽奖
$data = $lotteryRecordServices->getLotteryNum($uid, (int)$lottery['id']);
$lotteryData['todayCount'] = (int)max(bcsub((string)$lottery['lottery_num'], (string)$data['todayCount'], 0), 0);
$lotteryData['totalCount'] = (int)max(bcsub((string)$lottery['total_lottery_num'], (string)$data['totalCount'], 0), 0);
} else {
$lotteryData['totalCount'] = $lotteryData['todayCount'] = $lotteryData['lottery_num'] = (int)$lotteryData['lottery_num'];
}
$lotteryData['all_record'] = $all_record;
$lotteryData['user_record'] = $user_record;
$lotteryData['cache_time'] = in_array($factor, [3, 4]) ? $this->services->getCacheLotteryExpireTime($uid, $factor == 3 ? 'order' : 'comment') : 0;
return app('json')->successful('ok', $lotteryData);
}
/**
* 参与抽奖
* @param Request $request
* @return mixed
*/
public function luckLottery(Request $request)
{
[$id, $type, $channel_type] = $request->postMore([
['id', 0],
['type', 0],
['channel_type','']
], true);
$uid = (int)$request->uid();
if ($type == 5 && request()->isWechat()) {
/** @var WechatServices $wechat */
$wechat = app()->make(WechatServices::class);
$subscribe = $wechat->get(['user_type' => 'wechat', 'uid' => $uid, 'subscribe' => 1]);
if (!$subscribe) {
$url = '';
/** @var QrcodeServices $qrcodeService */
$qrcodeService = app()->make(QrcodeServices::class);
$url = $qrcodeService->getTemporaryQrcode('luckLottery-' . $uid, $uid)->url;
return app('json')->successful('请先关注公众号', ['code' => 'subscribe', 'url' => $url]);
}
}
if (!$id) {
return app('json')->fail('参数错误');
}
return app('json')->successful($this->services->luckLottery($uid, $id,$channel_type));
}
/**
* 领取奖品
* @param Request $request
* @param LuckLotteryRecordServices $lotteryRecordServices
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function lotteryReceive(Request $request, LuckLotteryRecordServices $lotteryRecordServices)
{
[$id, $name, $phone, $address, $mark] = $request->postMore([
['id', 0],
['name', ''],
['phone', ''],
['address', ''],
['mark', '']
], true);
if (!$id) {
return app('json')->fail('参数错误');
}
$uid = (int)$request->uid();
return app('json')->successful($lotteryRecordServices->receivePrize($uid, $id, compact('name', 'phone', 'address', 'mark')) ? '领取成功' : '领取失败');
}
/**
* 获取中奖记录
* @param Request $request
* @param LuckLotteryRecordServices $lotteryRecordServices
* @return mixed
*/
public function lotteryRecord(Request $request, LuckLotteryRecordServices $lotteryRecordServices)
{
$uid = (int)$request->uid();
return app('json')->successful($lotteryRecordServices->getRecord($uid));
}
}

View File

@@ -0,0 +1,92 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\api\v2\activity;
use app\services\activity\coupon\StoreCouponIssueServices;
use app\services\order\StoreOrderServices;use app\services\product\product\StoreProductCouponServices;
use think\annotation\Inject;
use think\exception\ValidateException;use think\Request;
/**
* 优惠券
* Class StoreCoupons
* @package app\controller\api\v2\store
*/
class StoreCoupons
{
/**
* @var StoreCouponIssueServices
*/
#[Inject]
protected StoreCouponIssueServices $services;
/**
* 可领取优惠券列表
* @param \app\Request $request
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function lst(Request $request)
{
$where = $request->getMore([
[['type', 'd'], ''],
[['product_id', 'd'], 0],
[['brand_id', 'd'], 0],
['defaultOrder', ''],
['timeOrder', ''],
['priceOrder', '']
]);
return app('json')->successful($this->services->getIssueCouponList((int)$request->uid(), $where, '*', true));
}
/**
* 获取新人券
* @return mixed
*/
public function getNewCoupon(Request $request)
{
$userInfo = $request->user();
$data = [];
/** @var StoreCouponIssueServices $couponService */
$couponService = app()->make(StoreCouponIssueServices::class);
$data['list'] = $couponService->getNewCoupon();
$data['image'] = '';
if ($userInfo->add_time === $userInfo->last_time) {
$data['show'] = 1;
} else {
$data['show'] = 0;
}
//会员领取优惠券
//$couponService->sendMemberCoupon($userInfo->uid);
return app('json')->success($data);
}
/**
* 获取每日新增的优惠券
* @param Request $request
* @param StoreCouponIssueServices $couponIssueServices
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getTodayCoupon(Request $request, StoreCouponIssueServices $couponIssueServices)
{
$uid = 0;
if ($request->hasMacro('uid')) $uid = (int)$request->uid();
$data['list'] = $couponIssueServices->getTodayCoupon($uid);
$data['image'] = '';
return app('json')->success($data);
}
}

View File

@@ -0,0 +1,125 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\api\v2\activity;
use app\Request;
use app\services\activity\promotions\StorePromotionsServices;
use app\services\activity\promotions\StorePromotionsAuxiliaryServices;
use app\services\product\product\StoreProductRelationServices;
use app\services\product\product\StoreProductServices;
use think\annotation\Inject;
/**
* 优惠活动
*/
class StorePromotions
{
/**
* @var StorePromotionsServices
*/
#[Inject]
protected StorePromotionsServices $services;
/**
* 某个优惠活动商品列表
* @param $type
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function productList($type)
{
$type = (int)($type ?? 0);
$product_where = [];
if ($type) {
$product_where = $this->services->collectProductByType([$type]);
}
$list = [];
if (!$product_where || (isset($product_where['ids']) && $product_where['ids'])) {
/** @var StoreProductServices $productServices */
$productServices = app()->make(StoreProductServices::class);
$list = $productServices->getGoodsList($product_where, 0, $type);
if ($list) {
foreach ($list as $key => &$item) {
if (isset($item['promotions']['promotions_type']) && $item['promotions']['promotions_type'] == 1) {
$item['price'] = floatval(bcmul((string)$item['price'], (string)bcdiv((string)$item['promotions']['discount'] ?? '100', '100', 2), 2));
}
}
}
}
return app('json')->success(compact('list'));
}
/**
* 获取凑单商品列表
* @param Request $request
* @return mixed
*/
public function collectOrderProduct(Request $request, StoreProductServices $productServices, StorePromotionsAuxiliaryServices $auxiliaryService)
{
[$promotions_id] = $request->getMore([
[['promotions_id', 'd'], 0]
], true);
$promotions = $this->services->get($promotions_id, ['*'], ['promotions']);
if (!$promotions) {
return app('json')->fail('活动已失效,请刷新页面');
}
$promotions = $promotions->toArray();
$product_where = $this->services->collectProductById((int)$promotions_id);
$list = $productServices->getGoodsList($product_where, (int)$request->uid());
return app('json')->success(compact('promotions','list'));
}
/**
* 获取优惠活动赠品
* @param $id
* @return mixed
*/
public function getPromotionsGive($id)
{
$result = [];
if($id) {
$promotionsInfo= $this->services->getInfo((int)$id);
if ($promotionsInfo && $promotionsInfo['promotions_type'] == 4) {
$giveIntegral = $giveCoupon = $giveProducts = [];
$promotions_cate = $promotionsInfo['promotions_cate'];
foreach ($promotionsInfo['promotions'] as $p) {
if ($promotions_cate == 2) {
$base = '每满' . floatval($p['threshold'] ?? 0);
} else {
$base = '满' . floatval($p['threshold'] ?? 0);
}
$base .= $p['threshold_type'] == 1 ? '元可领取' : '件可领取';
if (isset($p['give_integral']) && $p['give_integral']) {
$giveIntegral[] = ['threshold_title' => $base, 'give_integral' => intval($p['give_integral'])];
}
if (isset($p['giveCoupon']) && $p['giveCoupon']) {
foreach ($p['giveCoupon'] as &$coupon) {
$coupon['threshold_title'] = $base;
}
$giveCoupon = array_merge($giveCoupon, $p['giveCoupon']);
}
if (isset($p['giveProducts']) && $p['giveProducts']) {
foreach ($p['giveProducts'] as &$product) {
$product['threshold_title'] = $base;
}
$giveProducts = array_merge($giveProducts, $p['giveProducts']);
}
}
$result = compact('giveIntegral', 'giveCoupon', 'giveProducts');
}
}
return app('json')->success($result);
}
}