Store.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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\Config as ExpressConfig;
  12. use app\model\express\ExpressDeliver;
  13. use app\model\express\Local as LocalModel;
  14. use app\model\shop\Shop as ShopModel;
  15. use app\model\store\Store as StoreModel;
  16. use app\model\system\Address as AddressModel;
  17. use app\model\web\Config as ConfigModel;
  18. use app\model\web\Config as WebConfig;
  19. /**
  20. * 门店
  21. * Class Store
  22. * @package app\shop\controller
  23. */
  24. class Store extends BaseShop
  25. {
  26. /**
  27. * 门店列表
  28. * @return mixed
  29. */
  30. public function lists()
  31. {
  32. if (request()->isAjax()) {
  33. $store_model = new StoreModel();
  34. $page = input('page', 1);
  35. $page_size = input('page_size', PAGE_LIST_ROWS);
  36. // $order = input("order", "create_time desc");
  37. $keyword = input("search_text", '');
  38. $status = input("status", '');
  39. $type = input("type", '');
  40. $condition = [];
  41. if ($type == 1) {
  42. if ($status != null) {
  43. $condition[] = [ 'status', '=', $status ];
  44. $condition[] = [ 'is_frozen', '=', 0 ];
  45. }
  46. } else if ($type == 2) {
  47. $condition[] = [ 'is_frozen', '=', $status ];
  48. }
  49. $condition[] = [ 'site_id', "=", $this->site_id ];
  50. //关键字查询
  51. if (!empty($keyword)) {
  52. $condition[] = [ "store_name", "like", "%" . $keyword . "%" ];
  53. }
  54. $order = 'is_default desc,store_id desc';
  55. $list = $store_model->getStorePageList($condition, $page, $page_size, $order);
  56. return $list;
  57. } else {
  58. //判断门店插件是否存在
  59. $store_is_exit = addon_is_exit('store', $this->site_id);
  60. $this->assign('store_is_exit', $store_is_exit);
  61. $this->assign('title', $store_is_exit ? '门店' : '自提点');
  62. return $this->fetch("store/lists");
  63. }
  64. }
  65. /**
  66. * 添加门店
  67. * @return mixed
  68. */
  69. public function addStore()
  70. {
  71. $is_store = addon_is_exit('store');
  72. if (request()->isAjax()) {
  73. $store_name = input("store_name", '');
  74. $telphone = input("telphone", '');
  75. $store_image = input("store_image", '');
  76. $status = input("status", 0);
  77. $province_id = input("province_id", 0);
  78. $city_id = input("city_id", 0);
  79. $district_id = input("district_id", 0);
  80. $community_id = input("community_id", 0);
  81. $address = input("address", '');
  82. $full_address = input("full_address", '');
  83. $longitude = input("longitude", 0);
  84. $latitude = input("latitude", 0);
  85. $is_pickup = input("is_pickup", 0);
  86. $is_o2o = input("is_o2o", 0);
  87. $open_date = input("open_date", '');
  88. $start_time = input('start_time', 0);
  89. $end_time = input('end_time', 0);
  90. $time_type = input('time_type', 0);
  91. $time_week = input('time_week', '');
  92. $stock_type = input('stock_type', '');
  93. if (!empty($time_week)) {
  94. $time_week = implode(',', $time_week);
  95. }
  96. $data = array (
  97. "store_name" => $store_name,
  98. "telphone" => $telphone,
  99. "store_image" => $store_image,
  100. "status" => $status,
  101. "province_id" => $province_id,
  102. "city_id" => $city_id,
  103. "district_id" => $district_id,
  104. "community_id" => $community_id,
  105. "address" => $address,
  106. "full_address" => $full_address,
  107. "longitude" => $longitude,
  108. "latitude" => $latitude,
  109. 'is_pickup' => $is_pickup,
  110. "open_date" => $open_date,
  111. "site_id" => $this->site_id,
  112. 'start_time' => $start_time,
  113. 'end_time' => $end_time,
  114. 'time_type' => $time_type,
  115. 'time_week' => $time_week,
  116. 'stock_type' => $stock_type,
  117. 'time_interval' => input('time_interval', 30),
  118. 'delivery_time' => input('delivery_time', ''),
  119. 'advance_day' => input('advance_day', 0),
  120. 'most_day' => input('most_day', 7)
  121. );
  122. //判断是否开启多门店
  123. if ($is_store == 1) {
  124. $user_data = [
  125. 'username' => input('username', ''),
  126. 'password' => data_md5(input('password', '')),
  127. ];
  128. } else {
  129. $user_data = [];
  130. }
  131. $store_model = new StoreModel();
  132. $result = $store_model->addStore($data, $user_data, $is_store);
  133. return $result;
  134. } else {
  135. //查询省级数据列表
  136. $address_model = new AddressModel();
  137. $list = $address_model->getAreaList([ [ "pid", "=", 0 ], [ "level", "=", 1 ] ]);
  138. $this->assign("province_list", $list[ "data" ]);
  139. $this->assign("is_exit", $is_store);
  140. $this->assign('title', $is_store ? '门店' : '自提点');
  141. $this->assign("http_type", get_http_type());
  142. $config_model = new ConfigModel();
  143. $mp_config = $config_model->getMapConfig($this->site_id);
  144. $this->assign('tencent_map_key', $mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  145. //效验腾讯地图KEY
  146. $check_map_key = $config_model->checkQqMapKey($mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  147. $this->assign('check_map_key', $check_map_key);
  148. $express_type = ( new ExpressConfig() )->getEnabledExpressType($this->site_id);
  149. if (isset($express_type[ 'express' ])) unset($express_type[ 'express' ]);
  150. $this->assign('express_type', $express_type);
  151. return $this->fetch("store/add_store");
  152. }
  153. }
  154. /**
  155. * 编辑门店
  156. * @return mixed
  157. */
  158. public function editStore()
  159. {
  160. $is_exit = addon_is_exit("store");
  161. $store_id = input("store_id", 0);
  162. $condition = array (
  163. [ "site_id", "=", $this->site_id ],
  164. [ "store_id", "=", $store_id ]
  165. );
  166. $store_model = new StoreModel();
  167. if (request()->isAjax()) {
  168. $store_name = input("store_name", '');
  169. $telphone = input("telphone", '');
  170. $store_image = input("store_image", '');
  171. $status = input("status", 0);
  172. $province_id = input("province_id", 0);
  173. $city_id = input("city_id", 0);
  174. $district_id = input("district_id", 0);
  175. $community_id = input("community_id", 0);
  176. $address = input("address", '');
  177. $full_address = input("full_address", '');
  178. $longitude = input("longitude", 0);
  179. $latitude = input("latitude", 0);
  180. $is_pickup = input("is_pickup", 0);
  181. $is_o2o = input("is_o2o", 0);
  182. $open_date = input("open_date", '');
  183. $start_time = input('start_time', 0);
  184. $end_time = input('end_time', 0);
  185. $time_type = input('time_type', 0);
  186. $time_week = input('time_week', '');
  187. $stock_type = input('stock_type', '');
  188. if (!empty($time_week)) {
  189. $time_week = implode(',', $time_week);
  190. }
  191. $data = array (
  192. "store_name" => $store_name,
  193. "telphone" => $telphone,
  194. "store_image" => $store_image,
  195. "status" => $status,
  196. "province_id" => $province_id,
  197. "city_id" => $city_id,
  198. "district_id" => $district_id,
  199. "community_id" => $community_id,
  200. "address" => $address,
  201. "full_address" => $full_address,
  202. "longitude" => $longitude,
  203. "latitude" => $latitude,
  204. 'is_pickup' => $is_pickup,
  205. "open_date" => $open_date,
  206. 'start_time' => $start_time,
  207. 'end_time' => $end_time,
  208. 'time_type' => $time_type,
  209. 'time_week' => $time_week,
  210. 'stock_type' => $stock_type,
  211. 'time_interval' => input('time_interval', 30),
  212. 'delivery_time' => input('delivery_time', ''),
  213. 'advance_day' => input('advance_day', 0),
  214. 'most_day' => input('most_day', 7)
  215. );
  216. $user_type = input('user_type', 1);
  217. if ($is_exit == 1 && $user_type == 0) {
  218. $user_data = [
  219. 'username' => input('username', ''),
  220. 'password' => data_md5(input('password', '')),
  221. ];
  222. } else {
  223. $user_data = [];
  224. }
  225. $result = $store_model->editStore($data, $condition, $user_data, $is_exit, $user_type);
  226. return $result;
  227. } else {
  228. //查询省级数据列表
  229. $address_model = new AddressModel();
  230. $list = $address_model->getAreaList([ [ "pid", "=", 0 ], [ "level", "=", 1 ] ]);
  231. $this->assign("province_list", $list[ "data" ]);
  232. $info_result = $store_model->getStoreDetail($condition);//门店信息
  233. $info = $info_result[ "data" ];
  234. if (empty($info)) $this->error('未获取到门店数据', addon_url('shop/store/lists'));
  235. $this->assign("info", $info);
  236. $this->assign("store_id", $store_id);
  237. $this->assign("is_exit", $is_exit);
  238. $this->assign('title', $is_exit ? '门店' : '自提点');
  239. $this->assign("http_type", get_http_type());
  240. $config_model = new ConfigModel();
  241. $mp_config = $config_model->getMapConfig($this->site_id);
  242. $this->assign('tencent_map_key', $mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  243. //效验腾讯地图KEY
  244. $check_map_key = $config_model->checkQqMapKey($mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  245. $this->assign('check_map_key', $check_map_key);
  246. $express_type = ( new ExpressConfig() )->getEnabledExpressType($this->site_id);
  247. if (isset($express_type[ 'express' ])) unset($express_type[ 'express' ]);
  248. $this->assign('express_type', $express_type);
  249. return $this->fetch("store/edit_store");
  250. }
  251. }
  252. /**
  253. * 删除门店
  254. * @return mixed
  255. */
  256. public function deleteStore()
  257. {
  258. if (request()->isAjax()) {
  259. $store_id = input("store_id", 0);
  260. $condition = array (
  261. [ "site_id", "=", $this->site_id ],
  262. [ "store_id", "=", $store_id ]
  263. );
  264. $store_model = new StoreModel();
  265. $result = $store_model->deleteStore($condition);
  266. return $result;
  267. }
  268. }
  269. public function frozenStore()
  270. {
  271. if (request()->isAjax()) {
  272. $store_id = input('store_id', 0);
  273. $is_frozen = input('is_frozen', 0);
  274. $condition = [
  275. [ "site_id", "=", $this->site_id ],
  276. [ "store_id", "=", $store_id ]
  277. ];
  278. $store_model = new StoreModel();
  279. $res = $store_model->frozenStore($condition, $is_frozen);
  280. return $res;
  281. }
  282. }
  283. /**
  284. * 重置密码
  285. */
  286. public function modifyPassword()
  287. {
  288. if (request()->isAjax()) {
  289. $store_id = input('store_id', '');
  290. $password = input('password', '123456');
  291. $store_model = new StoreModel();
  292. return $store_model->resetStorePassword($password, [ [ 'store_id', '=', $store_id ] ]);
  293. }
  294. }
  295. /**
  296. * 同城配送
  297. */
  298. public function local()
  299. {
  300. $store_id = input('store_id', 0);
  301. $store_model = new StoreModel();
  302. $info_result = $store_model->getStoreInfo([ [ 'site_id', '=', $this->site_id ], [ 'store_id', '=', $store_id ] ]);//门店信息
  303. $info = $info_result[ "data" ];
  304. $local_model = new LocalModel();
  305. if (request()->isAjax()) {
  306. if (empty($info)) {
  307. return $this->error([], '门店未找到');
  308. }
  309. $data = [
  310. 'type' => input('type', 'default'),//配送方式 default 商家自配送 other 第三方配送
  311. 'area_type' => input('area_type', 1),//配送区域
  312. 'local_area_json' => input('local_area_json', ''),//区域及业务集合json
  313. 'time_is_open' => input('time_is_open', 0),
  314. 'time_type' => input('time_type', 0),//时间选取类型 0 全天 1 自定义
  315. 'time_week' => input('time_week', ''),
  316. 'start_time' => input('start_time', 0),
  317. 'end_time' => input('end_time', 0),
  318. 'update_time' => time(),
  319. 'is_open_step' => input('is_open_step', 0),
  320. 'start_distance' => input('start_distance', 0),
  321. 'start_delivery_money' => input('start_delivery_money', 0),
  322. 'continued_distance' => input('continued_distance', 0),
  323. 'continued_delivery_money' => input('continued_delivery_money', 0),
  324. 'start_money' => input('start_money', 0),
  325. 'delivery_money' => input('delivery_money', 0),
  326. 'area_array' => input('area_array', ''),//地域集合
  327. 'man_money' => input('man_money', ''),
  328. 'man_type' => input('man_type', ''),
  329. 'man_discount' => input('man_discount', ''),
  330. 'time_interval' => input('time_interval', 30),
  331. 'delivery_time' => input('delivery_time', '')
  332. ];
  333. $condition = array (
  334. [ 'site_id', '=', $this->site_id ],
  335. [ 'store_id', '=', $store_id ],
  336. );
  337. return $local_model->editLocal($data, $condition);
  338. } else {
  339. if (empty($info)) {
  340. return $this->error([], '门店未找到');
  341. }
  342. $this->assign('store_detail', $info);
  343. $local_result = $local_model->getLocalInfo([ [ 'site_id', '=', $this->site_id ], [ 'store_id', '=', $store_id ] ]);
  344. $district_list = [];
  345. if ($info[ 'province_id' ] > 0 && $info[ 'city_id' ] > 0) {
  346. //查询省级数据列表
  347. $address_model = new AddressModel();
  348. $list = $address_model->getAreaList([ [ "pid", "=", $info[ 'city_id' ] ], [ "level", "=", 3 ] ]);
  349. $district_list = $list[ "data" ];
  350. }
  351. $this->assign('district_list', $district_list);
  352. $this->assign('local_info', $local_result[ 'data' ]);
  353. $config_model = new WebConfig();
  354. $mp_config = $config_model->getMapConfig($this->site_id);
  355. $this->assign('tencent_map_key', $mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  356. $config_model = new WebConfig();
  357. $mp_config = $config_model->getMapConfig($this->site_id);
  358. $this->assign('tencent_map_key', $mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  359. $this->assign('store_id', $store_id);
  360. $this->forthMenu([ 'store_id' => $store_id ]);
  361. return $this->fetch('store/local');
  362. }
  363. }
  364. /**
  365. * 配送员列表
  366. */
  367. public function deliverLists()
  368. {
  369. $store_id = input('store_id', 0);
  370. $deliver_model = new ExpressDeliver();
  371. if (request()->isAjax()) {
  372. $page = input('page', '1');
  373. $page_size = input('page_size', PAGE_LIST_ROWS);
  374. $condition = [
  375. [
  376. 'site_id', '=', $this->site_id,
  377. ],
  378. [
  379. 'store_id', '=', $store_id,
  380. ]
  381. ];
  382. $search_text = input('search_text', '');
  383. if (!empty($search_text)) {
  384. $condition[] = [ 'deliver_name', 'like', '%' . $search_text . '%' ];
  385. }
  386. $deliver_lists = $deliver_model->getDeliverPageLists($condition, '*', 'create_time desc', $page, $page_size);
  387. return $deliver_lists;
  388. } else {
  389. $this->assign('store_id', $store_id);
  390. $this->forthMenu([ 'store_id' => $store_id ]);
  391. return $this->fetch('store/deliverlists');
  392. }
  393. }
  394. /**
  395. * 添加配送员
  396. */
  397. public function addDeliver()
  398. {
  399. $store_id = input('store_id', 0);
  400. $this->assign('store_id', $store_id);
  401. return $this->fetch('local/adddeliver');
  402. }
  403. /**
  404. * 编辑配送员
  405. */
  406. public function editDeliver()
  407. {
  408. $store_id = input('store_id', 0);
  409. $this->assign('store_id', $store_id);
  410. $deliver_model = new ExpressDeliver();
  411. $deliver_id = input('deliver_id', 0);
  412. $this->assign('deliver_id', $deliver_id);
  413. $deliver_info = $deliver_model->getDeliverInfo($deliver_id, $this->site_id);
  414. $this->assign('deliver_info', $deliver_info[ 'data' ]);
  415. return $this->fetch('local/editdeliver');
  416. }
  417. /**
  418. * 选择门店
  419. * @return mixed
  420. */
  421. public function selectStore()
  422. {
  423. $store_list = ( new StoreModel() )->getStoreList([ [ 'site_id', '=', $this->site_id ] ], 'store_id,store_name,status,address,full_address,is_frozen');
  424. $this->assign('store_list', $store_list[ 'data' ]);
  425. $store_id = explode(',', input('store_id', ''));
  426. $this->assign('store_id', $store_id);
  427. return $this->fetch('store/select');
  428. }
  429. }