Sellerspec.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /*
  3. * 店铺规格值
  4. * 每个店铺都有对应分类下保存的规格值
  5. */
  6. namespace app\home\controller;
  7. use think\facade\View;
  8. use think\facade\Lang;
  9. /**
  10. * ============================================================================
  11. *
  12. * ============================================================================
  13. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  14. * 网站地址: https://www.valimart.net/
  15. * ----------------------------------------------------------------------------
  16. *
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Sellerspec extends BaseSeller
  21. {
  22. var $_store_id;
  23. public function initialize()
  24. {
  25. parent::initialize();
  26. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/sellerspec.lang.php');
  27. $this->_store_id = session('store_id');
  28. }
  29. /**
  30. * 选择分类
  31. */
  32. public function index()
  33. {
  34. // 获取商品分类
  35. $goodsclass_model = model('goodsclass');
  36. $gc_list = $goodsclass_model->getGoodsclass($this->_store_id);
  37. View::assign('gc_list', $gc_list);
  38. $this->setSellerCurItem('spec');
  39. $this->setSellerCurMenu('sellerspec');
  40. return View::fetch($this->template_dir.'index');
  41. }
  42. /**
  43. * 添加规格值
  44. */
  45. public function add_spec()
  46. {
  47. $sp_id = intval(input('param.spid'));
  48. $gc_id = intval(input('param.gcid'));
  49. // 验证参数
  50. if ($sp_id <= 0) {
  51. $this->error(lang('param_error'));
  52. }
  53. // 分类信息
  54. $gc_info = model('goodsclass')->getGoodsclassInfoById($gc_id);
  55. View::assign('gc_info', $gc_info);
  56. // 规格信息
  57. $spec_model = model('spec');
  58. $sp_info = $spec_model->getSpecInfo($sp_id, 'sp_id,sp_name');
  59. //halt($sp_info);
  60. View::assign('sp_info', $sp_info);
  61. // 规格值信息
  62. $sp_value_list = $spec_model->getSpecvalueList(array(
  63. 'store_id' => $this->_store_id, 'sp_id' => $sp_id,
  64. 'gc_id' => $gc_id
  65. ));
  66. View::assign('sp_value_list', $sp_value_list);
  67. return View::fetch($this->template_dir.'spec_add');
  68. }
  69. /**
  70. * 保存规格值
  71. */
  72. public function save_spec()
  73. {
  74. $sp_id = intval(input('post.sp_id'));
  75. $gc_id = intval(input('post.gc_id'));
  76. if ($sp_id <= 0 || $gc_id <= 0 ) {
  77. ds_json_encode(10001,lang('param_error'));
  78. }
  79. $spec_model = model('spec');
  80. // 更新原规格值
  81. $sv_array = input('post.sv/a');
  82. if (!empty($sv_array['old']) && is_array($sv_array['old'])) {
  83. foreach ($sv_array['old'] as $key => $value) {
  84. if (empty($value['name'])) {
  85. continue;
  86. }
  87. $where = array('spvalue_id' => $key);
  88. $update = array(
  89. 'spvalue_name' => $value['name'], 'sp_id' => $sp_id, 'gc_id' => $gc_id,
  90. 'store_id' => $this->_store_id,
  91. 'spvalue_color' => isset($value['color'])?$value['color']:'',
  92. 'spvalue_sort' => intval($value['sort'])
  93. );
  94. $spec_model->editSpecvalue($update, $where);
  95. }
  96. }
  97. // 添加新规格值
  98. if (!empty($sv_array['new']) && is_array($sv_array['new'])) {
  99. $insert_array = array();
  100. foreach ($sv_array['new'] as $value) {
  101. if (empty($value['name'])) {
  102. continue;
  103. }
  104. $tmp_insert = array(
  105. 'spvalue_name' => $value['name'], 'sp_id' => $sp_id, 'gc_id' => $gc_id,
  106. 'store_id' => $this->_store_id,
  107. 'spvalue_color' => isset($value['color'])?$value['color']:'',
  108. 'spvalue_sort' => intval($value['sort'])
  109. );
  110. $insert_array[] = $tmp_insert;
  111. }
  112. $spec_model->addSpecvalueALL($insert_array);
  113. }
  114. ds_json_encode(10000,lang('ds_common_op_succ'));
  115. }
  116. /**
  117. * ajax删除规格值
  118. */
  119. public function ajax_delspec()
  120. {
  121. $spvalue_id = intval(input('param.id'));
  122. if ($spvalue_id <= 0) {
  123. echo 'false';
  124. exit();
  125. }
  126. $rs = model('spec')->delSpecvalue(array('spvalue_id' => $spvalue_id, 'store_id' => $this->_store_id));
  127. if ($rs) {
  128. echo 'true';
  129. exit();
  130. }
  131. else {
  132. echo 'false';
  133. exit();
  134. }
  135. }
  136. /**
  137. * AJAX获取商品分类
  138. */
  139. public function ajax_class()
  140. {
  141. $id = intval(input('param.id'));
  142. $deep = intval(input('param.deep'));
  143. if ($id <= 0 || $deep <= 0 || $deep >= 4) {
  144. echo 'false';
  145. exit();
  146. }
  147. $deep += 1;
  148. $goodsclass_model = model('goodsclass');
  149. // 验证分类是否存在
  150. $gc_info = $goodsclass_model->getGoodsclassInfoById($id);
  151. if (empty($gc_info)) {
  152. echo 'false';
  153. exit();
  154. }
  155. // 读取商品分类
  156. if ($deep != 4) {
  157. $gc_list = $goodsclass_model->getGoodsclass($this->_store_id, $id, $deep);
  158. }
  159. // 分类不为空输出分类信息
  160. if (!empty($gc_list)) {
  161. $data = array('type' => 'class', 'data' => $gc_list, 'deep' => $deep);
  162. }
  163. else {
  164. // 查询类型
  165. $type_model = model('type');
  166. $spec_list = $type_model->getSpecByType(array('type_id' => $gc_info['type_id']), 't.type_id, s.*');
  167. $data = array('type' => 'spec', 'data' => $spec_list, 'gcid' => $id, 'deep' => $deep);
  168. }
  169. echo json_encode($data);
  170. exit();
  171. }
  172. /**
  173. * 用户中心右边,小导航
  174. *
  175. * @param string $menu_type 导航类型
  176. * @param string $menu_key 当前导航的menu_key
  177. * @return
  178. */
  179. protected function getSellerItemList()
  180. {
  181. $menu_array = array(
  182. array('name' => 'spec', 'text' => lang('edit_product_specifications'), 'url' => 'index')
  183. );
  184. return $menu_array;
  185. }
  186. }
  187. ?>