Goods.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\common\service;
  13. use app\common\library\helper;
  14. use app\common\model\Goods as GoodsModel;
  15. /**
  16. * 商品服务类
  17. * Class Goods
  18. * @package app\store\service
  19. */
  20. class Goods extends BaseService
  21. {
  22. /**
  23. * 设置商品数据
  24. * @param $data
  25. * @param bool $isMultiple
  26. * @param string $goodsIndex
  27. * @return mixed
  28. */
  29. public static function setGoodsData($data, $isMultiple = true, $goodsIndex = 'goods_id')
  30. {
  31. if (!$isMultiple) $dataSource = [&$data]; else $dataSource = &$data;
  32. // 获取商品列表
  33. $model = new GoodsModel;
  34. $goodsData = $model->getListByIds(helper::getArrayColumn($dataSource, $goodsIndex));
  35. $goodsList = helper::arrayColumn2Key($goodsData, 'goods_id');
  36. // 整理列表数据
  37. foreach ($dataSource as &$item) {
  38. $item['goods'] = isset($goodsList[$item[$goodsIndex]]) ? $goodsList[$item[$goodsIndex]] : null;
  39. }
  40. return $data;
  41. }
  42. /**
  43. * 商品多规格信息
  44. * @param GoodsModel|null $model
  45. * @return null|array
  46. */
  47. public static function getSpecData($model = null)
  48. {
  49. // 商品sku数据
  50. if (!is_null($model) && $model['spec_type'] == 20) {
  51. return $model->getManySpecData($model['spec_rel'], $model['skuList']);
  52. }
  53. return null;
  54. }
  55. }