SystemStoreSender.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 SystemStoreSender 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_sender';
  25. public static function verificWhere()
  26. {
  27. return self::where('is_show', 1)->where('is_del', 0);
  28. }
  29. /**
  30. * 获取门店信息
  31. * @param int $id
  32. * @return array|\think\Model|null
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public static function getStoreDispose($id = 0, $store_id = 0)
  38. {
  39. if ($id)
  40. $storeInfo = self::verificWhere()->where('id', $id)->find();
  41. else
  42. // $storeInfo = self::verificWhere()->find();
  43. $storeInfo = [];
  44. if ($storeInfo) {
  45. if ($store_id && $store_id != $storeInfo) {
  46. goto end;
  47. }
  48. $storeInfo['store'] = SystemStore::get($storeInfo['store_id'])->toArray();
  49. } else {
  50. end:
  51. $storeInfo['id'] = 0;
  52. $storeInfo['store'] = [];
  53. }
  54. return $storeInfo;
  55. }
  56. /**
  57. * 获取门店列表
  58. * @param $where
  59. * @return array
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. */
  64. public static function getStoreList($where)
  65. {
  66. $model = new self();
  67. if (isset($where['store_id']) && $where['store_id'] != '') {
  68. $model = $model->where('store_id', $where['store_id']);
  69. }
  70. if (isset($where['name']) && $where['name'] != '') {
  71. $model = $model->where('id|name', 'like', '%' . $where['name'] . '%');
  72. }
  73. if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
  74. $model = $model->where($data);
  75. }
  76. $count = $model->count();
  77. $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
  78. $item['store'] = SystemStore::get($item['store_id'])->value('name');
  79. });
  80. if ($where['excel'] == 1) {
  81. $export = [];
  82. foreach ($data as $index => $item) {
  83. $export[] = [
  84. $item['name'],
  85. $item['store'],
  86. $item['phone'],
  87. ];
  88. }
  89. PHPExcelService::setExcelHeader(['配送员姓名', '所属门店', '配送员电话'])
  90. ->setExcelTile('配送员导出', '配送员信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
  91. ->setExcelContent($export)
  92. ->ExcelSave();
  93. }
  94. return compact('count', 'data');
  95. }
  96. /**
  97. * 获取连表查询条件
  98. * @param $type
  99. * @return array
  100. */
  101. public static function setData($type)
  102. {
  103. switch ((int)$type) {
  104. case 1:
  105. $data = ['is_show' => 1, 'is_del' => 0];
  106. break;
  107. case 2:
  108. $data = ['is_show' => 0, 'is_del' => 0];
  109. break;
  110. case 3:
  111. $data = ['is_del' => 1];
  112. break;
  113. };
  114. return isset($data) ? $data : [];
  115. }
  116. public static function dropList()
  117. {
  118. $model = new self();
  119. $model = $model->where('is_del', 0);
  120. $list = $model->select()
  121. ->toArray();
  122. return $list;
  123. }
  124. }