GiftCardInfoLists.php 4.8 KB

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