SystemStore.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. $storeInfo['cid'] = $storeInfo['cid'] ? explode(',', $storeInfo['cid']) : [];
  53. $storeInfo['is_triple'] = $storeInfo['is_triple'] ? (string)$storeInfo['is_triple'] : "0";
  54. } else {
  55. $storeInfo['latlng'] = [];
  56. $storeInfo['valid_time'] = [];
  57. $storeInfo['valid_time'] = [];
  58. $storeInfo['day_time'] = [];
  59. $storeInfo['address'] = [];
  60. $storeInfo['id'] = 0;
  61. }
  62. return $storeInfo;
  63. }
  64. /**
  65. * 获取门店列表
  66. * @param $where
  67. * @return array
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public static function getStoreList($where)
  73. {
  74. $model = new self();
  75. if (isset($where['name']) && $where['name'] != '') {
  76. $model = $model->where('id|name|introduction', 'like', '%' . $where['name'] . '%');
  77. }
  78. if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
  79. $model = $model->where($data);
  80. }
  81. $count = $model->count();
  82. $data = $model->page((int)$where['page'], (int)$where['limit'])->select();
  83. if ($where['excel'] == 1) {
  84. $export = [];
  85. foreach ($data as $index => $item) {
  86. $export[] = [
  87. $item['name'],
  88. $item['phone'],
  89. $item['address'] .= ' ' . $item['detailed_address'],
  90. $item['introduction'],
  91. $item['day_time'],
  92. $item['valid_time']
  93. ];
  94. }
  95. PHPExcelService::setExcelHeader(['门店名称', '门店电话', '门店地址', '门店简介', '营业时间', '核销日期'])
  96. ->setExcelTile('门店导出', '门店信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  97. ->setExcelContent($export)
  98. ->ExcelSave();
  99. }
  100. return compact('count', 'data');
  101. }
  102. /**
  103. * 获取连表查询条件
  104. * @param $type
  105. * @return array
  106. */
  107. public static function setData($type)
  108. {
  109. switch ((int)$type) {
  110. case 1:
  111. $data = ['is_show' => 1, 'is_del' => 0];
  112. break;
  113. case 2:
  114. $data = ['is_show' => 0, 'is_del' => 0];
  115. break;
  116. case 3:
  117. $data = ['is_del' => 1];
  118. break;
  119. };
  120. return isset($data) ? $data : [];
  121. }
  122. public static function dropList()
  123. {
  124. $model = new self();
  125. $model = $model->where('is_del', 0);
  126. $list = $model->select()
  127. ->toArray();
  128. return $list;
  129. }
  130. }