feat: master 商品名称搜索优化

This commit is contained in:
赵世界 2024-03-14 14:29:23 +08:00
parent 5ea7e26b97
commit ab9e209910
16 changed files with 113 additions and 26 deletions

View File

@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands;
use App\Models\GoodsSku;
use Illuminate\Console\Command;
class UpdateGoodsSkuName extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update:goods_skus:name';
/**
* The console command description.
*
* @var string
*/
protected $description = '更新goods_sku的完整名称';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle()
{
GoodsSku::query()
->where('name', '')
->where('is_combination', 0)
->chunk(500, static function ($skus) {
foreach ($skus as $sku) {
$sku->name = $sku->goods->title . $sku->title;
$sku->save();
}
});
}
}

View File

@ -4,11 +4,6 @@ namespace App\Filters;
class GoodsFilter extends Filters class GoodsFilter extends Filters
{ {
protected function goodsTitle($value)
{
return $this->builder->where('title', 'like', "%$value%");
}
protected function typeId($value) protected function typeId($value)
{ {
if($value){ if($value){

View File

@ -61,6 +61,7 @@ class GoodsController extends Controller
$item['stock'] = $item['num']; $item['stock'] = $item['num'];
$item['reference_price'] = $item['cost'] * 1.5; $item['reference_price'] = $item['cost'] * 1.5;
$item['external_sku_id'] = $goods->goods_code . '_' . $item['sku_code']; $item['external_sku_id'] = $goods->goods_code . '_' . $item['sku_code'];
$item['name'] = $goods->goods_code . $item['title'];
$goodsSkus[] = $item; $goodsSkus[] = $item;
} }
$collection = $goods->skus()->createMany($goodsSkus)->toArray(); $collection = $goods->skus()->createMany($goodsSkus)->toArray();

View File

@ -140,10 +140,13 @@ class GoodsSkusController extends Controller
->toArray(); ->toArray();
$builder->whereIn('id', $skuIds); $builder->whereIn('id', $skuIds);
} }
if ($request->get('goods_title') || $request->get('type_id') || $request->get('brand_id')) { if ($request->get('type_id') || $request->get('brand_id')) {
$goodsIds = Goods::query()->filter()->pluck('id')->toArray(); $goodsIds = Goods::query()->filter()->pluck('id')->toArray();
$builder->whereIn('goods_id', $goodsIds); $builder->whereIn('goods_id', $goodsIds);
} }
if ($request->get('goods_title')) {
$builder->where('name', 'like', '%' . $request->goods_title . '%');
}
} }
public function show($id) public function show($id)
@ -185,6 +188,7 @@ class GoodsSkusController extends Controller
$this->setBeforeUpdateForLog($sku->toArray()); $this->setBeforeUpdateForLog($sku->toArray());
$skuInfo = $request->sku; $skuInfo = $request->sku;
$skuInfo['external_sku_id'] = $request->goods['goods_code'] . '_' . $request->sku['sku_code']; $skuInfo['external_sku_id'] = $request->goods['goods_code'] . '_' . $request->sku['sku_code'];
$skuInfo['name'] = $request->goods['title'] . $request->sku['title'];
$sku->update($skuInfo); $sku->update($skuInfo);
$this->setAfterUpdateForLog($sku->toArray()); $this->setAfterUpdateForLog($sku->toArray());
$this->addLog($id, 'update'); $this->addLog($id, 'update');

View File

@ -10,7 +10,6 @@ class Goods extends Model
//查询字段 //查询字段
public $fieldSearchable = [ public $fieldSearchable = [
'goods_title',
'type_id', 'type_id',
'brand_id', 'brand_id',
]; ];

View File

@ -28,7 +28,7 @@ class CreateGroupsTable extends Migration
$table->string('activity_no')->nullable()->comment('团号'); $table->string('activity_no')->nullable()->comment('团号');
$table->unsignedTinyInteger('create_status')->default(3)->comment('1-创建成功,2-创建失败,3-创建中'); $table->unsignedTinyInteger('create_status')->default(3)->comment('1-创建成功,2-创建失败,3-创建中');
$table->string('error_msg')->nullable()->comment('create_status为2时有创建团失败原因'); $table->string('error_msg')->nullable()->comment('create_status为2时有创建团失败原因');
$table->text('qr_code_url')->nullable()->comment('create_status为1时有团小程序二维码图片地址'); $table->string('qr_code_url')->default('')->comment('create_status为1时有团小程序二维码图片地址');
$table->unsignedBigInteger('create_time')->nullable(); $table->unsignedBigInteger('create_time')->nullable();
$table->unsignedTinyInteger('is_help_sell')->nullable()->comment('是否帮卖0-我发布的,1-我帮卖的'); $table->unsignedTinyInteger('is_help_sell')->nullable()->comment('是否帮卖0-我发布的,1-我帮卖的');
$table->tinyInteger('status')->default(-10)->comment('团状态(-10:待发布/预览中,-5:未开始1:跟团中20:已结束30:已删除'); $table->tinyInteger('status')->default(-10)->comment('团状态(-10:待发布/预览中,-5:未开始1:跟团中20:已结束30:已删除');

View File

@ -13,6 +13,9 @@ class CreateDailyReportsTable extends Migration
*/ */
public function up() public function up()
{ {
if (Schema::hasTable('daily_reports')) {
return;
}
Schema::create('daily_reports', function (Blueprint $table) { Schema::create('daily_reports', function (Blueprint $table) {
$table->bigIncrements('id'); $table->bigIncrements('id');
$table->date('date'); $table->date('date');

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddNameToGoodsSkusTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasColumn('goods_skus', 'name')) {
return;
}
Schema::table('goods_skus', function (Blueprint $table) {
$table->string('name')->default('')->comment('完整商品名称');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('goods_skus', function (Blueprint $table) {
$table->dropColumn('name');
});
}
}

View File

@ -17,7 +17,7 @@ export function goods(params) {
params, params,
}); });
} }
// 新建商品 // 新增商品/规格
export function addGoods(data) { export function addGoods(data) {
return http({ return http({
url: "/api/goods", url: "/api/goods",

View File

@ -18,7 +18,7 @@ const list = [
}, },
{ {
path: "ADDGOODS", path: "ADDGOODS",
name: "新建商品", name: "新增商品/规格",
component: () => import("../views/goods/addgoods/addgoods.vue"), component: () => import("../views/goods/addgoods/addgoods.vue"),
}, },
{ {

View File

@ -62,6 +62,7 @@ export default {
} }
if (data.token) { if (data.token) {
localStorage.setItem("userName", this.form.name);
this.form = {}; this.form = {};
localStorage.setItem("token", data.token); localStorage.setItem("token", data.token);
this.$message({ this.$message({

View File

@ -1,7 +1,7 @@
<template> <template>
<div> <div>
<el-card class="box-card"> <el-card class="box-card">
<!-- 商品进入显示 --> <!-- 商品进入显示 -->
<el-form ref="form" :inline="true" :model="form"> <el-form ref="form" :inline="true" :model="form">
<div> <div>
<el-form-item label="商品列表:"> <el-form-item label="商品列表:">

View File

@ -6,7 +6,7 @@
<div class="goods"> <div class="goods">
<el-form ref="form" :inline="true" :model="form"> <el-form ref="form" :inline="true" :model="form">
<el-form-item label="商品名称:"> <el-form-item label="商品名称:">
<el-input v-model="form.goods_title" placeholder="商品名称" style="width: 100px"> <el-input v-model="form.goods_title" placeholder="商品名称" style="width: 240px">
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item label="商品种类:"> <el-form-item label="商品种类:">
@ -36,7 +36,7 @@
<el-option v-for="item in options3" :key="item.value" :label="item.label" :value="item.value"> <el-option v-for="item in options3" :key="item.value" :label="item.label" :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
<el-date-picker v-model="value1" type="datetimerange" range-separator="" start-placeholder="开始时间" <el-date-picker v-model="value1" type="datetimerange" range-separator="-" start-placeholder="开始时间"
end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss" @change="getSTime" end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss" @change="getSTime"
style="width: 300px"> style="width: 300px">
</el-date-picker> </el-date-picker>
@ -69,7 +69,7 @@
:on-error="inventoryError" style="display:inline-block;margin: 0 10px 0 10px;"> :on-error="inventoryError" style="display:inline-block;margin: 0 10px 0 10px;">
<el-button type="primary" plain>盘点导入</el-button> <el-button type="primary" plain>盘点导入</el-button>
</el-upload> </el-upload>
<el-button type="primary" plain @click="addNewgoods">商品</el-button> <el-button type="primary" plain @click="addNewgoods">商品</el-button>
<el-button type="primary" plain @click="handleImport()">导入商品</el-button> <el-button type="primary" plain @click="handleImport()">导入商品</el-button>
<el-button type="primary" plain @click="handleExport()">表格导出</el-button> <el-button type="primary" plain @click="handleExport()">表格导出</el-button>
<el-button type="primary" plain @click="onCount()">库存盘点</el-button> <el-button type="primary" plain @click="onCount()">库存盘点</el-button>
@ -87,7 +87,7 @@
<img :src="scope.row.goods.img_url" class="Img" /> <img :src="scope.row.goods.img_url" class="Img" />
</div> </div>
<div> <div>
<p>{{ scope.row.goods.title }}&nbsp;{{ scope.row.title }}</p> <p>{{ scope.row.name }}</p>
<p> <p>
{{ scope.row.goods.goods_code + "_" + scope.row.sku_code }} {{ scope.row.goods.goods_code + "_" + scope.row.sku_code }}
</p> </p>
@ -104,7 +104,7 @@
</div> </div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="规格" prop="title" width="130"></el-table-column> <el-table-column label="规格" prop="title"></el-table-column>
<el-table-column label="品牌"> <el-table-column label="品牌">
<template slot-scope="scope"> <template slot-scope="scope">
<div> <div>
@ -168,7 +168,7 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column sortable label="订单"> <el-table-column sortable label="销量">
<template slot-scope="scope"> <template slot-scope="scope">
<div> <div>
<span>{{ scope.row.order_goods_num }}</span> <span>{{ scope.row.order_goods_num }}</span>
@ -242,7 +242,7 @@
</el-table-column> </el-table-column>
<el-table-column prop="status" label="状态"> </el-table-column> <el-table-column prop="status" label="状态"> </el-table-column>
<el-table-column label="操作" width="130"> <el-table-column label="操作">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="text" @click="ejectstock(scope.row)">库存</el-button> <el-button type="text" @click="ejectstock(scope.row)">库存</el-button>
<el-button type="text" @click="handleEdit(scope.row.id)">编辑</el-button> <el-button type="text" @click="handleEdit(scope.row.id)">编辑</el-button>
@ -453,7 +453,7 @@ export default {
}, },
Paginationdata: {}, // Paginationdata: {}, //
current_page: 1, // current_page: 1, //
per_page: 100, // per_page: 10, //
multipleSelection: [], //id multipleSelection: [], //id
updateType: "", //newest-, inventory-, stock- updateType: "", //newest-, inventory-, stock-
stock: false, // stock: false, //

View File

@ -2,7 +2,7 @@
<div> <div>
<el-container> <el-container>
<el-container> <el-container>
<el-aside :class="show ? 'width' : 'width1'"> <el-aside :class="show ? 'aside-show' : 'aside-hide'">
<el-menu router background-color="#282c34" text-color="#fff" :default-active="$route.path" <el-menu router background-color="#282c34" text-color="#fff" :default-active="$route.path"
:default-openeds="openeds"> :default-openeds="openeds">
<div v-for="item in menu" :key="item.id"> <div v-for="item in menu" :key="item.id">
@ -66,7 +66,7 @@ export default {
menu: [], // menu: [], //
show: true, // show: true, //
levelData: [], // table levelData: [], // table
titie: [], // 线 titie: [], //
head: "", // name head: "", // name
onindex: 0, // onindex: 0, //
openeds: ["GOODS_MANAGE"], openeds: ["GOODS_MANAGE"],
@ -140,13 +140,13 @@ export default {
}; };
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.width { .aside-show {
transition: all 0.3s; transition: all 0.3s;
opacity: 0; opacity: 0;
width: 0px !important; width: 0px !important;
} }
.width1 { .aside-hide {
transition: all 0.3s; transition: all 0.3s;
opacity: 1; opacity: 1;
width: 200px !important; width: 200px !important;

View File

@ -211,7 +211,7 @@ export default {
confirm_at_start: this.form.confirm_at[0], confirm_at_start: this.form.confirm_at[0],
confirm_at_end: this.form.confirm_at[1] confirm_at_end: this.form.confirm_at[1]
}); });
this.initWebSocket(); // this.initWebSocket();
}, },
mounted() { mounted() {
// //

View File

@ -7,8 +7,8 @@ module.exports = {
proxy: { proxy: {
// 配置代理 // 配置代理
"/api": { "/api": {
// target: "http://erp.test", target: "http://erp.local",
target: "http://erp.chutang66.com", // target: "http://erp.chutang66.com",
changeOrigin: true, // 开启代理 changeOrigin: true, // 开启代理
pathRewrite: { pathRewrite: {
// 重命名 // 重命名