GoodsWidget.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/9/9
  8. * Time: 15:38
  9. */
  10. namespace app\backend\modules\goods\widget;
  11. use app\backend\modules\goods\models\Brand;
  12. use app\backend\modules\goods\models\Category;
  13. use app\backend\modules\goods\models\GoodsOption;
  14. class GoodsWidget extends BaseGoodsWidget
  15. {
  16. public $group = 'base';
  17. public $widget_key = 'goods';
  18. public $code = 'goods';
  19. public function pluginFileName()
  20. {
  21. return 'goods';
  22. }
  23. public function getCategoryList()
  24. {
  25. return Category::getAllCategoryGroupArray();
  26. }
  27. public function categoryLevel()
  28. {
  29. return \Setting::get('shop.category')['cat_level']?:2;
  30. }
  31. public function getData()
  32. {
  33. //商品属性默认值
  34. $goods = [
  35. 'is_recommand' => 0,
  36. 'is_new' => 0,
  37. 'is_hot' => 0,
  38. 'is_discount' => 0,
  39. 'hide_goods_sales' => 0,
  40. 'hide_goods_sales_alone' => 0,
  41. ];
  42. $result['category_level'] = $this->categoryLevel();
  43. $result['category_list'] = $this->getCategoryList();
  44. $result['brand'] = Brand::getBrands()->getQuery()->select(['id','name'])->get();
  45. $result['goods'] = $goods;
  46. if (is_null($this->goods)) {
  47. $result['goods']['hide_goods_sales_switch'] = in_array($this->request->route,['goods.goods.widget-column','plugin.auction.admin.auction.widget-column']) ? 1 : 0;
  48. return $result;
  49. }
  50. $goods = array_merge($goods, $this->goods->toArray());
  51. $goods = array_except($goods,['content','old_id','is_deleted','created_at','updated_at','deleted_at']);
  52. if ($this->goods->thumb) {
  53. $goods['thumb_link'] = yz_tomedia($this->goods->thumb);
  54. }
  55. //商品其它图片反序列化
  56. $thumb_url = !empty($this->goods->thumb_url) ? unserialize($this->goods->thumb_url) : [];
  57. $goods['thumb_url'] = collect($thumb_url)->map(function ($item) {
  58. return ['thumb_link'=>yz_tomedia($item), 'thumb' => $item];
  59. })->values()->all();
  60. //商品视频处理
  61. $goods['goods_video'] = $this->goods->hasOneGoodsVideo->goods_video?: '';
  62. $goods['video_image'] = $this->goods->hasOneGoodsVideo->video_image ?: '';
  63. $goods['goods_video_link'] = $this->goods->hasOneGoodsVideo->goods_video? yz_tomedia($this->goods->hasOneGoodsVideo->goods_video) : '';
  64. $goods['video_image_link'] = $this->goods->hasOneGoodsVideo->video_image? yz_tomedia($this->goods->hasOneGoodsVideo->video_image) : '';
  65. $goods['withhold_stock'] = $this->goods->withhold_stock;
  66. //分类
  67. if (!$this->goods->hasManyGoodsCategory->isEmpty()){
  68. $category = [];
  69. $category_to_option = [];
  70. foreach($this->goods->hasManyGoodsCategory->toArray() as $goods_category){
  71. $category_ids = explode(",", $goods_category['category_ids']);
  72. //商品分类层级大于设置层级
  73. if (count($category_ids) > $result['category_level']) {
  74. array_pop($category_ids);
  75. }
  76. $category_item = Category::select('id','name','level')->uniacid()
  77. ->whereIn('id', $category_ids)->orderBy('level')->get();
  78. if (!$category_item->isEmpty() && $category_item->count() > 1) {
  79. $category[] = $category_item->toArray();
  80. $category_to_option[] = ['goods_option_id'=>$goods_category['goods_option_id']?:''];
  81. }
  82. }
  83. $goods['category'] = $category;
  84. $goods['category_to_option'] = $category_to_option;
  85. } else {
  86. $goods['category'] = [];
  87. $goods['category_to_option'] = [];
  88. }
  89. $result['goods'] = $goods;
  90. $result['options'] = [];
  91. $result['category_to_option_open'] = \Setting::get('shop.category.category_to_option') ? : 0;
  92. if (!in_array($this->getRoute(),['shop','supplier'])) {
  93. $result['category_to_option_open'] = 0;
  94. }
  95. if (!is_null($this->goods) && $this->goods->has_option) {
  96. $result['options'] = GoodsOption::uniacid()
  97. ->select('id','title')
  98. ->where('goods_id',$this->goods->id)
  99. ->get()->toArray();
  100. }
  101. $result['goods']['hide_goods_sales_switch'] = in_array($this->goods->plugin_id, [0, 67]) ? 1 : 0;
  102. return $result;
  103. }
  104. /**
  105. * hide_status 隐藏状态
  106. * hide_weight 隐藏重量
  107. * hide_volume 隐藏体积
  108. * hide_product_sn 隐藏商品条码
  109. * appoint_type 指定商品类型
  110. * appoint_need_address 指定下单是否需要地址
  111. * appoint_need_address 指定下单是否需要地址
  112. * @return array
  113. */
  114. public function attrHide()
  115. {
  116. return [];
  117. }
  118. public function pagePath()
  119. {
  120. return $this->getPath('resources/views/goods/assets/js/components/');
  121. }
  122. }