Compare commits

...

10 Commits

Author SHA1 Message Date
a3a079edd4 fix : stat 2025-08-06 16:00:58 +08:00
26f58eee32 fix : stat 2025-08-06 15:59:02 +08:00
00aa36c574 fix : stat 2025-08-06 15:38:48 +08:00
ff1ab9a008 fix : good cache 2025-08-06 15:23:06 +08:00
cf4a2d9436 fix : good cache 2025-08-06 15:21:18 +08:00
30bed90d27 fix : good cache 2025-08-06 15:13:08 +08:00
ed4ce5bebe fix : coupon date 2025-08-06 15:10:12 +08:00
eb0ce8a347 fix : coupon date 2025-08-06 12:44:58 +08:00
edf270a6ce fix : coupon date 2025-08-06 11:41:52 +08:00
c4c154cbb9 fix : coupon date 2025-08-06 11:41:35 +08:00
8 changed files with 122 additions and 10 deletions

View File

@@ -210,7 +210,7 @@ class GoodCache
foreach ($list as &$item) { foreach ($list as &$item) {
$item['sku_list'] = $skuListArr[$item['id']] ?? []; $item['sku_list'] = $skuListArr[$item['id']] ?? [];
$item['spu_image_url'] = $imageList[$item['image_id']] ?? ''; $item['spu_image_url']['url'] = $imageList[$item['image_id']]['url'] ?? '';
$item['image_list'] = $imageArr[$item['id']] ?? []; $item['image_list'] = $imageArr[$item['id']] ?? [];
$item['price'] = !empty($price[$item['id']]) ? (min($price[$item['id']]) ?? 0) : 0; $item['price'] = !empty($price[$item['id']]) ? (min($price[$item['id']]) ?? 0) : 0;
} }
@@ -349,7 +349,10 @@ class GoodCache
*/ */
private function buildStockData(&$data): mixed private function buildStockData(&$data): mixed
{ {
if (empty($data)) return $data;
foreach ($data as &$spu) { foreach ($data as &$spu) {
if (empty($spu['sku_list'])) continue;
foreach ($spu['sku_list'] as &$sku) { foreach ($spu['sku_list'] as &$sku) {
$sku['stock'] = $this->getStock($sku['id']); $sku['stock'] = $this->getStock($sku['id']);
} }

View File

@@ -12,6 +12,7 @@ use App\Service\Api\System\GetLeaderboardService;
use App\Service\Api\System\MiniWxConfigService; use App\Service\Api\System\MiniWxConfigService;
use App\Service\Api\System\SiteListService; use App\Service\Api\System\SiteListService;
use App\Service\Api\System\SystemConfigService; use App\Service\Api\System\SystemConfigService;
use App\Service\Api\System\TestService;
use App\Service\Api\User\IndexService; use App\Service\Api\User\IndexService;
use DateMalformedStringException; use DateMalformedStringException;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
@@ -87,4 +88,10 @@ class SystemController extends AbstractController
{ {
return (new GetLeaderboardService)->handle(); return (new GetLeaderboardService)->handle();
} }
#[RequestMapping(path: "test", methods: "GET")]
public function test()
{
return (new TestService)->handle();
}
} }

View File

@@ -0,0 +1,53 @@
<?php
/**
* This crontab file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Cron\Coupon;
use App\Constants\Common\CouponCode;
use App\Lib\Log;
use App\Model\UserCoupon;
use Exception;
use Hyperf\Crontab\Annotation\Crontab;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
#[Crontab(rule: "* * * * *", name: "UserCouponTask", singleton: true , callback: "execute", memo: "每秒执行优惠券过期")]
class UserCouponTask
{
/**
* @var Log
*/
#[Inject]
protected Log $log;
/**
* @var UserCoupon
*/
#[Inject]
protected UserCoupon $userCouponModel;
/**
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function execute(): void
{
try {
$this->userCouponModel
->where('status', CouponCode::COUPON_STATUS_UNUSED)
->where('validity_end_time', '<', date('Y-m-d H:i:s'))
->update(['status' => CouponCode::COUPON_STATUS_EXPIRE]);
}catch (Exception $e){
$this->log->error(__CLASS__.$e->getMessage());
}
}
}

View File

@@ -63,7 +63,7 @@ class YlyPrintService implements PrintOrderInterface
* @var Log * @var Log
*/ */
#[Inject] #[Inject]
private Log $log; protected Log $log;
/** /**
* @return void * @return void

View File

@@ -87,10 +87,16 @@ class ChefService extends BaseService
$skuIds = array_column($list['data'], 'sku_id'); $skuIds = array_column($list['data'], 'sku_id');
$chefIds = array_column($list['data'], 'chef_id'); $chefIds = array_column($list['data'], 'chef_id');
$skuList = $this->skuModel->whereIn('id', $skuIds)->pluck('title', 'id')->toArray(); $skuList = $this->skuModel->whereIn('id', $skuIds)->select('price','title','id')->get();
$chefList = $this->adminUserModel->whereIn('id',$chefIds)->pluck('chinese_name','id')->toArray(); if ($skuList->isNotEmpty()) {
$skuList = array_column($skuList->toArray(), null,'id');
}
$chefList = $this->adminUserModel->getChefNameByIds($chefIds);
foreach ($list['data'] as &$v) { foreach ($list['data'] as &$v) {
$v['sku_title'] = $skuList[$v['sku_id']] ?? ''; $v['sku_title'] = $skuList[$v['sku_id']]['title'] ?? '';
$v['sku_price'] = $skuList[$v['sku_id']]['price'] ?? '0.00';
$v['total_price'] = bcmul($skuList[$v['sku_id']]['price'],(string)$v['sale'],2);
$v['chef_name'] = $chefList[$v['chef_id']] ?? ''; $v['chef_name'] = $chefList[$v['chef_id']] ?? '';
} }

View File

@@ -114,9 +114,11 @@ class OptionalListService extends BaseService
$favorable = []; $favorable = [];
$skuList = []; $skuList = [];
foreach ($data as &$item) { foreach ($data as &$item) {
foreach ($item['sku_list'] as &$v) { if (!empty($item['sku_list'])) {
$v['surplus_stock'] = $this->redisCache->zScore($stockKey,$v['id']) ?? 0; foreach ($item['sku_list'] as &$v) {
$v['category_id'] = $item['category_id']; $v['surplus_stock'] = $this->redisCache->zScore($stockKey,$v['id']) ?? 0;
$v['category_id'] = $item['category_id'];
}
} }
if ($item['favorable'] == GoodCode::IS_FAVORABLE) { if ($item['favorable'] == GoodCode::IS_FAVORABLE) {
@@ -136,10 +138,10 @@ class OptionalListService extends BaseService
} }
$res[$item['category_id']]['spu_list'][] = $item; $res[$item['category_id']]['spu_list'][] = $item;
$skuList = array_merge($skuList, $item['sku_list']); $skuList = array_merge($skuList, $item['sku_list'] ?? []);
} }
if (empty($skuList)) throw new ErrException('数据错误'); if (empty($skuList)) return array_values($res);
$skuList = array_column($skuList,null,'id'); $skuList = array_column($skuList,null,'id');
if (!empty($purchaseData)) { if (!empty($purchaseData)) {

View File

@@ -0,0 +1,39 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Api\System;
use App\Constants\Common\CouponCode;
use App\Model\UserCoupon;
use App\Service\Api\BaseService;
use Hyperf\Di\Annotation\Inject;
class TestService extends BaseService
{
/**
* @var UserCoupon
*/
#[Inject]
protected UserCoupon $userCouponModel;
public function handle()
{
var_dump(date('Y-m-d H:i:s'));
$data = $this->userCouponModel
->where('status', CouponCode::COUPON_STATUS_UNUSED)
->where('validity_end_time', '<', date('Y-m-d H:i:s'))
->get();
$data = $data->toArray();
var_dump($data);
}
}

View File

@@ -33,8 +33,10 @@ trait CouponTrait
$couponInfo = $this->userCouponModel->where('id', $orderInfo->coupon_id)->where('user_id',$orderInfo->user_id)->first(); $couponInfo = $this->userCouponModel->where('id', $orderInfo->coupon_id)->where('user_id',$orderInfo->user_id)->first();
if (empty($couponInfo)) return; if (empty($couponInfo)) return;
if ($couponInfo->status != CouponCode::COUPON_STATUS_USED) return;
$couponInfo->status = CouponCode::COUPON_STATUS_UNUSED; $couponInfo->status = CouponCode::COUPON_STATUS_UNUSED;
$couponInfo->use_time = null;
if (date('Y-m-d H:i:s') > $couponInfo->validity_end_time) $couponInfo->status = CouponCode::COUPON_STATUS_EXPIRE; if (date('Y-m-d H:i:s') > $couponInfo->validity_end_time) $couponInfo->status = CouponCode::COUPON_STATUS_EXPIRE;