SystemStore.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace app\adminapi\controller\v1\merchant;
  3. use app\models\system\SystemConfig;
  4. use think\facade\Route as Url;
  5. use app\adminapi\controller\AuthController;
  6. use app\models\system\{SystemStore as SystemStoreModel, SystemStoreStaff, SystemProductStore};
  7. use crmeb\services\{FormBuilder as Form, UtilService as Util};
  8. /**
  9. * 门店管理控制器
  10. * Class SystemAttachment
  11. * @package app\admin\controller\system
  12. *
  13. */
  14. class SystemStore extends AuthController
  15. {
  16. /**
  17. * 获取门店列表1
  18. * @return mixed
  19. */
  20. public function index()
  21. {
  22. $where = Util::getMore([
  23. [['page', 'd'], 1],
  24. [['limit', 'd'], 15],
  25. [['keywords', 's'], ''],
  26. [['type', 'd'], 0],
  27. ]);
  28. $mer_id = $this->merId ?: '';
  29. return $this->success(SystemStoreModel::lst(0, 0, $where['page'], $where['limit'], $where['keywords'], $where['type'], $mer_id));
  30. }
  31. /**
  32. * 获取门店列表(不分页)
  33. */
  34. public function get_store_list()
  35. {
  36. $mer_id = $this->merId ?: '';
  37. return $this->success(SystemStoreModel::where('mer_id', $mer_id)->where('is_del', 0)->where('is_show', 1)->select()->toArray());
  38. }
  39. /**
  40. * 获取门店头部
  41. * @return mixed
  42. */
  43. public function get_header()
  44. {
  45. $count['show']['name'] = '显示中的提货点';
  46. $count['hide']['name'] = '隐藏中的提货点';
  47. $count['recycle']['name'] = '回收站的提货点';
  48. $count['show']['num'] = SystemStoreModel::merSet($this->merId)->where('is_show', 1)->where('is_del', 0)->count('id');//显示中的门店
  49. $count['hide']['num'] = SystemStoreModel::merSet($this->merId)->where('is_show', 0)->count('id');//隐藏的门店
  50. $count['recycle']['num'] = SystemStoreModel::merSet($this->merId)->where('is_del', 1)->count('id');//删除的门店
  51. return $this->success(compact('count'));
  52. }
  53. /*
  54. * 门店设置
  55. * */
  56. public function get_info()
  57. {
  58. list($id) = Util::getMore([
  59. [['id', 'd'], 0],
  60. ], $this->request, true);
  61. $info = SystemStoreModel::getStoreInfo($id);
  62. return $this->success(compact('info'));
  63. }
  64. /*
  65. * 位置选择
  66. * */
  67. public function select_address()
  68. {
  69. $key = SystemConfig::getConfigValue('tengxun_map_key');
  70. if (!$key) return $this->fail('请前往设置->系统设置->物流配置 配置腾讯地图KEY');
  71. return $this->success(compact('key'));
  72. }
  73. /**
  74. * 设置单个门店是否显示
  75. * @param string $is_show
  76. * @param string $id
  77. * @return json
  78. */
  79. public function set_show($is_show = '', $id = '')
  80. {
  81. ($is_show == '' || $id == '') && $this->fail('缺少参数');
  82. $res = SystemStoreModel::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  83. if ($res) {
  84. return $this->success($is_show == 1 ? '设置显示成功' : '设置隐藏成功');
  85. } else {
  86. return $this->fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败');
  87. }
  88. }
  89. /*
  90. * 保存修改门店信息
  91. * param int $id
  92. * */
  93. public function save($id = 0)
  94. {
  95. $data = Util::postMore([
  96. ['name', ''],
  97. ['introduction', ''],
  98. ['image', ''],
  99. ['phone', ''],
  100. ['address', ''],
  101. ['detailed_address', ''],
  102. ['latlng', ''],
  103. ['day_time', []],
  104. ['pids', []]
  105. ]);
  106. $this->validate($data, \app\adminapi\validates\merchant\SystemStoreValidate::class, 'save');
  107. if($this->merId){
  108. $data['mer_id'] = $this->merId;
  109. }
  110. SystemStoreModel::beginTrans();
  111. try {
  112. $data['address'] = implode(',', $data['address']);
  113. $data['latlng'] = explode(',', $data['latlng']);
  114. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return $this->fail('请选择门店位置');
  115. $data['latitude'] = $data['latlng'][0];
  116. $data['longitude'] = $data['latlng'][1];
  117. $data['day_time'] = implode(' - ', $data['day_time']);
  118. unset($data['latlng']);
  119. if ($data['image'] && strstr($data['image'], 'http') === false) {
  120. $site_url = SystemConfig::getConfigValue('site_url');
  121. $data['image'] = $site_url . $data['image'];
  122. }
  123. $pids = $data['pids'];
  124. unset($data['pids']);
  125. if ($id) {
  126. SystemStoreModel::where('id', $id)->update($data);
  127. SystemProductStore::saveStoreProduct($pids, $id);
  128. SystemStoreModel::commitTrans();
  129. return $this->success('修改成功');
  130. } else {
  131. $data['add_time'] = time();
  132. $data['is_show'] = 1;
  133. $res = SystemStoreModel::create($data);
  134. SystemProductStore::saveStoreProduct($pids, $res->id);
  135. SystemStoreModel::commitTrans();
  136. return $this->success('保存成功', ['id' => $res->id]);
  137. }
  138. } catch (\Exception $e) {
  139. SystemStoreModel::rollbackTrans();
  140. return $this->fail($e->getMessage());
  141. }
  142. }
  143. /**
  144. * 删除恢复门店
  145. * @param $id
  146. */
  147. public function delete($id)
  148. {
  149. if (!$id) return $this->fail('数据不存在');
  150. if (!SystemStoreModel::be(['id' => $id])) return $this->fail('数据不存在');
  151. if (SystemStoreModel::be(['id' => $id, 'is_del' => 1])) {
  152. $data['is_del'] = 0;
  153. if (!SystemStoreModel::edit($data, $id))
  154. return $this->fail(SystemStoreModel::getErrorInfo('恢复失败,请稍候再试!'));
  155. else
  156. return $this->success('恢复门店成功!');
  157. } else {
  158. $data['is_del'] = 1;
  159. if (!SystemStoreModel::edit($data, $id))
  160. return $this->fail(SystemStoreModel::getErrorInfo('删除失败,请稍候再试!'));
  161. else
  162. return $this->success('删除门店成功!');
  163. }
  164. }
  165. }