SystemStorePoint.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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)
  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. $storeInfo['latlng'] = self::getLatlngAttr(null, $storeInfo);
  50. $storeInfo['valid_time'] = $storeInfo['valid_time'] ? explode(' - ', $storeInfo['valid_time']) : [];
  51. $storeInfo['day_time'] = $storeInfo['day_time'] ? explode(' - ', $storeInfo['day_time']) : [];
  52. $storeInfo['address'] = $storeInfo['address'] ? explode(',', $storeInfo['address']) : [];
  53. } else {
  54. $storeInfo['latlng'] = [];
  55. $storeInfo['valid_time'] = [];
  56. $storeInfo['day_time'] = [];
  57. $storeInfo['address'] = [];
  58. $storeInfo['id'] = 0;
  59. }
  60. return $storeInfo;
  61. }
  62. /**
  63. * 获取门店列表
  64. * @param $where
  65. * @return array
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\DbException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. */
  70. public static function getStoreList($where)
  71. {
  72. $model = new self();
  73. if (isset($where['store_id']) && $where['store_id'] != '') {
  74. $model = $model->where('store_id', $where['store_id']);
  75. }
  76. if (isset($where['name']) && $where['name'] != '') {
  77. $model = $model->where('id|name', 'like', '%' . $where['name'] . '%');
  78. }
  79. if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
  80. $model = $model->where($data);
  81. }
  82. $count = $model->count();
  83. $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
  84. $item['deposit'] = StoreOrder::where('store_id', $item['store_id'])
  85. ->where('point_id', $item['id'])
  86. ->where('paid', 1)
  87. ->where('is_del', 0)
  88. ->where('is_system_del', 0)
  89. ->where('refund_status', 0)->sum('deposit');
  90. $item['deposit_back'] = 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_back');
  96. $item['store'] = SystemStore::get($item['store_id'])->value('name');
  97. });
  98. if ($where['excel'] == 1) {
  99. $export = [];
  100. foreach ($data as $index => $item) {
  101. $export[] = [
  102. $item['name'],
  103. $item['store'],
  104. $item['phone'],
  105. $item['address'] .= ' ' . $item['detailed_address'],
  106. $item['deposit'],
  107. $item['deposit_back'],
  108. $item['day_time'],
  109. $item['valid_time']
  110. ];
  111. }
  112. PHPExcelService::setExcelHeader(['自提点名称', '所属门店', '自提点电话', '自提点地址', '总押金', '已退押金', '营业时间', '核销日期'])
  113. ->setExcelTile('自提点导出', '自提点信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  114. ->setExcelContent($export)
  115. ->ExcelSave();
  116. }
  117. return compact('count', 'data');
  118. }
  119. /**
  120. * 获取连表查询条件
  121. * @param $type
  122. * @return array
  123. */
  124. public static function setData($type)
  125. {
  126. switch ((int)$type) {
  127. case 1:
  128. $data = ['is_show' => 1, 'is_del' => 0];
  129. break;
  130. case 2:
  131. $data = ['is_show' => 0, 'is_del' => 0];
  132. break;
  133. case 3:
  134. $data = ['is_del' => 1];
  135. break;
  136. };
  137. return isset($data) ? $data : [];
  138. }
  139. public static function dropList()
  140. {
  141. $model = new self();
  142. $model = $model->where('is_del', 0);
  143. $list = $model->select()
  144. ->toArray();
  145. return $list;
  146. }
  147. }