商品表优化
This commit is contained in:
@@ -22,7 +22,7 @@ use Modules\AnnoRoute\Attribute\RequestAttribute;
|
||||
use Modules\Common\Http\Controllers\BaseController;
|
||||
|
||||
/**
|
||||
* 商品档案管理(A1 商品列表 / A2 价格矩阵与批量调价 / 多等级价格体系)
|
||||
* 商品档案管理
|
||||
*/
|
||||
#[RequestAttribute('/product/goods', 'product.goods')]
|
||||
class ProductController extends BaseController
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Modules\SystemTool\Models\SysFileModel;
|
||||
|
||||
/**
|
||||
* 商品档案模型(品名/规格包规/供应商/等级/多等级价格体系)
|
||||
@@ -16,9 +18,9 @@ class ProductModel extends Model
|
||||
use SoftDeletes, HasFactory;
|
||||
|
||||
/** 状态:下架 */
|
||||
public const STATUS_OFF = 0;
|
||||
public const int STATUS_OFF = 0;
|
||||
/** 状态:上架 */
|
||||
public const STATUS_ON = 1;
|
||||
public const int STATUS_ON = 1;
|
||||
|
||||
protected $table = 'product';
|
||||
protected $primaryKey = 'id';
|
||||
@@ -28,10 +30,12 @@ class ProductModel extends Model
|
||||
'supplier_id',
|
||||
'name',
|
||||
'spec',
|
||||
'grade',
|
||||
'unit',
|
||||
'image',
|
||||
'images',
|
||||
'content',
|
||||
'sort',
|
||||
'shelf_life',
|
||||
'stock',
|
||||
'status',
|
||||
'remark',
|
||||
];
|
||||
@@ -39,10 +43,26 @@ class ProductModel extends Model
|
||||
protected $casts = [
|
||||
'category_id' => 'integer',
|
||||
'supplier_id' => 'integer',
|
||||
'shelf_life' => 'integer',
|
||||
'stock' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
public function images(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function($value){
|
||||
if (empty($value)) {
|
||||
return collect();
|
||||
}
|
||||
$ids = explode(',', $value);
|
||||
return SysFileModel::whereIn('id', $ids)->get();
|
||||
},
|
||||
set: fn ($value) => is_array($value) ? implode(',', $value) : $value,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所属分类
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user