$params['name'], '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'], ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑 * @param array $params * @return bool * @author likeadmin * @date 2025/07/11 11:41 */ public static function edit(array $params): bool { Db::startTrans(); try { Dishes::where('id', $params['id'])->update([ 'name' => $params['name'], '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'], ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除 * @param array $params * @return bool * @author likeadmin * @date 2025/07/11 11:41 */ public static function delete(array $params): bool { Dishes::destroy($params['id']); DishesProduct::destroy(['dishes_id' => $params['id']]); return true; } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2025/07/11 11:41 */ public static function detail($params): array { $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; } }