GoodsCommentAssistantLists.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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\goods;
  20. use app\adminapi\lists\BaseAdminDataLists;
  21. use app\common\enum\DeliveryEnum;
  22. use app\common\enum\GoodsEnum;
  23. use app\common\enum\YesNoEnum;
  24. use app\common\lists\ListsSearchInterface;
  25. use app\common\model\Goods;
  26. /**
  27. * 商品列表接口
  28. * Class GoodsCommentAssistantLists
  29. * @package app\adminapi\lists\goods
  30. */
  31. class GoodsCommentAssistantLists extends BaseAdminDataLists
  32. {
  33. /**
  34. * @notes 搜索条件
  35. * @author Tab
  36. * @datetime 2022/1/18 9:06
  37. */
  38. public function setSearch()
  39. {
  40. // 商品名称
  41. if (isset($this->params['goods_name']) && $this->params['goods_name'] != '') {
  42. $this->searchWhere[] = ['name', 'like', '%' . $this->params['goods_name'] . '%'];
  43. }
  44. // 销售状态
  45. if (isset($this->params['status']) && in_array($this->params['status'], [GoodsEnum::STATUS_STORAGE, GoodsEnum::STATUS_SELL])) {
  46. $this->searchWhere[] = ['status', '=', $this->params['status']];
  47. }
  48. // 配送方式
  49. if (isset($this->params['delivery_type']) && $this->params['delivery_type'] == DeliveryEnum::EXPRESS_DELIVERY) {
  50. $this->searchWhere[] = ['is_express', '=', YesNoEnum::YES];
  51. }
  52. if (isset($this->params['delivery_type']) && $this->params['delivery_type'] == DeliveryEnum::SELF_DELIVERY) {
  53. $this->searchWhere[] = ['is_selffetch', '=', YesNoEnum::YES];
  54. }
  55. }
  56. public function lists(): array
  57. {
  58. $this->setSearch();
  59. $field = [
  60. 'id',
  61. 'image',
  62. 'name',
  63. 'spec_type',
  64. 'min_price',
  65. 'max_price',
  66. 'total_stock',
  67. 'sales_num',
  68. 'status',
  69. 'create_time',
  70. ];
  71. $lists = Goods::field($field)
  72. ->append(['price_text', 'category_text', 'status_text', 'comment_text'])
  73. ->withSearch(['category_id'], $this->params)
  74. ->where($this->searchWhere)
  75. ->order('id', 'desc')
  76. ->limit($this->limitOffset, $this->limitLength)
  77. ->select()
  78. ->toArray();
  79. return $lists;
  80. }
  81. public function count(): int
  82. {
  83. $this->setSearch();
  84. $field = [
  85. 'id',
  86. 'image',
  87. 'name',
  88. 'spec_type',
  89. 'min_price',
  90. 'max_price',
  91. 'total_stock',
  92. 'sales_num',
  93. 'status',
  94. 'create_time',
  95. ];
  96. $count = Goods::field($field)
  97. ->append(['price_text', 'category_text', 'status_text', 'comment_text'])
  98. ->where($this->searchWhere)
  99. ->count();
  100. return $count;
  101. }
  102. }