From 9734d058e3f9ddf80a829760caaab5fec48e6bfa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E4=B8=96=E7=95=8C?= <642747453@qq.com>
Date: Mon, 3 Apr 2023 20:25:57 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20#10000=20=E6=9A=82=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/Filters/BusinessOrderFilter.php | 1 -
app/Filters/GoodsSkuLocationFilter.php | 47 +++++
.../Business/BusinessOrderController.php | 50 +++++
.../Controllers/Goods/GoodsController.php | 1 -
.../Goods/GoodsSkuLocationController.php | 77 ++++++++
.../Resources/GoodsSkuLocationResource.php | 19 ++
app/Imports/GoodsSkuLocationImport.php | 55 ++++++
app/Models/BusinessOrderItem.php | 5 +
app/Models/GoodsSkuLocation.php | 35 ++++
...65820_create_goods_sku_locations_table.php | 40 ++++
resources/frontend/src/api/plat.js | 16 ++
.../frontend/src/views/plat/orderList.vue | 181 ++++++++++++++++++
routes/api.php | 1 +
13 files changed, 526 insertions(+), 2 deletions(-)
create mode 100644 app/Filters/GoodsSkuLocationFilter.php
create mode 100644 app/Http/Controllers/Goods/GoodsSkuLocationController.php
create mode 100644 app/Http/Resources/GoodsSkuLocationResource.php
create mode 100644 app/Imports/GoodsSkuLocationImport.php
create mode 100644 app/Models/GoodsSkuLocation.php
create mode 100644 database/migrations/2023_04_03_165820_create_goods_sku_locations_table.php
create mode 100644 resources/frontend/src/views/plat/orderList.vue
diff --git a/app/Filters/BusinessOrderFilter.php b/app/Filters/BusinessOrderFilter.php
index e13794c..38f7722 100644
--- a/app/Filters/BusinessOrderFilter.php
+++ b/app/Filters/BusinessOrderFilter.php
@@ -9,7 +9,6 @@ class BusinessOrderFilter extends Filters
return $this->builder->where('participate_no', '=', trim($value));
}
-
protected function shopId($value)
{
return $this->builder->where('shop_id', '=', trim($value));
diff --git a/app/Filters/GoodsSkuLocationFilter.php b/app/Filters/GoodsSkuLocationFilter.php
new file mode 100644
index 0000000..3eba5fa
--- /dev/null
+++ b/app/Filters/GoodsSkuLocationFilter.php
@@ -0,0 +1,47 @@
+builder->where('date', '=', $value);
+ }
+
+ public function goodsTitle($value)
+ {
+ $goodsId = Goods::query()->where('title', $value)->value('id');
+
+ return $this->builder->where('goods_id', '=', $goodsId);
+ }
+
+ public function goodsCode($value)
+ {
+ $goodsId = Goods::query()->where('goods_code', $value)->value('id');
+
+ return $this->builder->where('goods_id', '=', $goodsId);
+ }
+
+ 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);
+ }
+
+ public function location($value)
+ {
+ return $this->builder->where('location', '=', $value);
+ }
+
+ public function status($value)
+ {
+ return $this->builder->where('status', '=', $value);
+ }
+}
diff --git a/app/Http/Controllers/Business/BusinessOrderController.php b/app/Http/Controllers/Business/BusinessOrderController.php
index 91ea68f..b444c9f 100644
--- a/app/Http/Controllers/Business/BusinessOrderController.php
+++ b/app/Http/Controllers/Business/BusinessOrderController.php
@@ -4,6 +4,8 @@ namespace App\Http\Controllers\Business;
use App\Http\Controllers\Controller;
use App\Models\BusinessOrder;
+use App\Utils\DateTimeUtils;
+use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Resources\BusinessOrderResource;
@@ -21,6 +23,54 @@ class BusinessOrderController extends Controller
public function exportOrderBlank(Request $request)
{
+ $shopId = $request->get('shop_id');
+ $startNo = $request->get('start_no');
+ $endNo = $request->get('end_no');
+ $startTime = BusinessOrder::query()->where('participate_no', $startNo)->value('confirm_at');
+ $endTime = BusinessOrder::query()->where('participate_no', $endNo)->value('confirm_at');
+ $orders = BusinessOrder::query()
+ ->with([
+ 'items:id,business_order_id,external_sku_id,goods_number,goods_name',
+ 'items.goodsSkuLocation:id,external_sku_id,location'
+ ])
+ ->where('shop_id', $shopId)
+ ->where('confirm_at', '>=', $startTime)
+ ->where('confirm_at', '<=', $endTime)
+ ->where('after_sales_status', 0)
+ ->where('cancel_status', 0)
+ ->where('is_supplier', 1)
+ ->orderByDesc('confirm_at')
+ ->get(['id', 'participate_no']);
+ $distribution = [];
+ $no = [];
+ foreach ($orders as $key => $order) {
+ $no[] = $order->participate_no;
+ foreach ($order->items as $item) {
+ if (isset($distribution[$item['external_sku_id']])) {
+ $distribution[$item['external_sku_id']]['p'][] = $key;
+ $distribution[$item['external_sku_id']]['num'] += $item['goods_number'];
+ } else {
+ $distribution[$item['external_sku_id']] = [
+ 'p' => [$key],
+ 'local' => 0,
+ 'num' => $item['goods_number']
+ ];
+ }
+ }
+ }
+ var_dump($distribution, $no);
+ }
+ public function groupActivity(Request $request, $shopId)
+ {
+ $todayTime = Carbon::today()->timestamp;
+ $todayTime = DateTimeUtils::getMicroTime($todayTime);
+
+ return BusinessOrder::query()
+ ->where('shop_id', $shopId)
+ ->where('confirm_at', '>=', $todayTime)
+ ->groupBy('activity_no')
+ ->pluck('activity_title', 'activity_no')
+ ->toArray();
}
}
diff --git a/app/Http/Controllers/Goods/GoodsController.php b/app/Http/Controllers/Goods/GoodsController.php
index fbb7fef..26ab99c 100644
--- a/app/Http/Controllers/Goods/GoodsController.php
+++ b/app/Http/Controllers/Goods/GoodsController.php
@@ -13,7 +13,6 @@ use Illuminate\Support\Facades\Validator;
use App\Models\Goods;
use App\Http\Requests\GoodsRequest;
use App\Models\DailyStockRecord;
-use Illuminate\Support\Facades\Storage;
class GoodsController extends Controller
{
diff --git a/app/Http/Controllers/Goods/GoodsSkuLocationController.php b/app/Http/Controllers/Goods/GoodsSkuLocationController.php
new file mode 100644
index 0000000..f91d21d
--- /dev/null
+++ b/app/Http/Controllers/Goods/GoodsSkuLocationController.php
@@ -0,0 +1,77 @@
+with([
+ 'goods:id,title,goods_code,brand_id,type_id',
+ 'goods.brand:id,name',
+ 'goods.type:id,name',
+ 'goodsSku:id,title,sku_code,stock',
+ ])
+ ->filter()
+ ->paginate($request->get('per_page'));
+
+ return GoodsSkuLocationResource::collection($goodsSkuLocation);
+ }
+
+ public function update(Request $request, $id)
+ {
+ $goodsSkuLocation = GoodsSkuLocation::query()->findOrFail($id);
+ if ($location = $request->get('location')) {
+ $goodsSkuLocation->location = $location;
+ }
+ if ($todayInitNum = $request->get('today_init_num')) {
+ $goodsSkuLocation->today_init_num = $todayInitNum;
+ }
+ if ($status = $request->get('status')) {
+ $goodsSkuLocation->status = $status;
+ }
+ if ($note = $request->get('note')) {
+ $goodsSkuLocation->note = $note;
+ }
+ $goodsSkuLocation->save();
+
+ return response()->json($this->res);
+ }
+
+ public function delete(Request $request, $id)
+ {
+ GoodsSkuLocation::query()->delete($id);
+
+ return response()->json($this->res);
+ }
+
+ public function importLocation(Request $request)
+ {
+ if (!$request->hasFile('goodsSkuLocation')) {
+ $this->res = [
+ 'httpCode' => 404,
+ 'errorCode' => 404404,
+ 'errorMessage' => 'not found file',
+ ];
+ }
+ try {
+ $import = new GoodsSkuLocationImport();
+ $path = $request->file('goodsSkuLocation');
+ Excel::import($import, $path);
+ $this->addLog(0, 'import');
+ } catch (ValidationException $exception) {
+ $this->setValidatorFailResponse($exception->validator->getMessageBag()->getMessages());
+ }
+
+ return response($this->res, $this->res['httpCode']);
+ }
+}
diff --git a/app/Http/Resources/GoodsSkuLocationResource.php b/app/Http/Resources/GoodsSkuLocationResource.php
new file mode 100644
index 0000000..2b0f464
--- /dev/null
+++ b/app/Http/Resources/GoodsSkuLocationResource.php
@@ -0,0 +1,19 @@
+whereIn('location', $deleteLocation)->delete();
+ unset($row);
+ $goods = Goods::query()
+ ->with(['skus:id,goods_id,sku_code'])
+ ->whereIn('goods_code', $goodsCode)
+ ->get(['id', 'goods_code']);
+ $goodsSkus = [];
+ foreach ($goods as $goodsItem) {
+ $goodsSkus[$goodsItem['goods_code']][$goodsItem->skus->sku_code] = [
+ 'goods_id' => $goodsItem->id,
+ 'goods_sku_id' => $goodsItem->skus->id,
+ 'external_sku_id' => $goodsItem['goods_code'] . '_' . $goodsItem->skus->sku_code,
+ ];
+ }
+ $data = [];
+ foreach ($array as $row) {
+ if (isset($goodsSkus[$row[2]][$row[4]])) {
+ $data[] = array_merge($goodsSkus[$row[2]][$row[4]], [
+ 'date' => date('Y-m-d'),
+ 'today_init_num' => $row[1],
+ 'location' => $row[5],
+ ]);
+ }
+ }
+ $model = new GoodsSkuLocation();
+ $model->batchInsert($data);
+ }
+}
diff --git a/app/Models/BusinessOrderItem.php b/app/Models/BusinessOrderItem.php
index 0aa80da..20bc1f3 100644
--- a/app/Models/BusinessOrderItem.php
+++ b/app/Models/BusinessOrderItem.php
@@ -39,4 +39,9 @@ class BusinessOrderItem extends Model
{
return $this->belongsTo(Shop::class, 'shop_id', 'id');
}
+
+ public function goodsSkuLocation()
+ {
+ return $this->hasOne(GoodsSkuLocation::class, 'external_sku_id', 'external_sku_id');
+ }
}
diff --git a/app/Models/GoodsSkuLocation.php b/app/Models/GoodsSkuLocation.php
new file mode 100644
index 0000000..6700e67
--- /dev/null
+++ b/app/Models/GoodsSkuLocation.php
@@ -0,0 +1,35 @@
+belongsTo(Goods::class, 'goods_id', 'id');
+ }
+
+ public function goodsSku()
+ {
+ return $this->belongsTo(GoodsSku::class, 'goods_sku_id', 'id');
+ }
+
+ public function getStatusAttribute($value)
+ {
+ $map = ['未使用', '正常', '过期'];
+
+ return $map[$value];
+ }
+}
diff --git a/database/migrations/2023_04_03_165820_create_goods_sku_locations_table.php b/database/migrations/2023_04_03_165820_create_goods_sku_locations_table.php
new file mode 100644
index 0000000..cb56e8c
--- /dev/null
+++ b/database/migrations/2023_04_03_165820_create_goods_sku_locations_table.php
@@ -0,0 +1,40 @@
+bigIncrements('id');
+ $table->date('date');
+ $table->unsignedBigInteger('goods_id');
+ $table->unsignedBigInteger('goods_sku_id');
+ $table->string('location');
+ $table->integer('today_init_num');
+ $table->string('external_sku_id');
+ $table->tinyInteger('status')->default(1);
+ $table->string('note')->nullable();
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('goods_sku_locations');
+ }
+}
diff --git a/resources/frontend/src/api/plat.js b/resources/frontend/src/api/plat.js
index 283cc2d..7313748 100644
--- a/resources/frontend/src/api/plat.js
+++ b/resources/frontend/src/api/plat.js
@@ -30,3 +30,19 @@ export function syncStock(id) {
method: "post",
});
}
+
+export function activityList(shopId) {
+ return http({
+ url: "/api/plat_group_activity/" + shopId,
+ method: "get",
+ });
+}
+
+// 平台订单列表
+export function platOrderList(params) {
+ return http({
+ url: "/api/plat_orders",
+ method: "get",
+ params
+ });
+}
diff --git a/resources/frontend/src/views/plat/orderList.vue b/resources/frontend/src/views/plat/orderList.vue
new file mode 100644
index 0000000..96d4ba0
--- /dev/null
+++ b/resources/frontend/src/views/plat/orderList.vue
@@ -0,0 +1,181 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 筛选
+ 重置筛选
+
+
+
+
+
+
+
+
+ {{ scope.row.shop.name }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/routes/api.php b/routes/api.php
index d7a1195..1cdde12 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -48,6 +48,7 @@ Route::middleware(['auth:api', 'check.permissions'])->group(function () {
// 平台
Route::resource('plat_goods', 'Business\BusinessGoodsSkusController', ['only' => ['index', 'update', 'destroy']]);
Route::get('plat_orders', [BusinessOrderController::class, 'index']);
+ Route::get('plat_group_activity/{shopId}', [BusinessOrderController::class, 'groupActivity']);
Route::post('plat/sync/{id}/stock', [BusinessGoodsSkusController::class, 'syncStock'])->name('plat.sync.stock');
// 团购
Route::resource('group', 'Group\GroupsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]);