Local.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shop\controller;
  11. use app\model\express\ExpressDeliver;
  12. use app\model\express\Local as LocalModel;
  13. use app\model\shop\Shop as ShopModel;
  14. use app\model\system\Address as AddressModel;
  15. use app\model\web\Config as WebConfig;
  16. use app\model\store\Store;
  17. /**
  18. * 配送
  19. * Class Express
  20. * @package app\shop\controller
  21. */
  22. class Local extends BaseShop
  23. {
  24. /**
  25. * 本地配送设置
  26. */
  27. public function local()
  28. {
  29. $shop_model = new ShopModel();
  30. $shop_info_result = $shop_model->getShopInfo([ [ 'site_id', '=', $this->site_id ] ]);
  31. $shop_info = $shop_info_result[ 'data' ];
  32. $local_model = new LocalModel();
  33. $store = new Store();
  34. $default_store = $store->getStoreInfo([ ['site_id', '=', $this->site_id], ['is_default', '=', 1] ], 'store_id')['data'] ?? [];
  35. $store_id = $default_store['store_id'] ?? 0;
  36. if (request()->isAjax()) {
  37. if (empty($shop_info)) {
  38. return $local_model->error([], '店铺地址尚为配置');
  39. }
  40. $data = [
  41. 'type' => input('type', 'default'),//配送方式 default 商家自配送 other 第三方配送
  42. 'area_type' => input('area_type', 1),//配送区域
  43. 'local_area_json' => input('local_area_json', ''),//区域及业务集合json
  44. 'time_is_open' => input('time_is_open', 0),
  45. 'time_type' => input('time_type', 0),//时间选取类型 0 全天 1 自定义
  46. 'time_week' => input('time_week', ''),
  47. 'start_time' => input('start_time', 0),
  48. 'end_time' => input('end_time', 0),
  49. 'update_time' => time(),
  50. 'is_open_step' => input('is_open_step', 0),
  51. 'start_distance' => input('start_distance', 0),
  52. 'start_delivery_money' => input('start_delivery_money', 0),
  53. 'continued_distance' => input('continued_distance', 0),
  54. 'continued_delivery_money' => input('continued_delivery_money', 0),
  55. 'start_money' => input('start_money', 0),
  56. 'delivery_money' => input('delivery_money', 0),
  57. 'area_array' => input('area_array', ''),//地域集合
  58. 'man_money' => input('man_money', ''),
  59. 'man_type' => input('man_type', ''),
  60. 'man_discount' => input('man_discount', ''),
  61. 'time_interval' => input('time_interval', 30),
  62. 'delivery_time' => input('delivery_time', ''),
  63. 'advance_day' => input('advance_day', 0),
  64. 'most_day' => input('most_day', 7)
  65. ];
  66. $condition = array (
  67. [ 'site_id', '=', $this->site_id ],
  68. [ 'store_id', '=', $store_id ]
  69. );
  70. return $local_model->editLocal($data, $condition);
  71. } else {
  72. if (empty($shop_info)) {
  73. $this->error('店铺地址尚为配置');
  74. }
  75. $this->assign('shop_detail', $shop_info);
  76. $local_result = $local_model->getLocalInfo([ [ 'site_id', '=', $this->site_id ], ['store_id', '=', $store_id] ]);
  77. $district_list = [];
  78. if ($shop_info[ 'province' ] > 0 && $shop_info[ 'city' ] > 0) {
  79. //查询省级数据列表
  80. $address_model = new AddressModel();
  81. $list = $address_model->getAreaList([ [ "pid", "=", $shop_info[ 'city' ] ], [ "level", "=", 3 ] ]);
  82. $district_list = $list[ "data" ];
  83. }
  84. $this->assign('district_list', $district_list);
  85. $this->assign('local_info', $local_result['data']);
  86. $config_model = new WebConfig();
  87. $mp_config = $config_model->getMapConfig($this->site_id);
  88. $this->assign('tencent_map_key', $mp_config['data']['value']['tencent_map_key']);
  89. //效验腾讯地图KEY
  90. $check_map_key = $config_model->checkQqMapKey($mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  91. $this->assign('check_map_key', $check_map_key);
  92. return $this->fetch('local/local');
  93. }
  94. }
  95. /**
  96. * 配送员列表
  97. */
  98. public function deliverLists()
  99. {
  100. $deliver_model = new ExpressDeliver();
  101. if (request()->isAjax()) {
  102. $page = input('page', '1');
  103. $page_size = input('page_size', PAGE_LIST_ROWS);
  104. $condition = [
  105. [
  106. 'site_id', '=', $this->site_id
  107. ]
  108. ];
  109. $search_text = input('search_text', '');
  110. if (!empty($search_text)) {
  111. $condition[] = [ 'deliver_name', 'like', '%' . $search_text . '%' ];
  112. }
  113. $deliver_lists = $deliver_model->getDeliverPageLists($condition, '*', 'create_time desc', $page, $page_size);
  114. return $deliver_lists;
  115. } else {
  116. return $this->fetch('local/deliverlists');
  117. }
  118. }
  119. /**
  120. * 添加配送员
  121. */
  122. public function addDeliver()
  123. {
  124. $deliver_model = new ExpressDeliver();
  125. if (request()->isAjax()) {
  126. $data = [
  127. 'deliver_name' => input('deliver_name', ''),
  128. 'deliver_mobile' => input('deliver_mobile', ''),
  129. 'store_id' => input('store_id', 0),
  130. 'site_id' => $this->site_id,
  131. ];
  132. $result = $deliver_model->addDeliver($data);
  133. return $result;
  134. } else {
  135. return $this->fetch('local/adddeliver');
  136. }
  137. }
  138. /**
  139. * 编辑配送员
  140. */
  141. public function editDeliver()
  142. {
  143. $deliver_model = new ExpressDeliver();
  144. $deliver_id = input('deliver_id', 0);
  145. $site_id = $this->site_id;
  146. if (request()->isAjax()) {
  147. $data = [
  148. 'deliver_name' => input('deliver_name', ''),
  149. 'deliver_mobile' => input('deliver_mobile', ''),
  150. 'site_id' => $site_id,
  151. ];
  152. $result = $deliver_model->editDeliver($data, $deliver_id);
  153. return $result;
  154. } else {
  155. $this->assign('deliver_id', $deliver_id);
  156. $deliver_info = $deliver_model->getDeliverInfo($deliver_id, $site_id);
  157. $this->assign('deliver_info', $deliver_info[ 'data' ]);
  158. return $this->fetch('local/editdeliver');
  159. }
  160. }
  161. /**
  162. * 删除配送员
  163. */
  164. public function deleteDeliver()
  165. {
  166. $deliver_model = new ExpressDeliver();
  167. if (request()->isAjax()) {
  168. $deliver_ids = input('deliver_ids', 0);
  169. $site_id = $this->site_id;
  170. $result = $deliver_model->deleteDeliver($deliver_ids, $site_id);
  171. return $result;
  172. }
  173. }
  174. /**
  175. * 获取配送员
  176. */
  177. public function getDeliverList()
  178. {
  179. $deliver_model = new ExpressDeliver();
  180. $list = $deliver_model->getDeliverLists([ [ 'site_id', '=', $this->site_id ] ]);
  181. return $list;
  182. }
  183. }