diff --git a/app/Http/Controllers/Supplier/SuppliersController.php b/app/Http/Controllers/Supplier/SuppliersController.php new file mode 100644 index 0000000..657760f --- /dev/null +++ b/app/Http/Controllers/Supplier/SuppliersController.php @@ -0,0 +1,127 @@ +log = new LogModel([ + 'module' => 'supplier', + 'action' => $request->getMethod(), + 'target_type' => 'supplier', + ]); + } + + public function index(Request $request) + { + $suppliers = Suppliers::query()->paginate($request->get('per_page')); + return GoodsSkuResource::collection($suppliers); + } + public function store(Request $request) + { + //获取所有参数 + $allParams =$request->all(); + //进行校验验证 + $validator = Validator::make($allParams, [ + 'supplier_name' => 'required|string', + 'company_name' => 'required|string', + 'address' => 'sometimes|string', + 'link_tel' => 'sometimes|string', + 'payment_account' => 'sometimes|string', + 'agent_id' => 'sometimes|integer', + 'agent_name' => 'sometimes|string', + ]); + if ($validator->fails()) { + //校验失败返回异常 + $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); + return response($this->res, $this->res['httpCode']); + } + //保存数据 + $suppliers = new Suppliers(); + $suppliers->supplier_name = $request->supplier_name; + $suppliers->company_name = $request->company_name ?? ''; + $suppliers->link_tel = $request->link_tel ?? ''; + $suppliers->address = $request->address ?? ''; + $suppliers->payment_account = $request->payment_account ?? ''; + $suppliers->agent_id = $request->agent_id ?? 0; + $suppliers->agent_name = $request->agent_name ?? ''; + $suppliers->save(); + + return response($this->res, $this->res['httpCode']); + } + + + public function update($id, Request $request) + { + //获取所有参数 + $allParams =$request->all(); + //进行校验验证 + $validator = Validator::make($allParams, [ + 'supplier_name' => 'required|string', + 'company_name' => 'required|string', + 'address' => 'sometimes|string', + 'link_tel' => 'sometimes|string', + 'payment_account' => 'sometimes|string', + 'agent_id' => 'sometimes|integer', + 'agent_name' => 'sometimes|string', + ]); + if ($validator->fails()) { + //校验失败返回异常 + $this->setValidatorFailResponse($validator->getMessageBag()->getMessages()); + return response($this->res, $this->res['httpCode']); + } + //保存数据 + $suppliers = Suppliers::query()->find($id); + $suppliers->supplier_name = $request->supplier_name; + $suppliers->company_name = $request->company_name ?? ''; + $suppliers->link_tel = $request->link_tel ?? ''; + $suppliers->address = $request->address ?? ''; + $suppliers->payment_account = $request->payment_account ?? ''; + $suppliers->agent_id = $request->agent_id ?? 0; + $suppliers->agent_name = $request->agent_name ?? ''; + $suppliers->save(); + + return response($this->res, $this->res['httpCode']); + } + + public function destroy($id) + { + $goodsType = Suppliers::query()->find($id); + $goodsType->delete(); + $this->addLog($id, 'status'); + + return response($this->res, $this->res['httpCode']); + } +} diff --git a/database/migrations/2024_07_24_144851_create_purchase_records_table.php b/database/migrations/2024_07_24_144851_create_purchase_records_table.php new file mode 100644 index 0000000..830e139 --- /dev/null +++ b/database/migrations/2024_07_24_144851_create_purchase_records_table.php @@ -0,0 +1,42 @@ +bigIncrements('id'); + $table->bigInteger('sku_id')->nullable()->comment('goods sku表的id'); + $table->string('external_sku_id')->comment('唯一sku标识'); + $table->Integer('num')->default(0)->comment('采购数量'); + $table->unsignedDecimal('cost')->default(0)->comment('成本'); + $table->string('buyer_name')->nullable()->comment('采购人'); + $table->string('status')->default(0)->comment('盘点完近似状态 0未完成1已售卖完成'); + $table->string('supplier_name')->nullable()->comment('供应商名称'); + $table->unsignedDecimal('supplier_id')->nullable()->comment('供应商id'); + // 索引 + $table->index('sku_id'); + $table->index('external_sku_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('purchase_records'); + } +} diff --git a/database/migrations/2024_07_24_144925_create_loss_records_table.php b/database/migrations/2024_07_24_144925_create_loss_records_table.php new file mode 100644 index 0000000..1d5a924 --- /dev/null +++ b/database/migrations/2024_07_24_144925_create_loss_records_table.php @@ -0,0 +1,40 @@ +bigIncrements('id'); + $table->bigInteger('sku_id')->nullable()->comment('goods sku表的id'); + $table->string('external_sku_id')->comment('唯一sku标识'); + $table->Integer('num')->default(0)->comment('报损数量'); + $table->unsignedDecimal('cost')->default(0)->comment('成本'); + $table->string('buyer_name')->nullable()->comment('采购人'); + $table->string('reason')->nullable()->comment('报损原因'); + // 索引 + $table->index('sku_id'); + $table->index('external_sku_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('loss_records'); + } +} diff --git a/database/migrations/2024_07_24_144950_create_website_messages_table.php b/database/migrations/2024_07_24_144950_create_website_messages_table.php new file mode 100644 index 0000000..2191bab --- /dev/null +++ b/database/migrations/2024_07_24_144950_create_website_messages_table.php @@ -0,0 +1,38 @@ +bigIncrements('id'); + $table->string('content')->comment('消息内容'); + $table->string('role')->comment('角色名称'); + $table->Integer('uid')->comment('用户id 存在非0值表示当前uid可见'); + $table->tinyInteger('status')->comment('消息状态 0未读 1已读'); + $table->string('extend')->comment('拓展字段 后续拓展用'); + + $table->index(["role","uid"]); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('website_messages'); + } +} diff --git a/database/migrations/2024_07_24_145032_create_suppliers_table.php b/database/migrations/2024_07_24_145032_create_suppliers_table.php new file mode 100644 index 0000000..feb70b6 --- /dev/null +++ b/database/migrations/2024_07_24_145032_create_suppliers_table.php @@ -0,0 +1,40 @@ +bigIncrements('id'); + $table->string('supplier_name')->comment('供应商名称'); + $table->string('company_name',100)->nullable()->comment('公司名称'); + $table->string('address')->nullable()->comment('地址'); + $table->string('link_tel',100)->nullable()->comment('联系方式'); + $table->string('payment_account',100)->nullable()->comment('支付方式'); + $table->string('agent_name')->nullable()->comment('代理人名称'); + $table->Integer('agent_id')->nullable()->comment('代理人id'); + + $table->index('supplier_name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('suppliers'); + } +} diff --git a/database/migrations/2024_07_24_145201_add_sale_stock_and_quality_period_to_goods_skus_table.php b/database/migrations/2024_07_24_145201_add_sale_stock_and_quality_period_to_goods_skus_table.php new file mode 100644 index 0000000..f051e43 --- /dev/null +++ b/database/migrations/2024_07_24_145201_add_sale_stock_and_quality_period_to_goods_skus_table.php @@ -0,0 +1,40 @@ +integer('sale_stock')->default(0)->comment("在售库存数"); + $table->integer('quality_period')->nullable()->comment("保质期时间,单位天"); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('goods_skus', function (Blueprint $table) { + // + $table->dropColumn('sale_stock'); + $table->dropColumn('quality_period'); + }); + } +} diff --git a/resources/lang/zh-CN/permission.php b/resources/lang/zh-CN/permission.php index a245aec..204b062 100644 --- a/resources/lang/zh-CN/permission.php +++ b/resources/lang/zh-CN/permission.php @@ -477,4 +477,36 @@ return [ 'name' => '销售数据列表', 'parent_id' => 180, ], + 'SUPPLIER_MANAGE' => [ + 'id' => 19, + 'name' => '供应链管理', + 'parent_id' => 0, + 'show' => 1, + ], + 'SUPPLIER' => [ + 'id' => 190, + 'name' => '供应商管理', + 'parent_id' => 19, + 'show' => 1, + ], + 'supplier.index' => [ + 'id' => 1901, + 'name' => '供应商列表', + 'parent_id' => 190, + ], + 'supplier.store' => [ + 'id' => 1902, + 'name' => '供应商新增', + 'parent_id' => 190, + ], + 'supplier.update' => [ + 'id' => 1903, + 'name' => '供应商更新', + 'parent_id' => 190, + ], + 'supplier.destroy' => [ + 'id' => 1904, + 'name' => '供应商删除', + 'parent_id' => 190, + ], ]; diff --git a/routes/api.php b/routes/api.php index e804ec4..4fd0820 100644 --- a/routes/api.php +++ b/routes/api.php @@ -72,6 +72,9 @@ Route::middleware(['auth:api', 'check.permissions'])->group(function () { Route::post('shop/ship/senders', [ShipController::class, 'saveSenders'])->name('shop_ship.senders.save'); // 数据中心 Route::get('data_center/sales_report', [DataCenterController::class, 'salesReport'])->name('sales_report.index'); + + Route::resource('supplier', 'Supplier\SuppliersController', ['only' => ['index', 'update', 'store','destroy']]); + }); Route::get('stock/goods_skus', [GoodsSkusController::class, 'stockNum'])->middleware('auth:api'); Route::get('goods/filter/{title}', [GoodsCombinationController::class, 'goodsSkus'])->middleware('auth:api');