SystemStore.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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['cid']) && $where['cid'] != '') {
  84. $cid = $where['cid'];
  85. $model = $model->where(function ($query) use ($cid) {
  86. $query->where('find_in_set("' . $cid . '",cid)');
  87. $cids = SystemStoreCategory::where('pid', $cid)->column('id');
  88. foreach ($cids as $v) {
  89. $query->whereOr('find_in_set("' . $v . '",cid)');
  90. }
  91. });
  92. }
  93. if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
  94. $model = $model->where($data);
  95. }
  96. $count = $model->count();
  97. $data = $model->page((int)$where['page'], (int)$where['limit'])->select();
  98. if ($where['excel'] == 1) {
  99. $export = [];
  100. foreach ($data as $index => $item) {
  101. $export[] = [
  102. $item['name'],
  103. $item['phone'],
  104. $item['address'] .= ' ' . $item['detailed_address'],
  105. $item['introduction'],
  106. $item['day_time'],
  107. $item['valid_time']
  108. ];
  109. }
  110. PHPExcelService::setExcelHeader(['门店名称', '门店电话', '门店地址', '门店简介', '营业时间', '核销日期'])
  111. ->setExcelTile('门店导出', '门店信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  112. ->setExcelContent($export)
  113. ->ExcelSave();
  114. }
  115. return compact('count', 'data');
  116. }
  117. /**
  118. * 获取连表查询条件
  119. * @param $type
  120. * @return array
  121. */
  122. public static function setData($type)
  123. {
  124. switch ((int)$type) {
  125. case 1:
  126. $data = ['is_show' => 1, 'is_del' => 0];
  127. break;
  128. case 2:
  129. $data = ['is_show' => 0, 'is_del' => 0];
  130. break;
  131. case 3:
  132. $data = ['is_del' => 1];
  133. break;
  134. };
  135. return isset($data) ? $data : [];
  136. }
  137. public static function dropList()
  138. {
  139. $model = new self();
  140. $model = $model->where('is_del', 0);
  141. $list = $model->select()
  142. ->toArray();
  143. return $list;
  144. }
  145. }