鲜花2.0-供应商管理

This commit is contained in:
杨建炊 2024-07-24 17:46:48 +08:00
parent f1d31ac865
commit 9d96dc07ec
8 changed files with 362 additions and 0 deletions

View File

@ -0,0 +1,127 @@
<?php
namespace App\Http\Controllers\Supplier;
use App\Events\BatchStockUpdateEvent;
use App\Events\StockUpdateEvent;
use App\Exports\GoodsSkusExport;
use App\Exports\WeekDataExport;
use App\Http\Controllers\Controller;
use App\Http\Requests\GoodsRequest;
use App\Http\Requests\GoodsSkuRequest;
use App\Imports\InventoryImport;
use App\Imports\NewSetImport;
use App\Models\BusinessOrderItem;
use App\Models\DailySalesReport;
use App\Models\DeveloperConfig;
use App\Models\Goods;
use App\Models\Log;
use App\Models\Log as LogModel;
use App\Models\Suppliers;
use App\Utils\ArrayUtils;
use App\Utils\DateTimeUtils;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Models\GoodsSku;
use App\Http\Resources\GoodsSkuResource;
use App\Imports\GoodsSkusImport;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Maatwebsite\Excel\Facades\Excel;
use App\Models\DailyStockRecord;
use App\Models\Shop;
class SuppliersController extends Controller
{
public function __construct(Request $request)
{
$this->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']);
}
}

View File

@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePurchaseRecordsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('purchase_records', function (Blueprint $table) {
$table->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');
}
}

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateLossRecordsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('loss_records', function (Blueprint $table) {
$table->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');
}
}

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateWebsiteMessagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('website_messages', function (Blueprint $table) {
$table->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');
}
}

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSuppliersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('suppliers', function (Blueprint $table) {
$table->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');
}
}

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddSaleStockAndQualityPeriodToGoodsSkusTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasColumns('goods_skus', ['sale_stock', 'quality_period'])) {
return;
}
Schema::table('goods_skus', function (Blueprint $table) {
//
$table->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');
});
}
}

View File

@ -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,
],
];

View File

@ -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');