Memberaddress.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Memberaddress extends BaseMember {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/memberaddress.lang.php');
  21. }
  22. /*
  23. * 收货地址列表
  24. */
  25. public function index() {
  26. $address_model=model('address');
  27. $chain_model = model('chain');
  28. $address_list = $address_model->getAddressList(array('member_id'=>session('member_id')));
  29. foreach($address_list as $key => $val){
  30. $address_list[$key]['cityerror'] = '';
  31. if($val['chain_id'] > 0){
  32. $condition = array();
  33. $condition[] = array('chain_id','=',$val['chain_id']);
  34. $chain_info = $chain_model->getChainInfo($condition,'chain_area_2,chain_area_3');
  35. if($val['city_id'] !== $chain_info['chain_area_2'] || $val['area_id'] !== $chain_info['chain_area_3']){
  36. $address_list[$key]['cityerror'] = lang('city_fail');
  37. }
  38. }
  39. }
  40. View::assign('address_list', $address_list);
  41. /* 设置买家当前菜单 */
  42. $this->setMemberCurMenu('member_address');
  43. /* 设置买家当前栏目 */
  44. $this->setMemberCurItem('my_address');
  45. return View::fetch($this->template_dir . 'index');
  46. }
  47. public function add() {
  48. if (!request()->isPost()) {
  49. $area_mod=model('area');
  50. $region_list = $area_mod->getAreaList(array('area_parent_id'=>'0'));
  51. View::assign('region_list', $region_list);
  52. $address = array(
  53. 'address_realname' => '',
  54. 'area_id' => '',
  55. 'city_id' => '',
  56. 'address_detail' => '',
  57. 'address_tel_phone' => '',
  58. 'address_mob_phone' => '',
  59. 'address_is_default' => '',
  60. 'area_info' => '',
  61. 'address_longitude' => '',
  62. 'address_latitude' => '',
  63. );
  64. View::assign('address', $address);
  65. /* 设置买家当前菜单 */
  66. $this->setMemberCurMenu('member_address');
  67. /* 设置买家当前栏目 */
  68. $this->setMemberCurItem('my_address_add');
  69. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  70. return View::fetch($this->template_dir . 'form');
  71. } else {
  72. $address_is_default = input('post.is_default') == 1 ? 1 : 0;
  73. $data = array(
  74. 'member_id' => session('member_id'),
  75. 'address_realname' => input('post.true_name'),
  76. 'area_id' => input('post.area_id'),
  77. 'city_id' => input('post.city_id'),
  78. 'address_detail' => input('post.address'),
  79. 'address_longitude' => input('post.longitude'),
  80. 'address_latitude' => input('post.latitude'),
  81. 'address_tel_phone' => input('post.tel_phone'),
  82. 'address_mob_phone' => input('post.mob_phone'),
  83. 'address_is_default' => $address_is_default,
  84. 'area_info' => input('post.area_info'),
  85. );
  86. $memberaddress_validate = ds_validate('memberaddress');
  87. if (!$memberaddress_validate->scene('add')->check($data)) {
  88. ds_json_encode(10001,$memberaddress_validate->getError());
  89. }
  90. //当默认地址为1时,把当前用户的地址设置为非默认地址
  91. if ($address_is_default == 1) {
  92. model('address')->editAddress(array('address_is_default' => 0), array('member_id' => session('member_id')));
  93. }
  94. $address_model=model('address');
  95. $result = $address_model->addAddress($data);
  96. if ($result) {
  97. ds_json_encode(10000,lang('ds_common_save_succ'));
  98. } else {
  99. ds_json_encode(10001,lang('ds_common_save_fail'));
  100. }
  101. }
  102. }
  103. public function edit() {
  104. $address_id = intval(input('param.address_id'));
  105. if (0 >= $address_id) {
  106. ds_json_encode(10001,lang('param_error'));
  107. }
  108. $address_model=model('address');
  109. $address = $address_model->getAddressInfo(array('member_id' => session('member_id'), 'address_id' => $address_id));
  110. if (empty($address)) {
  111. ds_json_encode(10001,lang('address_does_not_exist'));
  112. }
  113. if (!request()->isPost()) {
  114. $area_mod=model('area');
  115. $region_list = $area_mod->getAreaList(array('area_parent_id'=>'0'));
  116. View::assign('region_list', $region_list);
  117. View::assign('address', $address);
  118. /* 设置买家当前菜单 */
  119. $this->setMemberCurMenu('member_address');
  120. /* 设置买家当前栏目 */
  121. $this->setMemberCurItem('my_address_edit');
  122. View::assign('baidu_ak', config('ds_config.baidu_ak'));
  123. return View::fetch($this->template_dir . 'form');
  124. } else {
  125. $address_is_default = input('post.is_default') == 1 ? 1 : 0;
  126. $data = array(
  127. 'address_realname' => input('post.true_name'),
  128. 'area_id' => input('post.area_id'),
  129. 'city_id' => input('post.city_id'),
  130. 'address_detail' => input('post.address'),
  131. 'address_longitude' => input('post.longitude'),
  132. 'address_latitude' => input('post.latitude'),
  133. 'address_tel_phone' => input('post.tel_phone'),
  134. 'address_mob_phone' => input('post.mob_phone'),
  135. 'address_is_default' => $address_is_default,
  136. 'area_info' => input('post.area_info'),
  137. );
  138. $memberaddress_validate = ds_validate('memberaddress');
  139. if (!$memberaddress_validate->scene('edit')->check($data)) {
  140. ds_json_encode(10001,$memberaddress_validate->getError());
  141. }
  142. //当默认地址为1时,把当前用户的地址设置为非默认地址
  143. if ($address_is_default == 1) {
  144. model('address')->editAddress(array('address_is_default' => 0), array('member_id' => session('member_id')));
  145. }
  146. $result = $address_model->editAddress($data,array('member_id' => session('member_id'), 'address_id' => $address_id));
  147. if ($result) {
  148. ds_json_encode(10000,lang('ds_common_save_succ'));
  149. } else {
  150. ds_json_encode(10001,lang('ds_common_save_fail'));
  151. }
  152. }
  153. }
  154. public function drop() {
  155. $address_id = intval(input('param.address_id'));
  156. if (0 >= $address_id) {
  157. ds_json_encode(10001,lang('empty_error'));
  158. }
  159. $address_model=model('address');
  160. $condition = array();
  161. $condition[] = array('address_id','=',$address_id);
  162. $condition[] = array('member_id','=',session('member_id'));
  163. $result = $address_model->delAddress($condition);
  164. if ($result) {
  165. ds_json_encode(10000,lang('ds_common_del_succ'));
  166. } else {
  167. ds_json_encode(10001,lang('ds_common_del_fail'));
  168. }
  169. }
  170. /**
  171. * 添加门店收货地址
  172. */
  173. public function chain_add() {
  174. if (request()->isPost()) {
  175. $info = model('chain')->getChainOpenInfo(array(array('chain_id' ,'=', intval(input('param.chain_id')))));
  176. if (empty($info)) {
  177. ds_json_encode(10001,lang('pick_up_point_exist'));
  178. }
  179. $data = array();
  180. $data['member_id'] = session('member_id');
  181. $data['address_realname'] = input('param.true_name');
  182. $data['area_id'] = $info['chain_area_3'];
  183. $data['city_id'] = $info['chain_area_2'];
  184. $data['area_info'] = $info['chain_area_info'];
  185. $data['address_detail'] = $info['chain_address'];
  186. $data['address_tel_phone'] = input('param.tel_phone');
  187. $data['address_mob_phone'] = input('param.mob_phone');
  188. $data['chain_id'] = $info['chain_id'];
  189. $data['address_is_default'] = 0;
  190. if (intval(input('param.address_id'))) {
  191. $result = model('address')->editAddress($data, array('address_id' => intval(input('param.address_id'))));
  192. } else {
  193. $count = model('address')->getAddressCount(array('member_id' => session('member_id')));
  194. if ($count >= 20) {
  195. ds_json_encode(10001,lang('valid_addresses_allowed'));
  196. }
  197. $result = model('address')->addAddress($data);
  198. }
  199. if (!$result) {
  200. ds_json_encode(10001,lang('ds_common_save_fail'));
  201. }
  202. ds_json_encode(10000,lang('ds_common_save_succ'));
  203. } else {
  204. if (intval(input('param.address_id')) > 0) {
  205. $address_model = model('address');
  206. $condition = array('address_id' => intval(input('param.address_id')), 'member_id' => session('member_id'));
  207. $address_info = $address_model->getAddressInfo($condition);
  208. //取出省级ID
  209. $area_info = model('area')->getAreaInfo(array('area_id' => $address_info['city_id']));
  210. $address_info['province_id'] = $area_info['area_parent_id'];
  211. View::assign('address_info', $address_info);
  212. }
  213. /* 设置买家当前菜单 */
  214. $this->setMemberCurMenu('member_address');
  215. /* 设置买家当前栏目 */
  216. $this->setMemberCurItem('chain_add');
  217. return View::fetch($this->template_dir . 'chain_add');
  218. }
  219. }
  220. /**
  221. * 展示门店列表
  222. */
  223. public function chain_list() {
  224. $chain_model = model('chain');
  225. $condition = array();
  226. $condition[]=array('chain_area_3','=',intval(input('param.area_id')));
  227. $condition[]=array('chain_if_collect','=',1);
  228. $chain_list = $chain_model->getChainOpenList($condition, 5);
  229. View::assign('show_page', $chain_model->page_info->render());
  230. View::assign('chain_list', $chain_list);
  231. /* 设置买家当前菜单 */
  232. $this->setMemberCurMenu('member_address');
  233. /* 设置买家当前栏目 */
  234. $this->setMemberCurItem('chain_list');
  235. echo View::fetch($this->template_dir . 'chain_list');exit;
  236. }
  237. /**
  238. * 栏目菜单
  239. */
  240. function getMemberItemList() {
  241. $item_list = array(
  242. array(
  243. 'name' => 'my_address',
  244. 'text' => lang('my_address'),
  245. 'url' => (string)url('Memberaddress/index'),
  246. ),
  247. array(
  248. 'name' => 'my_address_add',
  249. 'text' => lang('new_address'),
  250. 'url' => (string)url('Memberaddress/add'),
  251. ),
  252. );
  253. if (request()->action() == 'edit') {
  254. $item_list[] = array(
  255. 'name' => 'my_address_edit',
  256. 'text' => lang('edit_address'),
  257. 'url' => "javascript:void(0)",
  258. );
  259. }
  260. if (request()->action() == 'chain_add') {
  261. $item_list[] = array(
  262. 'name' => 'chain_add',
  263. 'text' => lang('to_set'),
  264. 'url' => "javascript:void(0)",
  265. );
  266. }
  267. return $item_list;
  268. }
  269. }
  270. ?>