SystemStorePoint.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace app\admin\model\system;
  3. use app\admin\model\order\StoreOrder;
  4. use crmeb\traits\ModelTrait;
  5. use crmeb\basic\BaseModel;
  6. use crmeb\services\PHPExcelService;
  7. /**
  8. * 门店自提 model
  9. * Class SystemStore
  10. * @package app\admin\model\system
  11. */
  12. class SystemStorePoint extends BaseModel
  13. {
  14. use ModelTrait;
  15. /**
  16. * 数据表主键
  17. * @var string
  18. */
  19. protected $pk = 'id';
  20. /**
  21. * 模型名称
  22. * @var string
  23. */
  24. protected $name = 'system_store_point';
  25. public static function getLatlngAttr($value, $data)
  26. {
  27. return $data['latitude'] . ',' . $data['longitude'];
  28. }
  29. public static function verificWhere()
  30. {
  31. return self::where('is_show', 1)->where('is_del', 0);
  32. }
  33. /**
  34. * 获取门店信息
  35. * @param int $id
  36. * @return array|\think\Model|null
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public static function getStoreDispose($id = 0, $store_id = 0)
  42. {
  43. if ($id)
  44. $storeInfo = self::verificWhere()->where('id', $id)->find();
  45. else
  46. // $storeInfo = self::verificWhere()->find();
  47. $storeInfo = [];
  48. if ($storeInfo) {
  49. if ($store_id && $store_id != $storeInfo) {
  50. goto end;
  51. }
  52. $storeInfo['latlng'] = self::getLatlngAttr(null, $storeInfo);
  53. $storeInfo['valid_time'] = $storeInfo['valid_time'] ? explode(' - ', $storeInfo['valid_time']) : [];
  54. $storeInfo['day_time'] = $storeInfo['day_time'] ? explode(' - ', $storeInfo['day_time']) : [];
  55. $storeInfo['address'] = $storeInfo['address'] ? explode(',', $storeInfo['address']) : [];
  56. $storeInfo['store'] = SystemStore::get($storeInfo['store_id'])->toArray();
  57. } else {
  58. end:
  59. $storeInfo['latlng'] = [];
  60. $storeInfo['valid_time'] = [];
  61. $storeInfo['day_time'] = [];
  62. $storeInfo['address'] = [];
  63. $storeInfo['id'] = 0;
  64. $storeInfo['store'] = [];
  65. }
  66. return $storeInfo;
  67. }
  68. /**
  69. * 获取门店列表
  70. * @param $where
  71. * @return array
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\DbException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. */
  76. public static function getStoreList($where)
  77. {
  78. $model = new self();
  79. if (isset($where['store_id']) && $where['store_id'] != '') {
  80. $model = $model->where('store_id', $where['store_id']);
  81. }
  82. if (isset($where['name']) && $where['name'] != '') {
  83. $model = $model->where('id|name', 'like', '%' . $where['name'] . '%');
  84. }
  85. if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
  86. $model = $model->where($data);
  87. }
  88. $count = $model->count();
  89. $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
  90. $item['deposit'] = StoreOrder::where('store_id', $item['store_id'])
  91. ->where('point_id', $item['id'])
  92. ->where('paid', 1)
  93. ->where('is_del', 0)
  94. ->where('is_system_del', 0)
  95. ->where('refund_status', 0)->sum('deposit');
  96. $item['deposit_back'] = StoreOrder::where('store_id', $item['store_id'])
  97. ->where('point_id', $item['id'])
  98. ->where('paid', 1)
  99. ->where('is_del', 0)
  100. ->where('is_system_del', 0)
  101. ->where('refund_status', 0)->sum('deposit_back');
  102. $item['store'] = SystemStore::get($item['store_id'])->value('name');
  103. });
  104. if ($where['excel'] == 1) {
  105. $export = [];
  106. foreach ($data as $index => $item) {
  107. $export[] = [
  108. $item['name'],
  109. $item['store'],
  110. $item['phone'],
  111. $item['address'] .= ' ' . $item['detailed_address'],
  112. $item['deposit'],
  113. $item['deposit_back'],
  114. $item['day_time'],
  115. $item['valid_time']
  116. ];
  117. }
  118. PHPExcelService::setExcelHeader(['自提点名称', '所属门店', '自提点电话', '自提点地址', '总押金', '已退押金', '营业时间', '核销日期'])
  119. ->setExcelTile('自提点导出', '自提点信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  120. ->setExcelContent($export)
  121. ->ExcelSave();
  122. }
  123. return compact('count', 'data');
  124. }
  125. /**
  126. * 获取连表查询条件
  127. * @param $type
  128. * @return array
  129. */
  130. public static function setData($type)
  131. {
  132. switch ((int)$type) {
  133. case 1:
  134. $data = ['is_show' => 1, 'is_del' => 0];
  135. break;
  136. case 2:
  137. $data = ['is_show' => 0, 'is_del' => 0];
  138. break;
  139. case 3:
  140. $data = ['is_del' => 1];
  141. break;
  142. };
  143. return isset($data) ? $data : [];
  144. }
  145. public static function dropList()
  146. {
  147. $model = new self();
  148. $model = $model->where('is_del', 0);
  149. $list = $model->select()
  150. ->toArray();
  151. return $list;
  152. }
  153. }