Sellerspec.php 6.7 KB

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