Mlselection.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * 多级选择:地区选择,分类选择
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Lang;
  7. /**
  8. * ============================================================================
  9. *
  10. * ============================================================================
  11. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  12. * 网站地址: https://www.valimart.net/
  13. * ----------------------------------------------------------------------------
  14. *
  15. * ============================================================================
  16. * 控制器
  17. */
  18. class Mlselection extends BaseHome {
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/mlselection.lang.php');
  22. }
  23. function index() {
  24. $type = input('param.type');
  25. $pid = intval(input('param.pid'));
  26. $result=array();
  27. in_array($type, array('region', 'goodsclass')) or json_encode('invalid type');
  28. switch ($type) {
  29. case 'region':
  30. $area_mod=model('area');
  31. $regions = $area_mod->getAreaList(array('area_parent_id'=>$pid));
  32. foreach ($regions as $key => $region) {
  33. $result[$key]['area_name'] = htmlspecialchars($region['area_name']);
  34. $result[$key]['area_id'] = $region['area_id'];
  35. }
  36. ds_json_encode(10000,'',$result);
  37. break;
  38. case 'goodsclass':
  39. $goodsclass_model = model('goodsclass');
  40. $goods_class = $goodsclass_model->getGoodsclassListByParentId($pid);
  41. $array = array();
  42. if (is_array($goods_class) and count($goods_class) > 0) {
  43. foreach ($goods_class as $val) {
  44. $array[$val['gc_id']] = array('gc_id' => $val['gc_id'], 'gc_name' => htmlspecialchars($val['gc_name']), 'gc_parent_id' => $val['gc_parent_id'], 'commis_rate' => $val['commis_rate'], 'gc_sort' => $val['gc_sort']);
  45. }
  46. }
  47. ds_json_encode(10000,'',array_values($array));
  48. break;
  49. }
  50. }
  51. }
  52. ?>