小程序会员权益接口

This commit is contained in:
2026-04-25 14:01:00 +08:00
parent 52c0b234db
commit 18aae7e3e0
2 changed files with 131 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\api\controller\wdsxh\member;
use app\common\controller\Api;
class MemberBenefits extends Api
{
protected $noNeedLogin = ['index'];
protected $noNeedRight = ['*'];
protected $level_model = null;
protected $benefits_model = null;
protected $article_model = null;
public function _initialize()
{
parent::_initialize();
$this->level_model = new \app\api\model\wdsxh\member\Level();
$this->benefits_model = new \app\api\model\wdsxh\member\MemberBenefits();
$this->article_model = new \app\api\model\wdsxh\article\Article();
}
/**
* 根据入会类型查询会员级别及权益(每个级别下展示入会类型所有权益,并标记拥有状态)
*
* @param int $join_config_id 入会类型ID
* @return \think\Response
*/
public function index()
{
$join_config_id = $this->request->param('join_config_id', 0);
if (empty($join_config_id)) {
$this->error('入会类型参数不能为空');
}
// 查询该入会类型下的所有会员级别(按权重升序)
$levels = $this->level_model
->field(['id', 'join_config_id', 'benefits_id', 'name', 'image', 'fees', 'content'])
->where('join_config_id', $join_config_id)
->where('status', 'normal')
->order('weigh', 'asc')
->select();
// 查询该入会类型下的所有会员权益(按排序值升序,排除禁用的)
$all_benefits = $this->benefits_model
->field(['id', 'join_config_id', 'title', 'image', 'desc'])
->where('join_config_id', $join_config_id)
->where('disabled', 0)
->order('sort', 'asc')
->select();
// 为每个级别构建完整的权益列表(含 has 标记)
$result_levels = [];
foreach ($levels as $level) {
$owned_ids = json_decode($level['benefits_id'], true) ?: [];
$owned_ids = array_map('intval', $owned_ids);
$benefits_with_flag = [];
foreach ($all_benefits as $benefit) {
$benefit['has'] = in_array(intval($benefit['id']), $owned_ids);
$benefits_with_flag[] = $benefit;
}
$level['benefits'] = $benefits_with_flag;
$result_levels[] = $level;
}
// 会员动态
$result_articles = $this->article_model->alias('a')
->field(['a.id', 'a.type', 'a.title', 'a.image', 'a.link', 'a.createtime'])
->join('wdsxh_article_cat c', 'c.id = a.cat_id')
->where('c.id', 4)
->where('c.status', '1')
->where('a.status', '1')
->order([
'a.weigh' => 'desc',
'a.id' => 'desc'
])
->find();
$this->success('请求成功', [
'levels_benefits' => $result_levels,
'articles' => $result_articles,
]);
}
}

View File

@@ -0,0 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
/**
* Class MemberBenefits
* Desc 会员权益模型
* Create on 2024/3/8 9:56
* Create by wangyafang
*/
namespace app\api\model\wdsxh\member;
use app\api\model\wdsxh\Base;
class MemberBenefits extends Base
{
// 表名
protected $name = 'wdsxh_member_benefits';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
protected $deleteTime = false;
}