Manage.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. namespace Area\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. /**
  7. * 更新信息
  8. *
  9. * @return mixed
  10. */
  11. public function up($id, $name, $data)
  12. {
  13. $update = array();
  14. $area = Dever::param('area', $data);
  15. $name = Dever::param('name', $data);
  16. if ($area) {
  17. $temp = is_string($area) ? explode(',', $area) : $area;
  18. $update['province_id'] = $temp[0];
  19. $update['city_id'] = $temp[1];
  20. $table = 'area/county';
  21. if (isset($temp[2])) {
  22. $table = 'area/town';
  23. $update['county_id'] = $temp[2];
  24. }
  25. if (isset($temp[3])) {
  26. $table = 'area/village';
  27. $update['town_id'] = $temp[3];
  28. }
  29. $update['name'] = $name;
  30. Dever::load('area/import')->pinyin($update);
  31. $update['where_id'] = $id;
  32. Dever::db($table)->update($update);
  33. }
  34. }
  35. public function level($id, $name, $data)
  36. {
  37. $update = array();
  38. $city = Dever::param('city', $data);
  39. if ($city) {
  40. Dever::db('area/city')->updateLevel(array('where_level_id' => $id, 'set_level_id' => -1));
  41. $city = explode('、', $city);
  42. foreach ($city as $k => $v) {
  43. $v = trim($v);
  44. if (!$v) {
  45. continue;
  46. }
  47. $w['name'] = $v;
  48. $source = Dever::db('area/city')->getDatas($w);
  49. if ($source) {
  50. foreach ($source as $k => $v) {
  51. $update['where_id'] = $v['id'];
  52. $update['level_id'] = $id;
  53. Dever::db('area/city')->update($update);
  54. }
  55. }
  56. }
  57. if ($id == 1) {
  58. $this->setTown_api();
  59. }
  60. }
  61. }
  62. # 设置国家镇级市、超级街道
  63. public function setTown_api()
  64. {
  65. $data = array
  66. (
  67. # 镇级市
  68. '河南省,安阳市,安阳县,水冶镇',
  69. '河南省,信阳市,平桥区,明港镇',
  70. '河南省,郑州市,巩义市,回郭镇',//'河南省,巩义市,安阳县,回郭镇',
  71. '甘肃省,武威市,凉州区,黄羊镇',
  72. '甘肃省,定西市,陇西县,首阳镇',
  73. '甘肃省,天水市,甘谷县,磐安镇',
  74. '广西,南宁市,宾阳县,黎塘镇',
  75. '广西,梧州市,藤县,太平镇',
  76. '广西,北海市,合浦县,公馆镇',
  77. '广西,贵港市,平南县,大安镇',
  78. '吉林省,长春市,公主岭市,范家屯镇',//'吉林省,四平市,公主岭市,范家屯镇',
  79. '吉林省,四平市,梨树县,郭家店镇',
  80. '吉林省,吉林市,吉林中国新加坡食品区,岔路河镇',// '吉林省,吉林市,永吉县,岔路河镇',
  81. '吉林省,白山市,抚松县,松江河镇',//'吉林省,吉林市,抚松县,松江河镇',
  82. '辽宁省,锦州市,北镇市,沟帮子街道 ',//'辽宁省,锦州市,北镇市,沟帮子镇',
  83. '辽宁省,辽阳市,辽阳县,刘二堡镇',//'辽宁省,辽阳市,辽阳县,刘二堡新市镇',
  84. '辽宁省,铁岭市,昌图县,八面城镇',
  85. '黑龙江省,哈尔滨市,巴彦县,兴隆镇',
  86. '黑龙江省,牡丹江市,海林市,柴河镇',
  87. '黑龙江省,牡丹江市,宁安市,东京城镇',
  88. '黑龙江省,伊春市,大箐山县,朗乡镇',//'黑龙江省,伊春市,铁力市,朗乡镇',
  89. '黑龙江省,黑龙江农垦总局,建三江农垦分局,三江镇',//未知
  90. '黑龙江省,红兴隆市,红兴隆农垦分局,兴隆镇',//未知
  91. '黑龙江省,鹤岗市,萝北县,宝泉岭农场',//'黑龙江省,宝泉岭市,宝泉岭农垦分局,宝泉岭镇',
  92. '黑龙江省,鸡西市,密山市,裴德镇',//'黑龙江省,牡丹江市,牡丹江农垦分局,裴德镇',
  93. '黑龙江省,黑河市,嫩江市,双山镇',//'黑龙江省,九三垦区分局,九三垦区分局,双山镇',
  94. '江苏省,苏州市,吴江区,盛泽镇',
  95. '江苏省,无锡市,宜兴市,丁蜀镇',
  96. '江苏省,南通市,启东市,启东吕四镇',//未知
  97. '河北省,廊坊市,三河市,燕郊镇',
  98. '河北省,廊坊市,霸州市,胜芳镇',
  99. '江西省,南昌市,南昌县,向塘镇',
  100. '安徽省,宿州市,萧县,黄口镇',
  101. '安徽省,亳州市,谯城区,古城镇',
  102. '湖南省,郴州市,永兴县,马田镇',
  103. '湖南省,怀化市,洪江市,安江镇',
  104. '湖南省,益阳市,桃江县,灰山港镇',
  105. '湖北省,襄阳市,樊城区,太平店镇',//'湖北省,襄阳市,襄阳区,太平店镇',
  106. '湖北省,荆门市,钟祥市,胡集镇',
  107. '湖北省,孝感市,汉川市,马口镇',
  108. '湖北省,宜昌市,夷陵区,龙泉镇',
  109. '福建省,漳州市,龙海市,角美镇',
  110. '福建省,泉州市,南安市,水头镇',
  111. '福建省,泉州市,晋江市,东石镇',
  112. '福建省,莆田市,秀屿区,忠门镇',
  113. '浙江省,温州,苍南县,龙港镇',
  114. '浙江省,绍兴市,诸暨市,店口镇',
  115. '重庆市,重庆市,江津区,白沙镇',
  116. '重庆市,重庆市,大足区,龙水镇',
  117. '重庆市,重庆市,九龙坡区,西彭镇',
  118. '四川省,南充市,仪陇县,金城镇',
  119. '四川省,内江市,资中县,重龙镇',
  120. '四川省,广元市,利州区,宝轮镇',
  121. '四川省,达州市,宣汉县,南坝镇',
  122. '广东省,佛山市,南海区,狮山镇',
  123. '广东省,东莞市,东莞市,长安镇',
  124. '广东省,东莞市,东莞市,虎门镇',
  125. '广东省,东莞市,东莞市,塘厦镇',
  126. # 超级街道
  127. '广东省,深圳市,南山区,粤海街道',
  128. '广东省,深圳市,龙岗区,坂田街道',
  129. '广东省,深圳市,龙岗区,布吉街道',
  130. '广东省,深圳市,龙岗区,龙城街道',
  131. '广东省,深圳市,龙岗区,平湖街道',
  132. '广东省,深圳市,龙岗区,龙岗街道',
  133. );
  134. foreach ($data as $k => $v) {
  135. $temp = explode(',', $v);
  136. if (isset($temp[3])) {
  137. $province = Dever::db('area/province')->getLike(array('name' => $temp[0]));
  138. if ($province) {
  139. $city = Dever::db('area/city')->getLike(array('name' => $temp[1], 'province_id' => $province['id']));
  140. if ($city) {
  141. $county = Dever::db('area/county')->getLike(array('name' => $temp[2], 'city_id' => $city['id']));
  142. if ($county) {
  143. $town = Dever::db('area/town')->getLike(array('name' => $temp[3], 'county_id' => $county['id']));
  144. if ($town) {
  145. if (strstr($temp[3], '街道')) {
  146. $type = 3;
  147. } else {
  148. $type = 2;
  149. }
  150. Dever::db('area/town')->update(array('where_id' => $town['id'], 'type' => $type));
  151. }
  152. }
  153. }
  154. }
  155. }
  156. }
  157. return 'ok';
  158. }
  159. public function outProvince($data)
  160. {
  161. $file = Dever::input('excel_name');
  162. $header = array('区域ID', '区域名称', '区域拼音', '区域拼音首字母');
  163. $body = array();
  164. if ($data) {
  165. foreach ($data as $k => $v) {
  166. if (is_array($v)) {
  167. $d = array
  168. (
  169. $v['id'],
  170. $v['name'],
  171. $v['pinyin'],
  172. $v['pinyin_first'],
  173. );
  174. $body[] = $d;
  175. }
  176. }
  177. }
  178. return Dever::excelExport($body, $header, $file);
  179. }
  180. public function outCity($data)
  181. {
  182. $file = Dever::input('excel_name');
  183. $header = array('区域ID', '区域名称', '区域拼音', '区域拼音首字母', '区域价值', '区域状态', '上级区域ID', '上级区域名称');
  184. $body = array();
  185. if ($data) {
  186. foreach ($data as $k => $v) {
  187. if (is_array($v)) {
  188. $province = Dever::db('area/province')->find($v['province_id']);
  189. if (!$province) {
  190. $province['name'] = '';
  191. }
  192. $status = '未占用';
  193. if ($v['status'] == 2) {
  194. $status = '已占用';
  195. }
  196. if ($v['price'] < 0) {
  197. $price = Dever::load('area/api')->getPrice(1, $v['province_id'] . ',' . $v['id']);
  198. } else {
  199. $price = $v['price'] * 10000;
  200. }
  201. $d = array
  202. (
  203. $v['id'],
  204. $v['name'],
  205. $v['pinyin'],
  206. $v['pinyin_first'],
  207. $price,
  208. $status,
  209. $v['province_id'],
  210. $province['name']
  211. );
  212. $body[] = $d;
  213. }
  214. }
  215. }
  216. return Dever::excelExport($body, $header, $file);
  217. }
  218. public function outCounty($data)
  219. {
  220. $file = Dever::input('excel_name');
  221. $header = array('区域ID', '区域名称', '区域拼音', '区域拼音首字母', '区域价值', '区域状态', '上级区域ID', '上级区域名称');
  222. $body = array();
  223. if ($data) {
  224. foreach ($data as $k => $v) {
  225. if (is_array($v)) {
  226. $province = Dever::db('area/province')->find($v['province_id']);
  227. $city = Dever::db('area/city')->find($v['city_id']);
  228. if (!$province) {
  229. $province['name'] = '';
  230. }
  231. if (!$city) {
  232. $city['name'] = '';
  233. }
  234. $status = '未占用';
  235. if ($v['status'] == 2) {
  236. $status = '已占用';
  237. }
  238. //$v['name'] = $province['name'] . '' . $city['name'] . '' . $v['name'];
  239. if ($v['price'] < 0) {
  240. $price = Dever::load('area/api')->getPrice(2, $v['province_id'] . ',' . $v['city_id'] . ',' . $v['id']);
  241. } else {
  242. $price = $v['price'] * 10000;
  243. }
  244. $d = array
  245. (
  246. $v['id'],
  247. $v['name'],
  248. $v['pinyin'],
  249. $v['pinyin_first'],
  250. $price,
  251. $status,
  252. $v['city_id'],
  253. $province['name'] . $city['name']
  254. );
  255. $body[] = $d;
  256. }
  257. }
  258. }
  259. return Dever::excelExport($body, $header, $file);
  260. }
  261. public function outTown($data)
  262. {
  263. $file = Dever::input('excel_name');
  264. $header = array('区域ID', '区域名称', '区域拼音', '区域拼音首字母', '区域价值', '区域状态', '上级区域ID', '上级区域名称');
  265. $body = array();
  266. if ($data) {
  267. foreach ($data as $k => $v) {
  268. if (is_array($v)) {
  269. $province = Dever::db('area/province')->find($v['province_id']);
  270. $city = Dever::db('area/city')->find($v['city_id']);
  271. $county = Dever::db('area/county')->find($v['county_id']);
  272. if (!$province) {
  273. $province['name'] = '';
  274. }
  275. if (!$city) {
  276. $city['name'] = '';
  277. }
  278. if (!$county) {
  279. $county['name'] = '';
  280. }
  281. $status = '未占用';
  282. if ($v['status'] == 2) {
  283. $status = '已占用';
  284. }
  285. //$v['name'] = $province['name'] . '' . $city['name'] . '' . $county['name'] . '' . $v['name'];
  286. if ($v['price'] < 0) {
  287. $price = Dever::load('area/api')->getPrice(3, $v['province_id'] . ',' . $v['city_id'] . ',' . $v['county_id'] . ',' . $v['id']);
  288. } else {
  289. $price = $v['price'] * 10000;
  290. }
  291. $d = array
  292. (
  293. $v['id'],
  294. $v['name'],
  295. $v['pinyin'],
  296. $v['pinyin_first'],
  297. $price,
  298. $status,
  299. $v['county_id'],
  300. $province['name'] . $city['name'] . $county['name']
  301. );
  302. $body[] = $d;
  303. }
  304. }
  305. }
  306. return Dever::excelExport($body, $header, $file);
  307. }
  308. }