SystemStore.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\store\StoreCate;
  5. use crmeb\services\JsonService;
  6. use crmeb\services\JsonService as Json;
  7. use app\admin\model\system\SystemStore as SystemStoreModel;
  8. use crmeb\services\UtilService;
  9. use crmeb\services\FormBuilder as Form;
  10. use think\facade\Route as Url;
  11. /**
  12. * 门店管理控制器
  13. * Class SystemAttachment
  14. * @package app\admin\controller\system
  15. *
  16. */
  17. class SystemStore extends AuthController
  18. {
  19. /**
  20. * 门店列表
  21. */
  22. public function list()
  23. {
  24. $where = UtilService::getMore([
  25. ['page', 1],
  26. ['limit', 20],
  27. ['name', ''],
  28. ['excel', 0],
  29. ['type', $this->request->param('type')]
  30. ]);
  31. return JsonService::successlayui(SystemStoreModel::getStoreList($where));
  32. }
  33. /**
  34. * 门店设置
  35. * @return string
  36. */
  37. public function index()
  38. {
  39. $type = $this->request->param('type');
  40. $show = SystemStoreModel::where('is_show', 1)->where('is_del', 0)->count();//显示中的门店
  41. $hide = SystemStoreModel::where('is_show', 0)->count();//隐藏的门店
  42. $recycle = SystemStoreModel::where('is_del', 1)->count();//删除的门店
  43. if ($type == null) $type = 1;
  44. $this->assign(compact('type', 'show', 'hide', 'recycle'));
  45. return $this->fetch();
  46. }
  47. /**
  48. * 门店添加
  49. * @param int $id
  50. * @return string
  51. */
  52. public function add($id = 0)
  53. {
  54. $store = SystemStoreModel::getStoreDispose($id);
  55. $this->assign(compact('store'));
  56. return $this->fetch();
  57. }
  58. /**
  59. * 删除恢复门店
  60. * @param $id
  61. */
  62. public function delete($id)
  63. {
  64. if (!$id) return $this->failed('数据不存在');
  65. if (!SystemStoreModel::be(['id' => $id])) return $this->failed('产品数据不存在');
  66. if (SystemStoreModel::be(['id' => $id, 'is_del' => 1])) {
  67. $data['is_del'] = 0;
  68. if (!SystemStoreModel::edit($data, $id))
  69. return Json::fail(SystemStoreModel::getErrorInfo('恢复失败,请稍候再试!'));
  70. else
  71. return Json::successful('恢复门店成功!');
  72. } else {
  73. $data['is_del'] = 1;
  74. if (!SystemStoreModel::edit($data, $id))
  75. return Json::fail(SystemStoreModel::getErrorInfo('删除失败,请稍候再试!'));
  76. else
  77. return Json::successful('删除门店成功!');
  78. }
  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 == '') && JsonService::fail('缺少参数');
  89. $res = SystemStoreModel::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  90. if ($res) {
  91. return JsonService::successful($is_show == 1 ? '设置显示成功' : '设置隐藏成功');
  92. } else {
  93. return JsonService::fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败');
  94. }
  95. }
  96. /**
  97. * 位置选择
  98. * @return string|void
  99. */
  100. public function select_address()
  101. {
  102. $key = sys_config('tengxun_map_key');
  103. if (!$key) return $this->failed('请前往设置->物流设置->物流配置 配置腾讯地图KEY', '#');
  104. $this->assign(compact('key'));
  105. return $this->fetch();
  106. }
  107. /**
  108. * 保存修改门店信息
  109. * @param int $id
  110. */
  111. public function save($id = 0)
  112. {
  113. $data = UtilService::postMore([
  114. ['name', ''],
  115. ['introduction', ''],
  116. ['image', ''],
  117. ['phone', ''],
  118. ['address', ''],
  119. ['detailed_address', ''],
  120. ['latlng', ''],
  121. ['valid_time', []],
  122. ['day_time', []],
  123. ]);
  124. SystemStoreModel::beginTrans();
  125. try {
  126. $data['address'] = implode(',', $data['address']);
  127. $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng'];
  128. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return JsonService::fail('请选择门店位置');
  129. $data['latitude'] = $data['latlng'][0];
  130. $data['longitude'] = $data['latlng'][1];
  131. $data['valid_time'] = implode(' - ', $data['valid_time']);
  132. $data['day_time'] = implode(' - ', $data['day_time']);
  133. unset($data['latlng']);
  134. if ($data['image'] && strstr($data['image'], 'http') === false) {
  135. $site_url = sys_config('site_url');
  136. $data['image'] = $site_url . $data['image'];
  137. }
  138. if ($id) {
  139. if (SystemStoreModel::where('id', $id)->update($data)) {
  140. SystemStoreModel::commitTrans();
  141. return JsonService::success('修改成功');
  142. } else {
  143. SystemStoreModel::rollbackTrans();
  144. return JsonService::fail('修改失败或者您没有修改什么!');
  145. }
  146. } else {
  147. $data['add_time'] = time();
  148. $data['is_show'] = 1;
  149. if ($res = SystemStoreModel::create($data)) {
  150. SystemStoreModel::commitTrans();
  151. return JsonService::success('保存成功', ['id' => $res->id]);
  152. } else {
  153. SystemStoreModel::rollbackTrans();
  154. return JsonService::fail('保存失败!');
  155. }
  156. }
  157. } catch (\Exception $e) {
  158. SystemStoreModel::rollbackTrans();
  159. return JsonService::fail($e->getMessage());
  160. }
  161. }
  162. /**
  163. * 上传店内图片
  164. * @param $id
  165. * @return string
  166. * @throws \think\db\exception\DataNotFoundException
  167. * @throws \think\db\exception\DbException
  168. * @throws \think\db\exception\ModelNotFoundException
  169. */
  170. public function up($id)
  171. {
  172. if (!$id) Json::fail('数据不存在');
  173. $data = SystemStoreModel::where('id', $id)->find();
  174. $f = [];
  175. if ($data['slider_image'] and $data['gatehead']){
  176. $f[] = Form::frameImages('gatehead', '门头图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'gatehead')), json_decode($data->getData('gatehead'), 1))->maxLength(5)->icon('images')->width('100%')->height('500px');
  177. $f[] = Form::frameImages('slider_image', '店内图片(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'slider_image')), json_decode($data->getData('slider_image'), 1))->maxLength(5)->icon('images')->width('100%')->height('500px');
  178. }else{
  179. $f[] = Form::frameImages('gatehead', '门头图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'gatehead')))->maxLength(5)->icon('images')->width('100%')->height('500px');
  180. $f[] = Form::frameImages('slider_image', '店内图片(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'slider_image')))->maxLength(5)->icon('images')->width('100%')->height('500px');
  181. }
  182. $f[] = Form::hidden('id', $id);
  183. $form = Form::make_post_form('修改', $f, Url::buildUrl('image_save', compact('id')));
  184. $this->assign(compact('form'));
  185. return $this->fetch('public/form-builder');
  186. }
  187. /**
  188. * 添加接口
  189. * @return void
  190. * @throws \think\db\exception\DataNotFoundException
  191. * @throws \think\db\exception\DbException
  192. * @throws \think\db\exception\ModelNotFoundException
  193. */
  194. public function image_save()
  195. {
  196. $data = UtilService::postMore([
  197. ['gatehead', ''],
  198. ['slider_image', ''],
  199. ['id']
  200. ]);
  201. if (empty($data['gatehead']) or empty($data['slider_image'])) return JsonService::fail('门头图或店内图不能为空');
  202. $store = SystemStoreModel::find($data['id']);
  203. $store['gatehead'] = json_encode($data['gatehead']);
  204. $store['slider_image'] = json_encode($data['slider_image']);
  205. $res = $store->save();
  206. if ($res) return JsonService::success('上传成功');
  207. return JsonService::fail('上传失败');
  208. }
  209. }