SaleGoods.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Created date 2017/12/14 10:03
  4. * Author: 芸众商城 www.yunzshop.com
  5. */
  6. namespace app\common\services\goods;
  7. use app\common\models\Goods;
  8. use app\common\models\Sale;
  9. class SaleGoods extends Sale
  10. {
  11. /**
  12. * 获取推广商品
  13. * @param [int] $goods_id [商品id]
  14. * @return [array] [推广的商品数据]
  15. */
  16. public static function getPushGoods($goodsSale){
  17. if ($goodsSale->is_push == 1) {
  18. $video_demand = new VideoDemandCourseGoods();
  19. $goods_ids = explode('-', $goodsSale->push_goods_ids);
  20. $push_goods = Goods::getPushGoods($goods_ids);
  21. $push_goods->vip_level_status;
  22. foreach ($push_goods as &$value) {
  23. $value['thumb'] = replace_yunshop(yz_tomedia($value['thumb']));
  24. $value['is_course'] = $video_demand->isCourse($value['id']);
  25. }
  26. } else {
  27. return array();
  28. }
  29. //去掉限制只显示4个 2020.05.21
  30. /*if (count($push_goods) > 4) {
  31. $push_goods = array_slice(self::shuffle_assoc($push_goods), 0, 4);
  32. }*/
  33. return $push_goods;
  34. }
  35. /**
  36. * 打乱二维数组
  37. * @param [type] $list [description]
  38. * @return [type] [description]
  39. */
  40. public static function shuffle_assoc($list) {
  41. if (!is_array($list)) return $list;
  42. $keys = array_keys($list);
  43. shuffle($keys);
  44. $random = array();
  45. foreach ($keys as $key) {
  46. $random[$key] = $list[$key];
  47. }
  48. return $random;
  49. }
  50. }