SystemStore.php 4.5 KB

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