Merge branch 'develop' into yezhenman
This commit is contained in:
commit
04a4abe7c7
@ -48,7 +48,7 @@ class Swoole extends Command
|
||||
$endTime = DateTimeUtils::getMicroTime();
|
||||
$beginTime = $endTime - 10000;
|
||||
foreach ($shops as $shop) {
|
||||
BusinessFactory::init()->make($shop->plat_id)->setShop($shop)->downloadOrdersAndSave($beginTime, $endTime, 'increment', 1);
|
||||
BusinessFactory::init()->make($shop->plat_id)->setShop($shop)->downloadOrdersAndSave($beginTime, $endTime, 'increment');
|
||||
}
|
||||
});
|
||||
Event::wait();
|
||||
|
||||
@ -36,9 +36,9 @@ class BusinessOrdersUpdate
|
||||
{
|
||||
[$goodsCode, $skuCode] = explode('_', $this->businessOrderItem['external_sku_id']);
|
||||
$this->goodsSku = GoodsSku::query()->where('sku_code', $skuCode)
|
||||
->with(['goods' => function ($query) use ($goodsCode) {
|
||||
->whereHas('goods', function ($query) use ($goodsCode) {
|
||||
$query->where('goods_code', $goodsCode);
|
||||
}])
|
||||
})
|
||||
->first();
|
||||
if ($this->goodsSku) {
|
||||
$this->goodsSku->stock += $this->num;
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\GoodsSku;
|
||||
use App\Models\Shop;
|
||||
use App\Http\Resources\ShopsResource;
|
||||
use Illuminate\Http\Request;
|
||||
@ -113,7 +114,7 @@ class ShopsController extends Controller
|
||||
$fields = implode(',', [
|
||||
'shop_id',
|
||||
'external_sku_id',
|
||||
'count(id) as count',
|
||||
'sum(goods_number) as num',
|
||||
]);
|
||||
$res = BusinessOrderItem::query()
|
||||
->select(DB::raw($fields))
|
||||
@ -123,9 +124,23 @@ class ShopsController extends Controller
|
||||
->get();
|
||||
$data = [];
|
||||
foreach ($res as $item) {
|
||||
$data[$item->external_sku_id][] = [
|
||||
[$goodsCode, $skuCode] = explode('_', $item['external_sku_id']);
|
||||
$sku = GoodsSku::query()->where('sku_code', $skuCode)
|
||||
->whereHas('goods', function ($query) use ($goodsCode) {
|
||||
$query->where('goods_code', $goodsCode);
|
||||
})
|
||||
->first();
|
||||
if (empty($sku)) {
|
||||
continue;
|
||||
}
|
||||
$sku = $sku->toArray();
|
||||
if (!isset($data[$sku['id']]['total'])) {
|
||||
$data[$sku['id']]['total'] = 0;
|
||||
}
|
||||
$data[$sku['id']]['total'] += $item->num;
|
||||
$data[$sku['id']]['items'][] = [
|
||||
'shop_name' => $item->shop->name,
|
||||
'count' => $item->count,
|
||||
'num' => $item->num,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ class StockUpdateListener
|
||||
*/
|
||||
public function handle(StockUpdateEvent $event)
|
||||
{
|
||||
$shops = Shop::query()->where('status', 1)->get(['id', 'plat_id']);
|
||||
$shops = Shop::query()->whereNotIn('status', [0, 3])->get(['id', 'plat_id']);
|
||||
if (empty($shops)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ class UpdateBusinessGoodsStock implements ShouldQueue
|
||||
|
||||
return;
|
||||
}
|
||||
$shops = Shop::query()->where('id', '<>', $event->businessOrderItem['shop_id'])->where('status', 1)->get(['id', 'plat_id']);
|
||||
$shops = Shop::query()->where('id', '<>', $event->businessOrderItem['shop_id'])->whereNotIn('status', [0, 3])->get(['id', 'plat_id']);
|
||||
if (empty($shops)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -139,11 +139,8 @@ abstract class BusinessClient
|
||||
$res = (new Client())->request($method, $url, $headers);
|
||||
$size = $res->getBody()->getSize();
|
||||
$res = json_decode($res->getBody()->getContents(), true);
|
||||
if ('pdd.ktt.increment.order.query' === $params['type']) {
|
||||
$log = Log::query()->where('user_id', $this->getShop()->id)->where('target_field', $params['type'])->first();
|
||||
} else {
|
||||
if (!in_array($params['type'], ['pdd.ktt.increment.order.query', 'pdd.ktt.order.list'], true)) {
|
||||
$log = new Log();
|
||||
}
|
||||
$log->module = 'plat';
|
||||
$log->action = $method;
|
||||
$log->target_type = $this->getShop()->plat_id;
|
||||
@ -154,6 +151,7 @@ abstract class BusinessClient
|
||||
$log->message = json_encode($res, 256);
|
||||
}
|
||||
$log->save();
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ class Goods
|
||||
$sku['spec_list'] = json_encode($sku['spec_list'], 256);
|
||||
$data = array_merge($businessGood, $sku);
|
||||
BusinessGoodsSku::updateOrCreate(
|
||||
['shop_id' => $shopId, 'activity_no' => $businessGood['activity_no'], 'goods_id' => $businessGood['goods_id'], 'sku_id' => $sku['sku_id']],
|
||||
['shop_id' => $shopId, 'goods_id' => $businessGood['goods_id'], 'sku_id' => $sku['sku_id']],
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
@ -18,13 +18,14 @@ class Goods
|
||||
|
||||
public static function incrQuantity($shopId, $quantity, $businessGoods)
|
||||
{
|
||||
[$goodsCode, $skuCode] = explode('_', $businessGoods['external_sku_id']);
|
||||
return [
|
||||
'data' => [
|
||||
'stock' => $quantity,
|
||||
'business_sku_id' => $businessGoods['sku_id'],
|
||||
'business_goods_id' => $businessGoods['goods_id'],
|
||||
'erp_shop_id' => $shopId,
|
||||
'erp_sku_id' => $businessGoods['external_sku_id'],
|
||||
'erp_sku_id' => $skuCode,
|
||||
],
|
||||
'type' => '更新库存',
|
||||
];
|
||||
|
||||
@ -16,16 +16,15 @@ class CreateUsersTable extends Migration
|
||||
Schema::defaultStringLength(191);
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('name')->unique();
|
||||
$table->string('email')->nullable()->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->string('api_token', 80)->unique()->nullable(false);
|
||||
$table->string('api_token', 80)->unique();
|
||||
$table->softDeletes();
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
// 索引
|
||||
$table->unique('name');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -16,11 +16,10 @@ class CreateGoodsTypesTable extends Migration
|
||||
Schema::defaultStringLength(191);
|
||||
Schema::create('goods_types', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name')->nullable(false);
|
||||
$table->string('name')->unique();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
// 索引
|
||||
$table->unique('name');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -16,11 +16,10 @@ class CreateGoodsBrandsTable extends Migration
|
||||
Schema::defaultStringLength(191);
|
||||
Schema::create('goods_brands', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name')->nullable(false);
|
||||
$table->string('name')->unique();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
// 索引
|
||||
$table->unique('name');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -16,14 +16,13 @@ class CreateGoodsTable extends Migration
|
||||
Schema::defaultStringLength(191);
|
||||
Schema::create('goods', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('title')->nullable(false);
|
||||
$table->string('title');
|
||||
$table->string('img_url')->nullable()->comment('商品图片');
|
||||
$table->unsignedBigInteger('type_id')->nullable(false)->comment('商品种类id');
|
||||
$table->unsignedBigInteger('type_id')->comment('商品种类id');
|
||||
$table->unsignedBigInteger('brand_id')->nullable()->comment('商品品牌id');
|
||||
$table->string('goods_code', 32)->nullable(false)->comment('商品编码');
|
||||
$table->string('goods_code', 32)->unique()->comment('商品编码');
|
||||
$table->timestamps();
|
||||
// 索引
|
||||
$table->unique('goods_code');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -16,9 +16,9 @@ class CreateGoodsSkusTable extends Migration
|
||||
Schema::defaultStringLength(191);
|
||||
Schema::create('goods_skus', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->unsignedBigInteger('goods_id')->nullable(false)->comment('商品id');
|
||||
$table->string('title')->nullable(false)->comment('商品规格');
|
||||
$table->string('sku_code', 32)->nullable(false)->comment('规格编码');
|
||||
$table->unsignedBigInteger('goods_id')->comment('商品id');
|
||||
$table->string('title')->comment('商品规格');
|
||||
$table->string('sku_code', 32)->comment('规格编码');
|
||||
$table->unsignedTinyInteger('status')->default(0)->comment('规格状态(0-下架,1在售,2预警)');
|
||||
$table->unsignedInteger('num')->default(0)->comment('总量');
|
||||
$table->unsignedInteger('stock')->default(0)->comment('库存');
|
||||
|
||||
@ -15,8 +15,8 @@ class CreateDailyStockRecordsTable extends Migration
|
||||
{
|
||||
Schema::create('daily_stock_records', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->bigInteger('sku_id')->nullable(false);
|
||||
$table->date('day')->nullable(false);
|
||||
$table->bigInteger('sku_id');
|
||||
$table->date('day');
|
||||
$table->unsignedInteger('arrived_today_num')->default(0)->comment('今日到货');
|
||||
$table->unsignedInteger('loss_num')->default(0)->comment('损耗');
|
||||
$table->unsignedInteger('inventory')->default(0)->comment('库存盘点');
|
||||
|
||||
@ -24,8 +24,9 @@ class CreateLogsTable extends Migration
|
||||
$table->text('after_update')->nullable()->comment('更新后数据');
|
||||
$table->text('message')->nullable()->comment('备注信息');
|
||||
$table->bigInteger('user_id')->comment('操作人id');
|
||||
$table->index(['target_type', 'target_id', 'target_field']);
|
||||
$table->timestamps();
|
||||
// 索引
|
||||
$table->index(['target_type', 'target_id', 'target_field']);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -16,14 +16,13 @@ class CreateMenusTable extends Migration
|
||||
Schema::defaultStringLength(191);
|
||||
Schema::create('menus', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('code', 32)->nullable(false)->comment('菜单编码');
|
||||
$table->string('name', 32)->nullable(false)->comment('菜单名称');
|
||||
$table->string('code', 32)->unique()->comment('菜单编码');
|
||||
$table->string('name', 32)->comment('菜单名称');
|
||||
$table->unsignedBigInteger('parent_id')->default(0);
|
||||
$table->unsignedInteger('seq')->default(0)->comment('排序序号');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
// 索引
|
||||
$table->unique('code');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -28,9 +28,10 @@ class CreateShopsTable extends Migration
|
||||
$table->unsignedInteger('refresh_token_expires_in')->nullable()->comment('refresh_token过期时间段,10表示10秒后过期');
|
||||
$table->text('scope')->nullable()->comment('接口列表');
|
||||
$table->text('pop_auth_token_create_response')->nullable()->comment('授权认证信息');
|
||||
$table->unsignedTinyInteger('status')->default(0)->comment('状态');
|
||||
$table->unsignedTinyInteger('status')->index()->default(0)->comment('状态');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
//索引
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -41,6 +41,8 @@ class CreateBusinessGoodsSkusTable extends Migration
|
||||
$table->string('thumb_url')->nullable();
|
||||
$table->bigInteger('total_quantity')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index(['shop_id', 'goods_id', 'sku_id']);
|
||||
$table->index(['shop_id', 'external_sku_id']);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -55,6 +55,8 @@ class CreateBusinessOrdersTable extends Migration
|
||||
$table->string('transaction_id')->nullable();
|
||||
$table->integer('verification_status')->nullable();
|
||||
$table->timestamps();
|
||||
// 索引
|
||||
$table->unique(['shop_id', 'order_sn']);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -39,6 +39,8 @@ class CreateBusinessOrderItemsTable extends Migration
|
||||
$table->string('thumb_url')->nullable();
|
||||
$table->integer('verification_number')->nullable();
|
||||
$table->timestamps();
|
||||
// 索引
|
||||
$table->index(['shop_id', 'business_order_id', 'goods_id', 'sku_id']);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user