SystemStore.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. ['uid' , 0],
  108. ['name', ''],
  109. ['introduction', ''],
  110. ['image', ''],
  111. ['oblong_image', ''],
  112. ['phone', ''],
  113. ['address', ''],
  114. ['detailed_address', ''],
  115. ['latlng', ''],
  116. ['day_time', []],
  117. ]);
  118. // 修改时验证数据
  119. if ($id) {
  120. $this->validate($data, \app\adminapi\validate\merchant\SystemStoreValidate::class, 'save');
  121. }
  122. if (is_array($data['address'])) {
  123. $data['address'] = implode(',', $data['address']);
  124. }
  125. $data['latlng'] = explode(',', $data['latlng']);
  126. // if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) {
  127. // return app('json')->fail(400125);
  128. // }
  129. // $data['latitude'] = $data['latlng'][0];
  130. // $data['longitude'] = $data['latlng'][1];
  131. if (is_array($data['day_time'])) {
  132. $data['day_time'] = implode(' - ', $data['day_time']);
  133. }
  134. // unset($data['latlng']);
  135. if ($data['image'] && strstr($data['image'], 'http') === false) {
  136. $site_url = sys_config('site_url');
  137. $data['image'] = $site_url . $data['image'];
  138. }
  139. $this->services->saveStore((int)$id, $data);
  140. return app('json')->success(100014);
  141. }
  142. /**
  143. * 删除恢复门店
  144. * @param $id
  145. * @return mixed
  146. */
  147. public function delete($id)
  148. {
  149. if (!$id) return app('json')->fail(100100);
  150. $storeInfo = $this->services->get($id);
  151. if (!$storeInfo) {
  152. return app('json')->fail(100026);
  153. }
  154. if ($storeInfo->is_del == 1) {
  155. $storeInfo->is_del = 0;
  156. if (!$storeInfo->save())
  157. return app('json')->fail(100041);
  158. else
  159. return app('json')->success(100040);
  160. } else {
  161. $storeInfo->is_del = 1;
  162. if (!$storeInfo->save())
  163. return app('json')->fail(100008);
  164. else
  165. return app('json')->success(100002);
  166. }
  167. }
  168. }