SystemStore.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\merchant;
  12. use think\facade\App;
  13. use app\adminapi\controller\AuthController;
  14. use app\services\system\store\SystemStoreServices;
  15. /**
  16. * 门店管理控制器
  17. * Class SystemAttachment
  18. * @package app\admin\controller\system
  19. *
  20. */
  21. class SystemStore extends AuthController
  22. {
  23. /**
  24. * 构造方法
  25. * SystemStore constructor.
  26. * @param App $app
  27. * @param SystemStoreServices $services
  28. */
  29. public function __construct(App $app, SystemStoreServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 门店列表
  36. * @return mixed
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function index()
  42. {
  43. $where = $this->request->getMore([
  44. [['keywords', 's'], ''],
  45. [['type', 'd'], 0]
  46. ]);
  47. return app('json')->success($this->services->getStoreList($where));
  48. }
  49. /**
  50. * 获取门店头部
  51. * @return mixed
  52. */
  53. public function get_header()
  54. {
  55. $count = $this->services->getStoreData();
  56. return app('json')->success(compact('count'));
  57. }
  58. /**
  59. * 门店设置
  60. * @return mixed
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. */
  65. public function get_info()
  66. {
  67. [$id] = $this->request->getMore([
  68. [['id', 'd'], 0],
  69. ], true);
  70. $info = $this->services->getStoreDispose($id);
  71. return app('json')->success(compact('info'));
  72. }
  73. /**
  74. * 位置选择
  75. * @return mixed
  76. */
  77. public function select_address()
  78. {
  79. $key = sys_config('tengxun_map_key');
  80. if (!$key) return app('json')->fail(400124);
  81. return app('json')->success(compact('key'));
  82. }
  83. /**
  84. * 设置单个门店是否显示
  85. * @param string $is_show
  86. * @param string $id
  87. * @return mixed
  88. */
  89. public function set_show($is_show = '', $id = '')
  90. {
  91. ($is_show == '' || $id == '') && app('json')->fail(100100);
  92. $res = $this->services->update((int)$id, ['is_show' => (int)$is_show]);
  93. if ($res) {
  94. return app('json')->success(100014);
  95. } else {
  96. return app('json')->fail(100015);
  97. }
  98. }
  99. /**
  100. * 保存修改门店信息
  101. * @param int $id
  102. * @return mixed
  103. */
  104. public function save($id = 0)
  105. {
  106. $data = $this->request->postMore([
  107. ['name', ''],
  108. ['introduction', ''],
  109. ['image', ''],
  110. ['oblong_image', ''],
  111. ['phone', ''],
  112. ['address', ''],
  113. ['detailed_address', ''],
  114. ['latlng', ''],
  115. ['day_time', []],
  116. ]);
  117. $this->validate($data, \app\adminapi\validate\merchant\SystemStoreValidate::class, 'save');
  118. $data['address'] = implode(',', $data['address']);
  119. $data['latlng'] = explode(',', $data['latlng']);
  120. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) {
  121. return app('json')->fail(400125);
  122. }
  123. $data['latitude'] = $data['latlng'][0];
  124. $data['longitude'] = $data['latlng'][1];
  125. $data['day_time'] = implode(' - ', $data['day_time']);
  126. unset($data['latlng']);
  127. if ($data['image'] && strstr($data['image'], 'http') === false) {
  128. $site_url = sys_config('site_url');
  129. $data['image'] = $site_url . $data['image'];
  130. }
  131. $this->services->saveStore((int)$id, $data);
  132. return app('json')->success(100014);
  133. }
  134. /**
  135. * 删除恢复门店
  136. * @param $id
  137. * @return mixed
  138. */
  139. public function delete($id)
  140. {
  141. if (!$id) return app('json')->fail(100100);
  142. $storeInfo = $this->services->get($id);
  143. if (!$storeInfo) {
  144. return app('json')->fail(100026);
  145. }
  146. if ($storeInfo->is_del == 1) {
  147. $storeInfo->is_del = 0;
  148. if (!$storeInfo->save())
  149. return app('json')->fail(100041);
  150. else
  151. return app('json')->success(100040);
  152. } else {
  153. $storeInfo->is_del = 1;
  154. if (!$storeInfo->save())
  155. return app('json')->fail(100008);
  156. else
  157. return app('json')->success(100002);
  158. }
  159. }
  160. }