feat: cycle
This commit is contained in:
40
app/Service/Admin/Good/CycleService.php
Normal file
40
app/Service/Admin/Good/CycleService.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Good;
|
||||
|
||||
use App\Model\Cycle;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class CycleService extends BaseService
|
||||
{
|
||||
/**
|
||||
* @var Cycle $cycleModel
|
||||
*/
|
||||
#[Inject]
|
||||
protected Cycle $cycleModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$arr = $this->cycleModel->whereBetween('dates',[
|
||||
date('Y-m-d',strtotime('-10 day',time())),
|
||||
date('Y-m-d',strtotime('+10 day',time())),
|
||||
])->orderBy('dates')->get();
|
||||
if (empty($arr)) return $this->return->success('success',['list' => []]);
|
||||
|
||||
$arr = $arr->toArray();
|
||||
|
||||
return $this->return->success('success',['list' => $arr]);
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,33 @@ class SkuService extends BaseService
|
||||
#[Inject]
|
||||
protected Sku $skuModel;
|
||||
|
||||
public function handle()
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
//todo Write logic
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$spuId = (int)$this->request->input('spu_id');
|
||||
|
||||
$list = $this->skuModel->where('spu_id',$spuId)->paginate($limit)->toArray();
|
||||
|
||||
$imageIdArr = array_column($list['data'],'image_ids');
|
||||
$imageIds = array_unique(explode(',',implode(',',$imageIdArr)));
|
||||
$imageList = $this->getOssObjects($imageIds);
|
||||
|
||||
foreach ($list['data'] as &$item) {
|
||||
$imageOneArr = [];
|
||||
foreach (explode(',',$item['image_ids']) as $imageId) {
|
||||
$imageOneArr[] = [
|
||||
'id' => $imageId,
|
||||
'url' => $imageList[$imageId]['url']
|
||||
];
|
||||
}
|
||||
|
||||
$item['image_list'] = $imageOneArr;
|
||||
}
|
||||
|
||||
return $this->return->success('success', ['list' => $list]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +117,7 @@ class SkuService extends BaseService
|
||||
if ($skuInfo->order_num > 0 && $skuInfo->price != $this->request->input('price')) throw new ErrException('已有订单不可改价,退单后即可操作');
|
||||
else $skuInfo->price = $this->request->input('price');
|
||||
|
||||
$requestOssIds = $this->request->input('oss_ids');
|
||||
$requestOssIds = $this->request->input('image_ids');
|
||||
|
||||
$updateOssIds = array_diff(explode(',',$requestOssIds), explode(',',$skuInfo->image_ids));
|
||||
$delOssIds = array_diff(explode(',',$skuInfo->image_ids), explode(',',$requestOssIds));
|
||||
@@ -113,7 +137,8 @@ class SkuService extends BaseService
|
||||
|
||||
if (!$skuInfo->save()) throw new ErrException('修改失败');
|
||||
|
||||
if ($forceCleanStockCache == 1) return $this->return->success();//todo 修改缓存
|
||||
if ($forceCleanStockCache == 1) return $this->return->success();
|
||||
//todo 修改缓存
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
@@ -153,7 +178,7 @@ class SkuService extends BaseService
|
||||
|
||||
$res = $skuInfo->toArray();
|
||||
|
||||
$res['image_list'] = $imageList;
|
||||
$res['image_list'] = array_values($imageList);
|
||||
|
||||
return $this->return->success('success',$res);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user