调试菜品、菜品商品、商品
This commit is contained in:
parent
ea0b6f1f65
commit
31f910e196
@ -1,65 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\DishesCategory;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* DishesCategory列表
|
||||
* Class DishesCategoryLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class DishesCategoryLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['pid', 'name'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return DishesCategory::where($this->searchWhere)
|
||||
->field(['id', 'pid', 'name', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return DishesCategory::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\DishesCategory;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* DishesCategory列表
|
||||
* Class DishesCategoryLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class DishesCategoryLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['pid', 'name'],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$list = DishesCategory::where($this->searchWhere)
|
||||
->field(['id', 'pid', 'name', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
$list = linear_to_tree($list, 'children');
|
||||
return $this->setDisable($list);
|
||||
}
|
||||
|
||||
public function setDisable($list)
|
||||
{
|
||||
foreach ($list as &$item) {
|
||||
$item['disabled'] = $item['level'] > 0;
|
||||
if (isset($item['children'])) {
|
||||
$item['children'] = $this->setDisable($item['children']);
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return DishesCategory::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,65 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\Dishes;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Dishes列表
|
||||
* Class DishesLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class DishesLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['name', 'dishes_category_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Dishes::where($this->searchWhere)
|
||||
->field(['id', 'name', 'dishes_category_id', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Dishes::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\Dishes;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\DishesCategory;
|
||||
|
||||
|
||||
/**
|
||||
* Dishes列表
|
||||
* Class DishesLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class DishesLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'like' => ['name'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = Dishes::where($this->searchWhere);
|
||||
if (!empty($this->params['dishes_category_id'])) {
|
||||
$dishesCategoryIds = DishesCategory::where('id', $this->params['dishes_category_id'])->whereOr('pid', $this->params['dishes_category_id'])->column('id');
|
||||
$query->whereIn('dishes_category_id', $dishesCategoryIds);
|
||||
}
|
||||
return $query->field(['id', 'name', 'dishes_category_id', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Dishes::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,65 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\DishesProduct;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* DishesProduct列表
|
||||
* Class DishesProductLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class DishesProductLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['dishes_id', 'product_id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return DishesProduct::where($this->searchWhere)
|
||||
->field(['id', 'dishes_id', 'product_id', 'unit_id', 'nums', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return DishesProduct::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\DishesProduct;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* DishesProduct列表
|
||||
* Class DishesProductLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class DishesProductLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['dishes_id', 'product_id'],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return DishesProduct::where($this->searchWhere)
|
||||
->with(['unit', 'product', 'dishes'])
|
||||
->field(['id', 'dishes_id', 'product_id', 'unit_id', 'nums', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return DishesProduct::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,65 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\Product;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Product列表
|
||||
* Class ProductLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class ProductLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['category_id', 'unit_id', 'name', 'product_type'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Product::where($this->searchWhere)
|
||||
->field(['id', 'category_id', 'unit_id', 'name', 'image', 'product_type', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Product::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\Product;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\ProductCategory;
|
||||
|
||||
|
||||
/**
|
||||
* Product列表
|
||||
* Class ProductLists
|
||||
* @package app\admin\lists
|
||||
*/
|
||||
class ProductLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['unit_id', 'name', 'product_type'],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = Product::where($this->searchWhere);
|
||||
if (!empty($this->params['category_id'])) {
|
||||
$query->whereFindInSet('category_ids', $this->params['category_id']);
|
||||
}
|
||||
return $query->with(['unit', 'category'])
|
||||
->field(['id', 'category_id', 'category_ids', 'unit_id', 'name', 'image', 'product_type', 'create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->each(function ($item) {
|
||||
$categories = ProductCategory::whereIn('id', $item['category_ids'])->column('name');
|
||||
$item['categories'] = implode('/', $categories);
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取数量
|
||||
* @return int
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Product::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace app\admin\logic;
|
||||
|
||||
use app\common\model\Product;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\ProductCategory;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -28,8 +29,10 @@ class ProductLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params['category_ids'] = ProductCategory::getParentUntilRoot($params['category_id']);
|
||||
Product::create([
|
||||
'category_id' => $params['category_id'],
|
||||
'category_ids' => implode(',', $params['category_ids']),
|
||||
'unit_id' => $params['unit_id'],
|
||||
'name' => $params['name'],
|
||||
'image' => $params['image'],
|
||||
@ -59,8 +62,10 @@ class ProductLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params['category_ids'] = ProductCategory::getParentUntilRoot($params['category_id']);
|
||||
Product::where('id', $params['id'])->update([
|
||||
'category_id' => $params['category_id'],
|
||||
'category_ids' => implode(',', $params['category_ids']),
|
||||
'unit_id' => $params['unit_id'],
|
||||
'name' => $params['name'],
|
||||
'image' => $params['image'],
|
||||
@ -78,7 +83,6 @@ class ProductLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除
|
||||
* @param array $params
|
||||
@ -103,4 +107,4 @@ class ProductLogic extends BaseLogic
|
||||
{
|
||||
return Product::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,82 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* DishesProduct验证器
|
||||
* Class DishesProductValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class DishesProductValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return DishesProductValidate
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return DishesProductValidate
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return DishesProductValidate
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return DishesProductValidate
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\admin\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* DishesProduct验证器
|
||||
* Class DishesProductValidate
|
||||
* @package app\admin\validate
|
||||
*/
|
||||
class DishesProductValidate extends BaseValidate
|
||||
{
|
||||
|
||||
/**
|
||||
* 设置校验规则
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'dishes_id' => 'require',
|
||||
'product_id' => 'require',
|
||||
'unit_id' => 'require',
|
||||
'nums' => 'require',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'dishes_id' => '菜品ID',
|
||||
'product_id' => '商品ID',
|
||||
'unit_id' => '单位ID',
|
||||
'nums' => '数量',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加场景
|
||||
* @return DishesProductValidate
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->remove('id', true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑场景
|
||||
* @return DishesProductValidate
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id', 'dishes_id', 'product_id', 'unit_id', 'nums']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除场景
|
||||
* @return DishesProductValidate
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 详情场景
|
||||
* @return DishesProductValidate
|
||||
* @author likeadmin
|
||||
* @date 2025/07/11 11:41
|
||||
*/
|
||||
public function sceneDetail()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,5 +18,19 @@ class DishesProduct extends BaseModel
|
||||
protected $name = 'dishes_product';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
||||
public function dishes()
|
||||
{
|
||||
return $this->hasOne(Dishes::class, 'id', 'dishes_id')->field('id,name');
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->hasOne(Product::class, 'id', 'product_id')->field('id,name,image');
|
||||
}
|
||||
|
||||
public function unit()
|
||||
{
|
||||
return $this->hasOne(ProductUnit::class, 'id', 'unit_id')->field('id,name');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,5 +18,14 @@ class Product extends BaseModel
|
||||
protected $name = 'product';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
||||
public function unit()
|
||||
{
|
||||
return $this->hasOne(ProductUnit::class, 'id', 'unit_id')->field('id,name,conversion_value');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->hasOne(ProductCategory::class, 'id', 'category_id')->field('id,name,pid');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,5 +18,15 @@ class ProductCategory extends BaseModel
|
||||
protected $name = 'product_category';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
||||
public static function getParentUntilRoot($id)
|
||||
{
|
||||
static $parentIds = [];
|
||||
$parentIds[] = $id;
|
||||
$pid = self::where('id', $id)->value('pid');
|
||||
if ($pid) {
|
||||
self::getParentUntilRoot($pid);
|
||||
}
|
||||
return $parentIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,20 +41,20 @@ abstract class Server
|
||||
if (empty($this->file)) {
|
||||
throw new Exception('未找到上传文件的信息');
|
||||
}
|
||||
$this->file->extension = pathinfo($this->file->getUploadName(), PATHINFO_EXTENSION);
|
||||
$extension = pathinfo($this->file->getUploadName(), PATHINFO_EXTENSION);
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
$this->file->getMime = finfo_file($finfo, $this->file->getPathname());
|
||||
$mimeType = finfo_file($finfo, $this->file->getPathname());
|
||||
// 校验上传文件后缀
|
||||
$limit = array_merge(config('project.file_image'), config('project.file_video'));
|
||||
if (!in_array(strtolower($this->file->extension), $limit)) {
|
||||
throw new Exception('不允许上传' . $this->file->extension . '后缀文件');
|
||||
if (!in_array(strtolower($extension), $limit)) {
|
||||
throw new Exception('不允许上传' . $extension . '后缀文件');
|
||||
}
|
||||
|
||||
// 文件信息
|
||||
$this->fileInfo = [
|
||||
'ext' => $this->file->extension,
|
||||
'ext' => $extension,
|
||||
'size' => $this->file->getSize(),
|
||||
'mime' => $this->file->getMime,
|
||||
'mime' => $mimeType,
|
||||
'name' => $this->file->getUploadName(),
|
||||
'realPath' => $this->file->getRealPath(),
|
||||
];
|
||||
|
@ -17,6 +17,7 @@ declare(strict_types=1);
|
||||
namespace app\common\validate;
|
||||
|
||||
use app\common\service\JsonService;
|
||||
use support\exception\BusinessException;
|
||||
use taoser\Validate;
|
||||
|
||||
class BaseValidate extends Validate
|
||||
@ -79,9 +80,9 @@ class BaseValidate extends Validate
|
||||
|
||||
if (!$result) {
|
||||
$exception = is_array($this->error) ? implode(';', $this->error) : $this->error;
|
||||
JsonService::throw($exception);
|
||||
throw new BusinessException($exception);
|
||||
}
|
||||
// 3.成功返回数据
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,7 @@ function create_password(string $plaintext, string $salt) : string
|
||||
* @param string $parent_id_name 数组祖先id名
|
||||
* @param int $level 此值请勿给参数
|
||||
* @param int $parent_id 此值请勿给参数
|
||||
* @param int $level 等级
|
||||
* @return array
|
||||
*/
|
||||
function linear_to_tree($data, $sub_key_name = 'sub', $id_name = 'id', $parent_id_name = 'pid', $parent_id = 0, $level = 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user