CenterMenu.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\shop\model\page;
  3. use app\common\model\page\CenterMenu as CenterMenuModel;
  4. use think\facade\Cache;
  5. /**
  6. * 模型
  7. */
  8. class CenterMenu extends CenterMenuModel
  9. {
  10. /**
  11. * 获取列表
  12. */
  13. public function getList($params)
  14. {
  15. $list = $this->order(['sort' => 'asc'])
  16. ->paginate($params);
  17. foreach ($list as $menus){
  18. if(strpos($menus['icon'], 'http') !== 0){
  19. $menus['icon'] = self::$base_url . $menus['icon'];
  20. }
  21. }
  22. return $list;
  23. }
  24. /**
  25. * 添加新记录
  26. */
  27. public function add($data)
  28. {
  29. $data['app_id'] = self::$app_id;
  30. $this->deleteCache();
  31. return $this->save($data);
  32. }
  33. /**
  34. * 编辑记录
  35. */
  36. public function edit($data)
  37. {
  38. $this->deleteCache();
  39. return $this->save($data);
  40. }
  41. /**
  42. * 删除记录
  43. */
  44. public function remove()
  45. {
  46. $this->deleteCache();
  47. return $this->delete();
  48. }
  49. /**
  50. * 删除缓存
  51. */
  52. private function deleteCache()
  53. {
  54. return Cache::delete('center_menu_' . static::$app_id);
  55. }
  56. }