ActivityRecordList.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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\bargain;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\lists\ListsExcelInterface;
  22. use app\common\lists\ListsExtendInterface;
  23. use app\common\lists\ListsSearchInterface;
  24. use app\common\model\BargainInitiate;
  25. use app\common\service\FileService;
  26. /**
  27. * 砍价活动列表
  28. * Class BargainActivityLists
  29. * @package app\adminapi\lists\bargain
  30. */
  31. class ActivityRecordList extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
  32. {
  33. /**
  34. * @notes 导出字段
  35. * @return string[]
  36. * @author Tab
  37. * @date 2021/9/24 17:50
  38. */
  39. public function setExcelFields(): array
  40. {
  41. return [
  42. 'sn' => '记录编号',
  43. 'goods_name' => '商品名称',
  44. 'item_spec_value_str' => '商品规格',
  45. 'nickname' => '发起用户',
  46. 'help_num' => '帮砍次数',
  47. 'current_price' => '当前价格',
  48. 'status_desc' => '砍价状态',
  49. 'create_time' => '发起时间',
  50. ];
  51. }
  52. /**
  53. * @notes 导出表名
  54. * @return string
  55. * @author Tab
  56. * @date 2021/9/24 17:50
  57. */
  58. public function setFileName(): string
  59. {
  60. return '活动记录';
  61. }
  62. /**
  63. * @notes 设置搜索
  64. * @return array
  65. * @author Tab
  66. * @date 2021/9/24 17:30
  67. */
  68. public function setSearch(): array
  69. {
  70. return [
  71. '=' => ['status'],
  72. 'between_time' => 'create_time'
  73. ];
  74. }
  75. /**
  76. * @notes 附加搜索
  77. * @author Tab
  78. * @date 2021/9/24 15:54
  79. */
  80. public function attachSearch()
  81. {
  82. $this->searchWhere[] = ['bi.activity_id', '=', $this->params['id']];
  83. }
  84. /**
  85. * @notes 列表
  86. * @return array
  87. * @author Tab
  88. * @date 2021/9/24 17:50
  89. */
  90. public function lists() : array
  91. {
  92. // $this->attachSearch();
  93. $field = [
  94. 'bi.id',
  95. 'bi.sn',
  96. 'bi.goods_snapshot',
  97. 'bi.bargain_snapshot',
  98. 'bi.help_num',
  99. 'bi.current_price',
  100. 'bi.status',
  101. 'bi.status' => 'status_desc',
  102. 'bi.create_time',
  103. 'u.avatar',
  104. 'u.nickname',
  105. ];
  106. $lists = BargainInitiate::alias('bi')
  107. ->leftJoin('user u', 'u.id = bi.user_id')
  108. ->withSearch(['goods_info', 'user_info', 'activity_info'], $this->params)
  109. ->field($field)
  110. ->order('bi.create_time', 'desc')
  111. ->where($this->searchWhere)
  112. ->limit($this->limitOffset, $this->limitLength)
  113. ->select()
  114. ->toArray();
  115. foreach ($lists as &$item) {
  116. $item['goods_snapshot']['goods_image'] = FileService::getFileUrl($item['goods_snapshot']['goods_image']);
  117. $item['avatar'] = FileService::getFileUrl($item['avatar']);
  118. $item['goods_name'] = $item['goods_snapshot']['goods_name'];
  119. $item['item_spec_value_str'] = $item['goods_snapshot']['item_spec_value_str'];
  120. }
  121. return $lists;
  122. }
  123. /**
  124. * @notes 记录数
  125. * @return int
  126. * @author Tab
  127. * @date 2021/9/24 17:51
  128. */
  129. public function count() : int
  130. {
  131. // $this->attachSearch();
  132. $count = BargainInitiate::alias('bi')
  133. ->leftJoin('user u', 'u.id = bi.user_id')
  134. ->withSearch(['goods_info', 'user_info'], $this->params)
  135. ->where($this->searchWhere)
  136. ->count();
  137. return $count;
  138. }
  139. }