Sellerbrand.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace app\home\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 Sellerbrand extends BaseSeller {
  18. public function initialize() {
  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. $brand_model = model('brand');
  27. $condition = array();
  28. $condition[] = array('store_id', '=', session('store_id'));
  29. if (!empty(input('param.brand_name'))) {
  30. $condition[] = array('brand_name', 'like', '%' . input('param.brand_name') . '%');
  31. }
  32. $brand_list = $brand_model->getBrandList($condition, '*', 10);
  33. View::assign('brand_list', $brand_list);
  34. View::assign('show_page', $brand_model->page_info->render());
  35. $this->setSellerCurMenu('seller_brand');
  36. $this->setSellerCurItem('brand_list');
  37. return View::fetch($this->template_dir . 'index');
  38. }
  39. /**
  40. * 品牌添加页面
  41. */
  42. public function brand_add() {
  43. $brand_model = model('brand');
  44. if (input('param.brand_id') != '') {
  45. $brand_array = $brand_model->getBrandInfo(array(
  46. 'brand_id' => input('param.brand_id'),
  47. 'store_id' => session('store_id')
  48. ));
  49. if (empty($brand_array)) {
  50. $this->error(lang('param_error'));
  51. }
  52. View::assign('brand_array', $brand_array);
  53. }
  54. // 一级商品分类
  55. $gc_list = model('goodsclass')->getGoodsclassListByParentId(0);
  56. View::assign('gc_list', $gc_list);
  57. echo View::fetch($this->template_dir . 'add');
  58. }
  59. /**
  60. * 品牌保存
  61. */
  62. public function brand_save() {
  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. $brand_model = model('brand');
  110. $brand_id = intval(input('post.brand_id'));
  111. if ($brand_id <= 0) {
  112. $this->error(lang('ds_common_save_fail'));
  113. }
  114. if (request()->isPost()) {
  115. /**
  116. * 验证
  117. */
  118. $data = [
  119. 'brand_name' => input('post.brand_name'),
  120. 'brand_initial' => input('post.brand_initial'),
  121. ];
  122. $sellerbrand_validate = ds_validate('sellerbrand');
  123. if (!$sellerbrand_validate->scene('brand_edit')->check($data)) {
  124. $this->error($sellerbrand_validate->getError());
  125. } else {
  126. /**
  127. * 上传图片
  128. */
  129. if (!empty($_FILES['brand_pic']['name'])) {
  130. $file_name = session('store_id') . '_' . date('YmdHis') . rand(10000, 99999) . '.png';
  131. $res = ds_upload_pic(ATTACH_BRAND, 'brand_pic', $file_name);
  132. if ($res['code']) {
  133. $brand_pic = $res['data']['file_name'];
  134. //删除图片
  135. $brand_info = $brand_model->getBrandInfo(array('brand_id' => $brand_id));
  136. if (!empty($brand_info['brand_pic'])) {
  137. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_BRAND . DIRECTORY_SEPARATOR . $brand_info['brand_pic']);
  138. }
  139. } else {
  140. $this->error($res['msg']);
  141. }
  142. }
  143. $condition = array();
  144. $condition[] = array('brand_id', '=', $brand_id);
  145. $update_array = array();
  146. $update_array['brand_initial'] = strtoupper(input('post.brand_initial'));
  147. $update_array['brand_name'] = trim(input('post.brand_name'));
  148. $update_array['gc_id'] = input('post.class_id');
  149. $update_array['brand_class'] = input('post.brand_class');
  150. if (!empty($brand_pic)) {
  151. $update_array['brand_pic'] = $brand_pic;
  152. }
  153. $result = $brand_model->editBrand($condition, $update_array);
  154. if ($result) {
  155. $this->success(lang('ds_common_save_succ'), (string) url('Sellerbrand/index'));
  156. } else {
  157. $this->error(lang('ds_common_save_fail'));
  158. }
  159. }
  160. } else {
  161. $this->error(lang('ds_common_save_fail'));
  162. }
  163. }
  164. /**
  165. * 品牌删除
  166. */
  167. public function drop_brand() {
  168. $brand_model = model('brand');
  169. $brand_id = intval(input('param.brand_id'));
  170. if ($brand_id > 0) {
  171. $brand_model->delBrand(array(
  172. 'brand_id' => $brand_id, 'brand_apply' => 0, 'store_id' => session('store_id')
  173. ));
  174. ds_json_encode(10000, lang('ds_common_del_succ'));
  175. } else {
  176. ds_json_encode(10001, lang('ds_common_del_fail'));
  177. }
  178. }
  179. /**
  180. * 用户中心右边,小导航
  181. *
  182. * @param string $menu_type 导航类型
  183. * @param string $menu_key 当前导航的menu_key
  184. * @param array $array 附加菜单
  185. * @return
  186. */
  187. protected function getSellerItemList() {
  188. $menu_array = array(
  189. array(
  190. 'name' => 'brand_list', 'text' => lang('ds_member_path_brand_list'),
  191. 'url' => (string) url('Sellerbrand/index')
  192. )
  193. );
  194. return $menu_array;
  195. }
  196. }