diff --git a/plugins/cultural-space/src/api/GoodsController.php b/plugins/cultural-space/src/api/GoodsController.php new file mode 100644 index 00000000..b65051c3 --- /dev/null +++ b/plugins/cultural-space/src/api/GoodsController.php @@ -0,0 +1,32 @@ +successJson('success',$result); + } + + + + + + + + + + + +} \ No newline at end of file diff --git a/plugins/cultural-space/src/models/GoodsCulturalSpace.php b/plugins/cultural-space/src/models/GoodsCulturalSpace.php index d0104b70..10b00a8a 100644 --- a/plugins/cultural-space/src/models/GoodsCulturalSpace.php +++ b/plugins/cultural-space/src/models/GoodsCulturalSpace.php @@ -2,6 +2,7 @@ namespace Yunshop\CulturalSpace\models; +use app\common\facades\Setting; use app\common\models\BaseModel; use app\frontend\models\Goods; @@ -48,4 +49,53 @@ class GoodsCulturalSpace extends BaseModel{ return $this->belongsTo(Goods::class, 'goods_id', 'id'); } + + /** + * Common: 获取可以使用文创豆兑换的商品 + * Author: wu-hui + * Time: 2023/11/28 17:44 + * @return array + */ + public static function getExchangeGoodsList(){ + $result = self::uniacid() + ->select(['id','goods_id','legumes_exchange_price']) + ->with(['belongsToGoods'=>function($query){ + $query->select(['id','title','thumb']); + }]) + ->where('is_open',1) + ->where('is_legumes_exchange',1) + ->orderBy('id','DESC') + ->paginate(10) + ->toArray(); + $data = [ + 'current_page' => (int)$result['current_page'], + 'data' => (array)$result['data'], + 'last_page' => (int)$result['last_page'], + ]; + // 计算需要使用的文创豆 + $currentFee = (float)CulturalFund::uniacid()->value('current_fee');// 当前费率 + $holdExchangeLegumes = 0;// 当前用户持有的用以兑换商品的文创豆 + $data['data'] = array_map(function($item) use ($currentFee,$holdExchangeLegumes){ + // 使用的文创豆 + $useLegumes = ceil($item['legumes_exchange_price'] * $currentFee); + return [ + 'id' => $item['id'], + 'goods_id' => $item['goods_id'], + 'legumes_exchange_price' => $item['legumes_exchange_price'], + 'goods_title' => $item['belongs_to_goods']['title'], + 'goods_thumb' => $item['belongs_to_goods']['thumb'], + 'use_legumes' => $useLegumes, + 'is_allow_exchange' => (int)$holdExchangeLegumes >= $useLegumes, + ]; + },$data['data']); + + return $data; + } + + + + + + + } diff --git a/plugins/cultural-space/views/index/set.blade.php b/plugins/cultural-space/views/index/set.blade.php index 060e5882..9300c940 100644 --- a/plugins/cultural-space/views/index/set.blade.php +++ b/plugins/cultural-space/views/index/set.blade.php @@ -3,6 +3,8 @@ @section('content') + +