Store.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\store\shop\controller;
  11. use addon\store\model\Category;
  12. use addon\store\model\Label;
  13. use addon\store\model\StoreWithdraw;
  14. use app\model\express\Config as ExpressConfig;
  15. use app\model\express\ExpressDeliver;
  16. use app\model\express\Local as LocalModel;
  17. use app\model\order\Order;
  18. use app\model\store\Store as StoreModel;
  19. use app\model\system\Address as AddressModel;
  20. use app\model\system\User;
  21. use app\model\system\UserGroup;
  22. use app\model\web\Config as ConfigModel;
  23. use app\model\web\Config as WebConfig;
  24. use app\shop\controller\BaseShop;
  25. use addon\store\model\Config as StoreConfig;
  26. /**
  27. * 门店
  28. * Class Store
  29. * @package app\shop\controller
  30. */
  31. class Store extends BaseShop
  32. {
  33. /**
  34. * 门店首页
  35. */
  36. public function index()
  37. {
  38. if (request()->isAjax()) {
  39. $store_model = new StoreModel();
  40. $order_model = new Order();
  41. $withdrawal_model = new StoreWithdraw();
  42. $data = [
  43. 'store_num' => $store_model->getStoreCount([ [ 'site_id', '=', $this->site_id ] ])[ 'data' ],
  44. 'in_business_num' => $store_model->getStoreCount([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 1 ] ])[ 'data' ],
  45. 'total_order_num' => $order_model->getOrderCount([ [ 'site_id', '=', $this->site_id ], [ 'store_id', '>', 0 ], [ 'is_delete', '=', 0 ], [ 'pay_status', '=', 1 ] ])[ 'data' ],
  46. 'total_order_money' => $order_model->getOrderMoneySum([ [ 'site_id', '=', $this->site_id ], [ 'store_id', '>', 0 ], [ 'is_delete', '=', 0 ], [ 'pay_status', '=', 1 ] ])[ 'data' ],
  47. 'account_apply' => $store_model->getStoreSum([ [ 'site_id', '=', $this->site_id ] ], 'account_apply')[ 'data' ],
  48. 'wait_audit_num' => $withdrawal_model->getStoreWithdrawCount([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 0 ] ])[ 'data' ],
  49. 'wait_audit_money' => $withdrawal_model->getStoreWithdrawSum([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 0 ] ], 'money')[ 'data' ],
  50. 'wait_transfer_num' => $withdrawal_model->getStoreWithdrawCount([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 1 ] ])[ 'data' ],
  51. 'wait_transfer_money' => $withdrawal_model->getStoreWithdrawSum([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 1 ] ], 'money')[ 'data' ],
  52. ];
  53. return $store_model->success($data);
  54. }
  55. return $this->fetch("store/index");
  56. }
  57. /**
  58. * 门店排行
  59. */
  60. public function storeRanking()
  61. {
  62. if (request()->isAjax()) {
  63. $order = input('order', 'num');
  64. $stat_model = new \addon\store\model\Stat();
  65. $data = $stat_model->getStoreOrderRank([
  66. 'site_id' => $this->site_id,
  67. 'order' => $order,
  68. ]);
  69. return $data;
  70. }
  71. }
  72. /**
  73. * 商品排行
  74. */
  75. public function goodsRanking()
  76. {
  77. if (request()->isAjax()) {
  78. $order_model = new Order();
  79. $order = input('order', 'num');
  80. $condition = [
  81. [ 'og.site_id', '=', $this->site_id ],
  82. [ 'og.store_id', '>', 0 ],
  83. [ 'o.pay_status', '=', 1 ],
  84. [ 'o.is_delete', '=', 0 ]
  85. ];
  86. $join = [
  87. [ 'order o', 'o.order_id = og.order_id', 'inner' ],
  88. [ 'store s', 's.store_id = o.store_id', 'inner' ]
  89. ];
  90. $order = $order == 'num' ? 'goods_num desc' : 'goods_money desc';
  91. $res = $order_model->getOrderGoodsList($condition, 'sum(og.num) as goods_num, sum(o.goods_money) as goods_money,og.goods_name', $order, 5, 'og.goods_id', 'og', $join);
  92. return $res;
  93. }
  94. }
  95. /**
  96. * 门店列表
  97. * @return mixed
  98. */
  99. public function lists()
  100. {
  101. if (request()->isAjax()) {
  102. $store_model = new StoreModel();
  103. $page = input('page', 1);
  104. $page_size = input('page_size', PAGE_LIST_ROWS);
  105. // $order = input("order", "create_time desc");
  106. $keyword = input("search_text", '');
  107. $status = input("status", '');
  108. $type = input("type", '');
  109. $condition = [];
  110. if ($type == 1) {
  111. if ($status != null) {
  112. $condition[] = [ 'status', '=', $status ];
  113. $condition[] = [ 'is_frozen', '=', 0 ];
  114. }
  115. } else if ($type == 2) {
  116. $condition[] = [ 'is_frozen', '=', $status ];
  117. }
  118. $condition[] = [ 'site_id', "=", $this->site_id ];
  119. //关键字查询
  120. if (!empty($keyword)) {
  121. $condition[] = [ "store_name", "like", "%" . $keyword . "%" ];
  122. }
  123. $store_id_arr = [];
  124. $userGroupModel = new UserGroup();
  125. $userInfo = $this->user_info;
  126. $userGroupWhere['uid'] = $userInfo['uid'];
  127. $userGroupList = $userGroupModel->getUserList($userGroupWhere,'uid,store_id');
  128. $store_id_arr = array_column($userGroupList['data'],'store_id');
  129. if(!empty($store_id_arr) && !$userInfo['is_admin']){
  130. $condition[] = [ "store_id", "in", $store_id_arr];
  131. }
  132. $order = 'is_default desc,store_id desc';
  133. $list = $store_model->getStorePageList($condition, $page, $page_size, $order);
  134. return $list;
  135. } else {
  136. //判断门店插件是否存在
  137. $store_is_exit = addon_is_exit('store', $this->site_id);
  138. $this->assign('store_is_exit', $store_is_exit);
  139. $this->assign('title', $store_is_exit ? '门店' : '自提点');
  140. $this->assign('store_type', ( new StoreModel() )->getStoreType());
  141. $config_model = new ConfigModel();
  142. $default_img = $config_model->getDefaultImg($this->site_id, $this->app_module)[ 'data' ][ 'value' ];
  143. $this->assign("default_img", $default_img);
  144. return $this->fetch("store/lists");
  145. }
  146. }
  147. /**
  148. * 添加门店
  149. * @return mixed
  150. */
  151. public function addStore()
  152. {
  153. $is_store = addon_is_exit('store');
  154. if (request()->isAjax()) {
  155. $store_name = input("store_name", '');
  156. $telphone = input("telphone", '');
  157. $store_image = input("store_image", '');
  158. $province_id = input("province_id", 0);
  159. $city_id = input("city_id", 0);
  160. $district_id = input("district_id", 0);
  161. $community_id = input("community_id", 0);
  162. $address = input("address", '');
  163. $full_address = input("full_address", '');
  164. $longitude = input("longitude", 0);
  165. $latitude = input("latitude", 0);
  166. $is_pickup = input("is_pickup", 0);
  167. $is_o2o = input("is_o2o", 0);
  168. $open_date = input("open_date", '');
  169. $start_time = input('start_time', 0);
  170. $end_time = input('end_time', 0);
  171. $time_type = input('time_type', 0);
  172. $time_week = input('time_week', '');
  173. $stock_type = input('stock_type', '');
  174. if (!empty($time_week)) {
  175. $time_week = implode(',', $time_week);
  176. }
  177. $data = array (
  178. "store_name" => $store_name,
  179. "telphone" => $telphone,
  180. "store_image" => $store_image,
  181. "province_id" => $province_id,
  182. "city_id" => $city_id,
  183. "district_id" => $district_id,
  184. "community_id" => $community_id,
  185. "address" => $address,
  186. "full_address" => $full_address,
  187. "longitude" => $longitude,
  188. "latitude" => $latitude,
  189. "open_date" => $open_date,
  190. "site_id" => $this->site_id,
  191. 'start_time' => $start_time,
  192. 'end_time' => $end_time,
  193. 'time_type' => $time_type,
  194. 'time_week' => $time_week,
  195. 'stock_type' => $stock_type,
  196. 'is_pickup' => $is_pickup,
  197. 'is_o2o' => $is_o2o,
  198. 'store_type' => input('store_type', ''),
  199. 'category_id' => input('category_id', 0),
  200. 'category_name' => input('category_name', ''),
  201. 'label_id' => input('label_id', ''),
  202. 'label_name' => input('label_name', ''),
  203. 'store_images' => input('store_images', ''),
  204. 'store_introduce' => input('store_introduce', '')
  205. );
  206. //判断是否开启多门店
  207. if ($is_store == 1) {
  208. $user_data = [
  209. 'uid' => input('uid', ''),
  210. ];
  211. } else {
  212. $user_data = [];
  213. }
  214. $store_model = new StoreModel();
  215. $result = $store_model->addStore($data, $user_data, $is_store);
  216. return $result;
  217. } else {
  218. //查询省级数据列表
  219. $address_model = new AddressModel();
  220. $list = $address_model->getAreaList([ [ "pid", "=", 0 ], [ "level", "=", 1 ] ]);
  221. $this->assign("province_list", $list[ "data" ]);
  222. $this->assign("is_exit", $is_store);
  223. $this->assign('title', $is_store ? '门店' : '自提点');
  224. $this->assign("http_type", get_http_type());
  225. $config_model = new ConfigModel();
  226. $mp_config = $config_model->getMapConfig($this->site_id);
  227. $this->assign('tencent_map_key', $mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  228. //效验腾讯地图KEY
  229. $check_map_key = $config_model->checkQqMapKey($mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  230. $this->assign('check_map_key', $check_map_key);
  231. $express_type = ( new ExpressConfig() )->getEnabledExpressType($this->site_id);
  232. if (isset($express_type[ 'express' ])) unset($express_type[ 'express' ]);
  233. $this->assign('express_type', $express_type);
  234. $this->assign('store_type', ( new StoreModel() )->getStoreType());
  235. $user_list = ( new User() )->getUserList([ [ 'site_id', '=', $this->site_id ] ], 'uid,username')[ 'data' ];
  236. $this->assign('user_list', $user_list);
  237. $category = new Category();
  238. $category_config = $category->getCategoryConfig($this->site_id)[ 'data' ][ 'value' ];
  239. if ($category_config[ 'status' ]) {
  240. $category_list = $category->getStoreCategoryList([ [ 'site_id', '=', $this->site_id ] ], 'category_id,category_name')[ 'data' ];
  241. $this->assign('category_list', $category_list);
  242. }
  243. $this->assign('category_status', $category_config[ 'status' ]);
  244. $label_list = ( new Label() )->getStoreLabelList([ [ 'site_id', '=', $this->site_id ] ], 'label_id,label_name')[ 'data' ];
  245. $this->assign('label_list', $label_list);
  246. return $this->fetch("store/add_store");
  247. }
  248. }
  249. /**
  250. * 编辑门店
  251. * @return mixed
  252. */
  253. public function editStore()
  254. {
  255. $is_exit = addon_is_exit("store");
  256. $store_id = input("store_id", 0);
  257. $condition = array (
  258. [ "site_id", "=", $this->site_id ],
  259. [ "store_id", "=", $store_id ]
  260. );
  261. $store_model = new StoreModel();
  262. if (request()->isAjax()) {
  263. $store_name = input("store_name", '');
  264. $telphone = input("telphone", '');
  265. $store_image = input("store_image", '');
  266. $province_id = input("province_id", 0);
  267. $city_id = input("city_id", 0);
  268. $district_id = input("district_id", 0);
  269. $community_id = input("community_id", 0);
  270. $address = input("address", '');
  271. $full_address = input("full_address", '');
  272. $longitude = input("longitude", 0);
  273. $latitude = input("latitude", 0);
  274. $is_pickup = input("is_pickup", 0);
  275. $is_o2o = input("is_o2o", 0);
  276. $open_date = input("open_date", '');
  277. $start_time = input('start_time', 0);
  278. $end_time = input('end_time', 0);
  279. $time_type = input('time_type', 0);
  280. $time_week = input('time_week', '');
  281. $stock_type = input('stock_type', '');
  282. if (!empty($time_week)) {
  283. $time_week = implode(',', $time_week);
  284. }
  285. $data = array (
  286. "store_name" => $store_name,
  287. "telphone" => $telphone,
  288. "store_image" => $store_image,
  289. "province_id" => $province_id,
  290. "city_id" => $city_id,
  291. "district_id" => $district_id,
  292. "community_id" => $community_id,
  293. "address" => $address,
  294. "full_address" => $full_address,
  295. "longitude" => $longitude,
  296. "latitude" => $latitude,
  297. "open_date" => $open_date,
  298. 'start_time' => $start_time,
  299. 'end_time' => $end_time,
  300. 'time_type' => $time_type,
  301. 'time_week' => $time_week,
  302. 'stock_type' => $stock_type,
  303. 'is_pickup' => $is_pickup,
  304. 'is_o2o' => $is_o2o,
  305. 'store_type' => input('store_type', ''),
  306. 'category_id' => input('category_id', 0),
  307. 'category_name' => input('category_name', ''),
  308. 'label_id' => input('label_id', ''),
  309. 'label_name' => input('label_name', ''),
  310. 'store_images' => input('store_images', ''),
  311. 'store_introduce' => input('store_introduce', '')
  312. );
  313. $result = $store_model->editStore($data, $condition, [], $is_exit, 1);
  314. return $result;
  315. } else {
  316. //查询省级数据列表
  317. $address_model = new AddressModel();
  318. $list = $address_model->getAreaList([ [ "pid", "=", 0 ], [ "level", "=", 1 ] ]);
  319. $this->assign("province_list", $list[ "data" ]);
  320. $info_result = $store_model->getStoreDetail($condition);//门店信息
  321. $info = $info_result[ "data" ];
  322. if (empty($info)) $this->error('未获取到门店数据', addon_url('store://shop/store/lists'));
  323. $this->assign("info", $info);
  324. $this->assign("store_id", $store_id);
  325. $this->assign("is_exit", $is_exit);
  326. $this->assign('title', $is_exit ? '门店' : '自提点');
  327. $this->assign("http_type", get_http_type());
  328. $config_model = new ConfigModel();
  329. $mp_config = $config_model->getMapConfig($this->site_id);
  330. $this->assign('tencent_map_key', $mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  331. //效验腾讯地图KEY
  332. $check_map_key = $config_model->checkQqMapKey($mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  333. $this->assign('check_map_key', $check_map_key);
  334. $express_type = ( new ExpressConfig() )->getEnabledExpressType($this->site_id);
  335. if (isset($express_type[ 'express' ])) unset($express_type[ 'express' ]);
  336. $this->assign('express_type', $express_type);
  337. $this->assign('store_type', ( new StoreModel() )->getStoreType());
  338. $this->forthMenu([ 'store_id' => $store_id ]);
  339. $category = new Category();
  340. $category_config = $category->getCategoryConfig($this->site_id)[ 'data' ][ 'value' ];
  341. if ($category_config[ 'status' ]) {
  342. $category_list = $category->getStoreCategoryList([ [ 'site_id', '=', $this->site_id ] ], 'category_id,category_name')[ 'data' ];
  343. $this->assign('category_list', $category_list);
  344. }
  345. $this->assign('category_status', $category_config[ 'status' ]);
  346. $label_list = ( new Label() )->getStoreLabelList([ [ 'site_id', '=', $this->site_id ] ], 'label_id,label_name')[ 'data' ];
  347. $this->assign('label_list', $label_list);
  348. return $this->fetch("store/edit_store");
  349. }
  350. }
  351. /**
  352. * @return mixed
  353. */
  354. public function operate()
  355. {
  356. $store_id = input("store_id", 0);
  357. $condition = array (
  358. [ "site_id", "=", $this->site_id ],
  359. [ "store_id", "=", $store_id ]
  360. );
  361. $store_model = new StoreModel();
  362. if (request()->isAjax()) {
  363. $status = input("status", 0);
  364. $is_pickup = input("is_pickup", 0);
  365. $is_o2o = input("is_o2o", 0);
  366. $start_time = input('start_time', 0);
  367. $end_time = input('end_time', 0);
  368. $time_type = input('time_type', 0);
  369. $time_week = input('time_week', '');
  370. $stock_type = input('stock_type', '');
  371. if (!empty($time_week)) {
  372. $time_week = implode(',', $time_week);
  373. }
  374. $data = array (
  375. "status" => $status,
  376. 'start_time' => $start_time,
  377. 'end_time' => $end_time,
  378. 'time_type' => $time_type,
  379. 'time_week' => $time_week,
  380. 'stock_type' => $stock_type,
  381. 'is_pickup' => $is_pickup,
  382. 'is_o2o' => $is_o2o,
  383. 'time_interval' => input('time_interval', 30),
  384. 'delivery_time' => input('delivery_time', ''),
  385. 'advance_day' => input('advance_day', 0),
  386. 'most_day' => input('most_day', 7),
  387. 'is_express' => input('is_express', 0)
  388. );
  389. $result = $store_model->editStore($data, $condition, [], 1, 1);
  390. return $result;
  391. }
  392. $store_info = $store_model->getStoreDetail($condition)[ 'data' ];//门店信息
  393. if (empty($store_info)) $this->error('未获取到门店信息');
  394. $this->assign('info', $store_info);
  395. $this->assign('store_id', $store_id);
  396. $business_config = ( new StoreConfig() )->getStoreBusinessConfig($this->site_id);
  397. $this->assign('business_config', $business_config[ 'data' ][ 'value' ]);
  398. $this->forthMenu([ 'store_id' => $store_id ]);
  399. return $this->fetch("store/operate");
  400. }
  401. public function frozenStore()
  402. {
  403. if (request()->isAjax()) {
  404. $store_id = input('store_id', 0);
  405. $is_frozen = input('is_frozen', 0);
  406. $condition = [
  407. [ "site_id", "=", $this->site_id ],
  408. [ "store_id", "=", $store_id ]
  409. ];
  410. $store_model = new StoreModel();
  411. $res = $store_model->frozenStore($condition, $is_frozen);
  412. return $res;
  413. }
  414. }
  415. /**
  416. * 重置密码
  417. */
  418. public function modifyPassword()
  419. {
  420. if (request()->isAjax()) {
  421. $store_id = input('store_id', '');
  422. $password = input('password', '123456');
  423. $store_model = new StoreModel();
  424. return $store_model->resetStorePassword($password, [ [ 'store_id', '=', $store_id ] ]);
  425. }
  426. }
  427. /**
  428. * 同城配送
  429. */
  430. public function local()
  431. {
  432. $store_id = input('store_id', 0);
  433. $store_model = new StoreModel();
  434. $info_result = $store_model->getStoreInfo([ [ 'site_id', '=', $this->site_id ], [ 'store_id', '=', $store_id ] ]);//门店信息
  435. $info = $info_result[ "data" ];
  436. if (empty($info)) {
  437. $this->error([], '门店未找到');
  438. }
  439. $local_model = new LocalModel();
  440. if (request()->isAjax()) {
  441. $data = [
  442. 'type' => input('type', 'default'),//配送方式 default 商家自配送 other 第三方配送
  443. 'area_type' => input('area_type', 1),//配送区域
  444. 'local_area_json' => input('local_area_json', ''),//区域及业务集合json
  445. 'time_is_open' => input('time_is_open', 0),
  446. 'time_type' => input('time_type', 0),//时间选取类型 0 全天 1 自定义
  447. 'time_week' => input('time_week', ''),
  448. 'start_time' => input('start_time', 0),
  449. 'end_time' => input('end_time', 0),
  450. 'update_time' => time(),
  451. 'is_open_step' => input('is_open_step', 0),
  452. 'start_distance' => input('start_distance', 0),
  453. 'start_delivery_money' => input('start_delivery_money', 0),
  454. 'continued_distance' => input('continued_distance', 0),
  455. 'continued_delivery_money' => input('continued_delivery_money', 0),
  456. 'start_money' => input('start_money', 0),
  457. 'delivery_money' => input('delivery_money', 0),
  458. 'area_array' => input('area_array', ''),//地域集合
  459. 'man_money' => input('man_money', ''),
  460. 'man_type' => input('man_type', ''),
  461. 'man_discount' => input('man_discount', ''),
  462. 'time_interval' => input('time_interval', 30),
  463. 'delivery_time' => input('delivery_time', ''),
  464. 'advance_day' => input('advance_day', 0),
  465. 'most_day' => input('most_day', 7)
  466. ];
  467. $condition = array (
  468. [ 'site_id', '=', $this->site_id ],
  469. [ 'store_id', '=', $store_id ],
  470. );
  471. return $local_model->editLocal($data, $condition);
  472. } else {
  473. $this->assign('store_detail', $info);
  474. $local_result = $local_model->getLocalInfo([ [ 'site_id', '=', $this->site_id ], [ 'store_id', '=', $store_id ] ]);
  475. $district_list = [];
  476. if ($info[ 'province_id' ] > 0 && $info[ 'city_id' ] > 0) {
  477. //查询省级数据列表
  478. $address_model = new AddressModel();
  479. $list = $address_model->getAreaList([ [ "pid", "=", $info[ 'city_id' ] ], [ "level", "=", 3 ] ]);
  480. $district_list = $list[ "data" ];
  481. }
  482. $this->assign('district_list', $district_list);
  483. $this->assign('local_info', $local_result[ 'data' ]);
  484. $config_model = new WebConfig();
  485. $mp_config = $config_model->getMapConfig($this->site_id);
  486. $this->assign('tencent_map_key', $mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ]);
  487. $this->assign('store_id', $store_id);
  488. $this->forthMenu([ 'store_id' => $store_id ]);
  489. return $this->fetch('store/local');
  490. }
  491. }
  492. /**
  493. * 结算设置
  494. */
  495. public function settlement()
  496. {
  497. $store_id = input('store_id', 0);
  498. if (empty($store_id)) {
  499. $this->error('未获取到门店信息');
  500. }
  501. $store_model = new StoreModel();
  502. if (request()->isAjax()) {
  503. $is_settlement = input("is_settlement", 0);
  504. if (empty($is_settlement)) {
  505. $data = [
  506. 'is_settlement' => 0,
  507. 'settlement_rate' => 0
  508. ];
  509. } else {
  510. $data = [
  511. 'is_settlement' => 1,
  512. 'settlement_rate' => input("settlement_rate", 0),//跟随系统传入0,独立设置大于0
  513. 'bank_type' => input("bank_type", 0),//1微信 2.支付宝 3,银行卡
  514. 'bank_type_name' => input("bank_type_name", ''), //账户类型名称 微信默认为微信 支付宝默认是支付宝 银行卡需要传银行名称
  515. 'bank_user_name' => input("bank_user_name", ''), //账户所属人姓名 针对银行卡需要传入
  516. 'bank_type_account' => input("bank_type_account", ''), //具体账户信息,微信需要传入微信名称
  517. ];
  518. }
  519. $condition = array (
  520. [ 'site_id', '=', $this->site_id ],
  521. [ 'store_id', '=', $store_id ],
  522. );
  523. $result = $store_model->editStore($data, $condition, [], 1, 1);
  524. return $result;
  525. }
  526. $this->forthMenu([ 'store_id' => $store_id ]);
  527. $store_info = $store_model->getStoreInfo([ [ 'site_id', '=', $this->site_id ], [ 'store_id', '=', $store_id ] ]);//门店信息
  528. if (empty($store_info)) $this->error('未获取到门店信息');
  529. $this->assign('info', $store_info[ 'data' ]);
  530. $this->assign('store_id', $store_id);
  531. $withdraw_config = ( new StoreConfig() )->getStoreWithdrawConfig($this->site_id);
  532. $this->assign('withdraw_config', $withdraw_config[ 'data' ][ 'value' ]);
  533. return $this->fetch('store/settlement');
  534. }
  535. /**
  536. * 配送员列表
  537. */
  538. public function deliverLists()
  539. {
  540. $store_id = input('store_id', 0);
  541. $deliver_model = new ExpressDeliver();
  542. if (request()->isAjax()) {
  543. $page = input('page', '1');
  544. $page_size = input('page_size', PAGE_LIST_ROWS);
  545. $condition = [
  546. [
  547. 'site_id', '=', $this->site_id,
  548. ],
  549. [
  550. 'store_id', '=', $store_id,
  551. ]
  552. ];
  553. $search_text = input('search_text', '');
  554. if (!empty($search_text)) {
  555. $condition[] = [ 'deliver_name', 'like', '%' . $search_text . '%' ];
  556. }
  557. $deliver_lists = $deliver_model->getDeliverPageLists($condition, '*', 'create_time desc', $page, $page_size);
  558. return $deliver_lists;
  559. } else {
  560. $this->assign('store_id', $store_id);
  561. $this->forthMenu([ 'store_id' => $store_id ]);
  562. return $this->fetch('store/deliverlists');
  563. }
  564. }
  565. /**
  566. * 添加配送员
  567. */
  568. public function addDeliver()
  569. {
  570. $store_id = input('store_id', 0);
  571. $this->assign('store_id', $store_id);
  572. return $this->fetch('store/adddeliver');
  573. }
  574. /**
  575. * 编辑配送员
  576. */
  577. public function editDeliver()
  578. {
  579. $store_id = input('store_id', 0);
  580. $this->assign('store_id', $store_id);
  581. $deliver_model = new ExpressDeliver();
  582. $deliver_id = input('deliver_id', 0);
  583. $this->assign('deliver_id', $deliver_id);
  584. $deliver_info = $deliver_model->getDeliverInfo($deliver_id, $this->site_id);
  585. $this->assign('deliver_info', $deliver_info[ 'data' ]);
  586. return $this->fetch('store/editdeliver');
  587. }
  588. /**
  589. * 选择门店
  590. * @return mixed
  591. */
  592. public function selectStore()
  593. {
  594. $store_list = ( new StoreModel() )->getStoreList([ [ 'site_id', '=', $this->site_id ] ], 'store_id,store_name,status,address,full_address,is_frozen');
  595. $this->assign('store_list', $store_list[ 'data' ]);
  596. $store_id = explode(',', input('store_id', ''));
  597. $this->assign('store_id', $store_id);
  598. return $this->fetch('store/select');
  599. }
  600. /**
  601. * 门店主页装修
  602. */
  603. public function diy()
  604. {
  605. $data = [
  606. 'site_id' => $this->site_id,
  607. 'name' => 'DIY_STORE'
  608. ];
  609. $edit_view = event('DiyViewEdit', $data, true);
  610. return $edit_view;
  611. }
  612. /**
  613. * 门店分类
  614. * @return mixed
  615. */
  616. public function category()
  617. {
  618. $category = new Category();
  619. if (request()->isAjax()) {
  620. $page = input('page', 1);
  621. $page_size = input('page_size', PAGE_LIST_ROWS);
  622. $condition = [
  623. [ 'site_id', '=', $this->site_id ]
  624. ];
  625. if (!empty($search_text)) $condition[] = [ 'category_name', 'like', "%{$search_text}%" ];
  626. return $category->getStoreCategoryPageList($condition, $page, $page_size);
  627. }
  628. $config = $category->getCategoryConfig($this->site_id)[ 'data' ][ 'value' ];
  629. $this->assign('status', $config[ 'status' ]);
  630. return $this->fetch('store/category');
  631. }
  632. /**
  633. * 添加分类
  634. * @return array
  635. */
  636. public function addCategory()
  637. {
  638. if (request()->isAjax()) {
  639. $data = [
  640. 'category_name' => input('category_name', ''),
  641. 'site_id' => $this->site_id
  642. ];
  643. return ( new Category() )->addStoreCategory($data);
  644. }
  645. }
  646. /**
  647. * 编辑分类
  648. * @return array
  649. */
  650. public function editCategory()
  651. {
  652. if (request()->isAjax()) {
  653. $category_id = input('category_id', 0);
  654. $data = [
  655. 'category_name' => input('category_name', ''),
  656. 'sort' => input('sort', 0)
  657. ];
  658. return ( new Category() )->editStoreCategory($data, [ [ 'category_id', '=', $category_id ], [ 'site_id', '=', $this->site_id ] ]);
  659. }
  660. }
  661. /**
  662. * 删除分类
  663. * @return array
  664. */
  665. public function deleteCategory()
  666. {
  667. if (request()->isAjax()) {
  668. $category_id = input('category_id', 0);
  669. return ( new Category() )->deleteStoreCategory([ [ 'category_id', 'in', $category_id ], [ 'site_id', '=', $this->site_id ] ]);
  670. }
  671. }
  672. /**
  673. * 门店分类是否启用
  674. */
  675. public function categoryConfig()
  676. {
  677. if (request()->isAjax()) {
  678. $status = input('status', 0);
  679. return ( new Category() )->setCategoryConfig([ 'status' => $status ], $this->site_id);
  680. }
  681. }
  682. /**
  683. * 门店标签
  684. * @return mixed
  685. */
  686. public function tag()
  687. {
  688. if (request()->isAjax()) {
  689. $page = input('page', 1);
  690. $page_size = input('page_size', PAGE_LIST_ROWS);
  691. $search_text = input('search_text', '');
  692. $condition = [
  693. [ 'site_id', '=', $this->site_id ]
  694. ];
  695. if (!empty($search_text)) $condition[] = [ 'label_name', 'like', "%{$search_text}%" ];
  696. return ( new Label() )->getStoreLabelPageList($condition, $page, $page_size);
  697. }
  698. return $this->fetch('store/tag');
  699. }
  700. /**
  701. * 添加标签
  702. * @return array
  703. */
  704. public function addLabel()
  705. {
  706. if (request()->isAjax()) {
  707. $data = [
  708. 'label_name' => input('label_name', ''),
  709. 'site_id' => $this->site_id,
  710. 'create_time' => time()
  711. ];
  712. return ( new Label() )->addStoreLabel($data);
  713. }
  714. }
  715. /**
  716. * 编辑标签
  717. * @return array
  718. */
  719. public function editLabel()
  720. {
  721. if (request()->isAjax()) {
  722. $label_id = input('label_id', 0);
  723. $data = [
  724. 'label_name' => input('label_name', ''),
  725. 'sort' => input('sort', 0)
  726. ];
  727. return ( new Label() )->editStoreLabel($data, [ [ 'label_id', '=', $label_id ], [ 'site_id', '=', $this->site_id ] ]);
  728. }
  729. }
  730. /**
  731. * 删除标签
  732. * @return array
  733. */
  734. public function deleteLabel()
  735. {
  736. if (request()->isAjax()) {
  737. $label_id = input('label_id', 0);
  738. return ( new Label() )->deleteStoreLabel([ [ 'label_id', '=', $label_id ], [ 'site_id', '=', $this->site_id ] ]);
  739. }
  740. }
  741. /**
  742. * 门店标签选择框
  743. * @return mixed
  744. */
  745. public function labelSelect()
  746. {
  747. if (request()->isAjax()) {
  748. $page = input('page', 1);
  749. $page_size = input('page_size', PAGE_LIST_ROWS);
  750. $search_text = input('search_text', '');
  751. $condition = [
  752. [ 'site_id', '=', $this->site_id ]
  753. ];
  754. if (!empty($search_text)) $condition[] = [ 'label_name', 'like', "%{$search_text}%" ];
  755. return ( new Label() )->getStoreLabelPageList($condition, $page, $page_size);
  756. } else {
  757. $select_id = input('select_id', '');
  758. $this->assign('select_id', $select_id);
  759. return $this->fetch('store/label_select');
  760. }
  761. }
  762. /**
  763. * 修改排序
  764. */
  765. public function modifySort()
  766. {
  767. if (request()->isAjax()) {
  768. $sort = input('sort', 0);
  769. $label_id = input('label_id', 0);
  770. $label_model = new Label();
  771. $res = $label_model->modifySort($sort, $label_id, $this->site_id);
  772. return $res;
  773. }
  774. }
  775. }