SystemStore.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 SystemStore 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';
  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. $storeInfo['pictures'] = $storeInfo['pictures'] ? explode(',', $storeInfo['pictures']) : [];
  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()->each(function ($item) {
  83. $item['deposit'] = StoreOrder::where('store_id', $item['id'])
  84. ->where('paid', 1)
  85. ->where('is_del', 0)
  86. ->where('is_system_del', 0)
  87. ->where('refund_status', 0)->sum('deposit');
  88. $item['deposit_back'] = StoreOrder::where('store_id', $item['id'])
  89. ->where('paid', 1)
  90. ->where('is_del', 0)
  91. ->where('is_system_del', 0)
  92. ->where('refund_status', 0)->sum('deposit_back');
  93. });
  94. if ($where['excel'] == 1) {
  95. $export = [];
  96. foreach ($data as $index => $item) {
  97. $export[] = [
  98. $item['name'],
  99. $item['phone'],
  100. $item['address'] .= ' ' . $item['detailed_address'],
  101. $item['deposit'],
  102. $item['deposit_back'],
  103. $item['introduction'],
  104. $item['day_time'],
  105. $item['valid_time']
  106. ];
  107. }
  108. PHPExcelService::setExcelHeader(['门店名称', '门店电话', '门店地址', '总押金', '已退押金', '门店简介', '营业时间', '核销日期'])
  109. ->setExcelTile('门店导出', '门店信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  110. ->setExcelContent($export)
  111. ->ExcelSave();
  112. }
  113. return compact('count', 'data');
  114. }
  115. /**
  116. * 获取连表查询条件
  117. * @param $type
  118. * @return array
  119. */
  120. public static function setData($type)
  121. {
  122. switch ((int)$type) {
  123. case 1:
  124. $data = ['is_show' => 1, 'is_del' => 0];
  125. break;
  126. case 2:
  127. $data = ['is_show' => 0, 'is_del' => 0];
  128. break;
  129. case 3:
  130. $data = ['is_del' => 1];
  131. break;
  132. };
  133. return isset($data) ? $data : [];
  134. }
  135. public static function dropList()
  136. {
  137. $model = new self();
  138. $model = $model->where('is_del', 0);
  139. $list = $model->select()
  140. ->toArray();
  141. return $list;
  142. }
  143. //获取某用户的详细信息
  144. public static function getStoreInfo($uid)
  145. {
  146. $item = self::get($uid);
  147. $Address = '';
  148. return [
  149. ['image' => false, 'col' => 12, 'name' => '门店名称', 'value' => $item['name'] ?: ''],
  150. ['image' => true, 'col' => 12, 'name' => 'LOGO', 'value' => $item['image'] ?: ''],
  151. ['image' => false, 'col' => 12, 'name' => '门店地址', 'value' => $item['address'] ?: '' . ' ' . ($item['detailed_address' ?: ''])],
  152. ['image' => false, 'name' => '门店坐标', 'value' => '[' . ($item['latitude'] ?: 0) . ',' . ($item['longitude'] ?: 0) . ']'],
  153. ['image' => false, 'name' => '营业时间', 'value' => $item['day_time'] ?: ''],
  154. ['image' => false, 'name' => '门店佣金', 'value' => $item['brokerage_price'] ?: 0],
  155. ['image' => false, 'col' => 12, 'name' => '简介', 'value' => $item['introduction'] ?: ''],
  156. ];
  157. }
  158. }