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.
136 lines
4.1 KiB
136 lines
4.1 KiB
<?php
|
|
|
|
namespace app\controller;
|
|
|
|
use app\BaseController;
|
|
use app\middleware\CheckUser;
|
|
use app\model\ConsumptionRecords;
|
|
use app\model\Zone as ZoneModel;
|
|
use app\model\ZoneGoods;
|
|
use app\logic\Zone as ZoneLogic;
|
|
use think\facade\Request;
|
|
use think\facade\Session;
|
|
|
|
/**
|
|
* 专区
|
|
*/
|
|
class Zone extends BaseController
|
|
{
|
|
|
|
protected $middleware = [CheckUser::class];
|
|
|
|
/**
|
|
* 首页专区列表
|
|
* @return array
|
|
*/
|
|
public function zoneList()
|
|
{
|
|
return $this->renderSuccess('数据返回成功',ZoneModel::getList());
|
|
}
|
|
|
|
/**
|
|
* 刮奖专区列表
|
|
* @return array
|
|
*/
|
|
public function zoneGoodsList()
|
|
{
|
|
$param = Request::param();
|
|
return $this->renderSuccess('数据返回成功',ZoneGoods::getList($param,true));
|
|
}
|
|
|
|
/**
|
|
* 刮奖初始化数据
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function beginInitInfo()
|
|
{
|
|
|
|
$param = Request::param();
|
|
$zoneGoodsId = $param['zone_goods_id'];
|
|
|
|
$info = ZoneGoods::where(['status' => 1,'id' => $zoneGoodsId])
|
|
->field('max_awards_amount,content,price,bg_image')
|
|
->find();
|
|
if (empty($info)) $this->renderError('数据不存在');
|
|
$info['important'] = '最高中奖金额'.format_money($info['max_awards_amount']);
|
|
if ($info['bg_image']) $info['bg_image'] = get_image_url($info['bg_image']);
|
|
unset($info['max_awards_amount']);
|
|
return $this->renderSuccess('数据返回成功',['data' => $info]);
|
|
}
|
|
|
|
/**
|
|
* 立即刮奖
|
|
* @param $zoneGoodsId
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function beginLottery()
|
|
{
|
|
$param = Request::param();
|
|
$zoneGoodsId = $param['zone_goods_id'];
|
|
$userData = $this->request->userInfo;
|
|
|
|
# 判断余额够不够
|
|
$judgeRes = ZoneLogic::judgeBalance($userData['id'],$zoneGoodsId);
|
|
if (!$judgeRes) return $this->renderError('余额不足');
|
|
|
|
# 获取刮奖图片
|
|
$data = ZoneLogic::createOrder($userData['id'],$zoneGoodsId);
|
|
if (!$data['status']) $this->renderError($data['msg']);
|
|
|
|
return $this->renderSuccess('开始刮奖',['list' => $data['data'], 'c_r_id' => $data['c_r_id']]);
|
|
}
|
|
|
|
/**
|
|
* 结束刮奖
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function endLottery()
|
|
{
|
|
$param = Request::param();
|
|
$c_r_id = $param['c_r_id'];
|
|
$userData = $this->request->userInfo;
|
|
|
|
$res = ZoneLogic::endOrder($userData['id'],$c_r_id);
|
|
|
|
if (!$res['status']) return $this->renderError($res['msg']);
|
|
|
|
return $this->renderSuccess(
|
|
$res['awards_amount'] > 0 ? '恭喜你中奖了' : '未中奖',
|
|
['awards_amount' => $res['awards_amount'],'list' => $res['data']]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 查看中奖结果
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function queryAwardsResult()
|
|
{
|
|
$param = Request::param();
|
|
$c_r_id = $param['c_r_id'];
|
|
$userData = $this->request->userInfo;
|
|
|
|
$queryWhere = ['status' => 1, 'user_id' => $userData['id'], 'id' => $c_r_id];
|
|
$ConsumptionRecords = new ConsumptionRecords();
|
|
$query = $ConsumptionRecords->where($queryWhere)->field('text_data,zone_goods_id')->find();
|
|
if (!$query['text_data']) return $this->renderError('中奖结果数据不存在');
|
|
$returnData = ZoneLogic::handleTextData(unserialize($query['text_data']));
|
|
|
|
return $this->renderSuccess('数据返回成功', ['list' => $returnData]);
|
|
}
|
|
|
|
|
|
|
|
}
|