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