SystemStore.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\merchant;
  12. use think\facade\App;
  13. use app\controller\admin\AuthController;
  14. use app\services\store\SystemStoreServices;
  15. /**
  16. * 门店管理控制器
  17. * Class SystemAttachment
  18. * @package app\controller\admin\v1\merchant
  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. * 获取门店列表1
  36. * @return mixed
  37. */
  38. public function index()
  39. {
  40. $where = $this->request->getMore([
  41. [['keywords', 's'], ''],
  42. [['type', 'd'], 0]
  43. ]);
  44. return $this->success($this->services->getStoreList($where));
  45. }
  46. /**
  47. * 获取门店头部
  48. * @return mixed
  49. */
  50. public function get_header()
  51. {
  52. $count = $this->services->getStoreData();
  53. return $this->success(compact('count'));
  54. }
  55. /**
  56. * 门店设置
  57. * @return mixed
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public function get_info()
  63. {
  64. [$id] = $this->request->getMore([
  65. [['id', 'd'], 0],
  66. ], true);
  67. $info = $this->services->getStoreDispose($id);
  68. return $this->success(compact('info'));
  69. }
  70. /**
  71. * 位置选择
  72. * @return mixed
  73. */
  74. public function select_address()
  75. {
  76. $key = sys_config('tengxun_map_key');
  77. if (!$key) return $this->fail('提示:前往设置->系统设置->第三方接口 配置腾讯地图KEY');
  78. return $this->success(compact('key'));
  79. }
  80. /**
  81. * 设置单个门店是否显示
  82. * @param string $is_show
  83. * @param string $id
  84. * @return json
  85. */
  86. public function set_show($is_show = '', $id = '')
  87. {
  88. ($is_show == '' || $id == '') && $this->fail('缺少参数');
  89. $res = $this->services->update((int)$id, ['is_show' => (int)$is_show]);
  90. if ($res) {
  91. return $this->success($is_show == 1 ? '设置显示成功' : '设置隐藏成功');
  92. } else {
  93. return $this->fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败');
  94. }
  95. }
  96. /**
  97. * 保存修改门店信息
  98. * param int $id
  99. * */
  100. public function save($id = 0)
  101. {
  102. $data = $this->request->postMore([
  103. ['name', ''],
  104. ['introduction', ''],
  105. ['image', ''],
  106. ['phone', ''],
  107. ['address', ''],
  108. ['detailed_address', ''],
  109. ['latlng', ''],
  110. ['day_time', []],
  111. ]);
  112. $this->validate($data, \app\validate\admin\merchant\SystemStoreValidate::class, 'save');
  113. $data['address'] = implode(',', $data['address']);
  114. $data['latlng'] = explode(',', $data['latlng']);
  115. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) {
  116. return $this->fail('请选择门店位置');
  117. }
  118. $data['latitude'] = $data['latlng'][0];
  119. $data['longitude'] = $data['latlng'][1];
  120. $data['day_time'] = implode(' - ', $data['day_time']);
  121. unset($data['latlng']);
  122. if ($data['image'] && strstr($data['image'], 'http') === false) {
  123. $site_url = sys_config('site_url');
  124. $data['image'] = $site_url . $data['image'];
  125. }
  126. $this->services->saveStore((int)$id, $data);
  127. return $this->success('操作成功!');
  128. }
  129. /**
  130. * 删除恢复门店
  131. * @param $id
  132. */
  133. public function delete($id)
  134. {
  135. if (!$id) return $this->fail('数据不存在');
  136. $storeInfo = $this->services->get($id);
  137. if (!$storeInfo) {
  138. return $this->fail('数据不存在');
  139. }
  140. if ($storeInfo->is_del == 1) {
  141. $storeInfo->is_del = 0;
  142. if (!$storeInfo->save())
  143. return $this->fail('恢复失败,请稍候再试!');
  144. else
  145. return $this->success('恢复门店成功!');
  146. } else {
  147. $storeInfo->is_del = 1;
  148. if (!$storeInfo->save())
  149. return $this->fail('删除失败,请稍候再试!');
  150. else
  151. return $this->success('删除门店成功!');
  152. }
  153. }
  154. }