113 lines
2.8 KiB
PHP
113 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Models\ProductSku;
|
|
use App\Models\ProductSkuVerify;
|
|
|
|
trait Release
|
|
{
|
|
/**
|
|
* SKU上架
|
|
*
|
|
* @param array|ProductSku $data
|
|
* @return void
|
|
*/
|
|
public static function skuUp(array|ProductSku $ids)
|
|
{
|
|
$nowTime = now();
|
|
if ($ids instanceof ProductSku) {
|
|
$ids[] = $ids->id;
|
|
}
|
|
$query = ProductSku::query()->whereIn('id', $ids)->where('verify_state', 0)->whereNull('release_at');
|
|
|
|
//执行上架审核动作
|
|
$query->update([
|
|
'verify_state'=> 1,
|
|
]);
|
|
ProductSkuVerify::query()->insert(array_map(function ($key) use ($nowTime) {
|
|
return [
|
|
'sku_id' => $key,
|
|
'created_at' => $nowTime,
|
|
'updated_at' => $nowTime,
|
|
];
|
|
}, $ids));
|
|
}
|
|
|
|
/**
|
|
* SKU下架操作
|
|
*
|
|
* @param array|ProductSku $ids
|
|
* @return void
|
|
*/
|
|
public static function skuDown(array|ProductSku $ids)
|
|
{
|
|
if ($ids instanceof ProductSku) {
|
|
$ids[] = $ids->id;
|
|
}
|
|
|
|
$query = ProductSku::query()->whereIn('id', $ids)->where('verify_state', 0)->whereNotNull('release_at');
|
|
//执行下架动作
|
|
$query->update([
|
|
'release_at'=> null,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 取消SKU上架申请
|
|
*
|
|
* @param array|ProductSku $ids
|
|
* @return void
|
|
*/
|
|
public static function releaseCancel(array|ProductSku $ids)
|
|
{
|
|
if ($ids instanceof ProductSku) {
|
|
$ids[] = $ids->id;
|
|
}
|
|
$query = ProductSku::query()->whereIn('id', $ids)->where('verify_state', 1)->whereNull('release_at');
|
|
|
|
//执行取消上架申请
|
|
$query->update([
|
|
'verify_state'=> 0,
|
|
]);
|
|
ProductSkuVerify::whereIn('sku_id', $ids)->where('status', 0)->update(['status'=>3]);
|
|
}
|
|
|
|
/**
|
|
* 审核SKU
|
|
*
|
|
* @param array $ids
|
|
* @param integer $status
|
|
* @param string $remarks
|
|
* @return void
|
|
*/
|
|
public static function skuVerify(array $ids, int $status, ?string $remarks)
|
|
{
|
|
//获得审核中商品
|
|
$query = ProductSku::query()->whereIn('id', $ids)->where('verify_state', 1)->whereNull('release_at');
|
|
|
|
switch ($status) {
|
|
case 1://成功
|
|
$query->update([
|
|
'verify_state'=> 0,
|
|
'release_at'=>now(),
|
|
]);
|
|
break;
|
|
case 2://失败
|
|
$query->update([
|
|
'verify_state'=> 2,
|
|
]);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
ProductSkuVerify::whereIn('sku_id', $ids)->where('status', 0)->update([
|
|
'status'=>$status,
|
|
'remarks'=>$remarks,
|
|
]);
|
|
|
|
return;
|
|
}
|
|
}
|