LuckyDrawList.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\lists\lucky_draw;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\enum\LuckyDrawEnum;
  22. use app\common\lists\ListsExcelInterface;
  23. use app\common\lists\ListsExtendInterface;
  24. use app\common\model\LuckyDraw;
  25. /**
  26. * 幸运抽奖活动列表
  27. */
  28. class LuckyDrawList extends BaseAdminDataLists implements ListsExtendInterface,ListsExcelInterface
  29. {
  30. public function setExcelFields(): array
  31. {
  32. return [
  33. 'name' => '活动名称',
  34. 'start_time_desc' => '开始时间',
  35. 'end_time_desc' => '结束时间',
  36. 'join_num' => '抽奖人数',
  37. 'win_num' => '中奖人数',
  38. 'status_desc' => '活动状态',
  39. 'create_time' => '创建时间',
  40. ];
  41. }
  42. public function setFileName(): string
  43. {
  44. return '幸运抽奖活动列表';
  45. }
  46. public function extend()
  47. {
  48. $all = LuckyDraw::count();
  49. $wait = LuckyDraw::where('status', LuckyDrawEnum::WAIT)->count();
  50. $ing = LuckyDraw::where('status', LuckyDrawEnum::ING)->count();
  51. $end = LuckyDraw::where('status', LuckyDrawEnum::END)->count();
  52. return [
  53. 'all' => $all,
  54. 'wait' => $wait,
  55. 'ing' => $ing,
  56. 'end' => $end,
  57. ];
  58. }
  59. /**
  60. * @notes 附加搜索条件
  61. * @author Tab
  62. * @date 2021/11/25 17:36
  63. */
  64. public function setSearch()
  65. {
  66. if (isset($this->params['status']) && trim($this->params['status']) != '') {
  67. $this->searchWhere[] = ['status', '=', $this->params['status']];
  68. }
  69. if (isset($this->params['name']) && !empty($this->params['name'])) {
  70. $this->searchWhere[] = ['name', 'like', '%' . trim($this->params['name']) . '%'];
  71. }
  72. if (isset($this->params['start_time']) && isset($this->params['end_time']) && !empty($this->params['start_time']) && !empty($this->params['end_time'])) {
  73. $this->searchWhere[] = ['start_time', '<=', strtotime($this->params['start_time'])];
  74. $this->searchWhere[] = ['end_time', '>=', strtotime($this->params['end_time'])];
  75. }
  76. }
  77. public function lists(): array
  78. {
  79. $this->setSearch();
  80. $field = [
  81. 'id',
  82. 'name',
  83. 'start_time',
  84. 'end_time',
  85. 'status',
  86. 'create_time',
  87. ];
  88. $lists = LuckyDraw::field($field)
  89. ->append(['start_time_desc', 'end_time_desc','join_num', 'win_num', 'status_desc'])
  90. ->where($this->searchWhere)
  91. ->order('id', 'desc')
  92. ->limit($this->limitOffset, $this->limitLength)
  93. ->select()
  94. ->toArray();
  95. return $lists;
  96. }
  97. public function count(): int
  98. {
  99. $this->setSearch();
  100. $count = LuckyDraw::where($this->searchWhere)->count();
  101. return $count;
  102. }
  103. }