DiscountLists.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\marketing;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\enum\GoodsEnum;
  22. use app\common\lists\ListsSearchInterface;
  23. use app\common\model\Goods;
  24. /**
  25. * 折扣列表
  26. * Class DiscountLists
  27. * @package app\adminapi\lists\marketing
  28. */
  29. class DiscountLists extends BaseAdminDataLists implements ListsSearchInterface
  30. {
  31. /**
  32. * @notes 设置搜索条件
  33. * @return array
  34. * @author cjhao
  35. * @date 2022/5/5 12:09
  36. */
  37. public function setSearch(): array
  38. {
  39. return array_intersect(array_keys($this->params), ['name', 'status', 'goods_type', 'discount']);
  40. }
  41. /**
  42. * @notes 折扣商品列表
  43. * @return array
  44. * @author cjhao
  45. * @date 2022/5/5 12:09
  46. */
  47. public function lists(): array
  48. {
  49. $lists = Goods::alias('G')
  50. ->leftJoin('discount_goods dg', 'G.id = dg.goods_id')
  51. ->withSearch($this->setSearch(), $this->params)
  52. ->field('G.id,image,name,type,status,spec_type,min_price,max_price,total_stock,sales_num+virtual_click_num as sales_num,is_discount')
  53. ->limit($this->limitOffset, $this->limitLength)
  54. ->order('id desc')
  55. ->select()->toArray();
  56. foreach ($lists as $key => $goods) {
  57. $lists[$key]['status_desc'] = GoodsEnum::getStatusDesc($goods['status']);
  58. $lists[$key]['price'] = $goods['min_price'];
  59. if ($goods['min_price'] != $goods['max_price']) {
  60. $lists[$key]['price'] = $goods['min_price'] . '~' . $goods['max_price'];
  61. }
  62. if (null == $goods['is_discount']) {
  63. $lists[$key]['is_discount'] = 0;
  64. }
  65. }
  66. return $lists;
  67. }
  68. /**
  69. * @notes 折扣商品统计
  70. * @return int
  71. * @author cjhao
  72. * @date 2022/5/5 12:09
  73. */
  74. public function count(): int
  75. {
  76. return Goods::alias('G')
  77. ->leftJoin('discount_goods dg', 'G.id = dg.goods_id')
  78. ->withSearch($this->setSearch(), $this->params)
  79. ->count();
  80. }
  81. }