SystemStore.php 11 KB

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