SystemStore.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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, 0);
  67. $this->assign(compact('store', 'type', 'company', 'admin_id', 'users'));
  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. ]);
  144. SystemStoreModel::beginTrans();
  145. try {
  146. $data['address'] = implode(',', $data['address']);
  147. $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng'];
  148. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return JsonService::fail('请选择门店位置');
  149. $data['latitude'] = $data['latlng'][0];
  150. $data['longitude'] = $data['latlng'][1];
  151. $data['valid_time'] = implode(' - ', $data['valid_time']);
  152. $data['day_time'] = implode(' - ', $data['day_time']);
  153. unset($data['latlng']);
  154. if ($data['image'] && strstr($data['image'], 'http') === false) {
  155. $site_url = sys_config('site_url');
  156. $data['image'] = $site_url . $data['image'];
  157. }
  158. if ($id) {
  159. $data['admin_id'] = intval($data['admin_id']);
  160. if (SystemStoreModel::where('id', $id)->update($data)) {
  161. SystemStoreModel::commitTrans();
  162. return JsonService::success('修改成功');
  163. } else {
  164. SystemStoreModel::rollbackTrans();
  165. return JsonService::fail('修改失败或者您没有修改什么!');
  166. }
  167. } else {
  168. $data['add_time'] = time();
  169. $data['is_show'] = 1;
  170. if ($res = SystemStoreModel::create($data)) {
  171. SystemStoreModel::commitTrans();
  172. return JsonService::success('保存成功', ['id' => $res->id]);
  173. } else {
  174. SystemStoreModel::rollbackTrans();
  175. return JsonService::fail('保存失败!');
  176. }
  177. }
  178. } catch (\Exception $e) {
  179. SystemStoreModel::rollbackTrans();
  180. return JsonService::fail($e->getMessage());
  181. }
  182. }
  183. public function init()
  184. {
  185. $store_id = $this->request->get('store_id');
  186. SystemStoreStock::store_init($store_id, 1);
  187. JsonService::success('保存成功');
  188. }
  189. public function apply()
  190. {
  191. $type = $this->request->param('type');
  192. $show = SystemStoreApply::where('status', 0)->count();//显示中的门店
  193. $hide = SystemStoreApply::where('status', 1)->count();//隐藏的门店
  194. $recycle = SystemStoreApply::where('status', 2)->count();//删除的门店
  195. if ($type == null) $type = 1;
  196. $this->assign(compact('type', 'show', 'hide', 'recycle'));
  197. return $this->fetch();
  198. }
  199. public function apply_list()
  200. {
  201. $where = UtilService::getMore([
  202. ['page', 1],
  203. ['limit', 20],
  204. ['name', ''],
  205. ['type', $this->request->param('type')]
  206. ]);
  207. return JsonService::successlayui(SystemStoreApply::getList($where));
  208. }
  209. /**
  210. * 门店审核
  211. * @param int $id
  212. * @return string
  213. */
  214. public function check_apply($id = 0)
  215. {
  216. $store = SystemStoreApply::getDetail($id);
  217. $users = User::field('uid,nickname,phone')->select();
  218. $this->assign(compact('store', 'users'));
  219. return $this->fetch();
  220. }
  221. /**
  222. * 保存修改门店信息
  223. * @param int $id
  224. */
  225. public function save_check_apply($id = 0)
  226. {
  227. $data = UtilService::postMore([
  228. ['name', ''],
  229. ['introduction', ''],
  230. ['image', ''],
  231. ['phone', ''],
  232. ['address', ''],
  233. ['detailed_address', ''],
  234. ['latlng', ''],
  235. ['uid', 0],
  236. ['spread_uid', 0],
  237. ['cert', ''],
  238. ['leader', ''],
  239. ['id_card', ''],
  240. ['status', 0],
  241. ['reason', ''],
  242. ]);
  243. SystemStoreApply::beginTrans();
  244. try {
  245. $data['address'] = implode(',', $data['address']);
  246. $data['latlng'] = is_string($data['latlng']) ? explode(',', $data['latlng']) : $data['latlng'];
  247. if (!isset($data['latlng'][0]) || !isset($data['latlng'][1])) return JsonService::fail('请选择门店位置');
  248. $data['latitude'] = $data['latlng'][0];
  249. $data['longitude'] = $data['latlng'][1];
  250. unset($data['latlng']);
  251. if ($data['image'] && strstr($data['image'], 'http') === false) {
  252. $site_url = sys_config('site_url');
  253. $data['image'] = $site_url . $data['image'];
  254. }
  255. if ($data['cert'] && strstr($data['cert'], 'http') === false) {
  256. $site_url = sys_config('site_url');
  257. $data['cert'] = $site_url . $data['cert'];
  258. }
  259. if (SystemStoreApply::where('id', $id)->update($data)) {
  260. if ($data['status'] == 1) {
  261. $store_date = $data;
  262. $store_date['admin_id'] = $this->adminId;
  263. $store_date['is_triple'] = 1;
  264. $store_date['day_time'] = '00:00:00 - 23:59:59';
  265. $store_date['add_time'] = time();
  266. $store_date['is_show'] = 1;
  267. if ($res = SystemStoreModel::create($store_date)) {
  268. User::where('uid', $data['uid'])->update(['user_store_id' => $res->id]);
  269. SystemStoreApply::commitTrans();
  270. return JsonService::success('审核成功', ['id' => $res->id]);
  271. } else {
  272. SystemStoreApply::rollbackTrans();
  273. return JsonService::fail('审核失败!');
  274. }
  275. }
  276. SystemStoreApply::commitTrans();
  277. return JsonService::success('审核成功');
  278. } else {
  279. SystemStoreApply::rollbackTrans();
  280. return JsonService::fail('修改失败或者您没有修改什么!');
  281. }
  282. } catch (\Exception $e) {
  283. SystemStoreApply::rollbackTrans();
  284. return JsonService::fail($e->getMessage());
  285. }
  286. }
  287. }