CenterMenu.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\common\model\page;
  3. use app\common\model\BaseModel;
  4. use think\facade\Cache;
  5. /**
  6. * 个人中心菜单
  7. */
  8. class CenterMenu extends BaseModel
  9. {
  10. //表名
  11. protected $name = 'center_menu';
  12. //主键字段名
  13. protected $pk = 'menu_id';
  14. /**
  15. * 详情
  16. */
  17. public static function detail($menu_id)
  18. {
  19. return (new static())->find($menu_id);
  20. }
  21. /**
  22. * 查询所有
  23. */
  24. public static function getAll(){
  25. $model = new static();
  26. if (!Cache::get('center_menu_' . $model::$app_id)) {
  27. $list = $model->order(['sort' => 'asc'])->select();
  28. if(count($list) == 0){
  29. $sys_menus = $model->getSysMenu();
  30. $save_data = [];
  31. foreach($sys_menus as $menu){
  32. $save_data[] = array_merge($sys_menus[$menu['sys_tag']], [
  33. 'app_id' => self::$app_id
  34. ]);
  35. }
  36. $model->saveAll($save_data);
  37. $list = $model->order(['sort' => 'asc'])->select();
  38. }
  39. Cache::tag('cache')->set('center_menu_' . $model::$app_id, $list);
  40. }
  41. return Cache::get('center_menu_' . $model::$app_id);
  42. }
  43. /**
  44. * 系统菜单
  45. */
  46. public static function getSysMenu(){
  47. return [
  48. 'address' => [
  49. 'sys_tag' => 'address',
  50. 'name' => '收货地址',
  51. 'path' => '/pages/user/address/address',
  52. 'icon' => 'image/center_menu/address.png'
  53. ],
  54. 'coupon' => [
  55. 'sys_tag' => 'coupon',
  56. 'name' => '领券中心',
  57. 'path' => '/pages/coupon/coupon',
  58. 'icon' => 'image/center_menu/coupon.png'
  59. ],
  60. 'my_coupon' => [
  61. 'sys_tag' => 'my_coupon',
  62. 'name' => '我的优惠券',
  63. 'path' => '/pages/user/my-coupon/my-coupon',
  64. 'icon' => 'image/center_menu/my_coupon.png'
  65. ],
  66. 'my_fav' => [
  67. 'sys_tag' => 'my_fav',
  68. 'name' => '我的收藏',
  69. 'path' => '/pages/user/favorite/favorite',
  70. 'icon' => 'image/center_menu/my_fav.png'
  71. ],
  72. 'agent' => [
  73. 'sys_tag' => 'agent',
  74. 'name' => '分销中心',
  75. 'path' => '/pages/agent/index/index',
  76. 'icon' => 'image/center_menu/agent.png'
  77. ],
  78. 'bargain' => [
  79. 'sys_tag' => 'bargain',
  80. 'name' => '我的砍价',
  81. 'path' => '/pages/user/my-bargain/my-bargain',
  82. 'icon' => 'image/center_menu/bargain.png'
  83. ],
  84. 'sign' => [
  85. 'sys_tag' => 'sign',
  86. 'name' => '签到',
  87. 'path' => '/pages/plus/signin/signin',
  88. 'icon' => 'image/center_menu/sign.png'
  89. ],
  90. 'gift' => [
  91. 'sys_tag' => 'gift',
  92. 'name' => '我的礼包',
  93. 'path' => '/pages/plus/giftpackage/giftlist',
  94. 'icon' => 'image/center_menu/gift.png'
  95. ],
  96. 'settings' => [
  97. 'sys_tag' => 'settings',
  98. 'name' => '设置',
  99. 'path' => '/pages/user/set/set',
  100. 'icon' => 'image/center_menu/settings.png'
  101. ],
  102. ];
  103. }
  104. }