offpay_area.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * 货到付款地区设置
  4. *
  5. * */
  6. defined('InShopNC') or exit('Access Invalid!');
  7. class offpay_areaControl extends SystemControl {
  8. public function __construct(){
  9. parent::__construct();
  10. }
  11. public function indexOp() {
  12. $model_parea = Model('offpay_area');
  13. $model_area = Model('area');
  14. if (!defined('DEFAULT_PLATFORM_STORE_ID')) {
  15. showMessage('请系统管理员配置完自营店铺后再设置货到付款','index.php?act=dashboard&op=aboutus','html','error',1,5000);
  16. }
  17. $store_id = DEFAULT_PLATFORM_STORE_ID;
  18. if (chksubmit()) {
  19. if (!preg_match('/^[\d,]+$/',$_POST['county'])) {
  20. $_POST['county'] = '';
  21. }
  22. //内置自营店ID
  23. $area_info = $model_parea->getAreaInfo(array('store_id'=>$store_id));
  24. $data = array();
  25. $county = trim($_POST['county'],',');
  26. $data['area_id'] = serialize(explode(',',$county));
  27. if (!$area_info) {
  28. $data['store_id'] = $store_id;
  29. $result = $model_parea->addArea($data);
  30. } else {
  31. $result = $model_parea->updateArea(array('store_id'=>$store_id),$data);
  32. }
  33. if ($result) {
  34. showMessage('保存成功');
  35. } else {
  36. showMessage('保存失败','','html','error');
  37. }
  38. }
  39. //取出支持货到付款的县ID及上级市ID
  40. $parea_info = $model_parea->getAreaInfo(array('store_id'=>$store_id));
  41. if (!empty($parea_info['area_id'])) {
  42. $parea_ids = @unserialize($parea_info['area_id']);
  43. }
  44. if (empty($parea_ids)) {
  45. $parea_ids = array();
  46. }
  47. //取出支持货到付款县ID的上级市ID
  48. $city_checked_child_array = array();
  49. $county_array = $model_area->getAreaList(array('area_deep'=>3,'area_id'=>array('in',$parea_ids)),'area_id,area_parent_id');
  50. foreach ($county_array as $v) {
  51. if (in_array($v['area_id'],$parea_ids)) {
  52. $city_checked_child_array[$v['area_parent_id']][] = $v['area_id'];
  53. }
  54. }
  55. Tpl::output('city_checked_child_array',$city_checked_child_array);
  56. //市级下面的县是不是全部支持货到付款,如果全部支持,默认选中,如果其中部分县支持货到付款,默认不选中但显示一个支付到付县的数量
  57. //格式 city_id => 下面支持到付的县ID数量
  58. $city_count_array = array();
  59. //格式 city_id => 是否选中true/false
  60. $city_checked_array = array();
  61. $list = $model_area->getAreaList(array('area_deep'=>3),'area_parent_id,count(area_id) as child_count','area_parent_id');
  62. foreach ($list as $k => $v) {
  63. $city_count_array[$v['area_parent_id']] = $v['child_count'];
  64. }
  65. foreach ($city_checked_child_array as $city_id => $city_child) {
  66. if (count($city_child) > 0) {
  67. if (count($city_child) == $city_count_array[$city_id]) {
  68. $city_checked_array[$city_id] = true;
  69. }
  70. }
  71. }
  72. Tpl::output('city_checked_array',$city_checked_array);
  73. //取得省级地区及直属子地区(循环输出)
  74. require(BASE_DATA_PATH.'/area/area.php');
  75. foreach ($area_array as $k => $v) {
  76. if ($v['area_parent_id'] != '0') {
  77. $area_array[$v['area_parent_id']]['child'][$k] = $v['area_name'];
  78. unset($area_array[$k]);
  79. }
  80. }
  81. Tpl::output('province_array',$area_array);
  82. //计算哪些省需要默认选中(即该省下面的所有县都支持到付,即所有市都是选中状态)
  83. $province_array = $area_array;
  84. foreach ($province_array as $pid => $value) {
  85. if (is_array($value['child'])) {
  86. foreach ($value['child'] as $k => $v) {
  87. if (!array_key_exists($k, $city_checked_array)) {
  88. unset($province_array[$pid]);
  89. break;
  90. }
  91. }
  92. }
  93. }
  94. Tpl::output('province_checked_array',$province_array);
  95. Tpl::showpage('offpay_area.index');
  96. }
  97. }