刮刮后端接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.6 KiB

<?php
declare (strict_types = 1);
namespace app\controller;
use app\BaseController;
use app\model\ZoneGoods;
use app\model\ZoneGoodsParam;
use app\validate\Zone as ZoneValidate;
use think\exception\ValidateException;
use think\facade\Request;
class AdminZoneManage extends BaseController
{
/**
* 刮奖专区列表
* @return array
*/
public function zoneGoodsList()
{
$param = Request::param();
return $this->renderSuccess('数据返回成功',ZoneGoods::getList($param['zone_id'],true));
}
/**
* 刮奖专区启用禁用
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function zoneGoodsChangeStatus()
{
$param = Request::param();
try {
validate(ZoneValidate::class)->scene('changeStatus')->check($param);
$id = $param['zone_goods_id'];
$status = $param['status'];
$ZoneGoods = new ZoneGoods();
$ZoneGoodsUp = $ZoneGoods->find($id);
$ZoneGoodsUp->status = $status;
$ZoneGoodsUp->save();
return $this->renderSuccess($status == 1 ? '已启用' : '已禁用');
} catch (ValidateException $validateException) {
return $this->renderError($validateException->getMessage());
}
}
/**
* 奖金设置列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function goodsParamList()
{
$param = Request::param();
try {
validate(ZoneValidate::class)->scene('goodsParamList')->check($param);
$zone_goods_id = $param['zone_goods_id'];
$ZoneGoodsParam = new ZoneGoodsParam();
$list = $ZoneGoodsParam->where('zone_goods_id',$zone_goods_id)
->field('id,amount,image,probability')
->order('amount','desc')
->select()
->toArray();
foreach ($list as &$item) {
$item['probability'] = ($item['probability'] * 100) .'%';
$item['amount_str'] = format_money($item['amount']);
$item['image'] = get_image_url($item['image']);
}
return $this->renderSuccess('数据返回成功',['list' => $list]);
} catch (ValidateException $validateException) {
return $this->renderError($validateException->getMessage());
}
}
}