feat: 添加产品购买链接添加接口
This commit is contained in:
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace app\admin\validate\v1;
|
||||
|
||||
use app\admin\controller\v1\ProductPurchaseLink;
|
||||
use app\admin\model\v1\ProductPurchaseLinkModel;
|
||||
use think\Validate;
|
||||
|
||||
@@ -19,6 +18,7 @@ class ProductPurchaseLinkValidate extends Validate
|
||||
protected $rule = [
|
||||
'id' => 'require|integer',
|
||||
'link' => 'url|max:255',
|
||||
'product_id' => 'require|integer',
|
||||
'platform_id' => 'sameSpuPlatformCheck|integer'
|
||||
];
|
||||
|
||||
@@ -33,6 +33,8 @@ class ProductPurchaseLinkValidate extends Validate
|
||||
'id.integer' => 'id字段类型错误',
|
||||
'link.url' => '链接格式不正确',
|
||||
'link.max' => '链接不能超过255个字符',
|
||||
'product_id.require' => '产品id不能为空',
|
||||
'product_id.integer' => '产品id类型错误',
|
||||
'platform_id.sameSpuPlatformCheck' => '同型号平台不能重复',
|
||||
'platform_id.integer' => '平台id类型错误'
|
||||
|
||||
@@ -43,16 +45,28 @@ class ProductPurchaseLinkValidate extends Validate
|
||||
*/
|
||||
protected function sameSpuPlatformCheck($value, $rule, $data = [])
|
||||
{
|
||||
$sql = ProductPurchaseLinkModel::alias('s')
|
||||
->field(['s.product_id'])
|
||||
->where('s.id', '=', $data['id'])
|
||||
->limit(1)
|
||||
->buildSql();
|
||||
$product = 0;
|
||||
if (!empty($data['id'])) {
|
||||
$sql = ProductPurchaseLinkModel::alias('s')
|
||||
->field(['s.product_id'])
|
||||
->where('s.id', '=', $data['id'])
|
||||
->limit(1)
|
||||
->buildSql();
|
||||
$product = \think\facade\Db::raw($sql);
|
||||
} else {
|
||||
if (empty($data['product_id'])) {
|
||||
return false;
|
||||
}
|
||||
$product = $data['product_id'];
|
||||
}
|
||||
|
||||
$platforms = ProductPurchaseLinkModel::alias('p')
|
||||
->where('p.product_id', '=', \think\facade\Db::raw($sql))
|
||||
->where('p.id', '<>', $data['id'])
|
||||
->where('p.language_id', '=', $data['language_id'])
|
||||
->where(function ($query) use ($data, $product) {
|
||||
$query->where('p.product_id', '=', $product)->where('p.language_id', '=', $data['language_id']);
|
||||
if (!empty($data['id'])) {
|
||||
$query->where('p.id', '<>', $data['id']);
|
||||
}
|
||||
})
|
||||
->column(['p.platform_id']);
|
||||
if (!empty($platforms) && in_array($value, $platforms)) {
|
||||
return false;
|
||||
@@ -61,11 +75,19 @@ class ProductPurchaseLinkValidate extends Validate
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加场景
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['link', 'product_id', 'platform_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新场景
|
||||
*/
|
||||
public function sceneUpdate()
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'link', 'platform_id'])->remove('id', 'require');
|
||||
return $this->only(['id', 'link', 'platform_id']);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user