GoodsCommonLists.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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\ActivityEnum,
  22. enum\GoodsEnum,
  23. enum\YesNoEnum,
  24. model\DiscountGoods,
  25. model\DistributionGoods,
  26. model\Goods,
  27. model\GoodsItem,
  28. lists\ListsSearchInterface};
  29. /**
  30. * 商品公共列表
  31. * Class GoodsCommonLists
  32. * @package app\adminapi\lists\goods
  33. */
  34. class GoodsCommonLists extends BaseAdminDataLists
  35. {
  36. function where(): array
  37. {
  38. $where[] = ['status','=',1];
  39. if (isset($this->params['name']) && $this->params['name'] != '') {
  40. $where[] = ['name','like','%'.$this->params['name'].'%'];
  41. }
  42. if (isset($this->params['is_distribution']) && $this->params['is_distribution'] != '') {
  43. // 获取已开启分销的商品id
  44. $joinIds = DistributionGoods::where('is_distribution', YesNoEnum::YES)->column('goods_id');
  45. if ($this->params['is_distribution'] == 1) {
  46. $where[] = ['id','in',$joinIds];
  47. }
  48. if ($this->params['is_distribution'] == 0) {
  49. $where[] = ['id','not in',$joinIds];
  50. }
  51. }
  52. if (isset($this->params['is_discount']) && $this->params['is_discount'] != '') {
  53. // 获取已开启会员折扣的商品id
  54. $joinIds = DiscountGoods::where('is_discount', YesNoEnum::YES)->column('goods_id');
  55. if ($this->params['is_discount'] == 1) {
  56. $where[] = ['id','in',$joinIds];
  57. }
  58. if ($this->params['is_discount'] == 0) {
  59. $where[] = ['id','not in',$joinIds];
  60. }
  61. }
  62. return $where;
  63. }
  64. public function lists(): array
  65. {
  66. $lists = Goods::where($this->where())
  67. ->limit($this->limitOffset, $this->limitLength)
  68. ->order('id', 'desc')
  69. ->field('id,code,name,image,total_stock,spec_type,virtual_sales_num+sales_num as sales_num,max_price,max_lineation_price,min_price as sell_price,min_lineation_price as lineation_price')
  70. ->append(['is_distribution','is_discount'])
  71. ->select()
  72. ->toArray();
  73. $lists = array_column($lists,null,'id');
  74. //显示规格信息
  75. $isSpec = $this->params['is_spec'] ?? 0;
  76. foreach ($lists as $goodskey => $goodsVal){
  77. $isSpec && $lists[$goodskey]['item'] = [];
  78. $lists[$goodskey]['price'] = '¥'.$goodsVal['sell_price'].'~'.'¥'.$goodsVal['max_price'];
  79. if($goodsVal['sell_price'] !== $goodsVal['max_price']){
  80. $lists[$goodskey]['price'] = '¥'.$goodsVal['sell_price'];
  81. }
  82. }
  83. if($isSpec){
  84. $goodsIds = array_keys($lists);
  85. //显示商品规格
  86. if($goodsIds){
  87. $goodsItemList = GoodsItem::where(['goods_id'=>$goodsIds])
  88. ->field('id,image,goods_id,spec_value_ids,spec_value_str,stock,sell_price')
  89. ->select();
  90. foreach ($goodsItemList as $item){
  91. // if(isset($lists[$item['goods_id']]) && GoodsEnum::SEPC_TYPE_MORE == $lists[$item['goods_id']]['spec_type']){
  92. $lists[$item['goods_id']]['item'][] = $item;
  93. // }
  94. }
  95. }
  96. }
  97. return array_values($lists);
  98. }
  99. public function count(): int
  100. {
  101. $count = Goods::where($this->where())->count();
  102. return $count;
  103. }
  104. }