GiftCardInfoLists.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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\gift_card;
  20. use app\adminapi\{
  21. lists\BaseAdminDataLists,
  22. };
  23. use app\common\{
  24. lists\ListsExcelInterface,
  25. lists\ListsExtendInterface,
  26. model\GiftCardInfo};
  27. use app\common\service\FileService;
  28. use app\common\service\GiftCardQrCodeService;
  29. /**
  30. * 批次礼品卡信息列表接口
  31. * Class GoodsLists
  32. * @package app\adminapi\lists\goods
  33. */
  34. class GiftCardInfoLists extends BaseAdminDataLists implements ListsExtendInterface,ListsExcelInterface
  35. {
  36. // ... existing code ...
  37. /**
  38. * 批量生成二维码
  39. * @return array
  40. */
  41. public function batchGenerateQrCode()
  42. {
  43. $giftCards = GiftCardInfo::where($this->setSearch())
  44. ->field('id,card_no,card_pass')
  45. ->select()
  46. ->toArray();
  47. return GiftCardQrCodeService::batchGenerateQrCode($giftCards);
  48. }
  49. // ... existing code ...
  50. /**
  51. * @notes 搜索条件
  52. * @return array
  53. * @author cjhao
  54. * @date 2021/7/22 10:51
  55. */
  56. public function setSearch(): array
  57. {
  58. $where = [];
  59. $params = $this->params;
  60. //下单时间
  61. if (isset($params['start_time']) && $params['start_time'] != '') {
  62. $where[] = ['create_time', '>=', strtotime($params['start_time'])];
  63. }
  64. if (isset($params['end_time']) && $params['end_time'] != '') {
  65. $where[] = ['create_time', '<=', strtotime($params['end_time'])];
  66. }
  67. $where[]=['gc_id','=',$params['id']];
  68. if(isset($params['card_no'])){
  69. $where[] = ['card_no', 'like', '%' . $params['card_no'] . '%'];
  70. }
  71. if(isset($params['is_used'])){
  72. $where[] = ['is_used', '=', $params['is_used']];
  73. }
  74. return $where;
  75. }
  76. /**
  77. * @notes 统计信息
  78. * @return array
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\DbException
  81. * @throws \think\db\exception\ModelNotFoundException
  82. * @author cjhao
  83. * @date 2021/7/22 10:51
  84. */
  85. public function extend(): array
  86. {
  87. return [];
  88. }
  89. /**
  90. * @notes 礼品卡列表
  91. * @return array
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\DbException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. * @author cjhao
  96. * @date 2021/7/21 18:31
  97. */
  98. public function lists(): array
  99. {
  100. $lists = GiftCardInfo::where($this->setSearch())
  101. ->with(['user'])
  102. ->append(['is_used_desc','used_user_name','batch_no','qr_code_url'])
  103. ->limit($this->limitOffset, $this->limitLength)
  104. ->order('id', 'desc')
  105. ->select()
  106. ->toArray();
  107. //
  108. foreach ($lists as &$list) {
  109. $list['qr_code_path'] = FileService::getFileUrl($list['qr_code_path']);
  110. }
  111. return $lists;
  112. }
  113. /**
  114. * @notes 总数
  115. * @return int
  116. * @author cjhao
  117. * @date 2021/7/21 18:32
  118. */
  119. public function count(): int
  120. {
  121. return GiftCardInfo::where($this->setSearch())->count();
  122. }
  123. /**
  124. * @notes 设置excel表名
  125. * @return string
  126. * @author cjhao
  127. * @date 2021/9/23 9:52
  128. */
  129. public function setFileName(): string
  130. {
  131. return '礼品卡列表';
  132. }
  133. /**
  134. * @notes 设置导出字段
  135. * @return array
  136. * @author cjhao
  137. * @date 2021/9/23 9:59
  138. */
  139. public function setExcelFields(): array
  140. {
  141. return [
  142. 'batch_no' => '批次',
  143. 'card_no' => '礼品卡卡号',
  144. 'card_pass' => '礼品卡密码',
  145. 'card_money' => '礼品卡价值',
  146. 'is_used_desc' => '是否使用',
  147. 'used_user_name' => '使用人',
  148. 'used_time' => '使用时间',
  149. 'create_time'=> '创建时间',
  150. ];
  151. }
  152. }