SystemStore.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\admin\model\system;
  3. use crmeb\traits\ModelTrait;
  4. use crmeb\basic\BaseModel;
  5. use crmeb\services\PHPExcelService;
  6. /**
  7. * 门店自提 model
  8. * Class SystemStore
  9. * @package app\admin\model\system
  10. */
  11. class SystemStore extends BaseModel
  12. {
  13. use ModelTrait;
  14. /**
  15. * 数据表主键
  16. * @var string
  17. */
  18. protected $pk = 'id';
  19. /**
  20. * 模型名称
  21. * @var string
  22. */
  23. protected $name = 'system_store';
  24. public static function getLatlngAttr($value, $data)
  25. {
  26. return $data['latitude'] . ',' . $data['longitude'];
  27. }
  28. public static function verificWhere()
  29. {
  30. return self::where('is_show', 1)->where('is_del', 0);
  31. }
  32. /**
  33. * 获取门店信息
  34. * @param int $id
  35. * @return array|\think\Model|null
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public static function getStoreDispose($id = 0)
  41. {
  42. if ($id)
  43. $storeInfo = self::verificWhere()->where('id', $id)->find();
  44. else
  45. // $storeInfo = self::verificWhere()->find();
  46. $storeInfo = [];
  47. if ($storeInfo) {
  48. $storeInfo['latlng'] = self::getLatlngAttr(null, $storeInfo);
  49. $storeInfo['valid_time'] = $storeInfo['valid_time'] ? explode(' - ', $storeInfo['valid_time']) : [];
  50. $storeInfo['day_time'] = $storeInfo['day_time'] ? explode(' - ', $storeInfo['day_time']) : [];
  51. $storeInfo['address'] = $storeInfo['address'] ? explode(',', $storeInfo['address']) : [];
  52. } else {
  53. $storeInfo['latlng'] = [];
  54. $storeInfo['valid_time'] = [];
  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['name']) && $where['name'] != '') {
  74. $model = $model->where('id|name|introduction', 'like', '%' . $where['name'] . '%');
  75. }
  76. if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
  77. $model = $model->where($data);
  78. }
  79. $count = $model->count();
  80. $data = $model->page((int)$where['page'], (int)$where['limit'])->select();
  81. if ($where['excel'] == 1) {
  82. $export = [];
  83. foreach ($data as $index => $item) {
  84. $export[] = [
  85. $item['name'],
  86. $item['phone'],
  87. $item['address'] .= ' ' . $item['detailed_address'],
  88. $item['introduction'],
  89. $item['day_time'],
  90. $item['valid_time']
  91. ];
  92. }
  93. PHPExcelService::setExcelHeader(['门店名称', '门店电话', '门店地址', '门店简介', '营业时间', '核销日期'])
  94. ->setExcelTile('门店导出', '门店信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  95. ->setExcelContent($export)
  96. ->ExcelSave();
  97. }
  98. return compact('count', 'data');
  99. }
  100. /**
  101. * 获取连表查询条件
  102. * @param $type
  103. * @return array
  104. */
  105. public static function setData($type)
  106. {
  107. switch ((int)$type) {
  108. case 1:
  109. $data = ['is_show' => 1, 'is_del' => 0];
  110. break;
  111. case 2:
  112. $data = ['is_show' => 0, 'is_del' => 0];
  113. break;
  114. case 3:
  115. $data = ['is_del' => 1];
  116. break;
  117. };
  118. return isset($data) ? $data : [];
  119. }
  120. public static function dropList()
  121. {
  122. $model = new self();
  123. $model = $model->where('is_del', 0);
  124. $list = $model->select()
  125. ->toArray();
  126. return $list;
  127. }
  128. }