6
0
Fork 0

添加通过广告位获取广告内容接口

release
vine_liutk 2021-11-25 09:48:35 +08:00
parent dd0b7dca77
commit 3532b1a136
19 changed files with 293 additions and 11 deletions

View File

@ -25,7 +25,7 @@ class AdController extends AdminController
return Grid::make($builder, function (Grid $grid) {
$grid->column('id')->sortable();
$grid->column('address.name');
$grid->column('src_path')->image(50, 100);
$grid->column('image')->image(50, 100);
$grid->column('sort');
$grid->column('jump_type')->using([
'0'=>__('admin_message.ad.jump_type.radio.0'),
@ -81,7 +81,7 @@ class AdController extends AdminController
return Show::make($id, new Ad(), function (Show $show) {
$show->field('id');
$show->field('address_id');
$show->field('src_path');
$show->field('image');
$show->field('sort');
$show->field('jump_type');
$show->field('jump_link');
@ -101,7 +101,7 @@ class AdController extends AdminController
return Form::make(new Ad(), function (Form $form) {
$form->display('id');
$form->select('address_id')->options(AdAddress::all()->pluck('name', 'id'));
$form->image('src_path')
$form->image('image')
->move('ads/'.Carbon::now()->toDateString())
->saveFullUrl()
->removable(false)

View File

@ -28,7 +28,7 @@ class ArticleController extends AdminController
$grid->column('category.name')->label();
// $grid->column('author_name');
$grid->column('subtitle')->limit(20);
$grid->column('cover_src_path')->images(100, 100);
$grid->column('cover')->images(100, 100);
$grid->column('jump_type')->using([
'0'=>__('admin_message.article.jump_type.radio.0'),
'1'=>__('admin_message.article.jump_type.radio.1'),
@ -99,7 +99,7 @@ class ArticleController extends AdminController
$show->field('title');
$show->field('author_name');
$show->field('subtitle');
$show->field('cover_src_path');
$show->field('cover');
$show->field('content');
$show->field('jump_type');
$show->field('jump_link');
@ -121,7 +121,7 @@ class ArticleController extends AdminController
$form->text('title')->required();
// $form->text('author_name');
$form->text('subtitle');
$form->image('cover_src_path')
$form->image('cover')
->move('articles/'.Carbon::now()->toDateString())
->saveFullUrl()
->removable(false)

View File

@ -24,7 +24,7 @@ use Dcat\Admin\Grid;
*
*/
Admin::css('/admin/css/app.css');
Admin::css('/dist/admin/css/app.css');
Grid::resolving(function (Grid $grid) {
$grid->disableRowSelector();

View File

@ -0,0 +1,26 @@
<?php
namespace App\Http\Controllers\Api\V1;
use App\Http\Resources\AdAddressResource;
use App\Models\AdAddress;
use Illuminate\Http\Request;
class AdController extends Controller
{
public function index(Request $request)
{
$addreseKeys = (array) $request->input('address_key');
$list = AdAddress::with(['ads'=>function ($query) {
$query->where('is_show', 1)->orderBy('sort', 'desc');
}])->where('is_show', 1)->whereIn('key', $addreseKeys)->get();
$data = [];
foreach ($addreseKeys as $key) {
$data[$key] = [];
}
$data = array_merge($data, array_column(AdAddressResource::collection($list)->toArray($request), 'ads', 'key'));
return $data;
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class AdAddressResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'key' => $this->key,
'ads' => AdResource::collection($this->ads),
];
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class AdResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'image'=>$this->image,
'jump_type'=>$this->jump_type,
'jump_link'=>$this->jump_link ?: '',
];
}
}

View File

@ -14,4 +14,9 @@ class AdAddress extends Model
protected $casts = [
'is_show' => 'boolean',
];
public function ads()
{
return $this->hasMany(Ad::class, 'address_id');
}
}

View File

@ -4,6 +4,7 @@ namespace App\Providers;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\ServiceProvider;
use Overtrue\EasySms\EasySms;
@ -18,6 +19,7 @@ class AppServiceProvider extends ServiceProvider
{
$this->registerEasySms();
$this->registerRequestRealIp();
JsonResource::withoutWrapping();
}
/**

View File

@ -25,7 +25,7 @@ class CreateAdsTable extends Migration
Schema::create('ads', function (Blueprint $table) {
$table->id();
$table->bigInteger('address_id')->default(0)->comment('广告位ID');
$table->string('src_path')->nullable()->comment('图片地址');
$table->string('image')->nullable()->comment('图片地址');
$table->integer('sort')->default(0)->comment('广告排序:逆序');
$table->tinyInteger('jump_type')->default(0)->comment('跳转类型0不跳转1跳转应用内页2H5链接');
$table->string('jump_link')->nullable()->comment('跳转地址');

View File

@ -19,7 +19,7 @@ class CreateArticlesTable extends Migration
$table->string('title')->comment('文章标题');
$table->string('author_name')->nullable()->comment('作者名称');
$table->string('subtitle')->nullable()->comment('副标题');
$table->string('cover_src_path')->nullable()->comment('文章封面图');
$table->string('cover')->nullable()->comment('文章封面图');
$table->text('content')->nullable()->comment('文章内容');
$table->tinyInteger('jump_type')->default(0)->comment('跳转类型0不跳转1跳转应用内页2H5链接');
$table->string('jump_link')->nullable()->comment('跳转地址');

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_categories', function (Blueprint $table) {
$table->id();
$table->string('name')->comment('分类名称');
$table->string('icon')->nullable()->comment('分类ICON');
$table->tinyInteger('is_show')->default(0)->comment('是否显示0不显示1显示');
$table->integer('sort')->default(0)->comment('排序');
$table->nestedSet();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_categories');
}
}

View File

@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductSpusTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_spus', function (Blueprint $table) {
$table->id();
$table->string('name')->comment('商品名称');
$table->string('subtitle')->nullable()->comment('商品副标题');
$table->string('cover')->nullable()->comment('封面图');
$table->json('images')->nullable()->comment('商品图片');
$table->text('description')->nullable()->comment('商品详情');
$table->bigInteger('sell_price')->unsigned()->default(0)->comment('销售价格:分');
$table->bigInteger('market_price')->unsigned()->default(0)->comment('市场价格:分');
$table->bigInteger('cost_price')->unsigned()->default(0)->comment('成本价格:分');
$table->bigInteger('user_price')->unsigned()->default(0)->comment('会员价格:分');
$table->string('media')->nullable()->comment('媒体地址');
$table->integer('weight')->unsigned()->nullable()->comment('重量:g');
$table->json('attrs')->nullable()->comment('属性文本');
$table->tinyInteger('is_sell')->unsigned()->default(0)->comment('在售状态');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_spus');
}
}

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductSpecsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_specs', function (Blueprint $table) {
$table->id();
$table->string('name')->column('规格名称');
$table->json('items')->nullable()->comment('规格可选值');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_specs');
}
}

View File

@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductSpuSpecsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_spu_specs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('product_spu_id')->comment('商品主ID');
$table->string('name')->column('规格名称');
/**
* [
* {"value":"","price":"10000"}
* ]
*/
$table->json('items')->nullable()->comment('规格值');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_spu_specs');
}
}

View File

@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductSkusTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_skus', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('spu_id')->comment('主商品ID');
$table->string('name')->comment('商品名称');
$table->string('subtitle')->nullable()->comment('商品副标题');
$table->string('cover')->nullable()->comment('封面图');
$table->json('images')->nullable()->comment('商品图片');
$table->text('description')->nullable()->comment('商品详情');
$table->bigInteger('sell_price')->unsigned()->default(0)->comment('销售价格:分');
$table->bigInteger('market_price')->unsigned()->default(0)->comment('市场价格:分');
$table->bigInteger('cost_price')->unsigned()->default(0)->comment('成本价格:分');
$table->bigInteger('user_price')->unsigned()->default(0)->comment('会员价格:分');
$table->string('media')->nullable()->comment('媒体地址');
$table->integer('weight')->unsigned()->nullable()->comment('重量:g');
$table->json('attrs')->nullable()->comment('属性文本');
$table->tinyInteger('is_sell')->unsigned()->default(0)->comment('在售状态');
$table->json('spec_items')->nullable()->comment('规格属性');
$table->integer('stock')->unsigned()->default(0)->comment('库存');
$table->integer('sells')->unsigned()->default(0)->comment('销量');
$table->timestamps();
$table->index('spu_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_skus');
}
}

View File

@ -7,7 +7,7 @@ return [
],
'fields' => [
'address_id' => '广告位',
'src_path' => '图片地址',
'image' => '图片地址',
'sort' => '广告排序',
'jump_type' => '跳转类型',
'jump_link' => '跳转地址',

View File

@ -10,7 +10,7 @@ return [
'title' => '文章标题',
'author_name' => '作者名称',
'subtitle' => '副标题',
'cover_src_path' => '文章封面图',
'cover' => '文章封面图',
'content' => '文章内容',
'jump_type' => '跳转类型',
'jump_link' => '跳转地址',

View File

@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\Api\V1\AdController;
use App\Http\Controllers\Api\V1\CaptchaController;
use App\Http\Controllers\Api\V1\SmsCodeController;
use Illuminate\Support\Facades\Route;
@ -8,3 +9,4 @@ Route::post('captchas', [CaptchaController::class, 'store']);
Route::get('captchas/{captcha}', [CaptchaController::class, 'show']);
Route::post('sms-codes', [SmsCodeController::class, 'store']);
Route::get('ads', [AdController::class, 'index']);