SystemStore.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\system\SystemAdmin;
  5. use app\admin\model\user\User;
  6. use app\models\system\SystemStoreApply;
  7. use app\models\system\SystemStoreStock;
  8. use crmeb\services\JsonService;
  9. use crmeb\services\JsonService as Json;
  10. use app\admin\model\system\SystemStore as SystemStoreModel;
  11. use crmeb\services\UtilService;
  12. /**
  13. * 门店管理控制器
  14. * Class SystemAttachment
  15. * @package app\admin\controller\system
  16. *
  17. */
  18. class SystemStore extends AuthController
  19. {
  20. /**
  21. * 门店列表
  22. */
  23. public function list()
  24. {
  25. $where = UtilService::getMore([
  26. ['page', 1],
  27. ['limit', 20],
  28. ['name', ''],
  29. ['excel', 0],
  30. ['cid', ''],
  31. ['type', $this->request->param('type')]
  32. ]);
  33. return JsonService::successlayui(SystemStoreModel::getStoreList($where));
  34. }
  35. /**
  36. * 门店设置
  37. * @return string
  38. */
  39. public function index()
  40. {
  41. $type = $this->request->param('type');
  42. $show = SystemStoreModel::where('is_show', 1)->where('is_del', 0)->count();//显示中的门店
  43. $hide = SystemStoreModel::where('is_show', 0)->count();//隐藏的门店
  44. $recycle = SystemStoreModel::where('is_del', 1)->count();//删除的门店
  45. if ($type == null) $type = 1;
  46. $this->assign(compact('type', 'show', 'hide', 'recycle'));
  47. return $this->fetch();
  48. }
  49. /**
  50. * 门店添加
  51. * @param int $id
  52. * @return string
  53. */
  54. public function add($id = 0)
  55. {
  56. $admininfo = $this->adminInfo;
  57. $store = SystemStoreModel::getStoreDispose($id);
  58. $type = $admininfo['type'];
  59. $where = UtilService::getMore([
  60. ['level', bcadd($admininfo->level, 1, 0)],
  61. ['type', 1],
  62. ]);
  63. $admin_id = $this->adminId;
  64. $company = SystemAdmin::where('level', bcadd($admininfo->level, 1, 0))->where('type', 1)->field('id,real_name')->select();
  65. $users = User::field('uid,nickname,phone')->select();
  66. $category = \app\admin\model\system\SystemStoreCategory::getTierList(null, 1);
  67. $this->assign(compact('store', 'type', 'company', 'admin_id', 'users', 'category'));
  68. return $this->fetch();
  69. }
  70. /**
  71. * 删除恢复门店
  72. * @param $id
  73. */
  74. public function delete($id)
  75. {
  76. if (!$id) return $this->failed('数据不存在');
  77. if (!SystemStoreModel::be(['id' => $id])) return $this->failed('产品数据不存在');
  78. if (SystemStoreModel::be(['id' => $id, 'is_del' => 1])) {
  79. $data['is_del'] = 0;
  80. if (!SystemStoreModel::edit($data, $id))
  81. return Json::fail(SystemStoreModel::getErrorInfo('恢复失败,请稍候再试!'));
  82. else
  83. return Json::successful('恢复门店成功!');
  84. } else {
  85. $data['is_del'] = 1;
  86. if (!SystemStoreModel::edit($data, $id))
  87. return Json::fail(SystemStoreModel::getErrorInfo('删除失败,请稍候再试!'));
  88. else
  89. return Json::successful('删除门店成功!');
  90. }
  91. }
  92. /**
  93. * 设置单个门店是否显示
  94. * @param string $is_show
  95. * @param string $id
  96. * @return json
  97. */
  98. public function set_show($is_show = '', $id = '')
  99. {
  100. ($is_show == '' || $id == '') && JsonService::fail('缺少参数');
  101. $res = SystemStoreModel::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  102. if ($res) {
  103. return JsonService::successful($is_show == 1 ? '设置显示成功' : '设置隐藏成功');
  104. } else {
  105. return JsonService::fail($is_show == 1 ? '设置显示失败' : '设置隐藏失败');
  106. }
  107. }
  108. /**
  109. * 位置选择
  110. * @return string|void
  111. */
  112. public function select_address()
  113. {
  114. $key = sys_config('tengxun_map_key');
  115. if (!$key) return $this->failed('请前往设置->物流设置->物流配置 配置腾讯地图KEY', '#');
  116. $this->assign(compact('key'));
  117. return $this->fetch();
  118. }
  119. /**
  120. * 保存修改门店信息
  121. * @param int $id
  122. */
  123. public function save($id = 0)
  124. {
  125. $data = UtilService::postMore([
  126. ['name', ''],
  127. ['introduction', ''],
  128. ['image', ''],
  129. ['phone', ''],
  130. ['address', ''],
  131. ['detailed_address', ''],
  132. ['latlng', ''],
  133. ['valid_time', []],
  134. ['day_time', []],
  135. ['terminal_number', ''],
  136. ['admin_id', $this->adminId],
  137. ['uid', 0],
  138. ['is_triple', 0],
  139. ['recommend', 0],
  140. ['commission', 0],
  141. ['commission_order', 0],
  142. ['spread_uid', 0],
  143. ['cid', []],
  144. ]);
  145. SystemStoreModel::beginTrans();
  146. try {
  147. $data['address'] = implode(',', $data['address']);
  148. $data['cid'] = implode(',', $data['cid']);
  149. $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng'];
  150. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return JsonService::fail('请选择门店位置');
  151. $data['latitude'] = $data['latlng'][0];
  152. $data['longitude'] = $data['latlng'][1];
  153. $data['valid_time'] = implode(' - ', $data['valid_time']);
  154. $data['day_time'] = implode(' - ', $data['day_time']);
  155. unset($data['latlng']);
  156. if ($data['image'] && strstr($data['image'], 'http') === false) {
  157. $site_url = sys_config('site_url');
  158. $data['image'] = $site_url . $data['image'];
  159. }
  160. if ($id) {
  161. $data['admin_id'] = intval($data['admin_id']);
  162. if (SystemStoreModel::where('id', $id)->update($data)) {
  163. SystemStoreModel::commitTrans();
  164. return JsonService::success('修改成功');
  165. } else {
  166. SystemStoreModel::rollbackTrans();
  167. return JsonService::fail('修改失败或者您没有修改什么!');
  168. }
  169. } else {
  170. $data['add_time'] = time();
  171. $data['is_show'] = 1;
  172. if ($res = SystemStoreModel::create($data)) {
  173. SystemStoreModel::commitTrans();
  174. return JsonService::success('保存成功', ['id' => $res->id]);
  175. } else {
  176. SystemStoreModel::rollbackTrans();
  177. return JsonService::fail('保存失败!');
  178. }
  179. }
  180. } catch (\Exception $e) {
  181. SystemStoreModel::rollbackTrans();
  182. return JsonService::fail($e->getMessage());
  183. }
  184. }
  185. public function init()
  186. {
  187. $store_id = $this->request->get('store_id');
  188. SystemStoreStock::store_init($store_id, 1);
  189. JsonService::success('保存成功');
  190. }
  191. public function apply()
  192. {
  193. $type = $this->request->param('type');
  194. $show = SystemStoreApply::where('status', 0)->count();//显示中的门店
  195. $hide = SystemStoreApply::where('status', 1)->count();//隐藏的门店
  196. $recycle = SystemStoreApply::where('status', 2)->count();//删除的门店
  197. if ($type == null) $type = 1;
  198. $this->assign(compact('type', 'show', 'hide', 'recycle'));
  199. return $this->fetch();
  200. }
  201. public function apply_list()
  202. {
  203. $where = UtilService::getMore([
  204. ['page', 1],
  205. ['limit', 20],
  206. ['name', ''],
  207. ['type', $this->request->param('type')]
  208. ]);
  209. return JsonService::successlayui(SystemStoreApply::getList($where));
  210. }
  211. /**
  212. * 门店审核
  213. * @param int $id
  214. * @return string
  215. */
  216. public function check_apply($id = 0)
  217. {
  218. $store = SystemStoreApply::getDetail($id);
  219. $users = User::field('uid,nickname,phone')->select();
  220. $this->assign(compact('store', 'users'));
  221. return $this->fetch();
  222. }
  223. /**
  224. * 保存修改门店信息
  225. * @param int $id
  226. */
  227. public function save_check_apply($id = 0)
  228. {
  229. $data = UtilService::postMore([
  230. ['name', ''],
  231. ['introduction', ''],
  232. ['image', ''],
  233. ['phone', ''],
  234. ['address', ''],
  235. ['detailed_address', ''],
  236. ['latlng', ''],
  237. ['uid', 0],
  238. ['spread_uid', 0],
  239. ['cert', ''],
  240. ['leader', ''],
  241. ['id_card', ''],
  242. ['status', 0],
  243. ['reason', ''],
  244. ]);
  245. SystemStoreApply::beginTrans();
  246. try {
  247. $data['address'] = implode(',', $data['address']);
  248. $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng'];
  249. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return JsonService::fail('请选择门店位置');
  250. $data['latitude'] = $data['latlng'][0];
  251. $data['longitude'] = $data['latlng'][1];
  252. unset($data['latlng']);
  253. if ($data['image'] && strstr($data['image'], 'http') === false) {
  254. $site_url = sys_config('site_url');
  255. $data['image'] = $site_url . $data['image'];
  256. }
  257. if ($data['cert'] && strstr($data['cert'], 'http') === false) {
  258. $site_url = sys_config('site_url');
  259. $data['cert'] = $site_url . $data['cert'];
  260. }
  261. if (SystemStoreApply::where('id', $id)->update($data)) {
  262. if ($data['status'] == 1) {
  263. $store_date = $data;
  264. $store_date['admin_id'] = $this->adminId;
  265. $store_date['is_triple'] = 1;
  266. $store_date['day_time'] = '00:00:00 - 23:59:59';
  267. $store_date['add_time'] = time();
  268. $store_date['is_show'] = 1;
  269. if ($res = SystemStoreModel::create($store_date)) {
  270. User::where('uid', $data['uid'])->update(['user_store_id' => $res->id]);
  271. SystemStoreApply::commitTrans();
  272. return JsonService::success('审核成功', ['id' => $res->id]);
  273. } else {
  274. SystemStoreApply::rollbackTrans();
  275. return JsonService::fail('审核失败!');
  276. }
  277. }
  278. SystemStoreApply::commitTrans();
  279. return JsonService::success('审核成功');
  280. } else {
  281. SystemStoreApply::rollbackTrans();
  282. return JsonService::fail('修改失败或者您没有修改什么!');
  283. }
  284. } catch (\Exception $e) {
  285. SystemStoreApply::rollbackTrans();
  286. return JsonService::fail($e->getMessage());
  287. }
  288. }
  289. }