mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
feat: #20220802 店铺
This commit is contained in:
parent
547ea0b9b4
commit
ec7ef4969e
@ -8,6 +8,8 @@ use Illuminate\Http\Request;
|
|||||||
use App\Models\GoodsSku;
|
use App\Models\GoodsSku;
|
||||||
use App\Http\Resources\GoodsSkuResource;
|
use App\Http\Resources\GoodsSkuResource;
|
||||||
use App\Imports\GoodsSkusImport;
|
use App\Imports\GoodsSkusImport;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
|
||||||
@ -35,7 +37,109 @@ class GoodsSkusController extends Controller
|
|||||||
|
|
||||||
public function update($id, Request $request)
|
public function update($id, Request $request)
|
||||||
{
|
{
|
||||||
|
$data = $request->all();
|
||||||
|
$this->validateUpdate($data);
|
||||||
|
$sku = GoodsSku::query()->find($id);
|
||||||
|
$this->setBeforeUpdate($sku->toArray());
|
||||||
|
$sku->save($data);
|
||||||
|
$this->setAfterUpdate($sku->toArray());
|
||||||
|
$this->addLog($id, 'update');
|
||||||
|
|
||||||
|
return new GoodsSkuResource($sku);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function batchUpdate(Request $request)
|
||||||
|
{
|
||||||
|
$appendRules = [
|
||||||
|
'*.id' => [
|
||||||
|
'required',
|
||||||
|
Rule::exists('goods_skus', 'id'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateField($id, Request $request)
|
||||||
|
{
|
||||||
|
$appendRules = [
|
||||||
|
'updateField' => [
|
||||||
|
'required',
|
||||||
|
Rule::in(['reference_price', 'reserve', 'loss_num', 'status'])
|
||||||
|
],
|
||||||
|
];
|
||||||
|
if ($request->has('loss_num')) {
|
||||||
|
$appendRules['reason'] = ['required', 'string'];
|
||||||
|
}
|
||||||
|
$this->validateUpdate($request->all(), $appendRules);
|
||||||
|
$updateField = \request('updateField');
|
||||||
|
$sku = GoodsSku::query()->find($id);
|
||||||
|
$this->setBeforeUpdate($sku->$updateField);
|
||||||
|
$sku->$updateField = $request->$updateField;
|
||||||
|
$sku->save();
|
||||||
|
$this->setAfterUpdate($sku->$updateField);
|
||||||
|
$this->addLog($id, $updateField);
|
||||||
|
|
||||||
|
return new GoodsSkuResource($sku);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateStock($id, Request $request)
|
||||||
|
{
|
||||||
|
$this->validateUpdate($request->all());
|
||||||
|
$sku = GoodsSku::query()->where('id', $id)->get(['id', 'two_days_ago_num', 'yesterday_num']);
|
||||||
|
if ($sku->two_days_ago_num != \request('t wo_days_ago_num') || $sku->yesterday_num != \request('yesterday_num')) {
|
||||||
|
$this->setBeforeUpdate($sku->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function validateUpdate($data, $appendRules = [])
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'*.two_days_ago_num' => [
|
||||||
|
'sometimes',
|
||||||
|
'integer',
|
||||||
|
],
|
||||||
|
'*.yesterday_num' => [
|
||||||
|
'sometimes',
|
||||||
|
'integer',
|
||||||
|
],
|
||||||
|
'*.arrived_today_num' => [
|
||||||
|
'sometimes',
|
||||||
|
'integer',
|
||||||
|
],
|
||||||
|
'*.cost' => [
|
||||||
|
'sometimes',
|
||||||
|
'numeric',
|
||||||
|
'gt:0'
|
||||||
|
],
|
||||||
|
'*.reference_price' => [
|
||||||
|
'sometimes',
|
||||||
|
'numeric',
|
||||||
|
'gt:0'
|
||||||
|
],
|
||||||
|
'*.reserve' => [
|
||||||
|
'sometimes',
|
||||||
|
'integer',
|
||||||
|
],
|
||||||
|
'*.loss_num' => [
|
||||||
|
'sometimes',
|
||||||
|
'integer',
|
||||||
|
],
|
||||||
|
'*.inventory' => [
|
||||||
|
'sometimes',
|
||||||
|
'integer',
|
||||||
|
],
|
||||||
|
'*.status' => [
|
||||||
|
'sometimes',
|
||||||
|
'integer',
|
||||||
|
Rule::in([0, 1, 2])
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$validator = Validator::make($data, array_merge($rules, $appendRules));
|
||||||
|
if ($validator->fails()) {
|
||||||
|
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
||||||
|
|
||||||
|
return response($this->res, $this->res['httpCode']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
|
|||||||
45
app/Http/Controllers/Shop/ShopsController.php
Normal file
45
app/Http/Controllers/Shop/ShopsController.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Shop;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Shop;
|
||||||
|
use App\Http\Resources\ShopsResource;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
class ShopsController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$shops = Shop::query()->paginate();
|
||||||
|
|
||||||
|
return ShopsResource::collection($shops);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlatList()
|
||||||
|
{
|
||||||
|
$shop = new Shop();
|
||||||
|
|
||||||
|
return new ShopsResource($shop->getPlatList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$validator = Validator::make($request->all(), [
|
||||||
|
'name' => 'required|string|max:255|unique:shops,name',
|
||||||
|
'plat_id' => 'required|integer',
|
||||||
|
]);
|
||||||
|
if ($validator->fails()) {
|
||||||
|
$this->setValidatorFailResponse($validator->getMessageBag()->getMessages());
|
||||||
|
|
||||||
|
return response($this->res, $this->res['httpCode']);
|
||||||
|
}
|
||||||
|
$shop = new Shop();
|
||||||
|
$shop->name = $request->name;
|
||||||
|
$shop->plat_id = $request->plat_id;
|
||||||
|
$shop->save();
|
||||||
|
|
||||||
|
return response($this->res, $this->res['httpCode']);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Http/Resources/ShopsResource.php
Normal file
19
app/Http/Resources/ShopsResource.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class ShopsResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
app/Models/Shop.php
Normal file
42
app/Models/Shop.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Shop extends Model
|
||||||
|
{
|
||||||
|
protected $hidden = [
|
||||||
|
'access_token',
|
||||||
|
'expires_at',
|
||||||
|
'expires_in',
|
||||||
|
'refresh_token',
|
||||||
|
'refresh_token_expires_at',
|
||||||
|
'refresh_token_expires_in',
|
||||||
|
'pop_auth_token_create_response',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getStatusAttribute($value)
|
||||||
|
{
|
||||||
|
$map = [
|
||||||
|
0 => '未授权',
|
||||||
|
1 => '已授权',
|
||||||
|
2 => '无需授权',
|
||||||
|
3 => '停用',
|
||||||
|
];
|
||||||
|
|
||||||
|
return $map[$value];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlatList()
|
||||||
|
{
|
||||||
|
return ['妙选', '快团团'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlatIdAttribute($value)
|
||||||
|
{
|
||||||
|
$map = $this->getPlatList();
|
||||||
|
|
||||||
|
return $map[$value];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,6 +20,7 @@ class CreateUsersTable extends Migration
|
|||||||
$table->timestamp('email_verified_at')->nullable();
|
$table->timestamp('email_verified_at')->nullable();
|
||||||
$table->string('password');
|
$table->string('password');
|
||||||
$table->string('api_token', 80)->unique()->nullable(false);
|
$table->string('api_token', 80)->unique()->nullable(false);
|
||||||
|
$table->softDeletes();
|
||||||
$table->rememberToken();
|
$table->rememberToken();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|||||||
45
database/migrations/2022_08_02_022448_create_shops_table.php
Normal file
45
database/migrations/2022_08_02_022448_create_shops_table.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateShopsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('shops', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->string('name')->unique();
|
||||||
|
$table->unsignedTinyInteger('plat_id')->comment('平台id');
|
||||||
|
$table->string('access_token')->nullable();
|
||||||
|
$table->unsignedMediumInteger('expires_at')->nullable()->comment('access_token过期时间点');
|
||||||
|
$table->unsignedInteger('expires_in')->nullable()->comment('access_token过期时间段,10(表示10秒后过期)');
|
||||||
|
$table->string('owner_id')->nullable()->comment('商家店铺id');
|
||||||
|
$table->string('owner_name')->nullable()->comment('商家账号名称');
|
||||||
|
$table->string('refresh_token')->nullable()->comment('refresh token,可用来刷新access_token');
|
||||||
|
$table->unsignedMediumInteger('refresh_token_expires_at')->nullable()->comment('Refresh token过期时间点');
|
||||||
|
$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->string('status')->default(0)->comment('状态');
|
||||||
|
$table->softDeletes();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('shops');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -30,6 +30,6 @@ class MenusTableSeeder extends Seeder
|
|||||||
['parent_id' => $id,'code' => 'PERMISSION_MANAGE', 'name' => '权限管理', 'seq' => 1],
|
['parent_id' => $id,'code' => 'PERMISSION_MANAGE', 'name' => '权限管理', 'seq' => 1],
|
||||||
]);
|
]);
|
||||||
// 系统日志
|
// 系统日志
|
||||||
DB::table('menus')->insertGetId(['parent_id' => 0,'code' => 'SYSTEM_LOG', 'name' => '系统管理', 'seq' => 4]);
|
DB::table('menus')->insertGetId(['parent_id' => 0,'code' => 'SYSTEM_LOG', 'name' => '系统日志', 'seq' => 4]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user