PresellLists.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\adminapi\lists\marketing;
  3. use app\adminapi\lists\BaseAdminDataLists;
  4. use app\common\enum\PresellEnum;
  5. use app\common\lists\ListsExcelInterface;
  6. use app\common\lists\ListsExtendInterface;
  7. use app\common\model\Presell;
  8. /**
  9. * @notes notes
  10. * author lbzy
  11. * @datetime 2024-04-24 14:09:18
  12. * @class PresellLists
  13. * @package app\adminapi\lists\marketing
  14. */
  15. class PresellLists extends BaseAdminDataLists implements ListsExtendInterface, ListsExcelInterface
  16. {
  17. function setExcelFields(): array
  18. {
  19. return [
  20. 'sn' => '预售编号',
  21. 'name' => '预售名称',
  22. 'start_time' => '开始时间',
  23. 'end_time' => '结束时间',
  24. 'create_time' => '创建时间',
  25. ];
  26. }
  27. public function setFileName(): string
  28. {
  29. return '预售列表';
  30. }
  31. /**
  32. * @inheritDoc
  33. */
  34. public function lists(): array
  35. {
  36. $withSearch = [ 'goods', 'name', 'start_time', 'end_time', 'status' ];
  37. $lists = Presell::alias('p')
  38. ->withSearch($withSearch, $this->params)
  39. ->append([ 'type_text', 'status_text', 'send_type_text' ])
  40. ->order('p.id desc')
  41. ->limit($this->limitOffset, $this->limitLength)
  42. ->select()
  43. ->toArray();
  44. return $lists;
  45. }
  46. /**
  47. * @inheritDoc
  48. */
  49. public function count(): int
  50. {
  51. $withSearch = [ 'goods', 'name', 'start_time', 'end_time', 'status' ];
  52. return Presell::alias('p')
  53. ->withSearch($withSearch, $this->params)
  54. ->order('p.id desc')
  55. ->count();
  56. }
  57. public function extend()
  58. {
  59. $withSearch = [ 'goods', 'name', 'start_time', 'end_time' ];
  60. $lists = Presell::alias('p')
  61. ->withSearch($withSearch, $this->params)
  62. ->field([ 'status,count(*) as count' ])
  63. ->group('status')
  64. ->select()->toArray();
  65. $lists = array_column($lists, 'count', 'status');
  66. return [
  67. 'all' => array_sum($lists),
  68. 'wait' => $lists[PresellEnum::STATUS_WAIT] ?? 0,
  69. 'start' => $lists[PresellEnum::STATUS_START] ?? 0,
  70. 'end' => $lists[PresellEnum::STATUS_END] ?? 0,
  71. ];
  72. }
  73. }