api 店铺商品
parent
713100d0ef
commit
b00238f320
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use App\Admin\Repositories\Tag;
|
|
||||||
use App\Exceptions\BizException;
|
use App\Exceptions\BizException;
|
||||||
use App\Models\Tag as TagModel;
|
use App\Models\Tag;
|
||||||
use App\Models\Taggable;
|
use App\Models\Taggable;
|
||||||
use Dcat\Admin\Admin;
|
use Dcat\Admin\Admin;
|
||||||
use Dcat\Admin\Form;
|
use Dcat\Admin\Form;
|
||||||
|
|
@ -24,11 +23,7 @@ class TagController extends AdminController
|
||||||
{
|
{
|
||||||
return Grid::make(new Tag(), function (Grid $grid) {
|
return Grid::make(new Tag(), function (Grid $grid) {
|
||||||
$grid->column('id')->sortable();
|
$grid->column('id')->sortable();
|
||||||
$grid->column('type')->using([
|
$grid->column('type')->using(Tag::$typeMaps)->label();
|
||||||
TagModel::TYPE_ORDER =>'订单',
|
|
||||||
TagModel::TYPE_PACKAGE=>'货运',
|
|
||||||
TagModel::TYPE_AFTER_SALE=>'售后',
|
|
||||||
])->label();
|
|
||||||
$grid->column('name');
|
$grid->column('name');
|
||||||
$grid->column('created_at')->sortable();
|
$grid->column('created_at')->sortable();
|
||||||
|
|
||||||
|
|
@ -52,11 +47,7 @@ class TagController extends AdminController
|
||||||
$grid->setResource('tags');
|
$grid->setResource('tags');
|
||||||
$grid->filter(function (Grid\Filter $filter) {
|
$grid->filter(function (Grid\Filter $filter) {
|
||||||
$filter->panel();
|
$filter->panel();
|
||||||
$filter->equal('type')->select([
|
$filter->equal('type')->select(Tag::$typeMaps)->width(3);
|
||||||
TagModel::TYPE_ORDER =>'订单',
|
|
||||||
TagModel::TYPE_PACKAGE =>'货运',
|
|
||||||
TagModel::TYPE_AFTER_SALE =>'售后',
|
|
||||||
])->width(3);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -87,11 +78,7 @@ class TagController extends AdminController
|
||||||
protected function form()
|
protected function form()
|
||||||
{
|
{
|
||||||
return Form::make(new Tag(), function (Form $form) {
|
return Form::make(new Tag(), function (Form $form) {
|
||||||
$types = [
|
$types = Tag::$typeMaps;
|
||||||
TagModel::TYPE_ORDER =>'订单',
|
|
||||||
TagModel::TYPE_PACKAGE=>'货运',
|
|
||||||
TagModel::TYPE_AFTER_SALE =>'售后',
|
|
||||||
];
|
|
||||||
$type = Request::Input('type', 0);
|
$type = Request::Input('type', 0);
|
||||||
if ($types[$type]) {
|
if ($types[$type]) {
|
||||||
$types = [
|
$types = [
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Admin\Repositories;
|
|
||||||
|
|
||||||
use App\Models\Tag as Model;
|
|
||||||
use Dcat\Admin\Repositories\EloquentRepository;
|
|
||||||
|
|
||||||
class Tag extends EloquentRepository
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Model.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $eloquentClass = Model::class;
|
|
||||||
}
|
|
||||||
|
|
@ -4,7 +4,8 @@ namespace App\Endpoint\Api\Http\Controllers\Order;
|
||||||
|
|
||||||
use App\Endpoint\Api\Http\Controllers\Controller;
|
use App\Endpoint\Api\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Models\{OrderPre, ProductSku, Store};
|
use App\Models\{OrderPre, ProductSku};
|
||||||
|
use App\Models\Store\Store;
|
||||||
use App\Services\OrderService;
|
use App\Services\OrderService;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use App\Exceptions\BizException;
|
use App\Exceptions\BizException;
|
||||||
|
|
@ -40,8 +41,19 @@ class OrderPreController extends Controller
|
||||||
$sku_id = $item['sku_id'];
|
$sku_id = $item['sku_id'];
|
||||||
|
|
||||||
// 验证商品是否属于该店铺
|
// 验证商品是否属于该店铺
|
||||||
if (!$store->productSkus()->wherePivot('product_sku_id', $sku_id)->exists()) {
|
$store_product = $store->productSkus()->wherePivot('product_sku_id', $sku_id)->first();
|
||||||
throw new BizException('商品未在该店铺出售, ' . $sku_id);
|
if (!$store_product) {
|
||||||
|
throw new BizException('店铺未出售商品: ' . $store_product->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证商品是否可销售
|
||||||
|
if (!$store_product->pivot->status) {
|
||||||
|
throw new BizException('店铺已下架商品: ' . $store_product->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证商品库存(店铺库存)
|
||||||
|
if ($store_product->pivot->amount < $quantity) {
|
||||||
|
throw new BizException('店铺商品: ' . $store_product->name . ' 库存不足');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证商品的购买数量 大于 发货数量
|
// 验证商品的购买数量 大于 发货数量
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,10 @@
|
||||||
namespace App\Endpoint\Api\Http\Controllers;
|
namespace App\Endpoint\Api\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Models\Store;
|
use App\Models\Store\Store;
|
||||||
use App\Endpoint\Api\Http\Resources\StoreResource;
|
|
||||||
use App\Endpoint\Api\Http\Resources\ProductSkuTinyResource;
|
|
||||||
use App\Models\ProductSku;
|
use App\Models\ProductSku;
|
||||||
use App\Helpers\Paginator;
|
use App\Helpers\Paginator;
|
||||||
|
use App\Endpoint\Api\Http\Resources\{StoreResource, StoreProductResource};
|
||||||
|
|
||||||
class StoreController extends Controller
|
class StoreController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -40,10 +39,15 @@ class StoreController extends Controller
|
||||||
$input['sort'] = '-id';
|
$input['sort'] = '-id';
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = ['id', 'name', 'cover', 'sell_price', 'vip_price', 'market_price'];
|
$fields = ['product_skus.id', 'product_skus.name', 'product_skus.cover', 'product_skus.sell_price', 'product_skus.vip_price', 'product_skus.market_price', 'store_product_skus.amount'];
|
||||||
|
|
||||||
$skus = $store->productSkus()->select($fields)->filter($input)->online()->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50));
|
$skus = $store->productSkus()
|
||||||
|
->select($fields)
|
||||||
|
->filter($input)
|
||||||
|
->online()
|
||||||
|
->wherePivot('status', 1)
|
||||||
|
->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50));
|
||||||
|
|
||||||
return ProductSkuTinyResource::collection($skus);
|
return StoreProductResource::collection($skus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Endpoint\Api\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class StoreProductResource extends JsonResource
|
||||||
|
{
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'name' => $this->name,
|
||||||
|
'cover' => (string) $this->cover,
|
||||||
|
'sell_price' => (string) $this->sell_price_format,
|
||||||
|
'vip_price' => (string) $this->vip_price_format,
|
||||||
|
'market_price' => (string) $this->market_price_format,
|
||||||
|
'amount' => (int) $this->pivot->amount
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,13 @@ class Tag extends Model
|
||||||
|
|
||||||
protected $fillable = ['type', 'name'];
|
protected $fillable = ['type', 'name'];
|
||||||
|
|
||||||
|
public static $typeMaps = [
|
||||||
|
self::TYPE_ORDER => '订单',
|
||||||
|
self::TYPE_PACKAGE => '货运',
|
||||||
|
self::TYPE_AFTER_SALE => '售后',
|
||||||
|
self::TYPE_STORE_STOCK => '店铺库存',
|
||||||
|
];
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * 标签下的订单
|
// * 标签下的订单
|
||||||
// *
|
// *
|
||||||
|
|
|
||||||
|
|
@ -243,13 +243,18 @@ class AdminMenuSeeder extends Seeder
|
||||||
'icon' => '',
|
'icon' => '',
|
||||||
'uri' => 'aftersale-tags?type=3',
|
'uri' => 'aftersale-tags?type=3',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'title' => '售后打款',
|
||||||
|
'icon' => '',
|
||||||
|
'uri' =>'finance-after-sales?state=5',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
[
|
// [
|
||||||
'title' => '财务管理',
|
// 'title' => '财务管理',
|
||||||
'icon' => 'fa fa-jpy',
|
// 'icon' => 'fa fa-jpy',
|
||||||
'uri'=> '',
|
// 'uri'=> '',
|
||||||
'children'=>[
|
// 'children'=>[
|
||||||
// [
|
// [
|
||||||
// 'title' => '可提账户',
|
// 'title' => '可提账户',
|
||||||
// 'icon'=>'',
|
// 'icon'=>'',
|
||||||
|
|
@ -270,13 +275,13 @@ class AdminMenuSeeder extends Seeder
|
||||||
// 'icon' => '',
|
// 'icon' => '',
|
||||||
// 'uri' =>'wallet-to-bank-logs',
|
// 'uri' =>'wallet-to-bank-logs',
|
||||||
// ],
|
// ],
|
||||||
[
|
// [
|
||||||
'title' => '售后打款',
|
// 'title' => '售后打款',
|
||||||
'icon' => '',
|
// 'icon' => '',
|
||||||
'uri' =>'finance-after-sales?state=5',
|
// 'uri' =>'finance-after-sales?state=5',
|
||||||
],
|
// ],
|
||||||
],
|
// ],
|
||||||
],
|
// ],
|
||||||
[
|
[
|
||||||
'title' => '系统管理',
|
'title' => '系统管理',
|
||||||
'icon' => 'feather icon-settings',
|
'icon' => 'feather icon-settings',
|
||||||
|
|
@ -307,6 +312,7 @@ class AdminMenuSeeder extends Seeder
|
||||||
'icon' => '',
|
'icon' => '',
|
||||||
'uri' => 'settings',
|
'uri' => 'settings',
|
||||||
],
|
],
|
||||||
|
['title' => '标签管理', 'icon' => '', 'uri' => 'tags']
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue