ShopGroup.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\model\shop;
  13. use think\facade\Cache;
  14. use app\model\BaseModel;
  15. use app\model\system\Menu as MenuModel;
  16. use app\model\system\Promotion as PrmotionModel;
  17. /**
  18. * 开店套餐
  19. */
  20. class ShopGroup extends BaseModel
  21. {
  22. /**
  23. * 添加开店套餐
  24. * @param array $data
  25. */
  26. public function addGroup($data)
  27. {
  28. $res = model('shop_group')->add($data);
  29. Cache::tag("shop_group")->clear();
  30. return $this->success($res);
  31. }
  32. /**
  33. * 修改开店套餐
  34. * @param array $data
  35. */
  36. public function editGroup($data)
  37. {
  38. $res = model('shop_group')->update($data, [[ 'group_id', '=', $data['group_id'] ]]);
  39. //修改对应店铺
  40. model('shop')->update(['group_name' => $data['group_name']], [[ 'group_id', '=', $data['group_id'] ]]);
  41. model('shop_apply')->update(['group_name' => $data['group_name']], [[ 'group_id', '=', $data['group_id'] ]]);
  42. Cache::tag("shop_group")->clear();
  43. return $this->success($res);
  44. }
  45. /**
  46. * 删除开店套餐
  47. * @param unknown $condition
  48. */
  49. public function deleteGroup($condition)
  50. {
  51. $check_condition = array_column($condition, 2, 0);
  52. $group_id = $check_condition['group_id'];
  53. $count = model('shop')->getCount([['group_id','in',$group_id]]);
  54. if($count==0) {
  55. $res = model('shop_group')->delete($condition);
  56. Cache::tag("shop_group")->clear();
  57. return $this->success($res);
  58. }else{
  59. return $this->error('','该开店套餐存在其他店铺,无法删除');
  60. }
  61. }
  62. /**
  63. * 获取开店套餐信息
  64. * @param unknown $condition
  65. * @param string $field
  66. */
  67. public function getGroupInfo($condition, $field = '*')
  68. {
  69. $data = json_encode([ $condition, $field]);
  70. $cache = Cache::get("shop_group_getGroupInfo_" . $data);
  71. if (!empty($cache)) {
  72. return $this->success($cache);
  73. }
  74. $res = model('shop_group')->getInfo( $condition, $field);
  75. Cache::tag("shop_group")->set("shop_group_getGroupInfo_" . $data, $res);
  76. return $this->success($res);
  77. }
  78. /**
  79. * 获取开店套餐列表
  80. * @param array $condition
  81. * @param string $field
  82. * @param string $order
  83. * @param string $limit
  84. */
  85. public function getGroupList($condition = [], $field = '*', $order = '', $limit = null)
  86. {
  87. $data = json_encode([ $condition, $field, $order, $limit ]);
  88. $cache = Cache::get("shop_group_getGroupList_" . $data);
  89. if (!empty($cache)) {
  90. return $this->success($cache);
  91. }
  92. $list = model('shop_group')->getList($condition, $field, $order, '', '', '', $limit);
  93. Cache::tag("shop_group")->set("shop_group_getGroupList_" . $data, $list);
  94. return $this->success($list);
  95. }
  96. /**
  97. * 获取开店套餐分页列表
  98. * @param array $condition
  99. * @param number $page
  100. * @param string $page_size
  101. * @param string $order
  102. * @param string $field
  103. */
  104. public function getGroupPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
  105. {
  106. $data = json_encode([ $condition, $field, $order, $page, $page_size ]);
  107. $cache = Cache::get("shop_group_getGroupPageList_" . $data);
  108. if (!empty($cache)) {
  109. return $this->success($cache);
  110. }
  111. $list = model('shop_group')->pageList($condition, $field, $order, $page, $page_size);
  112. Cache::tag("shop_group")->set("shop_group_getGroupPageList_" . $data, $list);
  113. return $this->success($list);
  114. }
  115. /**
  116. * 刷新开店套餐权限
  117. */
  118. public function refreshGroup() {
  119. $shop_group_list = $this->getGroupList();
  120. if ($shop_group_list['data']) {
  121. $promotion_model = new PrmotionModel();
  122. $promotions = $promotion_model->getPromotions();
  123. $all_promotion_name = array_column($promotions['shop'], 'name');
  124. $menu_model = new MenuModel();
  125. $menu_list = $menu_model->getMenuList([ [ 'app_module', "=", 'shop' ], ['addon', 'NOT IN', $all_promotion_name] ], "name");
  126. foreach ($shop_group_list['data'] as $shop_group) {
  127. $data = ['group_id' => $shop_group['group_id'], 'group_name' => $shop_group['group_name']];
  128. $data['menu_array'] = join(',', array_column($menu_list['data'], 'name'));
  129. if (!empty($shop_group['addon_array'])) {
  130. $addon_name = explode(',', $shop_group['addon_array']);
  131. $addon_menu = $menu_model->getMenuList([ [ 'app_module', "=", 'shop' ], ['addon', 'in', $addon_name] ], 'name');
  132. $addon_name = array_column($addon_menu['data'], 'name');
  133. $data['menu_array'] .= ',' . join(',', $addon_name);
  134. }
  135. $this->editGroup($data);
  136. }
  137. }
  138. $this->success();
  139. }
  140. }