SystemStore.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\controller\AuthController;
  4. use crmeb\services\JsonService;
  5. use crmeb\services\JsonService as Json;
  6. use app\admin\model\system\SystemStore as SystemStoreModel;
  7. use crmeb\services\UtilService;
  8. /**
  9. * 门店管理控制器
  10. * Class SystemAttachment
  11. * @package app\admin\controller\system
  12. *
  13. */
  14. class SystemStore extends AuthController
  15. {
  16. /**
  17. * 门店列表
  18. */
  19. public function list()
  20. {
  21. $where = UtilService::getMore([
  22. ['page', 1],
  23. ['limit', 20],
  24. ['name', ''],
  25. ['excel', 0],
  26. ['type', $this->request->param('type')]
  27. ]);
  28. return JsonService::successlayui(SystemStoreModel::getStoreList($where));
  29. }
  30. /**
  31. * 门店设置
  32. * @return string
  33. */
  34. public function index()
  35. {
  36. $type = $this->request->param('type');
  37. $show = SystemStoreModel::where('is_show', 1)->where('is_del', 0)->count();//显示中的门店
  38. $hide = SystemStoreModel::where('is_show', 0)->count();//隐藏的门店
  39. $recycle = SystemStoreModel::where('is_del', 1)->count();//删除的门店
  40. if ($type == null) $type = 1;
  41. $this->assign(compact('type', 'show', 'hide', 'recycle'));
  42. return $this->fetch();
  43. }
  44. /**
  45. * 门店添加
  46. * @param int $id
  47. * @return string
  48. */
  49. public function add($id = 0)
  50. {
  51. $store = SystemStoreModel::getStoreDispose($id);
  52. $this->assign(compact('store'));
  53. return $this->fetch();
  54. }
  55. /**
  56. * 删除恢复门店
  57. * @param $id
  58. */
  59. public function delete($id)
  60. {
  61. if (!$id) return $this->failed('数据不存在');
  62. if (!SystemStoreModel::be(['id' => $id])) return $this->failed('产品数据不存在');
  63. if (SystemStoreModel::be(['id' => $id, 'is_del' => 1])) {
  64. $data['is_del'] = 0;
  65. if (!SystemStoreModel::edit($data, $id))
  66. return Json::fail(SystemStoreModel::getErrorInfo('恢复失败,请稍候再试!'));
  67. else
  68. return Json::successful('恢复门店成功!');
  69. } else {
  70. $data['is_del'] = 1;
  71. if (!SystemStoreModel::edit($data, $id))
  72. return Json::fail(SystemStoreModel::getErrorInfo('删除失败,请稍候再试!'));
  73. else
  74. return Json::successful('删除门店成功!');
  75. }
  76. }
  77. /**
  78. * 设置单个门店是否显示
  79. * @param string $is_show
  80. * @param string $id
  81. * @return json
  82. */
  83. public function set_show($is_show = '', $id = '')
  84. {
  85. ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
  86. $res = SystemStoreModel::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  87. if ($res) {
  88. return JsonService::successful($is_show == 1 ? '设置显示成功' : '设置隐藏成功');
  89. } else {
  90. return JsonService::fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败');
  91. }
  92. }
  93. /**
  94. * 位置选择
  95. * @return string|void
  96. */
  97. public function select_address()
  98. {
  99. $key = sys_config('tengxun_map_key');
  100. if (!$key) return $this->failed('请前往设置->物流设置->物流配置 配置腾讯地图KEY', '#');
  101. $this->assign(compact('key'));
  102. return $this->fetch();
  103. }
  104. /**
  105. * 保存修改门店信息
  106. * @param int $id
  107. */
  108. public function save($id = 0)
  109. {
  110. $data = UtilService::postMore([
  111. ['name', ''],
  112. ['introduction', ''],
  113. ['image', ''],
  114. ['phone', ''],
  115. ['address', ''],
  116. ['detailed_address', ''],
  117. ['latlng', ''],
  118. ['valid_time', []],
  119. ['day_time', []],
  120. ]);
  121. SystemStoreModel::beginTrans();
  122. try {
  123. $data['address'] = implode(',', $data['address']);
  124. $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng'];
  125. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return JsonService::fail('请选择门店位置');
  126. $data['latitude'] = $data['latlng'][0];
  127. $data['longitude'] = $data['latlng'][1];
  128. $data['valid_time'] = implode(' - ', $data['valid_time']);
  129. $data['day_time'] = implode(' - ', $data['day_time']);
  130. unset($data['latlng']);
  131. if ($data['image'] && strstr($data['image'], 'http') === false) {
  132. $site_url = sys_config('site_url');
  133. $data['image'] = $site_url . $data['image'];
  134. }
  135. if ($id) {
  136. if (SystemStoreModel::where('id', $id)->update($data)) {
  137. SystemStoreModel::commitTrans();
  138. return JsonService::success('修改成功');
  139. } else {
  140. SystemStoreModel::rollbackTrans();
  141. return JsonService::fail('修改失败或者您没有修改什么!');
  142. }
  143. } else {
  144. $data['add_time'] = time();
  145. $data['is_show'] = 1;
  146. if ($res = SystemStoreModel::create($data)) {
  147. SystemStoreModel::commitTrans();
  148. return JsonService::success('保存成功', ['id' => $res->id]);
  149. } else {
  150. SystemStoreModel::rollbackTrans();
  151. return JsonService::fail('保存失败!');
  152. }
  153. }
  154. } catch (\Exception $e) {
  155. SystemStoreModel::rollbackTrans();
  156. return JsonService::fail($e->getMessage());
  157. }
  158. }
  159. }