feat: #10000 优化修改

This commit is contained in:
赵世界 2023-04-18 11:22:16 +08:00
parent 60ee98a6b4
commit 4e872a2d50
18 changed files with 160 additions and 16 deletions

View File

@ -19,6 +19,7 @@ class BusinessOrdersUpdate
public $num;
public $businessGoods;
public $goodsSku;
public $goodsSkus;
/**
* Create a new event instance.

View File

@ -59,6 +59,7 @@ class GoodsSkusExport implements FromCollection, ShouldAutoSize
->when($ids, function ($query, $ids) {
return $query->whereIn('id', $ids);
})
->where('is_combination', 0)
->with(['goods' => function ($query) {
$query->with(['type:id,name', 'brand:id,name'])
->orderBy('type_id')

View File

@ -28,11 +28,7 @@ class GoodsSkuLocationFilter extends Filters
public function externalSkuId($value)
{
[$goodsCode, $skuCode] = explode('_', $value);
$goodsId = Goods::query()->where('goods_code', $goodsCode)->value('id');
$skuId = GoodsSku::query()->where('sku_code', $skuCode)->value('id');
return $this->builder->where('goods_sku_id', $skuId)->where('goods_id', $goodsId);
return $this->builder->where('external_sku_id', $value);
}
public function location($value)

View File

@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers\Goods;
use App\Http\Controllers\Controller;
use App\Http\Resources\GoodsSkuResource;
use App\Models\GoodsSku;
use Illuminate\Http\Request;
class GoodsCombinationController extends Controller
{
public function index(Request $request)
{
$skus = GoodsSku::query()
->where('is_combination', 1)
->with([
'combinationItems:goods_sku_id,item_id,item_num',
'combinationItems.goodsSkuItem:id,goods_id,title,stock,external_sku_id',
'combinationItems.goodsSkuItem.goods:id,title',
])
->paginate($request->get('per_page'));
return GoodsSkuResource::collection($skus);
}
public function store(Request $request)
{
}
public function show(Request $request, $id)
{
}
public function update(Request $request, $id)
{
}
}

View File

@ -51,6 +51,7 @@ class GoodsSkusController extends Controller
->with(['daily' => function ($query) use ($day) {
$query->where('day', $day);
}])
->where('is_combination', 0)
->orderByDesc('updated_at')
->paginate(10);
$fields = implode(',', [
@ -509,9 +510,11 @@ class GoodsSkusController extends Controller
{
$roseTypeId = GoodsType::query()->where('name', '玫瑰')->value('id');
$totalNum = GoodsSku::query()
->where('is_combination', 0)
->where('status', '>', 0)
->sum('stock');
$roseNum = GoodsSku::query()
->where('is_combination', 0)
->whereHas('goods', function (Builder $query) use ($roseTypeId) {
$query->where('type_id', $roseTypeId);
})

View File

@ -191,6 +191,7 @@ class ShopsController extends Controller
{
$shopId = $request->get('shop_id');
$skus = GoodsSku::query()
->where('is_combination', 0)
->where('status', '>', 0)
->whereNotNull('external_sku_id')
->pluck('stock', 'external_sku_id')

View File

@ -78,6 +78,7 @@ class InventoryImport implements ToCollection, SkipsEmptyRows
}
sleep(2);
$onSkuIds = GoodsSku::query()
->where('is_combination', 0)
->where('status', '>', 0)
->pluck('id')
->toArray();

View File

@ -44,7 +44,7 @@ class UpdateBusinessGoodsStock implements ShouldQueue
$log->message = '未找到' . json_encode($event->businessGoods, 256);
$log->save();
return;
return false;
}
$builder = Shop::query()->whereNotIn('status', [Shop::$STATUS_UNAUTHORIZED, Shop::$STATUS_STOP]);
// 非订单影响库存变更,只更新本店铺下商品
@ -54,7 +54,7 @@ class UpdateBusinessGoodsStock implements ShouldQueue
$shops = $builder->get(['id', 'plat_id']);
if (empty($shops)) {
LogFile::info('可操作店铺为空');
return;
return false;
}
foreach ($shops as $shop) {

View File

@ -0,0 +1,13 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class CombinationGood extends Model
{
public function goodsSkuItem()
{
return $this->belongsTo(GoodsSku::class, 'id', 'item_id');
}
}

View File

@ -76,4 +76,9 @@ class GoodsSku extends Model
{
return $this->hasOne(DailyStockRecord::class, 'sku_id', 'id');
}
public function combinationItems()
{
return $this->hasMany(CombinationGood::class, 'goods_sku_id', 'id');
}
}

View File

@ -19,9 +19,9 @@ class CreateGoodsSkusTable extends Migration
Schema::defaultStringLength(191);
Schema::create('goods_skus', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('goods_id')->comment('商品id');
$table->string('title')->comment('商品规格');
$table->string('sku_code', 32)->comment('规格编码');
$table->unsignedBigInteger('goods_id')->default(0)->comment('商品id');
$table->string('title')->default('')->comment('商品规格');
$table->string('sku_code', 32)->default('')->comment('规格编码');
$table->unsignedTinyInteger('status')->default(0)->comment('规格状态(0-下架,1在售,2预警)');
$table->unsignedInteger('num')->default(0)->comment('总量');
$table->integer('stock')->default(0)->comment('库存');

View File

@ -23,8 +23,6 @@ class CreateMenusTable extends Migration
$table->string('name', 32)->comment('菜单名称');
$table->unsignedBigInteger('parent_id')->default(0);
$table->unsignedInteger('seq')->default(0)->comment('排序序号');
$table->softDeletes();
$table->timestamps();
// 索引
});
}

View File

@ -43,7 +43,7 @@ class CreateBusinessOrderItemsTable extends Migration
$table->integer('verification_number')->nullable();
$table->timestamps();
// 索引
$table->index(['shop_id', 'business_order_id', 'goods_id', 'sku_id']);
// $table->index(['shop_id', 'business_order_id', 'goods_id', 'sku_id']);
});
}

View File

@ -18,8 +18,10 @@ class AddExternalSkuIdToGoodsSkusTable extends Migration
}
Schema::defaultStringLength(191);
Schema::table('goods_skus', function (Blueprint $table) {
$table->string('external_sku_id')->nullable();
$table->string('external_sku_id')->default('')->nullable();
$table->tinyInteger('is_combination')->default(0);
$table->index('external_sku_id');
$table->index('is_combination');
});
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCombinationGoodsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('combination_goods')) {
return;
}
Schema::create('combination_goods', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('goods_sku_id');
$table->unsignedBigInteger('item_id');
$table->unsignedInteger('item_num');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('combination_goods');
}
}

View File

@ -2,6 +2,7 @@
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use App\Models\Menu;
class MenusTableSeeder extends Seeder
{
@ -12,6 +13,7 @@ class MenusTableSeeder extends Seeder
*/
public function run()
{
return $this->update();
// 商品管理-(商品列表,商品种类,商品品牌)
$id = DB::table('menus')->insertGetId(['parent_id' => 0, 'code' => 'GOODS_MANAGE', 'name' => '商品管理', 'seq' => 0]);
DB::table('menus')->insert([
@ -19,6 +21,7 @@ class MenusTableSeeder extends Seeder
['parent_id' => $id, 'code' => 'GOODS_TYPE', 'name' => '商品种类', 'seq' => 1],
['parent_id' => $id, 'code' => 'GOODS_BRAND', 'name' => '商品品牌', 'seq' => 2],
['parent_id' => $id, 'code' => 'GOODS_SKU_LOCATION', 'name' => '商品货架', 'seq' => 3],
['parent_id' => $id, 'code' => 'GOODS_COMBINATION', 'name' => '组合商品', 'seq' => 4],
]);
// 店铺管理
DB::table('menus')->insertGetId(['parent_id' => 0, 'code' => 'SHOP_MANAGE', 'name' => '店铺管理', 'seq' => 10]);
@ -40,4 +43,17 @@ class MenusTableSeeder extends Seeder
// 团购
DB::table('menus')->insertGetId(['parent_id' => 0, 'code' => 'GROUP_MANAGEMENT', 'name' => '团购管理', 'seq' => 1]);
}
public function update()
{
$routes = include(resource_path('lang/zh-CN/permission.php'));
foreach ($routes as $code => $route) {
if (false === strpos($code, '.')) {
DB::table('menus')->updateOrInsert(
['id' => $route['id'], 'parent_id' => $route['parent_id'], 'code' => $code],
['name' => $route['name']]
);
}
}
}
}

View File

@ -14,8 +14,8 @@ class PermissionsTableSeeder extends Seeder
public function run()
{
$routes = include(resource_path('lang/zh-CN/permission.php'));
foreach ($routes as $key => $route) {
$data = ['id' => $route['id'], 'name' => $key, 'guard_name' => 'api'];
foreach ($routes as $code => $route) {
$data = ['id' => $route['id'], 'name' => $code, 'guard_name' => 'api'];
Permission::firstOrCreate($data);
}
}

View File

@ -147,6 +147,36 @@ return [
'name' => '删除',
'parent_id' => 15,
],
'GOODS_COMBINATION' => [
'id' => 16,
'name' => '组合商品',
'parent_id' => 1,
],
'goods_combination.index' => [
'id' => 160,
'name' => '列表',
'parent_id' => 16,
],
'goods_combination.store' => [
'id' => 161,
'name' => '新增',
'parent_id' => 16,
],
'goods_combination.show' => [
'id' => 162,
'name' => '查看',
'parent_id' => 16,
],
'goods_combination.update' => [
'id' => 163,
'name' => '更新',
'parent_id' => 16,
],
'goods_combination.destroy' => [
'id' => 164,
'name' => '删除',
'parent_id' => 16,
],
// 店铺管理
'SHOP_MANAGE' => [
'id' => 5,