Storegrade.php 8.4 KB

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