80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
use app\api\logic\PointsLogic;
|
|
use app\api\logic\UserLogic;
|
|
|
|
class Points extends ApiBase
|
|
{
|
|
public $like_not_need_login = ['classify',''];
|
|
|
|
/**
|
|
* 获取积分商品的分类
|
|
* @return mixed
|
|
*/
|
|
public function classify()
|
|
{
|
|
$lists = PointsLogic::classify();
|
|
$this->_success('获取数据成功',$lists);
|
|
}
|
|
/**
|
|
* 获取积分的商品内容
|
|
* @return mixed
|
|
*/
|
|
public function goodslist(){
|
|
$clsssId = $this->request->get('classify_id');
|
|
$lists = PointsLogic::goodslist($clsssId);
|
|
$this->_success('获取数据成功',$lists);
|
|
}
|
|
/**
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function goodsIofo(){
|
|
|
|
$id = $this->request->get('id');
|
|
$data = PointsLogic::goodsIofo($id);
|
|
$this->_success('获取数据成功',$data);
|
|
|
|
}
|
|
|
|
public function goodsSub(){
|
|
$data = $this->request->post();
|
|
|
|
// 参数校验
|
|
if(empty($data) || !is_array($data)){
|
|
$this->_error('参数错误');
|
|
}
|
|
if(empty($data['id']) || empty($data['name']) || !isset($data['price'])){
|
|
$this->_error('参数不完整');
|
|
}
|
|
|
|
$data['user_id'] = $this->user_id;
|
|
$user_jf = UserLogic::getUserInfo($this->user_id);
|
|
|
|
if($user_jf['user_integral'] < $data['price']){
|
|
$this->_error('积分不足');
|
|
}else{
|
|
$result = PointsLogic::goodsSub($data);
|
|
if($result['code'] == 1){
|
|
$this->_success('兑换成功');
|
|
}else{
|
|
$this->_error($result['msg']);
|
|
}
|
|
}
|
|
}
|
|
|
|
//积分订单列表
|
|
public function orderList()
|
|
{
|
|
$data = $this->request->post();
|
|
// 参数校验
|
|
if(empty($data) || !is_array($data)){
|
|
$this->_error('参数错误');
|
|
}
|
|
$userId = $this->user_id;
|
|
$state = isset($data['state']) ? $data['state'] : null;
|
|
$result = PointsLogic::orderList($userId, $state);
|
|
$this->_success('获取数据成功',$result);
|
|
}
|
|
} |