Sellerbrand.php 7.9 KB

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