SystemStoreServices.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. $list = $this->dao->getStoreList($where, $field, $page, $limit, $latitude, $longitude);
  47. foreach ($list as &$item) {
  48. if (isset($item['distance'])) {
  49. $item['range'] = bcdiv($item['distance'], '1000', 1);
  50. }
  51. }
  52. $count = $this->dao->count($where);
  53. return compact('list', 'count');
  54. }
  55. /**
  56. * 获取提货点头部统计信息
  57. * @return mixed
  58. */
  59. public function getStoreData()
  60. {
  61. $data['show'] = [
  62. 'name' => '显示中的提货点',
  63. 'num' => $this->dao->count(['type' => 0]),
  64. ];
  65. $data['hide'] = [
  66. 'name' => '隐藏中的提货点',
  67. 'num' => $this->dao->count(['type' => 1]),
  68. ];
  69. $data['recycle'] = [
  70. 'name' => '回收站的提货点',
  71. 'num' => $this->dao->count(['type' => 2])
  72. ];
  73. return $data;
  74. }
  75. /**
  76. * 保存或修改门店
  77. * @param int $id
  78. * @param array $data
  79. * @return mixed
  80. */
  81. public function saveStore(int $id, array $data)
  82. {
  83. return $this->transaction(function () use ($id, $data) {
  84. if ($id) {
  85. if ($this->dao->update($id, $data)) {
  86. return true;
  87. } else {
  88. throw new AdminException(100007);
  89. }
  90. } else {
  91. $data['add_time'] = time();
  92. $data['is_show'] = 1;
  93. if ($this->dao->save($data)) {
  94. return true;
  95. } else {
  96. throw new AdminException(100006);
  97. }
  98. }
  99. });
  100. }
  101. /**
  102. * 后台获取提货点详情
  103. * @param int $id
  104. * @param string $felid
  105. * @return array|false|mixed|string|string[]|\think\Model|null
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\DbException
  108. * @throws \think\db\exception\ModelNotFoundException
  109. */
  110. public function getStoreDispose(int $id, string $felid = '')
  111. {
  112. if ($felid) {
  113. return $this->dao->value(['id' => $id], $felid);
  114. } else {
  115. $storeInfo = $this->dao->get($id);
  116. if ($storeInfo) {
  117. $storeInfo['latlng'] = $storeInfo['latitude'] . ',' . $storeInfo['longitude'];
  118. $storeInfo['dataVal'] = $storeInfo['valid_time'] ? explode(' - ', $storeInfo['valid_time']) : [];
  119. $storeInfo['timeVal'] = $storeInfo['day_time'] ? explode(' - ', $storeInfo['day_time']) : [];
  120. $storeInfo['address2'] = $storeInfo['address'] ? explode(',', $storeInfo['address']) : [];
  121. return $storeInfo;
  122. }
  123. return false;
  124. }
  125. }
  126. /**
  127. * 获取门店不分页
  128. * @return array
  129. * @throws \think\db\exception\DataNotFoundException
  130. * @throws \think\db\exception\DbException
  131. * @throws \think\db\exception\ModelNotFoundException
  132. */
  133. public function getStore()
  134. {
  135. return $this->dao->getStore(['type' => 0]);
  136. }
  137. /**
  138. * 获得导出店员列表
  139. * @param array $where
  140. * @return array
  141. * @throws \think\db\exception\DataNotFoundException
  142. * @throws \think\db\exception\DbException
  143. * @throws \think\db\exception\ModelNotFoundException
  144. */
  145. public function getExportData(array $where)
  146. {
  147. return $this->dao->getStoreList($where, ['*']);
  148. }
  149. }