Siteaddress.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\shop\controller;
  13. use app\model\system\Address as AddressModel;
  14. use app\model\shop\SiteAddress as SiteAddressModel;
  15. /**
  16. * 商家地址库
  17. * Class Siteaddress
  18. * @package app\shop\controller
  19. */
  20. class Siteaddress extends BaseShop
  21. {
  22. /**
  23. * 商家地址库列表
  24. * @return mixed
  25. */
  26. public function siteAddress()
  27. {
  28. if (request()->isAjax()) {
  29. $page = input('page', 1);
  30. $page_size = input('page_size', PAGE_LIST_ROWS);
  31. $search_keys = input('search_keys', "");
  32. $condition = array (
  33. [ 'site_id', "=", $this->site_id ]
  34. );
  35. if (!empty($search_keys)) {
  36. $condition[] = [ 'contact_name|full_address', 'like', '%' . $search_keys . '%' ];
  37. }
  38. $site_address_model = new SiteAddressModel();
  39. $list = $site_address_model->getAddressPageList($condition, $page, $page_size, 'id desc');
  40. return $list;
  41. } else {
  42. $this->forthMenu();
  43. return $this->fetch("siteaddress/site_address_list");
  44. }
  45. }
  46. /**
  47. * 添加商家地址库
  48. * @return mixed
  49. */
  50. public function addSiteAddress()
  51. {
  52. if (request()->isAjax()) {
  53. $contact_name = input('contact_name', '');//联系人
  54. $mobile = input('mobile', '');//手机号码
  55. $postcode = input('postcode', '');//邮编
  56. $province_id = input('province_id', '');//省id
  57. $city_id = input('city_id', '');//市id
  58. $district_id = input('district_id', '');//区id
  59. $community_id = input('community_id', '');//乡镇id
  60. $address = input('address', '');//详细地址
  61. $full_address = input('full_address', '');//完整地址
  62. $is_return = input('is_return', 0);//是否退货地址
  63. $is_return_default = input('is_return_default', 0);//是否是默认退货地址
  64. $is_delivery = input('is_delivery', 0);//是否发货地址
  65. $site_address_model = new SiteAddressModel();
  66. $data = array (
  67. "site_id" => $this->site_id,
  68. "contact_name" => $contact_name,
  69. "mobile" => $mobile,
  70. "postcode" => $postcode,
  71. "province_id" => $province_id,
  72. "city_id" => $city_id,
  73. "district_id" => $district_id,
  74. "community_id" => $community_id,
  75. "address" => $address,
  76. "full_address" => $full_address,
  77. "is_return" => $is_return,
  78. "is_return_default" => $is_return_default,
  79. "is_delivery" => $is_delivery
  80. );
  81. $result = $site_address_model->addAddress($data);
  82. return $result;
  83. } else {
  84. //查询省级数据列表
  85. $address_model = new AddressModel();
  86. $list = $address_model->getAreaList([ [ "pid", "=", 0 ], [ "level", "=", 1 ] ]);
  87. $this->assign("province_list", $list[ "data" ]);
  88. return $this->fetch('siteaddress/add_site_address');
  89. }
  90. }
  91. /**
  92. * 编辑商家地址库
  93. * @return mixed
  94. */
  95. public function editSiteAddress()
  96. {
  97. $site_address_model = new SiteAddressModel();
  98. $id = input('id', 0);//地址库id
  99. if (request()->isAjax()) {
  100. $contact_name = input('contact_name', '');//联系人
  101. $mobile = input('mobile', '');//手机号码
  102. $postcode = input('postcode', '');//邮编
  103. $province_id = input('province_id', '');//省id
  104. $city_id = input('city_id', '');//市id
  105. $district_id = input('district_id', '');//区id
  106. $community_id = input('community_id', '');//乡镇id
  107. $address = input('address', '');//详细地址
  108. $full_address = input('full_address', '');//完整地址
  109. $is_return = input('is_return', 0);//是否退货地址
  110. $is_return_default = input('is_return_default', 0);//是否是默认退货地址
  111. $is_delivery = input('is_delivery', 0);//是否发货地址
  112. $data = array (
  113. "contact_name" => $contact_name,
  114. "mobile" => $mobile,
  115. "postcode" => $postcode,
  116. "province_id" => $province_id,
  117. "city_id" => $city_id,
  118. "district_id" => $district_id,
  119. "community_id" => $community_id,
  120. "address" => $address,
  121. "full_address" => $full_address,
  122. "is_return" => $is_return,
  123. "is_return_default" => $is_return_default,
  124. "is_delivery" => $is_delivery
  125. );
  126. $condition = array (
  127. [ "id", "=", $id ],
  128. [ "site_id", "=", $this->site_id ],
  129. );
  130. $result = $site_address_model->editAddress($data, $condition);
  131. return $result;
  132. } else {
  133. //查询省级数据列表
  134. $address_model = new AddressModel();
  135. $list = $address_model->getAreaList([ [ "pid", "=", 0 ], [ "level", "=", 1 ] ]);
  136. $this->assign("province_list", $list[ "data" ]);
  137. $condition = array (
  138. [ "id", "=", $id ],
  139. [ "site_id", "=", $this->site_id ]
  140. );
  141. $site_address_info = $site_address_model->getAddressInfo($condition);
  142. $this->assign("site_address_info", $site_address_info[ 'data' ]);
  143. return $this->fetch('siteaddress/edit_site_address');
  144. }
  145. }
  146. /**
  147. * 删除商家地址库
  148. */
  149. public function deleteSiteAddress()
  150. {
  151. if (request()->isAjax()) {
  152. $id = input('id', '');
  153. $condition = array (
  154. [ "id", "=", $id ],
  155. [ "site_id", "=", $this->site_id ],
  156. );
  157. $site_address_model = new SiteAddressModel();
  158. $result = $site_address_model->deleteAddress($condition);
  159. return $result;
  160. }
  161. }
  162. /**
  163. * 退货地址
  164. * @return array
  165. */
  166. public function getSiteAddressList()
  167. {
  168. if (request()->isAjax()) {
  169. $is_return = input('is_refund', 0);
  170. $condition = array (
  171. [ 'site_id', '=', $this->site_id ]
  172. );
  173. if ($is_return) {
  174. $condition[] = [ 'is_return', '=', $is_return ];
  175. }
  176. //商家地址列表
  177. $site_address_model = new SiteAddressModel();
  178. $res = $site_address_model->getAddressList($condition, '*', 'id desc');
  179. return $res;
  180. }
  181. }
  182. }