feat: #20220728 商品列表查询

This commit is contained in:
赵世界 2022-07-28 16:06:15 +08:00
parent 6521b4e746
commit 2c17bb51b4
9 changed files with 81 additions and 16 deletions

View File

@ -1,15 +1,15 @@
APP_NAME=Laravel
APP_NAME=ERP
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_URL=http://erp.test
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_DATABASE=erp
DB_USERNAME=root
DB_PASSWORD=

View File

@ -14,9 +14,10 @@
1. `composer install`
2. `cp .env.example .env`
3. 创建数据库 `CREATE DATABASE IF NOT EXISTS `erp` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;`
4. 修改 .env 配置项为本地配置
5. `php artisan migration`
3. 修改 .env 配置项为本地配置
4. 创建数据库 `CREATE DATABASE IF NOT EXISTS `erp` DEFAULT CHARACTER SET utf8;`
5. `php artisan migrate`
6. `php artisan key:generate`
#### 使用说明

View File

@ -0,0 +1,21 @@
<?php
namespace App\Filters;
class GoodsFilter extends Filters
{
protected function title($value)
{
return $this->builder->where('title', 'like', "%$value%");
}
protected function typeId($value)
{
return $this->builder->where('type_id', '=', $value);
}
protected function brandId($value)
{
return $this->builder->where('brand_id', '=', $value);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Filters;
class GoodsSkuFilter extends Filters
{
protected function title($value)
{
return $this->builder->where('title', '=', $value);
}
protected function status($value)
{
return $this->builder->where('status', '=', $value);
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace App\Filters;
class LogFilter extends Filters
{
}

View File

@ -3,7 +3,6 @@
namespace App\Http\Controllers\Goods;
use App\Http\Controllers\Controller;
use App\Http\Resources\GoodsResource;
use App\Http\Resources\GoodsSkuResource;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -16,13 +15,16 @@ class GoodsController extends Controller
{
public function index(Request $request)
{
$goods = GoodsSku::query()
->with(['goods' => function($query) {
// $goodsIds = [];
$goodsSkus = GoodsSku::query()
->filter()
->with(['goods' => function ($query) {
$query->with(['type:id,name', 'brand:id,name'])->filter();
}])
// ->whereIn('goods_id', $goodsIds)
->paginate();
return GoodsSkuResource::collection($goods);
return GoodsSkuResource::collection($goodsSkus);
}
public function store(Request $request)

View File

@ -8,6 +8,13 @@ class Goods extends Model
{
use Filter;
//查询字段
public $fieldSearchable = [
'title',
'type_id',
'brand_id',
];
/**
* 多规格
*/

View File

@ -2,8 +2,18 @@
namespace App\Models;
use App\Models\traits\Filter;
class GoodsSku extends Model
{
use Filter;
//查询字段
public $fieldSearchable = [
'title',
'status',
];
/**
* 不可批量赋值的属性。为空则所有熟悉都可以批量赋值
*
@ -11,7 +21,7 @@ class GoodsSku extends Model
*/
protected $guarded = [];
protected $hidden = ['goods_id', 'created_at'];
protected $hidden = ['created_at'];
/**
* 此规格从属于一个商品

View File

@ -48,12 +48,12 @@ return [
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'database' => env('DB_DATABASE', 'erp'),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,