Storegrade.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Storegrade extends AdminControl {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/storegrade.lang.php');
  21. }
  22. public function index() {
  23. $like_storegrade_name = trim(input('param.like_storegrade_name'));
  24. $condition[]=array('storegrade_name','like', "%" . $like_storegrade_name . "%");
  25. $storegrade_list = model('storegrade')->getStoregradeList($condition);
  26. // 获取分页显示
  27. View::assign('storegrade_list', $storegrade_list);
  28. View::assign('like_storegrade_name', $like_storegrade_name);
  29. $this->setAdminCurItem('index');
  30. return View::fetch();
  31. }
  32. public function add() {
  33. if (!request()->isPost()) {
  34. return View::fetch('form');
  35. } else {
  36. $data = array(
  37. 'storegrade_name' => input('post.storegrade_name'),
  38. 'storegrade_goods_limit' => input('post.storegrade_goods_limit'),
  39. 'storegrade_album_limit' => input('post.storegrade_album_limit'),
  40. 'storegrade_space_limit' => input('post.storegrade_space_limit'),
  41. 'storegrade_price' => intval(input('post.storegrade_price')),
  42. 'storegrade_description' => input('post.storegrade_description'),
  43. 'storegrade_sort' => input('post.storegrade_sort'),
  44. );
  45. $storegrade_validate = ds_validate('storegrade');
  46. if (!$storegrade_validate->scene('add')->check($data)){
  47. $this->error($storegrade_validate->getError());
  48. }
  49. //验证等级名称
  50. if (!$this->checkGradeName(array('storegrade_name' => trim(input('post.storegrade_name'))))) {
  51. $this->error(lang('now_store_grade_name_is_there'));
  52. }
  53. //验证级别是否存在
  54. if (!$this->checkGradeSort(array('storegrade_sort' => trim(input('post.storegrade_sort'))))) {
  55. $this->error(lang('add_gradesortexist'));
  56. }
  57. $result = model('storegrade')->addStoregrade($data);
  58. if ($result) {
  59. dsLayerOpenSuccess(lang('ds_common_op_succ'),(string)url('Storegrade/index'));
  60. } else {
  61. $this->error(lang('ds_common_op_fail'));
  62. }
  63. }
  64. }
  65. public function edit() {
  66. //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量”
  67. $storegrade_id = input('param.storegrade_id');
  68. if (empty($storegrade_id)) {
  69. $this->error(lang('param_error'));
  70. }
  71. if (!request()->isPost()) {
  72. $storegrade = model('storegrade')->getOneStoregrade($storegrade_id);
  73. View::assign('storegrade', $storegrade);
  74. return View::fetch('form');
  75. } else {
  76. $data = array(
  77. 'storegrade_name' => input('post.storegrade_name'),
  78. 'storegrade_goods_limit' => input('post.storegrade_goods_limit'),
  79. 'storegrade_album_limit' => input('post.storegrade_album_limit'),
  80. 'storegrade_space_limit' => input('post.storegrade_space_limit'),
  81. 'storegrade_price' => intval(input('post.storegrade_price')),
  82. 'storegrade_description' => input('post.storegrade_description'),
  83. 'storegrade_sort' => input('post.storegrade_sort'),
  84. );
  85. $storegrade_validate = ds_validate('storegrade');
  86. if (!$storegrade_validate->scene('edit')->check($data)){
  87. $this->error($storegrade_validate->getError());
  88. }
  89. //验证等级名称
  90. if (!$this->checkGradeName(array('storegrade_name' => trim(input('post.storegrade_name')), 'storegrade_id' => intval(input('param.storegrade_id'))))) {
  91. $this->error(lang('now_store_grade_name_is_there'));
  92. }
  93. //验证级别是否存在
  94. if (!$this->checkGradeSort(array('storegrade_sort' => trim(input('post.storegrade_sort')), 'storegrade_id' => intval(input('param.storegrade_id'))))) {
  95. $this->error(lang('add_gradesortexist'));
  96. }
  97. $result = model('storegrade')->editStoregrade($storegrade_id,$data);
  98. if ($result>=0) {
  99. dsLayerOpenSuccess(lang('ds_common_op_succ'),(string)url('Storegrade/index'));
  100. } else {
  101. $this->error(lang('ds_common_op_fail'));
  102. }
  103. }
  104. }
  105. public function drop() {
  106. //注:pathinfo地址参数不能通过get方法获取,查看“获取PARAM变量”
  107. $storegrade_id = intval(input('param.storegrade_id'));
  108. if ($storegrade_id<=0) {
  109. ds_json_encode(10001, lang('param_error'));
  110. }
  111. if ($storegrade_id == '1') {
  112. ds_json_encode(10001, lang('default_store_grade_no_del'));
  113. }
  114. //判断该等级下是否存在店铺,存在的话不能删除
  115. if (!$this->isable_delStoregrade($storegrade_id)) {
  116. $this->error(lang('del_gradehavestore'), (string)url('Storegrade/index'));
  117. }
  118. $result = model('storegrade')->delStoregrade($storegrade_id);
  119. if ($result) {
  120. ds_json_encode(10000, lang('ds_common_del_succ'));
  121. } else {
  122. ds_json_encode(10001, lang('ds_common_del_fail'));
  123. }
  124. }
  125. /**
  126. * 查询店铺等级名称是否存在
  127. */
  128. private function checkGradeName($param) {
  129. $storegrade_model = model('storegrade');
  130. $condition[]=array('storegrade_name','=',$param['storegrade_name']);
  131. if (isset($param['storegrade_id'])) {
  132. $storegrade_id = intval($param['storegrade_id']);
  133. $condition[]=array('storegrade_id','<>', $storegrade_id);
  134. }
  135. $list = $storegrade_model->getStoregradeList($condition);
  136. if (empty($list)) {
  137. return true;
  138. } else {
  139. return false;
  140. }
  141. }
  142. /**
  143. * 查询店铺等级是否存在
  144. */
  145. private function checkGradeSort($param) {
  146. $storegrade_model = model('storegrade');
  147. $condition = array();
  148. $condition[]=array('storegrade_sort','=',$param['storegrade_sort']);
  149. if (isset($param['storegrade_id'])) {
  150. $storegrade_id = intval($param['storegrade_id']);
  151. $condition[]=array('storegrade_id','<>', $storegrade_id);
  152. }
  153. $list = array();
  154. $list = $storegrade_model->getStoregradeList($condition);
  155. if (is_array($list) && count($list) > 0) {
  156. return false;
  157. } else {
  158. return true;
  159. }
  160. }
  161. /**
  162. * 判断店铺等级是否能删除
  163. */
  164. public function isable_delStoregrade($storegrade_id) {
  165. //判断该等级下是否存在店铺,存在的话不能删除
  166. $store_model = model('store');
  167. $store_list = $store_model->getStoreList(array('grade_id' => $storegrade_id));
  168. if (count($store_list) > 0) {
  169. return false;
  170. }
  171. return true;
  172. }
  173. /**
  174. * 获取卖家栏目列表,针对控制器下的栏目
  175. */
  176. protected function getAdminItemList() {
  177. $menu_array = array(
  178. array(
  179. 'name' => 'index',
  180. 'text' => lang('ds_storegrade'),
  181. 'url' => (string)url('Storegrade/index')
  182. ),
  183. );
  184. if (request()->action() == 'add' || request()->action() == 'index') {
  185. $menu_array[] = array(
  186. 'name' => 'add',
  187. 'text' => lang('ds_new'),
  188. 'url' => "javascript:dsLayerOpen('".(string)url('Storegrade/add')."','".lang('ds_new')."')"
  189. );
  190. }
  191. return $menu_array;
  192. }
  193. }
  194. ?>