修改菜品管理
This commit is contained in:
parent
a0c2eaaf53
commit
a5a43f5674
@ -50,7 +50,10 @@ class DishesCategoryLists extends BaseAdminDataLists implements ListsSearchInter
|
||||
->select()
|
||||
->toArray();
|
||||
$list = linear_to_tree($list, 'children');
|
||||
return $this->setDisable($list);
|
||||
if (isset($this->params['disable'])) {
|
||||
$list = $this->setDisable($list);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function setDisable($list)
|
||||
|
@ -43,12 +43,12 @@ class DishesLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$query = Dishes::where($this->searchWhere);
|
||||
$query = Dishes::where($this->searchWhere)->with('dishesCategory');
|
||||
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', 'image', 'intro'])
|
||||
return $query->field(['id', 'name', 'dishes_category_id', 'create_time', 'image', 'intro', 'min_num', 'sale_num', 'time_type', 'feature', 'people', 'status'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
|
@ -5,6 +5,8 @@ namespace app\admin\logic;
|
||||
|
||||
use app\common\model\Dishes;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\DishesProduct;
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -30,8 +32,14 @@ class DishesLogic extends BaseLogic
|
||||
try {
|
||||
Dishes::create([
|
||||
'name' => $params['name'],
|
||||
'image' => $params['image'],
|
||||
'image' => implode(',', $params['image']),
|
||||
'intro' => $params['intro'],
|
||||
'min_num' => $params['min_num'],
|
||||
'sale_num' => $params['sale_num'],
|
||||
'time_type' => $params['time_type'],
|
||||
'feature' => $params['feature'],
|
||||
'people' => $params['people'],
|
||||
'status' => $params['status'],
|
||||
'dishes_category_id' => $params['dishes_category_id'],
|
||||
]);
|
||||
|
||||
@ -58,8 +66,14 @@ class DishesLogic extends BaseLogic
|
||||
try {
|
||||
Dishes::where('id', $params['id'])->update([
|
||||
'name' => $params['name'],
|
||||
'image' => $params['image'],
|
||||
'image' => implode(',', $params['image']),
|
||||
'intro' => $params['intro'],
|
||||
'min_num' => $params['min_num'],
|
||||
'sale_num' => $params['sale_num'],
|
||||
'time_type' => $params['time_type'],
|
||||
'feature' => $params['feature'],
|
||||
'people' => $params['people'],
|
||||
'status' => $params['status'],
|
||||
'dishes_category_id' => $params['dishes_category_id'],
|
||||
]);
|
||||
|
||||
@ -82,7 +96,9 @@ class DishesLogic extends BaseLogic
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return Dishes::destroy($params['id']);
|
||||
Dishes::destroy($params['id']);
|
||||
DishesProduct::destroy(['dishes_id' => $params['id']]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -95,6 +111,11 @@ class DishesLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return Dishes::findOrEmpty($params['id'])->toArray();
|
||||
$data = Dishes::findOrEmpty($params['id'])->toArray();
|
||||
$data['image'] = !empty($data['image']) ? explode(',', $data['image']) : [];
|
||||
foreach ($data['image'] as &$v) {
|
||||
$v = FileService::getFileUrl($v) ;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ namespace app\admin\logic;
|
||||
use app\common\model\Product;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\ProductCategory;
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
@ -35,7 +36,7 @@ class ProductLogic extends BaseLogic
|
||||
'category_ids' => implode(',', $params['category_ids']),
|
||||
'unit_id' => $params['unit_id'],
|
||||
'name' => $params['name'],
|
||||
'image' => $params['image'],
|
||||
'image' => implode(',', $params['image']),
|
||||
'intro' => $params['intro'],
|
||||
'conent' => $params['conent'],
|
||||
'product_type' => $params['product_type'],
|
||||
@ -68,7 +69,7 @@ class ProductLogic extends BaseLogic
|
||||
'category_ids' => implode(',', $params['category_ids']),
|
||||
'unit_id' => $params['unit_id'],
|
||||
'name' => $params['name'],
|
||||
'image' => $params['image'],
|
||||
'image' => implode(',', $params['image']),
|
||||
'intro' => $params['intro'],
|
||||
'conent' => $params['conent'],
|
||||
'product_type' => $params['product_type'],
|
||||
@ -105,6 +106,11 @@ class ProductLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return Product::findOrEmpty($params['id'])->toArray();
|
||||
$data = Product::findOrEmpty($params['id'])->toArray();
|
||||
$data['image'] = !empty($data['image']) ? explode(',', $data['image']) : [];
|
||||
foreach ($data['image'] as &$v) {
|
||||
$v = FileService::getFileUrl($v) ;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
@ -18,5 +18,9 @@ class Dishes extends BaseModel
|
||||
protected $name = 'dishes';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
|
||||
}
|
||||
public function dishesCategory()
|
||||
{
|
||||
return $this->hasOne(DishesCategory::class, 'id', 'dishes_category_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user