Store.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\cashier\storeapi\controller;
  11. use addon\cashier\model\Menu;
  12. use app\model\express\ExpressDeliver;
  13. use app\model\store\Store as StoreModel;
  14. use app\storeapi\controller\BaseStoreApi;
  15. /**
  16. * 门店控制器
  17. */
  18. class Store extends BaseStoreApi
  19. {
  20. /**
  21. * 获取门店信息
  22. * @return false|string
  23. * @throws \app\exception\ApiException
  24. */
  25. public function info()
  26. {
  27. $store_model = new StoreModel();
  28. $store_info = $store_model->getStoreInfo([ [ 'store_id', '=', $this->store_id ] ]);
  29. return $this->response($store_info);
  30. }
  31. public function checkPageAuth()
  32. {
  33. $page = $this->params[ 'page' ] ?? '';
  34. if ($this->user_info[ 'is_admin' ]) return $this->response($this->success());
  35. $name = ( new Menu() )->getMenuValue([ [ 'url', '=', substr($page, 1) ], [ 'type', '=', 'page' ] ], 'name')[ 'data' ];
  36. if (empty($name)) return $this->response($this->success());
  37. $menu_array = $this->store_list[ $this->store_id ][ 'menu_array' ] ?? '';
  38. if (empty($menu_array)) return $this->response($this->success());
  39. if (!in_array($name, explode(',', $menu_array))) return $this->response($this->error([], 'NO_PERMISSION'));
  40. return $this->response($this->success());
  41. }
  42. /**
  43. * 获取可管理的门店列表
  44. * @return false|string
  45. */
  46. public function lists()
  47. {
  48. $store_ids = array_keys($this->store_list);
  49. $store_model = new StoreModel();
  50. $store_info = $store_model->getStoreList([ [ 'store_id', 'in', $store_ids ] ], 'store_id,store_image,store_name,full_address,address,open_date', 'is_default desc');
  51. return $this->response($store_info);
  52. }
  53. /**
  54. * 编辑门店
  55. * @return mixed
  56. */
  57. public function editStore()
  58. {
  59. $store_id = $this->store_id;
  60. $condition = array (
  61. [ "site_id", "=", $this->site_id ],
  62. [ "store_id", "=", $store_id ]
  63. );
  64. $store_model = new StoreModel();
  65. $data = array (
  66. "store_name" => $this->params[ 'store_name' ] ?? '',
  67. "telphone" => $this->params[ 'telphone' ] ?? '',
  68. "store_image" => $this->params[ 'store_image' ] ?? '',
  69. "province_id" => $this->params[ 'province_id' ] ?? 0,
  70. "city_id" => $this->params[ 'city_id' ] ?? 0,
  71. "district_id" => $this->params[ 'district_id' ] ?? 0,
  72. "community_id" => $this->params[ 'community_id' ] ?? 0,
  73. "address" => $this->params[ 'address' ] ?? '',
  74. "full_address" => $this->params[ 'full_address' ] ?? '',
  75. "longitude" => $this->params[ 'longitude' ] ?? '',
  76. "latitude" => $this->params[ 'latitude' ] ?? '',
  77. "store_type" => $this->params[ 'store_type' ] ?? '',
  78. );
  79. $result = $store_model->editStore($data, $condition, [], 1, 1);
  80. return $this->response($result);
  81. }
  82. /**
  83. * 编辑门店运营设置
  84. * @return mixed
  85. */
  86. public function editStoreOperate()
  87. {
  88. $store_id = $this->store_id;
  89. $condition = array (
  90. [ "site_id", "=", $this->site_id ],
  91. [ "store_id", "=", $store_id ]
  92. );
  93. $store_model = new StoreModel();
  94. $data = array (
  95. 'store_image' => $this->params[ 'store_image' ] ?? '',
  96. 'start_time' => $this->params[ 'start_time' ] ?? '',
  97. 'end_time' => $this->params[ 'end_time' ] ?? '',
  98. 'time_type' => $this->params[ 'time_type' ] ?? '',
  99. 'time_week' => $this->params[ 'time_week' ] ?? '',
  100. 'stock_type' => $this->params[ 'stock_type' ] ?? '',
  101. 'is_pickup' => $this->params[ 'is_pickup' ] ?? '',
  102. 'is_o2o' => $this->params[ 'is_o2o' ] ?? '',
  103. 'open_date' => $this->params[ 'open_date' ] ?? '',
  104. "status" => $this->params[ 'status' ] ?? 0,
  105. );
  106. $result = $store_model->editStore($data, $condition, [], 1, 1);
  107. return $this->response($result);
  108. }
  109. /**
  110. * 配送员列表
  111. */
  112. public function deliverLists()
  113. {
  114. $deliver_model = new ExpressDeliver();
  115. $page = $this->params[ 'page' ] ?? '';
  116. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  117. $search_text = $this->params[ 'search_text' ] ?? '';
  118. $condition = [
  119. [
  120. 'site_id', '=', $this->site_id,
  121. ],
  122. [
  123. 'store_id', '=', $this->store_id,
  124. ]
  125. ];
  126. if (!empty($search_text)) {
  127. $condition[] = [ 'deliver_name', 'like', '%' . $search_text . '%' ];
  128. }
  129. $deliver_lists = $deliver_model->getDeliverPageLists($condition, '*', 'create_time desc', $page, $page_size);
  130. return $this->response($deliver_lists);
  131. }
  132. /**
  133. * 添加配送员
  134. */
  135. public function deliverinfo()
  136. {
  137. $deliver_id = $this->params[ 'deliver_id' ] ?? 0;
  138. $deliver_model = new ExpressDeliver();
  139. $result = $deliver_model->getDeliverInfo($deliver_id, $this->site_id, $this->store_id);
  140. return $this->response($result);
  141. }
  142. /**
  143. * 添加配送员
  144. */
  145. public function addDeliver()
  146. {
  147. $deliver_model = new ExpressDeliver();
  148. $data = [
  149. 'deliver_name' => $this->params[ 'deliver_name' ] ?? '',
  150. 'deliver_mobile' => $this->params[ 'deliver_mobile' ] ?? '',
  151. 'store_id' => $this->store_id,
  152. 'site_id' => $this->site_id,
  153. ];
  154. $result = $deliver_model->addDeliver($data);
  155. return $this->response($result);
  156. }
  157. /**
  158. * 编辑配送员
  159. */
  160. public function editDeliver()
  161. {
  162. $deliver_id = $this->params[ 'deliver_id' ] ?? 0;
  163. $deliver_model = new ExpressDeliver();
  164. $data = [
  165. 'deliver_name' => $this->params[ 'deliver_name' ] ?? '',
  166. 'deliver_mobile' => $this->params[ 'deliver_mobile' ] ?? '',
  167. 'site_id' => $this->site_id,
  168. 'store_id' => $this->store_id
  169. ];
  170. $result = $deliver_model->editDeliver($data, $deliver_id);
  171. return $this->response($result);
  172. }
  173. /**
  174. * 删除配送员
  175. */
  176. public function deleteDeliver()
  177. {
  178. $deliver_model = new ExpressDeliver();
  179. $deliver_id = $this->params[ 'deliver_id' ] ?? 0;
  180. $site_id = $this->site_id;
  181. $result = $deliver_model->deleteDeliver($deliver_id, $site_id, $this->store_id);
  182. return $this->response($result);
  183. }
  184. }