Browse Source

代理商专题管理及首页显示等修改

dev
李可松 4 years ago
parent
commit
24336a5919
  1. 133
      app/AdminAgent/Controllers/SpecialController.php
  2. 3
      app/AdminAgent/Renderable/SelectAgentProduct.php
  3. 16
      app/AdminAgent/Repositories/Special.php
  4. 1
      app/AdminAgent/routes.php
  5. 12
      app/Http/Controllers/Api/IndexController.php
  6. 6
      app/Http/Controllers/Api/SpecialController.php
  7. 20
      app/Models/Special.php
  8. 68
      dcat_admin_ide_helper.php
  9. 16
      resources/lang/zh_CN/special.php

133
app/AdminAgent/Controllers/SpecialController.php

@ -0,0 +1,133 @@
<?php
namespace App\AdminAgent\Controllers;
use App\AdminAgent\Renderable\SelectAgentProduct;
use App\AdminAgent\Repositories\Special;
use App\Models\AgentProduct;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Table;
use Illuminate\Support\Facades\Storage;
class SpecialController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(new Special(), function (Grid $grid) {
$grid->disableFilterButton();
$grid->model()->where('agent_id', Admin::user()->id);
$grid->column('id')->sortable();
$grid->column('picture_ad')->image('', 60, 60);
$grid->column('agent_product_id', '专题产品')
->display('查看')
->modal(function ($modal) use ($grid) {
$data = AgentProduct::with('product:id,title,pictures')
->whereIn('id', $this->agent_product_id)
->get(['id', 'product_id', 'sale', 'stock']);
$result = [];
$prefix = Storage::disk('public')->url('');
foreach ($data as $k => $v) {
$result[] = [
$v->id,
$v->product->title,
'<img data-action="preview-img" src="'.$prefix.$v->product->picture.'" style="max-width:60px;max-height:60px;cursor:pointer" class="img img-thumbnail">',
$v->sale,
$v->stock,
];
}
return Table::make(['产品ID', '标题', '图片', '销量', '库存'], $result);
});
$grid->column('sort');
$grid->column('created_at');
$grid->column('updated_at')->sortable();
$grid->filter(function (Grid\Filter $filter) {
$filter->panel();
$filter->equal('id');
});
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new Special(), function (Show $show) {
$show->field('id');
$show->field('picture_ad')->image('', 80, 80);
$show->field('picture')->image('', 80, 80);
$show->field('agent_product_id', '产品')
->unescape()
->as(function ($v) {
$data = AgentProduct::with('product:id,title')
->whereIn('id', $v)
->orderBy('id')->get(['id', 'product_id']);
return join("<br>", $data->map(fn($v) => $v->product->title)->toArray());
});
$show->field('sort');
$show->field('created_at');
$show->field('updated_at');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new Special(), function (Form $form) {
$form->display('id');
$form->image('picture_ad')
->required()->removable(false)->uniqueName()
->help('图片大小:750*230');
$form->multipleImage('picture')
->required()->removable(false)->uniqueName()
->help('图片大小:750*490');
$form->multipleSelectTable('agent_product_id')
->title('选择在售产品')->required()
->dialogWidth('80%;min-width:825px;')
->from(SelectAgentProduct::make())
->options(function ($v) {
if (!$v) return [];
$agent_product = AgentProduct::with('product:id,title')
->select(['id', 'product_id'])
->whereIn('id', $v)
->orderBy('id')->get();
$result = [];
foreach ($agent_product as $v) {
$result[$v->id] = $v->product->title ?? '';
}
return $result;
})
->pluck('product.title')
->value(join(',', $form->model()->agent_product_id ?? []));
$form->text('sort')->default(255);
})->saving(function (Form $form) {
//处理特殊字段
$form->hidden(['agent_id', 'created_at', 'updated_at']);
$form->agent_id = Admin::user()->id;
//不允许编辑的字段
$form->ignore(['id', 'agent_id', 'created_at', 'updated_at']);
});
}
}

3
app/AdminAgent/Renderable/SelectAgentProduct.php

@ -24,7 +24,8 @@ class SelectAgentProduct extends LazyRenderable
$grid->disableBatchDelete(); $grid->disableBatchDelete();
$grid->disableBatchActions(); $grid->disableBatchActions();
$grid->model()->where(['agent_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]);
$grid->model()->where('stock', '>', 0)
->where(['agent_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]);
$grid->quickSearch(['product.title', 'product.supplier.name'])->placeholder('搜索产品名称、供应商'); $grid->quickSearch(['product.title', 'product.supplier.name'])->placeholder('搜索产品名称、供应商');
$grid->column('id'); $grid->column('id');

16
app/AdminAgent/Repositories/Special.php

@ -0,0 +1,16 @@
<?php
namespace App\AdminAgent\Repositories;
use App\Models\Special as Model;
use Dcat\Admin\Repositories\EloquentRepository;
class Special extends EloquentRepository
{
/**
* Model.
*
* @var string
*/
protected $eloquentClass = Model::class;
}

1
app/AdminAgent/routes.php

@ -20,4 +20,5 @@ Route::group([
$router->resource('user/list', 'UserController'); $router->resource('user/list', 'UserController');
$router->resource('order/list', 'OrderController'); $router->resource('order/list', 'OrderController');
$router->resource('slide/list', 'SlideController'); $router->resource('slide/list', 'SlideController');
$router->resource('special/list', 'SpecialController');
}); });

12
app/Http/Controllers/Api/IndexController.php

@ -8,6 +8,7 @@ use App\Models\AgentProduct;
use App\Models\Slide; use App\Models\Slide;
use App\Models\Special; use App\Models\Special;
use App\Models\UserChannel; use App\Models\UserChannel;
use Illuminate\Support\Facades\Storage;
/** /**
* 小程序首页 * 小程序首页
@ -61,9 +62,14 @@ class IndexController extends Controller
# 专题列表 # 专题列表
$special = Special::query() $special = Special::query()
->where('agent_id', $this->agent_id) ->where('agent_id', $this->agent_id)
->orderBy('sort')
->orderBy('id')
->get(['id', 'picture_ad']);
->orderBy('sort')->orderBy('id')
->limit(6)->get(['id', 'picture_ad']);
if (!$special->isEmpty()) {
$prefix = Storage::disk('public')->url('');
foreach ($special as $k=>&$v) {
$v->picture_ad = $prefix . $v->picture_ad;
}
}
# 人气爆款 # 人气爆款
$hots = AgentProduct::query() $hots = AgentProduct::query()

6
app/Http/Controllers/Api/SpecialController.php

@ -4,7 +4,6 @@ namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\AgentProduct; use App\Models\AgentProduct;
use App\Models\Special; use App\Models\Special;
use Illuminate\Http\Request;
class SpecialController extends Controller class SpecialController extends Controller
{ {
@ -16,10 +15,9 @@ class SpecialController extends Controller
->select(['id', 'picture', 'picture_ad', 'updated_at', 'agent_product_id']) ->select(['id', 'picture', 'picture_ad', 'updated_at', 'agent_product_id'])
->find($id); ->find($id);
$detail->product = AgentProduct::query()
$detail->product = AgentProduct::list()
->where('agent_id', $this->agent_id)
->whereIn('id', $detail->agent_product_id) ->whereIn('id', $detail->agent_product_id)
->select('id', 'sale', 'product_id', 'price', 'original_price')
->with('product:id,title,pictures')
->limit(6)->get(); ->limit(6)->get();
unset($detail->agent_product_id); unset($detail->agent_product_id);

20
app/Models/Special.php

@ -8,32 +8,26 @@ class Special extends BaseModel
{ {
use HasFactory; use HasFactory;
protected $casts = ['picture' => 'array'];
//轮播图片 //轮播图片
public function getPictureAttribute($value): array public function getPictureAttribute($value): array
{ {
$value = json_decode($value, true); $value = json_decode($value, true);
if (is_array($value)) {
foreach ($value as &$v) {
$v = $v ? $this->host . $v : '';
}
}
return $value; return $value;
} }
//首页广告图
public function getPictureAdAttribute($value): string
{
return $value ? $this->host . $value : '';
}
//代理商产品ID //代理商产品ID
public function getAgentProductIdAttribute($value) public function getAgentProductIdAttribute($value)
{ {
return explode(',', $value); return explode(',', $value);
} }
public function agentProduct()
//代理商产品ID
public function setAgentProductIdAttribute($value)
{ {
return $this->belongsTo(AgentProduct::class);
if (is_array($value)) {
$this->attributes['agent_product_id'] = join(',', $value);
}
} }
} }

68
dcat_admin_ide_helper.php

@ -11,20 +11,16 @@ namespace Dcat\Admin {
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* @property Grid\Column|Collection id
* @property Grid\Column|Collection agent_id
* @property Grid\Column|Collection picture
* @property Grid\Column|Collection name
* @property Grid\Column|Collection tag
* @property Grid\Column|Collection desc
* @property Grid\Column|Collection created_at
* @property Grid\Column|Collection updated_at
* @property Grid\Column|Collection product_id * @property Grid\Column|Collection product_id
* @property Grid\Column|Collection know * @property Grid\Column|Collection know
* @property Grid\Column|Collection content * @property Grid\Column|Collection content
* @property Grid\Column|Collection id
* @property Grid\Column|Collection name
* @property Grid\Column|Collection type * @property Grid\Column|Collection type
* @property Grid\Column|Collection version * @property Grid\Column|Collection version
* @property Grid\Column|Collection detail * @property Grid\Column|Collection detail
* @property Grid\Column|Collection created_at
* @property Grid\Column|Collection updated_at
* @property Grid\Column|Collection is_enabled * @property Grid\Column|Collection is_enabled
* @property Grid\Column|Collection parent_id * @property Grid\Column|Collection parent_id
* @property Grid\Column|Collection order * @property Grid\Column|Collection order
@ -43,6 +39,10 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection password * @property Grid\Column|Collection password
* @property Grid\Column|Collection avatar * @property Grid\Column|Collection avatar
* @property Grid\Column|Collection remember_token * @property Grid\Column|Collection remember_token
* @property Grid\Column|Collection agent_id
* @property Grid\Column|Collection picture
* @property Grid\Column|Collection tag
* @property Grid\Column|Collection desc
* @property Grid\Column|Collection about * @property Grid\Column|Collection about
* @property Grid\Column|Collection reg_protocol * @property Grid\Column|Collection reg_protocol
* @property Grid\Column|Collection buy_protocol * @property Grid\Column|Collection buy_protocol
@ -93,6 +93,7 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection paid_money * @property Grid\Column|Collection paid_money
* @property Grid\Column|Collection paid_at * @property Grid\Column|Collection paid_at
* @property Grid\Column|Collection refund_info * @property Grid\Column|Collection refund_info
* @property Grid\Column|Collection verify_code
* @property Grid\Column|Collection email * @property Grid\Column|Collection email
* @property Grid\Column|Collection token * @property Grid\Column|Collection token
* @property Grid\Column|Collection pictures * @property Grid\Column|Collection pictures
@ -106,20 +107,16 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection openid * @property Grid\Column|Collection openid
* @property Grid\Column|Collection unionid * @property Grid\Column|Collection unionid
* *
* @method Grid\Column|Collection id(string $label = null)
* @method Grid\Column|Collection agent_id(string $label = null)
* @method Grid\Column|Collection picture(string $label = null)
* @method Grid\Column|Collection name(string $label = null)
* @method Grid\Column|Collection tag(string $label = null)
* @method Grid\Column|Collection desc(string $label = null)
* @method Grid\Column|Collection created_at(string $label = null)
* @method Grid\Column|Collection updated_at(string $label = null)
* @method Grid\Column|Collection product_id(string $label = null) * @method Grid\Column|Collection product_id(string $label = null)
* @method Grid\Column|Collection know(string $label = null) * @method Grid\Column|Collection know(string $label = null)
* @method Grid\Column|Collection content(string $label = null) * @method Grid\Column|Collection content(string $label = null)
* @method Grid\Column|Collection id(string $label = null)
* @method Grid\Column|Collection name(string $label = null)
* @method Grid\Column|Collection type(string $label = null) * @method Grid\Column|Collection type(string $label = null)
* @method Grid\Column|Collection version(string $label = null) * @method Grid\Column|Collection version(string $label = null)
* @method Grid\Column|Collection detail(string $label = null) * @method Grid\Column|Collection detail(string $label = null)
* @method Grid\Column|Collection created_at(string $label = null)
* @method Grid\Column|Collection updated_at(string $label = null)
* @method Grid\Column|Collection is_enabled(string $label = null) * @method Grid\Column|Collection is_enabled(string $label = null)
* @method Grid\Column|Collection parent_id(string $label = null) * @method Grid\Column|Collection parent_id(string $label = null)
* @method Grid\Column|Collection order(string $label = null) * @method Grid\Column|Collection order(string $label = null)
@ -138,6 +135,10 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection password(string $label = null) * @method Grid\Column|Collection password(string $label = null)
* @method Grid\Column|Collection avatar(string $label = null) * @method Grid\Column|Collection avatar(string $label = null)
* @method Grid\Column|Collection remember_token(string $label = null) * @method Grid\Column|Collection remember_token(string $label = null)
* @method Grid\Column|Collection agent_id(string $label = null)
* @method Grid\Column|Collection picture(string $label = null)
* @method Grid\Column|Collection tag(string $label = null)
* @method Grid\Column|Collection desc(string $label = null)
* @method Grid\Column|Collection about(string $label = null) * @method Grid\Column|Collection about(string $label = null)
* @method Grid\Column|Collection reg_protocol(string $label = null) * @method Grid\Column|Collection reg_protocol(string $label = null)
* @method Grid\Column|Collection buy_protocol(string $label = null) * @method Grid\Column|Collection buy_protocol(string $label = null)
@ -188,6 +189,7 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection paid_money(string $label = null) * @method Grid\Column|Collection paid_money(string $label = null)
* @method Grid\Column|Collection paid_at(string $label = null) * @method Grid\Column|Collection paid_at(string $label = null)
* @method Grid\Column|Collection refund_info(string $label = null) * @method Grid\Column|Collection refund_info(string $label = null)
* @method Grid\Column|Collection verify_code(string $label = null)
* @method Grid\Column|Collection email(string $label = null) * @method Grid\Column|Collection email(string $label = null)
* @method Grid\Column|Collection token(string $label = null) * @method Grid\Column|Collection token(string $label = null)
* @method Grid\Column|Collection pictures(string $label = null) * @method Grid\Column|Collection pictures(string $label = null)
@ -206,20 +208,16 @@ namespace Dcat\Admin {
class MiniGrid extends Grid {} class MiniGrid extends Grid {}
/** /**
* @property Show\Field|Collection id
* @property Show\Field|Collection agent_id
* @property Show\Field|Collection picture
* @property Show\Field|Collection name
* @property Show\Field|Collection tag
* @property Show\Field|Collection desc
* @property Show\Field|Collection created_at
* @property Show\Field|Collection updated_at
* @property Show\Field|Collection product_id * @property Show\Field|Collection product_id
* @property Show\Field|Collection know * @property Show\Field|Collection know
* @property Show\Field|Collection content * @property Show\Field|Collection content
* @property Show\Field|Collection id
* @property Show\Field|Collection name
* @property Show\Field|Collection type * @property Show\Field|Collection type
* @property Show\Field|Collection version * @property Show\Field|Collection version
* @property Show\Field|Collection detail * @property Show\Field|Collection detail
* @property Show\Field|Collection created_at
* @property Show\Field|Collection updated_at
* @property Show\Field|Collection is_enabled * @property Show\Field|Collection is_enabled
* @property Show\Field|Collection parent_id * @property Show\Field|Collection parent_id
* @property Show\Field|Collection order * @property Show\Field|Collection order
@ -238,6 +236,10 @@ namespace Dcat\Admin {
* @property Show\Field|Collection password * @property Show\Field|Collection password
* @property Show\Field|Collection avatar * @property Show\Field|Collection avatar
* @property Show\Field|Collection remember_token * @property Show\Field|Collection remember_token
* @property Show\Field|Collection agent_id
* @property Show\Field|Collection picture
* @property Show\Field|Collection tag
* @property Show\Field|Collection desc
* @property Show\Field|Collection about * @property Show\Field|Collection about
* @property Show\Field|Collection reg_protocol * @property Show\Field|Collection reg_protocol
* @property Show\Field|Collection buy_protocol * @property Show\Field|Collection buy_protocol
@ -288,6 +290,7 @@ namespace Dcat\Admin {
* @property Show\Field|Collection paid_money * @property Show\Field|Collection paid_money
* @property Show\Field|Collection paid_at * @property Show\Field|Collection paid_at
* @property Show\Field|Collection refund_info * @property Show\Field|Collection refund_info
* @property Show\Field|Collection verify_code
* @property Show\Field|Collection email * @property Show\Field|Collection email
* @property Show\Field|Collection token * @property Show\Field|Collection token
* @property Show\Field|Collection pictures * @property Show\Field|Collection pictures
@ -301,20 +304,16 @@ namespace Dcat\Admin {
* @property Show\Field|Collection openid * @property Show\Field|Collection openid
* @property Show\Field|Collection unionid * @property Show\Field|Collection unionid
* *
* @method Show\Field|Collection id(string $label = null)
* @method Show\Field|Collection agent_id(string $label = null)
* @method Show\Field|Collection picture(string $label = null)
* @method Show\Field|Collection name(string $label = null)
* @method Show\Field|Collection tag(string $label = null)
* @method Show\Field|Collection desc(string $label = null)
* @method Show\Field|Collection created_at(string $label = null)
* @method Show\Field|Collection updated_at(string $label = null)
* @method Show\Field|Collection product_id(string $label = null) * @method Show\Field|Collection product_id(string $label = null)
* @method Show\Field|Collection know(string $label = null) * @method Show\Field|Collection know(string $label = null)
* @method Show\Field|Collection content(string $label = null) * @method Show\Field|Collection content(string $label = null)
* @method Show\Field|Collection id(string $label = null)
* @method Show\Field|Collection name(string $label = null)
* @method Show\Field|Collection type(string $label = null) * @method Show\Field|Collection type(string $label = null)
* @method Show\Field|Collection version(string $label = null) * @method Show\Field|Collection version(string $label = null)
* @method Show\Field|Collection detail(string $label = null) * @method Show\Field|Collection detail(string $label = null)
* @method Show\Field|Collection created_at(string $label = null)
* @method Show\Field|Collection updated_at(string $label = null)
* @method Show\Field|Collection is_enabled(string $label = null) * @method Show\Field|Collection is_enabled(string $label = null)
* @method Show\Field|Collection parent_id(string $label = null) * @method Show\Field|Collection parent_id(string $label = null)
* @method Show\Field|Collection order(string $label = null) * @method Show\Field|Collection order(string $label = null)
@ -333,6 +332,10 @@ namespace Dcat\Admin {
* @method Show\Field|Collection password(string $label = null) * @method Show\Field|Collection password(string $label = null)
* @method Show\Field|Collection avatar(string $label = null) * @method Show\Field|Collection avatar(string $label = null)
* @method Show\Field|Collection remember_token(string $label = null) * @method Show\Field|Collection remember_token(string $label = null)
* @method Show\Field|Collection agent_id(string $label = null)
* @method Show\Field|Collection picture(string $label = null)
* @method Show\Field|Collection tag(string $label = null)
* @method Show\Field|Collection desc(string $label = null)
* @method Show\Field|Collection about(string $label = null) * @method Show\Field|Collection about(string $label = null)
* @method Show\Field|Collection reg_protocol(string $label = null) * @method Show\Field|Collection reg_protocol(string $label = null)
* @method Show\Field|Collection buy_protocol(string $label = null) * @method Show\Field|Collection buy_protocol(string $label = null)
@ -383,6 +386,7 @@ namespace Dcat\Admin {
* @method Show\Field|Collection paid_money(string $label = null) * @method Show\Field|Collection paid_money(string $label = null)
* @method Show\Field|Collection paid_at(string $label = null) * @method Show\Field|Collection paid_at(string $label = null)
* @method Show\Field|Collection refund_info(string $label = null) * @method Show\Field|Collection refund_info(string $label = null)
* @method Show\Field|Collection verify_code(string $label = null)
* @method Show\Field|Collection email(string $label = null) * @method Show\Field|Collection email(string $label = null)
* @method Show\Field|Collection token(string $label = null) * @method Show\Field|Collection token(string $label = null)
* @method Show\Field|Collection pictures(string $label = null) * @method Show\Field|Collection pictures(string $label = null)

16
resources/lang/zh_CN/special.php

@ -0,0 +1,16 @@
<?php
return [
'labels' => [
'Special' => '专题',
'special' => '专题',
],
'fields' => [
'agent_id' => '代理商ID',
'picture' => '专题页轮播图',
'picture_ad' => '首页广告图',
'agent_product_id' => '产品ID',
'sort' => '排序',
],
'options' => [
],
];
Loading…
Cancel
Save