feat: 添加产品购买链接添加接口
This commit is contained in:
@@ -261,6 +261,34 @@ class ProductPurchaseLink
|
|||||||
->select();
|
->select();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加购买链接
|
||||||
|
*/
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$post = request()->post([
|
||||||
|
'link',
|
||||||
|
'product_id',
|
||||||
|
'platform_id'
|
||||||
|
]);
|
||||||
|
$data = [
|
||||||
|
'link' => $post['link'],
|
||||||
|
'language_id' => request()->lang_id,
|
||||||
|
'product_id' => $post['product_id'],
|
||||||
|
'platform_id' => $post['platform_id']
|
||||||
|
];
|
||||||
|
$validate = new ProductPurchaseLinkValidate;
|
||||||
|
if (!$validate->scene('add')->check($data)) {
|
||||||
|
return error($validate->getError());
|
||||||
|
}
|
||||||
|
|
||||||
|
$link = ProductPurchaseLinkModel::create($data);
|
||||||
|
if ($link->isEmpty()) {
|
||||||
|
return error('操作失败');
|
||||||
|
}
|
||||||
|
return success('操作成功');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新购买链接
|
* 更新购买链接
|
||||||
*/
|
*/
|
||||||
@@ -279,7 +307,7 @@ class ProductPurchaseLink
|
|||||||
'platform_id' => $put['platform_id']
|
'platform_id' => $put['platform_id']
|
||||||
];
|
];
|
||||||
$validate = new ProductPurchaseLinkValidate;
|
$validate = new ProductPurchaseLinkValidate;
|
||||||
if (!$validate->scene('update')->check($data)) {
|
if (!$validate->scene('edit')->check($data)) {
|
||||||
return error($validate->getError());
|
return error($validate->getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -323,6 +323,9 @@ Route::group('v1', function () {
|
|||||||
// 购买链接导出
|
// 购买链接导出
|
||||||
Route::get('export', 'ProductPurchaseLink/export');
|
Route::get('export', 'ProductPurchaseLink/export');
|
||||||
|
|
||||||
|
// 购买链接添加
|
||||||
|
Route::post('save', 'ProductPurchaseLink/save');
|
||||||
|
|
||||||
// 购买链接更新
|
// 购买链接更新
|
||||||
Route::put('update/:id', 'ProductPurchaseLink/update');
|
Route::put('update/:id', 'ProductPurchaseLink/update');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace app\admin\validate\v1;
|
namespace app\admin\validate\v1;
|
||||||
|
|
||||||
use app\admin\controller\v1\ProductPurchaseLink;
|
|
||||||
use app\admin\model\v1\ProductPurchaseLinkModel;
|
use app\admin\model\v1\ProductPurchaseLinkModel;
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
|
|
||||||
@@ -19,6 +18,7 @@ class ProductPurchaseLinkValidate extends Validate
|
|||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require|integer',
|
'id' => 'require|integer',
|
||||||
'link' => 'url|max:255',
|
'link' => 'url|max:255',
|
||||||
|
'product_id' => 'require|integer',
|
||||||
'platform_id' => 'sameSpuPlatformCheck|integer'
|
'platform_id' => 'sameSpuPlatformCheck|integer'
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -33,6 +33,8 @@ class ProductPurchaseLinkValidate extends Validate
|
|||||||
'id.integer' => 'id字段类型错误',
|
'id.integer' => 'id字段类型错误',
|
||||||
'link.url' => '链接格式不正确',
|
'link.url' => '链接格式不正确',
|
||||||
'link.max' => '链接不能超过255个字符',
|
'link.max' => '链接不能超过255个字符',
|
||||||
|
'product_id.require' => '产品id不能为空',
|
||||||
|
'product_id.integer' => '产品id类型错误',
|
||||||
'platform_id.sameSpuPlatformCheck' => '同型号平台不能重复',
|
'platform_id.sameSpuPlatformCheck' => '同型号平台不能重复',
|
||||||
'platform_id.integer' => '平台id类型错误'
|
'platform_id.integer' => '平台id类型错误'
|
||||||
|
|
||||||
@@ -43,16 +45,28 @@ class ProductPurchaseLinkValidate extends Validate
|
|||||||
*/
|
*/
|
||||||
protected function sameSpuPlatformCheck($value, $rule, $data = [])
|
protected function sameSpuPlatformCheck($value, $rule, $data = [])
|
||||||
{
|
{
|
||||||
$sql = ProductPurchaseLinkModel::alias('s')
|
$product = 0;
|
||||||
->field(['s.product_id'])
|
if (!empty($data['id'])) {
|
||||||
->where('s.id', '=', $data['id'])
|
$sql = ProductPurchaseLinkModel::alias('s')
|
||||||
->limit(1)
|
->field(['s.product_id'])
|
||||||
->buildSql();
|
->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')
|
$platforms = ProductPurchaseLinkModel::alias('p')
|
||||||
->where('p.product_id', '=', \think\facade\Db::raw($sql))
|
->where(function ($query) use ($data, $product) {
|
||||||
->where('p.id', '<>', $data['id'])
|
$query->where('p.product_id', '=', $product)->where('p.language_id', '=', $data['language_id']);
|
||||||
->where('p.language_id', '=', $data['language_id'])
|
if (!empty($data['id'])) {
|
||||||
|
$query->where('p.id', '<>', $data['id']);
|
||||||
|
}
|
||||||
|
})
|
||||||
->column(['p.platform_id']);
|
->column(['p.platform_id']);
|
||||||
if (!empty($platforms) && in_array($value, $platforms)) {
|
if (!empty($platforms) && in_array($value, $platforms)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -61,11 +75,19 @@ class ProductPurchaseLinkValidate extends Validate
|
|||||||
return true;
|
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