Sellerbrand.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Sellerbrand extends BaseSeller
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerbrand.lang.php');
  18. }
  19. /**
  20. * 品牌列表
  21. */
  22. public function index()
  23. {
  24. $brand_model = model('brand');
  25. $condition = array();
  26. $condition[] = array('store_id', '=', session('store_id'));
  27. if (!empty(input('param.brand_name'))) {
  28. $condition[] = array('brand_name', 'like', '%' . input('param.brand_name') . '%');
  29. }
  30. $brand_list = $brand_model->getBrandList($condition, '*', 10);
  31. View::assign('brand_list', $brand_list);
  32. View::assign('show_page', $brand_model->page_info->render());
  33. $this->setSellerCurMenu('seller_brand');
  34. $this->setSellerCurItem('brand_list');
  35. return View::fetch($this->template_dir . 'index');
  36. }
  37. /**
  38. * 品牌添加页面
  39. */
  40. public function brand_add()
  41. {
  42. $brand_model = model('brand');
  43. if (input('param.brand_id') != '') {
  44. $brand_array = $brand_model->getBrandInfo(array(
  45. 'brand_id' => input('param.brand_id'),
  46. 'store_id' => session('store_id')
  47. ));
  48. if (empty($brand_array)) {
  49. $this->error(lang('param_error'));
  50. }
  51. View::assign('brand_array', $brand_array);
  52. }
  53. // 一级商品分类
  54. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  55. View::assign('gc_list', $gc_list);
  56. echo View::fetch($this->template_dir . 'add');
  57. }
  58. /**
  59. * 品牌保存
  60. */
  61. public function brand_save()
  62. {
  63. $brand_model = model('brand');
  64. if (request()->isPost()) {
  65. /**
  66. * 验证
  67. */
  68. $data = [
  69. 'brand_name' => input('param.brand_name'),
  70. 'brand_initial' => input('param.brand_initial'),
  71. ];
  72. $sellerbrand_validate = ds_validate('sellerbrand');
  73. if (!$sellerbrand_validate->scene('brand_save')->check($data)) {
  74. ds_json_encode(10001, $sellerbrand_validate->getError());
  75. }
  76. /**
  77. * 上传图片
  78. */
  79. $brand_pic = '';
  80. if (!empty($_FILES['brand_pic']['name'])) {
  81. $file_name = session('store_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  82. $res = ds_upload_pic(ATTACH_BRAND, 'brand_pic', $file_name);
  83. if ($res['code']) {
  84. $brand_pic = $res['data']['file_name'];
  85. } else {
  86. $this->error($res['msg']);
  87. }
  88. }
  89. $insert_array = array();
  90. $insert_array['brand_name'] = trim(input('param.brand_name'));
  91. $insert_array['brand_initial'] = strtoupper(input('param.brand_initial'));
  92. $insert_array['gc_id'] = input('param.class_id');
  93. $insert_array['brand_class'] = input('param.brand_class');
  94. $insert_array['brand_pic'] = $brand_pic;
  95. $insert_array['brand_apply'] = 0;
  96. $insert_array['store_id'] = session('store_id');
  97. $result = $brand_model->addBrand($insert_array);
  98. if ($result) {
  99. $this->success(lang('store_goods_brand_apply_success'), (string) url('Sellerbrand/index'));
  100. } else {
  101. $this->error(lang('ds_common_save_fail'));
  102. }
  103. }
  104. }
  105. /**
  106. * 品牌修改
  107. */
  108. public function brand_edit()
  109. {
  110. $brand_model = model('brand');
  111. $brand_id = intval(input('post.brand_id'));
  112. if ($brand_id <= 0) {
  113. $this->error(lang('ds_common_save_fail'));
  114. }
  115. if (request()->isPost()) {
  116. /**
  117. * 验证
  118. */
  119. $data = [
  120. 'brand_name' => input('post.brand_name'),
  121. 'brand_initial' => input('post.brand_initial'),
  122. ];
  123. $sellerbrand_validate = ds_validate('sellerbrand');
  124. if (!$sellerbrand_validate->scene('brand_edit')->check($data)) {
  125. $this->error($sellerbrand_validate->getError());
  126. } else {
  127. /**
  128. * 上传图片
  129. */
  130. if (!empty($_FILES['brand_pic']['name'])) {
  131. $file_name = session('store_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  132. $res = ds_upload_pic(ATTACH_BRAND, 'brand_pic', $file_name);
  133. if ($res['code']) {
  134. $brand_pic = $res['data']['file_name'];
  135. //删除图片
  136. $brand_info = $brand_model->getBrandInfo(array('brand_id' => $brand_id));
  137. if (!empty($brand_info['brand_pic'])) {
  138. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_BRAND . DIRECTORY_SEPARATOR . $brand_info['brand_pic']);
  139. }
  140. } else {
  141. $this->error($res['msg']);
  142. }
  143. }
  144. $condition = array();
  145. $condition[] = array('brand_id', '=', $brand_id);
  146. $update_array = array();
  147. $update_array['brand_initial'] = strtoupper(input('post.brand_initial'));
  148. $update_array['brand_name'] = trim(input('post.brand_name'));
  149. $update_array['gc_id'] = input('post.class_id');
  150. $update_array['brand_class'] = input('post.brand_class');
  151. if (!empty($brand_pic)) {
  152. $update_array['brand_pic'] = $brand_pic;
  153. }
  154. $result = $brand_model->editBrand($condition, $update_array);
  155. if ($result) {
  156. $this->success(lang('ds_common_save_succ'), (string) url('Sellerbrand/index'));
  157. } else {
  158. $this->error(lang('ds_common_save_fail'));
  159. }
  160. }
  161. } else {
  162. $this->error(lang('ds_common_save_fail'));
  163. }
  164. }
  165. /**
  166. * 品牌删除
  167. */
  168. public function drop_brand()
  169. {
  170. $brand_model = model('brand');
  171. $brand_id = intval(input('param.brand_id'));
  172. if ($brand_id > 0) {
  173. $brand_model->delBrand(array(
  174. 'brand_id' => $brand_id, 'brand_apply' => 0, 'store_id' => session('store_id')
  175. ));
  176. ds_json_encode(10000, lang('ds_common_del_succ'));
  177. } else {
  178. ds_json_encode(10001, lang('ds_common_del_fail'));
  179. }
  180. }
  181. /**
  182. * 用户中心右边,小导航
  183. *
  184. * @param string $menu_type 导航类型
  185. * @param string $menu_key 当前导航的menu_key
  186. * @param array $array 附加菜单
  187. * @return
  188. */
  189. protected function getSellerItemList()
  190. {
  191. $menu_array = array(
  192. array(
  193. 'name' => 'brand_list', 'text' => lang('ds_member_path_brand_list'),
  194. 'url' => (string) url('Sellerbrand/index')
  195. )
  196. );
  197. return $menu_array;
  198. }
  199. }