Compare commits
10 Commits
39c0de87b7
...
1798f6ea8c
| Author | SHA1 | Date | |
|---|---|---|---|
| 1798f6ea8c | |||
| d39df73150 | |||
| 8582d93678 | |||
| 7bfb0cca1e | |||
| 2227390f77 | |||
| d3594feabd | |||
| 1724bf8afb | |||
| 94572876fb | |||
| d469a2c9f2 | |||
| a16e1a0ff1 |
@@ -8,6 +8,9 @@ use app\admin\validate\v1\ArticleValidate;
|
|||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章管理控制器
|
||||||
|
*/
|
||||||
class Article
|
class Article
|
||||||
{
|
{
|
||||||
// 文章列表
|
// 文章列表
|
||||||
@@ -75,7 +78,7 @@ class Article
|
|||||||
'updated_at',
|
'updated_at',
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
])
|
])
|
||||||
->id(request()->param('id'))
|
->bypk(request()->param('id'))
|
||||||
->find();
|
->find();
|
||||||
if (is_null($article)) {
|
if (is_null($article)) {
|
||||||
return error('文章不存在');
|
return error('文章不存在');
|
||||||
@@ -143,7 +146,7 @@ class Article
|
|||||||
return error($validate->getError());
|
return error($validate->getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
$article = ArticleModel::id($id)->find();
|
$article = ArticleModel::bypk($id)->find();
|
||||||
if (is_null($article)) {
|
if (is_null($article)) {
|
||||||
return error('请确认操作对象是否存在');
|
return error('请确认操作对象是否存在');
|
||||||
}
|
}
|
||||||
@@ -154,11 +157,31 @@ class Article
|
|||||||
return success('操作成功');
|
return success('操作成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置排序值
|
||||||
|
public function sort()
|
||||||
|
{
|
||||||
|
$id = request()->param('id');
|
||||||
|
$sort = request()->post('sort');
|
||||||
|
|
||||||
|
$article = ArticleModel::bypk($id)->find();
|
||||||
|
if (empty($article)) {
|
||||||
|
return error('请确认操作对象是否存在');
|
||||||
|
}
|
||||||
|
if ($sort != $article->sort) {
|
||||||
|
$article->sort = $sort;
|
||||||
|
if (!$article->save()) {
|
||||||
|
return error('操作失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return success('操作成功');
|
||||||
|
}
|
||||||
|
|
||||||
// 删除文章
|
// 删除文章
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
$id = request()->param('id');
|
$id = request()->param('id');
|
||||||
$article = ArticleModel::id($id)->find();
|
$article = ArticleModel::bypk($id)->find();
|
||||||
if (is_null($article)) {
|
if (is_null($article)) {
|
||||||
return error('请确认操作对象是否存在');
|
return error('请确认操作对象是否存在');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ namespace app\admin\controller\v1;
|
|||||||
use app\admin\model\v1\ArticleCategoryModel;
|
use app\admin\model\v1\ArticleCategoryModel;
|
||||||
use app\admin\validate\v1\ArticleCategoryValidate;
|
use app\admin\validate\v1\ArticleCategoryValidate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章分类管理控制器
|
||||||
|
*/
|
||||||
class ArticleCategory
|
class ArticleCategory
|
||||||
{
|
{
|
||||||
// 分类列表
|
// 分类列表
|
||||||
@@ -58,8 +61,8 @@ class ArticleCategory
|
|||||||
public function read()
|
public function read()
|
||||||
{
|
{
|
||||||
$id = request()->param('id');
|
$id = request()->param('id');
|
||||||
$category = ArticleCategoryModel::where('id', '=', $id)
|
$category = ArticleCategoryModel::withoutField(['language_id', 'deleted_at'])
|
||||||
->withoutField(['language_id', 'deleted_at'])
|
->bypk($id)
|
||||||
->find();
|
->find();
|
||||||
if (is_null($category)) {
|
if (is_null($category)) {
|
||||||
return error('文章分类不存在');
|
return error('文章分类不存在');
|
||||||
@@ -111,8 +114,8 @@ class ArticleCategory
|
|||||||
return error($valiate->getError());
|
return error($valiate->getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
$category = ArticleCategoryModel::where('id', '=', $id)->find();
|
$category = ArticleCategoryModel::bypk($id)->find();
|
||||||
if (is_null($category)) {
|
if (empty($category)) {
|
||||||
return error('请确认操作对象是否存在');
|
return error('请确认操作对象是否存在');
|
||||||
}
|
}
|
||||||
if (!$category->save($data)) {
|
if (!$category->save($data)) {
|
||||||
@@ -122,11 +125,31 @@ class ArticleCategory
|
|||||||
return success('操作成功');
|
return success('操作成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置排序值
|
||||||
|
public function sort()
|
||||||
|
{
|
||||||
|
$id = request()->param('id');
|
||||||
|
$sort = request()->post('sort');
|
||||||
|
|
||||||
|
$category = ArticleCategoryModel::bypk($id)->find();
|
||||||
|
if (empty($category)) {
|
||||||
|
return error('请确认操作对象是否存在');
|
||||||
|
}
|
||||||
|
if ($sort != $category->sort) {
|
||||||
|
$category->sort = $sort;
|
||||||
|
if (!$category->save()) {
|
||||||
|
return error('操作失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return success('操作成功');
|
||||||
|
}
|
||||||
|
|
||||||
// 删除分类
|
// 删除分类
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
$id = request()->param('id');
|
$id = request()->param('id');
|
||||||
$category = ArticleCategoryModel::where('id', '=', $id)->find();
|
$category = ArticleCategoryModel::bypk($id)->find();
|
||||||
if (is_null($category)) {
|
if (is_null($category)) {
|
||||||
return error('请确认操作对象是否存在');
|
return error('请确认操作对象是否存在');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ use app\admin\model\v1\ArticleLeaveMessageModel;
|
|||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章留言(评论)管理控制器
|
||||||
|
*/
|
||||||
class ArticleLeaveMessage
|
class ArticleLeaveMessage
|
||||||
{
|
{
|
||||||
// 文章留言分页列表
|
// 文章留言分页列表
|
||||||
@@ -56,7 +59,7 @@ class ArticleLeaveMessage
|
|||||||
$id = request()->param('id');
|
$id = request()->param('id');
|
||||||
|
|
||||||
// 审核/反审核
|
// 审核/反审核
|
||||||
$message = ArticleLeaveMessageModel::id($id)->find();
|
$message = ArticleLeaveMessageModel::bypk($id)->find();
|
||||||
if (is_null($message)) {
|
if (is_null($message)) {
|
||||||
return error('请确认操作对象');
|
return error('请确认操作对象');
|
||||||
}
|
}
|
||||||
@@ -75,7 +78,7 @@ class ArticleLeaveMessage
|
|||||||
$id = request()->param('id');
|
$id = request()->param('id');
|
||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
$message = ArticleLeaveMessageModel::id($id)->find();
|
$message = ArticleLeaveMessageModel::bypk($id)->find();
|
||||||
if (is_null($message)) {
|
if (is_null($message)) {
|
||||||
return error('请确认操作对象');
|
return error('请确认操作对象');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ namespace app\admin\controller\v1;
|
|||||||
|
|
||||||
use app\admin\model\v1\ArticleModel;
|
use app\admin\model\v1\ArticleModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章回收站管理控制器
|
||||||
|
*/
|
||||||
class ArticleTrash
|
class ArticleTrash
|
||||||
{
|
{
|
||||||
// 文章回收站分页列表
|
// 文章回收站分页列表
|
||||||
@@ -50,7 +53,7 @@ class ArticleTrash
|
|||||||
return error('参数错误');
|
return error('参数错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
$article = ArticleModel::onlyTrashed()->id($id)->find();
|
$article = ArticleModel::onlyTrashed()->bypk($id)->find();
|
||||||
if (is_null($article)) {
|
if (is_null($article)) {
|
||||||
return error('请确认操作对象');
|
return error('请确认操作对象');
|
||||||
}
|
}
|
||||||
@@ -69,7 +72,7 @@ class ArticleTrash
|
|||||||
return error('参数错误');
|
return error('参数错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
$article = ArticleModel::onlyTrashed()->id($id)->find();
|
$article = ArticleModel::onlyTrashed()->bypk($id)->find();
|
||||||
if (is_null($article)) {
|
if (is_null($article)) {
|
||||||
return error('请确认操作对象');
|
return error('请确认操作对象');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ namespace app\admin\controller\v1;
|
|||||||
use think\facade\Cache;
|
use think\facade\Cache;
|
||||||
use think\facade\Config;
|
use think\facade\Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码控制器
|
||||||
|
*/
|
||||||
class Captcha
|
class Captcha
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ use app\admin\model\v1\ImageModel;
|
|||||||
use Intervention\Image\ImageManager;
|
use Intervention\Image\ImageManager;
|
||||||
use think\facade\Filesystem;
|
use think\facade\Filesystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片管理控制器
|
||||||
|
*/
|
||||||
class Images
|
class Images
|
||||||
{
|
{
|
||||||
// 上传
|
// 上传
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ use app\admin\model\v1\LanguageModel;
|
|||||||
use think\facade\Cookie;
|
use think\facade\Cookie;
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语言管理控制器
|
||||||
|
*/
|
||||||
class Language
|
class Language
|
||||||
{
|
{
|
||||||
// 语言列表
|
// 语言列表
|
||||||
@@ -32,7 +35,7 @@ class Language
|
|||||||
public function cutover()
|
public function cutover()
|
||||||
{
|
{
|
||||||
$id = request()->param('id');
|
$id = request()->param('id');
|
||||||
$language = LanguageModel::id($id)->find();
|
$language = LanguageModel::bypk($id)->find();
|
||||||
if (is_null($language)) {
|
if (is_null($language)) {
|
||||||
return error('语言不存在');
|
return error('语言不存在');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ use app\admin\validate\v1\LoginValidate;
|
|||||||
use thans\jwt\facade\JWTAuth;
|
use thans\jwt\facade\JWTAuth;
|
||||||
use think\facade\Cache;
|
use think\facade\Cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录控制器
|
||||||
|
*/
|
||||||
class Login
|
class Login
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,10 +6,15 @@ namespace app\admin\controller\v1;
|
|||||||
use app\admin\model\v1\ProductModel;
|
use app\admin\model\v1\ProductModel;
|
||||||
use app\admin\model\v1\ProductParamsModel;
|
use app\admin\model\v1\ProductParamsModel;
|
||||||
use app\admin\model\v1\ProductRelatedModel;
|
use app\admin\model\v1\ProductRelatedModel;
|
||||||
|
use app\admin\model\v1\ProductSkuAttrModel;
|
||||||
|
use app\admin\model\v1\ProductSkuModel;
|
||||||
use app\admin\validate\v1\ProductValidate;
|
use app\admin\validate\v1\ProductValidate;
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品管理控制器
|
||||||
|
*/
|
||||||
class Product
|
class Product
|
||||||
{
|
{
|
||||||
// 分页列表
|
// 分页列表
|
||||||
@@ -88,6 +93,15 @@ class Product
|
|||||||
}
|
}
|
||||||
$product->params = implode(PHP_EOL, $params);
|
$product->params = implode(PHP_EOL, $params);
|
||||||
|
|
||||||
|
// 获取sku数据
|
||||||
|
$product->skus = ProductSkuModel::withoutField(['created_at', 'updated_at'])
|
||||||
|
->with(['attrs' => function($query) {
|
||||||
|
$query->hidden(['sku_id']);
|
||||||
|
}])
|
||||||
|
->productId($product->id)
|
||||||
|
->select()
|
||||||
|
->hidden(['id', 'product_id']);
|
||||||
|
|
||||||
// 获取关联产品
|
// 获取关联产品
|
||||||
$product->related = ProductRelatedModel::field([
|
$product->related = ProductRelatedModel::field([
|
||||||
'related_product_id',
|
'related_product_id',
|
||||||
@@ -123,19 +137,22 @@ class Product
|
|||||||
'is_show',
|
'is_show',
|
||||||
'sort',
|
'sort',
|
||||||
'detail',
|
'detail',
|
||||||
'params' => '',
|
'params' => '',
|
||||||
|
'skus' => '',
|
||||||
'related' => '',
|
'related' => '',
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
'seo_title',
|
'seo_title',
|
||||||
'seo_keywords',
|
'seo_keywords',
|
||||||
'seo_desc'
|
'seo_desc'
|
||||||
]);
|
]);
|
||||||
|
$put = array_merge(
|
||||||
|
$put,
|
||||||
|
['skus' => json_decode($put['skus'], true)],
|
||||||
|
['related' => json_decode($put['related'], true)],
|
||||||
|
);
|
||||||
|
|
||||||
$validate = new ProductValidate();
|
$validate = new ProductValidate();
|
||||||
$check_data = array_merge($put, [
|
$check_data = array_merge($put, ['id' => $id, 'language_id' => request()->lang_id]);
|
||||||
'id' => $id,
|
|
||||||
'language_id' => request()->lang_id
|
|
||||||
]);
|
|
||||||
if (!$validate->scene('update')->check($check_data)) {
|
if (!$validate->scene('update')->check($check_data)) {
|
||||||
return error($validate->getError());
|
return error($validate->getError());
|
||||||
}
|
}
|
||||||
@@ -160,24 +177,92 @@ class Product
|
|||||||
'value' => $match_result[2][$i]
|
'value' => $match_result[2][$i]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
if (!empty($params)) ProductParamsModel::insertAll($params);
|
if (!empty($params)) {
|
||||||
|
ProductParamsModel::insertAll($params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新SKU
|
||||||
|
if (!empty($put['skus'])) {
|
||||||
|
$skus = [];
|
||||||
|
$attrs_group = [];
|
||||||
|
foreach ($put['skus'] as $val) {
|
||||||
|
$skus[] = [
|
||||||
|
'product_id' => $id,
|
||||||
|
'sku' => $val['sku'],
|
||||||
|
'main_image' => $val['main_image'],
|
||||||
|
'photo_album' => $val['photo_album'],
|
||||||
|
'sort' => $val['sort']
|
||||||
|
];
|
||||||
|
foreach ($val['attrs'] as $v) {
|
||||||
|
$attrs_group[$val['sku']][] = [
|
||||||
|
'attr_id' => $v['attr_id'],
|
||||||
|
'attr_value' => $v['attr_value']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($skus)) {
|
||||||
|
$sku_model = new ProductSkuModel;
|
||||||
|
// 删除原有SKU
|
||||||
|
$sku_model->productId($id)->delete();
|
||||||
|
// 添加SKU
|
||||||
|
$save_ret = $sku_model->saveAll($skus);
|
||||||
|
if (!$save_ret->isEmpty()) {
|
||||||
|
$sku_map = [];
|
||||||
|
foreach ($save_ret as $val) {
|
||||||
|
$sku_map[$val->sku] = $val->id;
|
||||||
|
}
|
||||||
|
$attrs = [];
|
||||||
|
foreach ($attrs_group as $sku => $sku_attrs) {
|
||||||
|
if (empty($sku_map[$sku])) {
|
||||||
|
unset($attrs_group[$sku]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($sku_attrs as $k => $v) {
|
||||||
|
$attrs[] = array_merge($v, ['sku_id' => $sku_map[$sku]]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(new ProductSkuAttrModel)->saveAll($attrs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新关联产品
|
// 更新关联产品
|
||||||
if ($put['related'] != "") {
|
if (!empty($put['related'])) {
|
||||||
|
// 删除原有关联产品
|
||||||
ProductRelatedModel::productId($id)->delete();
|
ProductRelatedModel::productId($id)->delete();
|
||||||
$encode_result = json_decode($put['related'], true);
|
// 添加关联产品
|
||||||
if (!empty($encode_result)) {
|
$related = [];
|
||||||
$related = [];
|
foreach ($put['related'] as $val) {
|
||||||
foreach ($encode_result as $val) {
|
$related[] = [
|
||||||
$related[] = [
|
'product_id' => $id,
|
||||||
'product_id' => $id,
|
'related_product_id' => $val['related_product_id'],
|
||||||
'related_product_id' => $val['related_product_id'],
|
'sort' => $val['sort']
|
||||||
'sort' => $val['sort']
|
];
|
||||||
];
|
}
|
||||||
}
|
if (!empty($related)) {
|
||||||
if (!empty($related)) ProductRelatedModel::insertAll($related);
|
ProductRelatedModel::insertAll($related);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return success('操作成功');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置排序值
|
||||||
|
public function sort()
|
||||||
|
{
|
||||||
|
$id = request()->param('id');
|
||||||
|
$sort = request()->post('sort');
|
||||||
|
|
||||||
|
$product = ProductModel::bypk($id)->find();
|
||||||
|
if (empty($product)) {
|
||||||
|
return error('请确认操作对象是否存在');
|
||||||
|
}
|
||||||
|
if ($sort != $product->sort) {
|
||||||
|
$product->sort = $sort;
|
||||||
|
if (!$product->save()) {
|
||||||
|
return error('操作失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ use app\admin\model\v1\ProductAttrModel;
|
|||||||
use app\admin\model\v1\ProductAttrPropModel;
|
use app\admin\model\v1\ProductAttrPropModel;
|
||||||
use app\admin\validate\v1\ProductAttrValidate;
|
use app\admin\validate\v1\ProductAttrValidate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品属性管理控制器
|
||||||
|
*/
|
||||||
class ProductAttr
|
class ProductAttr
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ namespace app\admin\controller\v1;
|
|||||||
use app\admin\model\v1\ProductCategoryModel;
|
use app\admin\model\v1\ProductCategoryModel;
|
||||||
use app\admin\validate\v1\ProductCategoryValidate;
|
use app\admin\validate\v1\ProductCategoryValidate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品分类管理控制器
|
||||||
|
*/
|
||||||
class ProductCategory
|
class ProductCategory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,12 +22,6 @@ class ArticleLeaveMessageModel extends ArticleLeaveMessageBaseModel
|
|||||||
return $this->belongsTo(ArticleModel::class, 'article_id', 'id');
|
return $this->belongsTo(ArticleModel::class, 'article_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id查询
|
|
||||||
public function scopeId($query, $value)
|
|
||||||
{
|
|
||||||
$query->where('id', '=', $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 审核状态查询
|
// 审核状态查询
|
||||||
public function scopeIsAudited($query, $is_audited)
|
public function scopeIsAudited($query, $is_audited)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,12 +40,6 @@ class ArticleModel extends ArticleBaseModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 主键查询
|
|
||||||
public function scopeId($query, $value)
|
|
||||||
{
|
|
||||||
$query->where('id', '=', $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 语言查询
|
// 语言查询
|
||||||
public function scopeLanguage($query, $value)
|
public function scopeLanguage($query, $value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,10 +15,4 @@ class LanguageModel extends LanguageBaseModel
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(CountryModel::class, 'country_id', 'id');
|
return $this->belongsTo(CountryModel::class, 'country_id', 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据id查询
|
|
||||||
public function scopeId($query, $value)
|
|
||||||
{
|
|
||||||
$query->where('id', '=', $value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
15
app/admin/model/v1/ProductSkuAttrModel.php
Normal file
15
app/admin/model/v1/ProductSkuAttrModel.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
declare (strict_types = 1);
|
||||||
|
|
||||||
|
namespace app\admin\model\v1;
|
||||||
|
|
||||||
|
use app\common\model\ProductSkuAttrBaseModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品 - sku属性模型
|
||||||
|
* @mixin \think\Model
|
||||||
|
*/
|
||||||
|
class ProductSkuAttrModel extends ProductSkuAttrBaseModel
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
30
app/admin/model/v1/ProductSkuModel.php
Normal file
30
app/admin/model/v1/ProductSkuModel.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
declare (strict_types = 1);
|
||||||
|
|
||||||
|
namespace app\admin\model\v1;
|
||||||
|
|
||||||
|
use app\common\model\ProductSkuBaseModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品 - sku模型
|
||||||
|
* @mixin \think\Model
|
||||||
|
*/
|
||||||
|
class ProductSkuModel extends ProductSkuBaseModel
|
||||||
|
{
|
||||||
|
// 设置json类型字段
|
||||||
|
protected $json = ['photo_album'];
|
||||||
|
// 设置JSON数据返回数组
|
||||||
|
protected $jsonAssoc = true;
|
||||||
|
|
||||||
|
// 关联产品sku属性
|
||||||
|
public function attrs()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ProductSkuAttrModel::class, 'sku_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 所属产品查询
|
||||||
|
public function scopeProductId($query, $id)
|
||||||
|
{
|
||||||
|
$query->where('product_id', '=', $id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,6 +55,9 @@ Route::group('v1', function () {
|
|||||||
// 文章更新
|
// 文章更新
|
||||||
Route::put('update/:id', 'Article/update');
|
Route::put('update/:id', 'Article/update');
|
||||||
|
|
||||||
|
// 设置排序值
|
||||||
|
Route::post('sort/:id', 'Article/sort');
|
||||||
|
|
||||||
// 文章删除
|
// 文章删除
|
||||||
Route::delete('delete/:id', 'Article/delete');
|
Route::delete('delete/:id', 'Article/delete');
|
||||||
|
|
||||||
@@ -78,6 +81,9 @@ Route::group('v1', function () {
|
|||||||
// 分类更新
|
// 分类更新
|
||||||
Route::put('update/:id', 'ArticleCategory/update');
|
Route::put('update/:id', 'ArticleCategory/update');
|
||||||
|
|
||||||
|
// 设置排序值
|
||||||
|
Route::post('sort/:id', 'ArticleCategory/sort');
|
||||||
|
|
||||||
// 分类删除
|
// 分类删除
|
||||||
Route::delete('delete/:id', 'ArticleCategory/delete');
|
Route::delete('delete/:id', 'ArticleCategory/delete');
|
||||||
});
|
});
|
||||||
@@ -121,6 +127,9 @@ Route::group('v1', function () {
|
|||||||
// 产品更新
|
// 产品更新
|
||||||
Route::put('update/:id', 'Product/update');
|
Route::put('update/:id', 'Product/update');
|
||||||
|
|
||||||
|
// 设置排序值
|
||||||
|
Route::post('sort/:id', 'Product/sort');
|
||||||
|
|
||||||
// 上/下架操作
|
// 上/下架操作
|
||||||
Route::get('updown_shelves/:id', 'Product/updownShelves');
|
Route::get('updown_shelves/:id', 'Product/updownShelves');
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ namespace app\admin\validate\v1;
|
|||||||
|
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
|
|
||||||
|
use function PHPSTORM_META\type;
|
||||||
|
|
||||||
class ProductValidate extends Validate
|
class ProductValidate extends Validate
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -14,25 +16,32 @@ class ProductValidate extends Validate
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'language_id' => 'require|integer',
|
'language_id' => 'require|integer',
|
||||||
'category_id' => 'integer',
|
'category_id' => 'integer',
|
||||||
'spu' => 'require|max:255',
|
'spu' => 'require|max:255',
|
||||||
'name' => 'require|max:125',
|
'name' => 'require|max:125',
|
||||||
'short_name' => 'max:64',
|
'short_name' => 'max:64',
|
||||||
'cover_image' => 'max:255',
|
'cover_image' => 'max:255',
|
||||||
'desc' => 'max:255',
|
'desc' => 'max:255',
|
||||||
'video_img' => 'max:255',
|
'video_img' => 'max:255',
|
||||||
'video_url' => 'max:255',
|
'video_url' => 'max:255',
|
||||||
'is_sale' => 'in:0,1',
|
'is_sale' => 'in:0,1',
|
||||||
'is_new' => 'in:0,1',
|
'is_new' => 'in:0,1',
|
||||||
'is_hot' => 'in:0,1',
|
'is_hot' => 'in:0,1',
|
||||||
'sort' => 'integer',
|
'is_show' => 'in:0,1',
|
||||||
'detail' => 'max:65535',
|
'sort' => 'integer',
|
||||||
'status' => 'in:-1,1',
|
'detail' => 'max:65535',
|
||||||
'seo_title' => 'max:255',
|
'status' => 'in:-1,1',
|
||||||
'seo_keywords' => 'max:255',
|
'seo_title' => 'max:255',
|
||||||
'seo_desc' => 'max:255',
|
'seo_keywords' => 'max:255',
|
||||||
'created_at' => 'checkFormatDatetimeRange'
|
'seo_desc' => 'max:255',
|
||||||
|
'created_at' => 'checkFormatDatetimeRange',
|
||||||
|
'skus.*.sku' => 'max:125',
|
||||||
|
'skus.*.main_image' => 'max:255',
|
||||||
|
'skus.*.sort' => 'integer',
|
||||||
|
'skus.*.attrs' => 'checkSkusAttrsItemType:attr_id,integer|checkSkusAttrsItemMax:attr_value,64',
|
||||||
|
'related.*.related_product_id' => 'integer',
|
||||||
|
'related.*.sort' => 'integer',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,28 +51,36 @@ class ProductValidate extends Validate
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $message = [
|
protected $message = [
|
||||||
'language_id.require' => '语言ID不能为空',
|
'language_id.require' => '语言ID不能为空',
|
||||||
'language_id.integer' => '语言ID必须为整数',
|
'language_id.integer' => '语言ID必须为整数',
|
||||||
'category_id.integer' => '分类ID必须为整数',
|
'category_id.integer' => '分类ID必须为整数',
|
||||||
'spu.require' => 'spu不能为空',
|
'spu.require' => 'spu不能为空',
|
||||||
'spu.max' => 'spu不能超过255个字符',
|
'spu.max' => 'spu不能超过255个字符',
|
||||||
'name.require' => '名称不能为空',
|
'name.require' => '名称不能为空',
|
||||||
'name.max' => '名称不能超过125个字符',
|
'name.max' => '名称不能超过125个字符',
|
||||||
'short_name.max' => '短标题不能超过64个字符',
|
'short_name.max' => '短标题不能超过64个字符',
|
||||||
'cover_image.max' => '封面图不能超过255个字符',
|
'cover_image.max' => '封面图不能超过255个字符',
|
||||||
'desc.max' => '描述不能超过255个字符',
|
'desc.max' => '描述不能超过255个字符',
|
||||||
'video_img.max' => '视频封面图不能超过255个字符',
|
'video_img.max' => '视频封面图不能超过255个字符',
|
||||||
'video_url.max' => '视频地址不能超过255个字符',
|
'video_url.max' => '视频地址不能超过255个字符',
|
||||||
'is_sale.in' => '上架状态值错误',
|
'is_sale.in' => '在售状态值错误',
|
||||||
'is_new.in' => '新品状态值错误',
|
'is_new.in' => '新品状态值错误',
|
||||||
'is_hot.in' => '热门状态值错误',
|
'is_hot.in' => '热门状态值错误',
|
||||||
'sort.integer' => '排序值类型错误',
|
'is_show.in' => '上下架状态值错误',
|
||||||
'detail.max' => '详情不能超过65535个字符',
|
'sort.integer' => '排序值类型错误',
|
||||||
'status.in' => '状态值错误',
|
'detail.max' => '详情不能超过65535个字符',
|
||||||
'seo_title.max' => 'seo标题不能超过255个字符',
|
'status.in' => '状态值错误',
|
||||||
'seo_keywords.max' => 'seo关键字不能超过255个字符',
|
'seo_title.max' => 'seo标题不能超过255个字符',
|
||||||
'seo_desc.max' => 'seo描述不能超过255个字符',
|
'seo_keywords.max' => 'seo关键字不能超过255个字符',
|
||||||
'created_at.checkFormatDatetimeRange' => '添加时间格式错误'
|
'seo_desc.max' => 'seo描述不能超过255个字符',
|
||||||
|
'created_at.checkFormatDatetimeRange' => '添加时间格式错误',
|
||||||
|
'skus.*.sku.max' => 'sku不能超过125个字符',
|
||||||
|
'skus.*.main_image.max' => 'sku主图不能超过255个字符',
|
||||||
|
'skus.*.sort.integer' => 'sku排序值类型错误',
|
||||||
|
'skus.*.attrs.checkSkusAttrsItemType' => 'sku属性值错误',
|
||||||
|
'skus.*.attrs.checkSkusAttrsItemMax' => 'sku属性值错误',
|
||||||
|
'related.*.related_product_id.integer' => '关联产品ID格式错误',
|
||||||
|
'related.*.sort.integer' => '关联产品排序值类型错误',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +88,7 @@ class ProductValidate extends Validate
|
|||||||
*/
|
*/
|
||||||
public function sceneIndex()
|
public function sceneIndex()
|
||||||
{
|
{
|
||||||
return $this->only(['created_id', 'is_sale', 'created_at']);
|
return $this->only(['categroy_id', 'is_show', 'created_at']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,12 +109,19 @@ class ProductValidate extends Validate
|
|||||||
'is_sale',
|
'is_sale',
|
||||||
'is_new',
|
'is_new',
|
||||||
'is_hot',
|
'is_hot',
|
||||||
|
'is_show',
|
||||||
'sort',
|
'sort',
|
||||||
'detail',
|
'detail',
|
||||||
'status',
|
'status',
|
||||||
'seo_title',
|
'seo_title',
|
||||||
'seo_keywords',
|
'seo_keywords',
|
||||||
'seo_desc',
|
'seo_desc',
|
||||||
|
'skus.*.sku',
|
||||||
|
'skus.*.main_image',
|
||||||
|
'skus.*.sort',
|
||||||
|
'skus.*.attrs',
|
||||||
|
'related.*.related_product_id',
|
||||||
|
'related.*.sort'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,4 +140,32 @@ class ProductValidate extends Validate
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function checkSkusAttrsItemType($value, $rule, $data)
|
||||||
|
{
|
||||||
|
$rule = explode(',', $rule);
|
||||||
|
foreach ($value as $v) {
|
||||||
|
if (!array_key_exists($rule[0], $v)) {
|
||||||
|
return 'sku属性值错误';
|
||||||
|
}
|
||||||
|
if ($rule[1] == gettype($rule[0])) {
|
||||||
|
return "sku中{$rule[0]}类型错误";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkSkusAttrsItemMax($value, $rule, $data)
|
||||||
|
{
|
||||||
|
$rule = explode(',', $rule);
|
||||||
|
foreach ($value as $v) {
|
||||||
|
if (!array_key_exists($rule[0], $v)) {
|
||||||
|
return 'sku属性值错误';
|
||||||
|
}
|
||||||
|
if (intval($rule[1]) < mb_strlen($v[$rule[0]], 'utf8')) {
|
||||||
|
return "sku属性{$rule[0]}不能超过{$rule[1]}个字符";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ declare (strict_types = 1);
|
|||||||
|
|
||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
use think\Model;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin \think\Model
|
* @mixin \think\Model
|
||||||
*/
|
*/
|
||||||
class ArticleBaseModel extends Model
|
class ArticleBaseModel extends BaseModel
|
||||||
{
|
{
|
||||||
// 表名
|
// 表名
|
||||||
protected $name = 'article';
|
protected $name = 'article';
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ declare (strict_types = 1);
|
|||||||
|
|
||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
use think\Model;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin \think\Model
|
* @mixin \think\Model
|
||||||
*/
|
*/
|
||||||
class ArticleCategoryBaseModel extends Model
|
class ArticleCategoryBaseModel extends BaseModel
|
||||||
{
|
{
|
||||||
// 表名
|
// 表名
|
||||||
protected $name = 'article_category';
|
protected $name = 'article_category';
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ declare (strict_types = 1);
|
|||||||
|
|
||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
use think\Model;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin \think\Model
|
* @mixin \think\Model
|
||||||
*/
|
*/
|
||||||
class ArticleLeaveMessageBaseModel extends Model
|
class ArticleLeaveMessageBaseModel extends BaseModel
|
||||||
{
|
{
|
||||||
// 表名
|
// 表名
|
||||||
protected $name = 'article_leave_message';
|
protected $name = 'article_leave_message';
|
||||||
|
|||||||
@@ -3,12 +3,10 @@ declare (strict_types = 1);
|
|||||||
|
|
||||||
namespace app\common\model;
|
namespace app\common\model;
|
||||||
|
|
||||||
use think\Model;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin \think\Model
|
* @mixin \think\Model
|
||||||
*/
|
*/
|
||||||
class LanguageBaseModel extends Model
|
class LanguageBaseModel extends BaseModel
|
||||||
{
|
{
|
||||||
// 表名
|
// 表名
|
||||||
protected $name = 'sys_language';
|
protected $name = 'sys_language';
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ class ProductSkuAttrBaseModel extends Model
|
|||||||
|
|
||||||
// 字段信息
|
// 字段信息
|
||||||
protected $schema = [
|
protected $schema = [
|
||||||
'sku_id' => 'int',
|
'sku_id' => 'int',
|
||||||
'attr_id' => 'int',
|
'attr_id' => 'int',
|
||||||
'prop_id' => 'int',
|
'attr_value' => 'string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class CreateProductSkuAttr extends Migrator
|
|||||||
$table = $this->table('product_sku_attr', ['id' => false,'engine' => 'InnoDB', 'comment' => '产品SKU属性表']);
|
$table = $this->table('product_sku_attr', ['id' => false,'engine' => 'InnoDB', 'comment' => '产品SKU属性表']);
|
||||||
$table->addColumn('sku_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '产品SKU ID'])
|
$table->addColumn('sku_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '产品SKU ID'])
|
||||||
->addColumn('attr_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '属性ID'])
|
->addColumn('attr_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '属性ID'])
|
||||||
->addColumn('prop_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '属性特征ID'])
|
->addColumn('attr_value', 'string', ['limit' => 64, 'null' => false, 'default' => '', 'comment' => '属性值'])
|
||||||
->addForeignKey('sku_id', 'product_sku', 'id', ['update' => 'CASCADE', 'delete' => 'CASCADE'])
|
->addForeignKey('sku_id', 'product_sku', 'id', ['update' => 'CASCADE', 'delete' => 'CASCADE'])
|
||||||
->create();
|
->create();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user