mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
feat: #20220728 商品列表查询
This commit is contained in:
parent
6521b4e746
commit
2c17bb51b4
@ -1,15 +1,15 @@
|
|||||||
APP_NAME=Laravel
|
APP_NAME=ERP
|
||||||
APP_ENV=local
|
APP_ENV=local
|
||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=http://localhost
|
APP_URL=http://erp.test
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
LOG_CHANNEL=stack
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
DB_CONNECTION=mysql
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_DATABASE=laravel
|
DB_DATABASE=erp
|
||||||
DB_USERNAME=root
|
DB_USERNAME=root
|
||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
|
|
||||||
|
|||||||
@ -14,9 +14,10 @@
|
|||||||
|
|
||||||
1. `composer install`
|
1. `composer install`
|
||||||
2. `cp .env.example .env`
|
2. `cp .env.example .env`
|
||||||
3. 创建数据库 `CREATE DATABASE IF NOT EXISTS `erp` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;`
|
3. 修改 .env 配置项为本地配置
|
||||||
4. 修改 .env 配置项为本地配置
|
4. 创建数据库 `CREATE DATABASE IF NOT EXISTS `erp` DEFAULT CHARACTER SET utf8;`
|
||||||
5. `php artisan migration`
|
5. `php artisan migrate`
|
||||||
|
6. `php artisan key:generate`
|
||||||
|
|
||||||
#### 使用说明
|
#### 使用说明
|
||||||
|
|
||||||
|
|||||||
21
app/Filters/GoodsFilter.php
Normal file
21
app/Filters/GoodsFilter.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Filters/GoodsSkuFilter.php
Normal file
16
app/Filters/GoodsSkuFilter.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
app/Filters/LogFilter.php
Normal file
8
app/Filters/LogFilter.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filters;
|
||||||
|
|
||||||
|
class LogFilter extends Filters
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,7 +3,6 @@
|
|||||||
namespace App\Http\Controllers\Goods;
|
namespace App\Http\Controllers\Goods;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Resources\GoodsResource;
|
|
||||||
use App\Http\Resources\GoodsSkuResource;
|
use App\Http\Resources\GoodsSkuResource;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@ -16,13 +15,16 @@ class GoodsController extends Controller
|
|||||||
{
|
{
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$goods = GoodsSku::query()
|
// $goodsIds = [];
|
||||||
|
$goodsSkus = GoodsSku::query()
|
||||||
|
->filter()
|
||||||
->with(['goods' => function ($query) {
|
->with(['goods' => function ($query) {
|
||||||
|
$query->with(['type:id,name', 'brand:id,name'])->filter();
|
||||||
}])
|
}])
|
||||||
|
// ->whereIn('goods_id', $goodsIds)
|
||||||
->paginate();
|
->paginate();
|
||||||
|
|
||||||
return GoodsSkuResource::collection($goods);
|
return GoodsSkuResource::collection($goodsSkus);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
|
|||||||
@ -8,6 +8,13 @@ class Goods extends Model
|
|||||||
{
|
{
|
||||||
use Filter;
|
use Filter;
|
||||||
|
|
||||||
|
//查询字段
|
||||||
|
public $fieldSearchable = [
|
||||||
|
'title',
|
||||||
|
'type_id',
|
||||||
|
'brand_id',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多规格
|
* 多规格
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -2,8 +2,18 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\traits\Filter;
|
||||||
|
|
||||||
class GoodsSku extends Model
|
class GoodsSku extends Model
|
||||||
{
|
{
|
||||||
|
use Filter;
|
||||||
|
|
||||||
|
//查询字段
|
||||||
|
public $fieldSearchable = [
|
||||||
|
'title',
|
||||||
|
'status',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不可批量赋值的属性。为空则所有熟悉都可以批量赋值
|
* 不可批量赋值的属性。为空则所有熟悉都可以批量赋值
|
||||||
*
|
*
|
||||||
@ -11,7 +21,7 @@ class GoodsSku extends Model
|
|||||||
*/
|
*/
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
|
||||||
protected $hidden = ['goods_id', 'created_at'];
|
protected $hidden = ['created_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 此规格从属于一个商品
|
* 此规格从属于一个商品
|
||||||
|
|||||||
@ -48,12 +48,12 @@ return [
|
|||||||
'url' => env('DATABASE_URL'),
|
'url' => env('DATABASE_URL'),
|
||||||
'host' => env('DB_HOST', '127.0.0.1'),
|
'host' => env('DB_HOST', '127.0.0.1'),
|
||||||
'port' => env('DB_PORT', '3306'),
|
'port' => env('DB_PORT', '3306'),
|
||||||
'database' => env('DB_DATABASE', 'forge'),
|
'database' => env('DB_DATABASE', 'erp'),
|
||||||
'username' => env('DB_USERNAME', 'forge'),
|
'username' => env('DB_USERNAME', ''),
|
||||||
'password' => env('DB_PASSWORD', ''),
|
'password' => env('DB_PASSWORD', ''),
|
||||||
'unix_socket' => env('DB_SOCKET', ''),
|
'unix_socket' => env('DB_SOCKET', ''),
|
||||||
'charset' => 'utf8mb4',
|
'charset' => 'utf8',
|
||||||
'collation' => 'utf8mb4_unicode_ci',
|
'collation' => 'utf8_general_ci',
|
||||||
'prefix' => '',
|
'prefix' => '',
|
||||||
'prefix_indexes' => true,
|
'prefix_indexes' => true,
|
||||||
'strict' => true,
|
'strict' => true,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user