feat : catering
This commit is contained in:
158
app/Service/ServiceTrait/Admin/Catering/PrintTrait.php
Normal file
158
app/Service/ServiceTrait/Admin/Catering/PrintTrait.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\ServiceTrait\Admin\Catering;
|
||||
|
||||
use App\Cache\Redis\Admin\AdminRedisKey;
|
||||
use App\Cache\Redis\RedisCache;
|
||||
use App\Constants\Admin\CateringCode;
|
||||
use App\Extend\DateUtil;
|
||||
use App\Extend\StringUtil;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
trait PrintTrait
|
||||
{
|
||||
/**
|
||||
* @var RedisCache
|
||||
*/
|
||||
#[Inject]
|
||||
protected RedisCache $redis;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected string $printKey;
|
||||
protected string $stopOrderKey;
|
||||
protected string $pickupCodeKey;
|
||||
protected string $isCateringKey;
|
||||
|
||||
/**
|
||||
* 前缀
|
||||
* @var string
|
||||
*/
|
||||
protected string $currentPrefix;
|
||||
|
||||
/**
|
||||
* 分组
|
||||
* @var array
|
||||
*/
|
||||
protected array $currentHeapSort;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function __initRedisKey(): void
|
||||
{
|
||||
$this->printKey = AdminRedisKey::optionCateringIsPrint($this->cycleId);
|
||||
$this->stopOrderKey = AdminRedisKey::optionCateringStopOrder($this->cycleId);
|
||||
$this->pickupCodeKey = AdminRedisKey::optionCateringBuildPickupCode($this->cycleId);
|
||||
$this->isCateringKey = AdminRedisKey::optionIsCatering($this->cycleId);
|
||||
|
||||
$script = <<<lua
|
||||
local isPrint = redis.call('exists',KEYS[1])
|
||||
if isPrint == 0 then
|
||||
redis.call('hSET',KEYS[1],0,ARGV[1])
|
||||
redis.call('Expire',KEYS[1],ARGV[2])
|
||||
end
|
||||
|
||||
local isStop = redis.call('exists',KEYS[2])
|
||||
if isStop == 0 then
|
||||
redis.call('hSET',KEYS[2],0,ARGV[1])
|
||||
redis.call('Expire',KEYS[2],ARGV[2])
|
||||
end
|
||||
|
||||
local isPick = redis.call('exists',KEYS[3])
|
||||
if isPick == 0 then
|
||||
redis.call('hSET',KEYS[3],0,ARGV[1])
|
||||
redis.call('Expire',KEYS[3],ARGV[2])
|
||||
end
|
||||
|
||||
local isCatering = redis.call('exists',KEYS[4])
|
||||
if isCatering == 0 then
|
||||
redis.call('hSET',KEYS[4],0,ARGV[1])
|
||||
redis.call('Expire',KEYS[4],ARGV[2])
|
||||
end
|
||||
lua;
|
||||
|
||||
$this->redis->eval($script, [$this->printKey, $this->stopOrderKey, $this->pickupCodeKey, $this->isCateringKey, CateringCode::REDIS_FINISH_VALUE, DateUtil::DAY], 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function closePrint(): void
|
||||
{
|
||||
if (CateringCode::REDIS_FINISH_VALUE == $this->redis->hGet($this->printKey, $this->logInfo->id)) return;
|
||||
|
||||
$this->redis->hSet($this->printKey, $this->logInfo->id, CateringCode::REDIS_FINISH_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function closeSite(): void
|
||||
{
|
||||
if (CateringCode::REDIS_FINISH_VALUE == $this->redis->hGet($this->stopOrderKey, $this->logInfo->site_id)) return;
|
||||
|
||||
$this->redis->hSet($this->stopOrderKey, $this->logInfo->site_id, CateringCode::REDIS_FINISH_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function closeWholeLine(): void
|
||||
{
|
||||
$siteArr = $this->siteModel->where('delivered_id',$this->siteInfo->delivered_id)->pluck('id');
|
||||
|
||||
//没有日志数据 跳出
|
||||
$logArr = $this
|
||||
->orderOptionCateringLogModel
|
||||
->where('cycle_id',$this->cycleId)
|
||||
->whereIn('site_id',$siteArr)
|
||||
->pluck('site_id')
|
||||
->toArray();
|
||||
if (empty($logArr)) return;
|
||||
|
||||
//没有缓存数据 跳出
|
||||
$cacheData = $this->redis->hGetAll($this->stopOrderKey);
|
||||
if (empty($cacheData)) return;
|
||||
$cacheData = array_diff(array_keys($cacheData),[0]); //需要排除默认写的值
|
||||
|
||||
//数量不对等 跳出
|
||||
if (count($logArr) !== count($cacheData)) return;
|
||||
|
||||
//如果相反交集有一个不为空就是不对的 跳出
|
||||
if (!empty(array_diff($logArr,$cacheData)) || !empty(array_diff($cacheData,$logArr))) return;
|
||||
|
||||
//批量写入 hashmap
|
||||
$insertCacheData = [];
|
||||
foreach ($siteArr as $one) {
|
||||
$insertCacheData[$one] = CateringCode::REDIS_FINISH_VALUE;
|
||||
}
|
||||
|
||||
$this->redis->hMset($this->stopOrderKey, $insertCacheData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function isBuildPickupCode(): bool
|
||||
{
|
||||
if (CateringCode::REDIS_FINISH_VALUE == $this->redis->hGet($this->pickupCodeKey, $this->logInfo->id)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Service\ServiceTrait;
|
||||
|
||||
use App\Cache\Redis\Api\SiteCache;
|
||||
use App\Constants\Admin\CateringCode;
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Model\OrderMealCateringLog;
|
||||
use App\Model\OrderOptionCateringLog;
|
||||
@@ -77,7 +78,7 @@ trait CateringTrait
|
||||
return;
|
||||
}
|
||||
|
||||
if ($logInfo->status == 2) {
|
||||
if ($logInfo->status == CateringCode::CATERING_STATUS_FINISH) {
|
||||
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubOptionCateringLog:已经截单不需要修改,订单信息:'.json_encode($this->orderInfo->toArray()));
|
||||
return;
|
||||
}
|
||||
@@ -107,7 +108,7 @@ trait CateringTrait
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($logInfo->status == 2) {
|
||||
if ($logInfo->status == CateringCode::CATERING_STATUS_FINISH) {
|
||||
$this->log->error(__CLASS__.':Function:refundCallBackHandle:manageSubMealCateringLog:已经截单不需要修改,订单信息:'.json_encode($this->orderInfo->toArray()).':订单商品信息:'.json_encode($orderGoods));
|
||||
continue;
|
||||
}
|
||||
@@ -143,10 +144,10 @@ trait CateringTrait
|
||||
$logInfo->kitchen_id = (int)$siteInfo['kitchen_id'];
|
||||
$logInfo->quantity = 0;
|
||||
$logInfo->add_staple_food_num = 0;
|
||||
$logInfo->status = 1;
|
||||
$logInfo->status = CateringCode::CATERING_STATUS_UNDERWAY;
|
||||
}
|
||||
|
||||
if ($logInfo->status == 2) return false;
|
||||
if ($logInfo->status == CateringCode::CATERING_STATUS_FINISH) return false;
|
||||
|
||||
$logInfo->quantity = $logInfo->quantity + $this->orderInfo->copies;
|
||||
$logInfo->add_staple_food_num = $this->orderInfo->add_staple_food_num + $addStapleFoodNum;
|
||||
@@ -174,10 +175,10 @@ trait CateringTrait
|
||||
$logInfo->cycle_id = $this->orderInfo->cycle_id;
|
||||
$logInfo->sku_id = (int)$key;
|
||||
$logInfo->quantity = 0;
|
||||
$logInfo->status = 1;
|
||||
$logInfo->status = CateringCode::CATERING_STATUS_UNDERWAY;
|
||||
}
|
||||
|
||||
if ($logInfo->status == 2) return false;
|
||||
if ($logInfo->status == CateringCode::CATERING_STATUS_FINISH) return false;
|
||||
|
||||
$logInfo->quantity = $logInfo->quantity + $orderGood;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user