tp5签到积分兑换商品功能
作者:互联网
public function order(){
$gid = input('gid');
//接收当前用户的积分
$count = input('count');
//查询商品
$goods = Db::table('goods')->where(['gid'=>$gid])->find();
//判断用户积分是否大于商品兑换积分
if ($count>$goods['gcount']){
//如果已经提交订单 则不能再提交
if ($goods['state'] == '审核中'){
$this->error('您已提交订单,请耐心等待管理员审核','/show');
}else if ($goods['state'] == '已兑换'){
$this->error('您已兑换成功,请勿重复兑换','/show');
}else{
return view('order/order',['goods'=>$goods]);
}
}else{
$this->error('积分不足,无法兑换','/show');
}
}
public function orderDo(){
//接收session中的用户id
$data['uid'] = session('id');
//接收商品id
$data['gid'] = request()->param('gid');
$data['oname'] = request()->param('oname');
$data['ohome'] = request()->param('ohome');
$data['ophone'] = request()->param('ophone');
$data['odesct'] = request()->param('odesct');
//生成随机订单号 用户id+当前时间+随机数
$data['numb'] = session('id').time().rand(0000,9999);
//向订单表里添加数据
$orderIns = Db::table('orders')->insert($data);
//如果数据添加成功
if ($orderIns){
//则修改 商品表里的用户id 和 审核状态
$goodsIns = Db::table('goods')->where(['gid'=>$data['gid']])->update(['uid'=>$data['uid'],'state'=>'审核中']);
if ($goodsIns){
$this->success('提交成功,请耐心等待','/show');
}else{
$this->error('提交失败','/show');
}
}
}
标签:goods,show,签到,积分,request,tp5,gid,data,id 来源: https://www.cnblogs.com/guobusong/p/15102350.html