SystemStoreServices.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\system\store;
  12. use app\dao\system\store\SystemStoreDao;
  13. use app\services\BaseServices;
  14. use crmeb\exceptions\AdminException;
  15. /**
  16. * 门店
  17. * Class SystemStoreServices
  18. * @package app\services\system\store
  19. * @method update($id, array $data, ?string $key = null) 修改数据
  20. * @method get(int $id, ?array $field = []) 获取数据
  21. */
  22. class SystemStoreServices extends BaseServices
  23. {
  24. /**
  25. * 构造方法
  26. * SystemStoreServices constructor.
  27. * @param SystemStoreDao $dao
  28. */
  29. public function __construct(SystemStoreDao $dao)
  30. {
  31. $this->dao = $dao;
  32. }
  33. /**
  34. * 获取提货点列表
  35. * @param array $where
  36. * @param string $latitude
  37. * @param string $longitude
  38. * @return array
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function getStoreList(array $where, array $field = ['*'], string $latitude = '', string $longitude = '')
  44. {
  45. [$page, $limit] = $this->getPageValue();
  46. $where['status'] = 1;
  47. $list = $this->dao->getStoreList($where, $field, $page, $limit, $latitude, $longitude);
  48. foreach ($list as &$item) {
  49. if (isset($item['distance'])) {
  50. $item['range'] = bcdiv($item['distance'], '1000', 1);
  51. }
  52. }
  53. $count = $this->dao->count($where);
  54. return compact('list', 'count');
  55. }
  56. /**
  57. * 获取提货点头部统计信息
  58. * @return mixed
  59. */
  60. public function getStoreData()
  61. {
  62. $data['show'] = [
  63. 'name' => '显示中的提货点',
  64. 'num' => $this->dao->count(['type' => 0]),
  65. ];
  66. $data['hide'] = [
  67. 'name' => '隐藏中的提货点',
  68. 'num' => $this->dao->count(['type' => 1]),
  69. ];
  70. $data['recycle'] = [
  71. 'name' => '回收站的提货点',
  72. 'num' => $this->dao->count(['type' => 2])
  73. ];
  74. return $data;
  75. }
  76. /**
  77. * 保存或修改门店
  78. * @param int $id
  79. * @param array $data
  80. * @return mixed
  81. */
  82. public function saveStore(int $id, array $data)
  83. {
  84. return $this->transaction(function () use ($id, $data) {
  85. if ($id) {
  86. if ($this->dao->update($id, $data)) {
  87. return true;
  88. } else {
  89. throw new AdminException(100007);
  90. }
  91. } else {
  92. $data['add_time'] = time();
  93. $data['is_show'] = 1;
  94. if ($this->dao->save($data)) {
  95. return true;
  96. } else {
  97. throw new AdminException(100006);
  98. }
  99. }
  100. });
  101. }
  102. /**
  103. * 后台获取提货点详情
  104. * @param int $id
  105. * @param string $felid
  106. * @return array|false|mixed|string|string[]|\think\Model|null
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\DbException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. */
  111. public function getStoreDispose(int $id, string $felid = '')
  112. {
  113. if ($felid) {
  114. return $this->dao->value(['id' => $id], $felid);
  115. } else {
  116. $storeInfo = $this->dao->get($id);
  117. if ($storeInfo) {
  118. $storeInfo['latlng'] = $storeInfo['latitude'] . ',' . $storeInfo['longitude'];
  119. $storeInfo['dataVal'] = $storeInfo['valid_time'] ? explode(' - ', $storeInfo['valid_time']) : [];
  120. $storeInfo['timeVal'] = $storeInfo['day_time'] ? explode(' - ', $storeInfo['day_time']) : [];
  121. $storeInfo['address2'] = $storeInfo['address'] ? explode(',', $storeInfo['address']) : [];
  122. return $storeInfo;
  123. }
  124. return false;
  125. }
  126. }
  127. /**
  128. * 获取门店不分页
  129. * @return array
  130. * @throws \think\db\exception\DataNotFoundException
  131. * @throws \think\db\exception\DbException
  132. * @throws \think\db\exception\ModelNotFoundException
  133. */
  134. public function getStore()
  135. {
  136. return $this->dao->getStore(['type' => 0]);
  137. }
  138. /**
  139. * 获得导出店员列表
  140. * @param array $where
  141. * @return array
  142. * @throws \think\db\exception\DataNotFoundException
  143. * @throws \think\db\exception\DbException
  144. * @throws \think\db\exception\ModelNotFoundException
  145. */
  146. public function getExportData(array $where)
  147. {
  148. return $this->dao->getStoreList($where, ['*']);
  149. }
  150. /**
  151. * 获取门店申请列表
  152. * @param array $where
  153. * @return array
  154. * @throws \think\db\exception\DataNotFoundException
  155. * @throws \think\db\exception\DbException
  156. * @throws \think\db\exception\ModelNotFoundException
  157. */
  158. public function getApplyList(array $where)
  159. {
  160. // 构建查询条件
  161. $searchWhere = [];
  162. if (isset($where['keywords']) && $where['keywords'] !== '') {
  163. $searchWhere[] = ['name|phone', 'like', '%' . $where['keywords'] . '%'];
  164. }
  165. if (isset($where['status']) && $where['status'] !== '') {
  166. $searchWhere['status'] = $where['status'];
  167. }
  168. // 只查询未删除的门店
  169. $searchWhere['is_del'] = 0;
  170. [$page, $limit] = $this->getPageValue();
  171. $list = $this->dao->getStoreList($searchWhere, ['*'], $page, $limit);
  172. $count = $this->dao->count($searchWhere);
  173. return compact('list', 'count');
  174. }
  175. }