...
|
...
|
@@ -701,107 +701,94 @@ class Pay extends Api |
|
|
//查询该用户信息以及是否为会员身份
|
|
|
$user = Db::name('user')->where('id',$data['user_id'])->find();
|
|
|
$mobile = $user['mobile'];
|
|
|
Log::info($user);
|
|
|
Log::info($mobile);
|
|
|
$str = "【仁甲看见】";
|
|
|
// 启动事务
|
|
|
Db::startTrans();
|
|
|
try{
|
|
|
if(!empty($pic_id)){
|
|
|
//将购买次数加1
|
|
|
foreach ($pic_id as $key => $v){
|
|
|
//非会员
|
|
|
if($user['is_vip'] == 0){
|
|
|
$pic = Db::name('pic')->field('id,price,buy_num,money')->where('id',$v)->find();
|
|
|
$total_money = $pic['money'] + $pic['price'];
|
|
|
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1,'money'=>$total_money]);
|
|
|
}else{
|
|
|
//是会员
|
|
|
$pic = Db::name('pic')->field('id,price,buy_num,money')->where('id',$v)->find();
|
|
|
$total_money = $pic['money'] + ($pic['price']*0.75);
|
|
|
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1,'money'=>$total_money]);
|
|
|
}
|
|
|
}
|
|
|
//拼接发送短信的内容
|
|
|
foreach ($pic_id as $key => $v){
|
|
|
$pic = Db::name('pic')->field('id,title,url,code')->where('id',$v)->find();
|
|
|
$str .= "图片标题:$pic[title],云盘地址:$pic[url],提取码:$pic[code],";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(!empty($video_id)){
|
|
|
//判断是否为会员
|
|
|
if(!empty($pic_id)){
|
|
|
//将购买次数加1
|
|
|
foreach ($pic_id as $key => $v){
|
|
|
//非会员
|
|
|
if($user['is_vip'] == 0){
|
|
|
//不是会员的情况
|
|
|
//将购买次数加1
|
|
|
foreach ($video_id as $key => $val){
|
|
|
$video = Db::name('video')->field('id,buy_num,price,four_price,eight_price,money')->where('id',$val['id'])->find();
|
|
|
if($val['attr'] == 1){
|
|
|
$video_money = $video['money'] + $video['price'];
|
|
|
}elseif ($val['attr'] == 2){
|
|
|
$video_money = $video['money'] + $video['four_price'];
|
|
|
}else{
|
|
|
$video_money = $video['money'] + $video['eight_price'];
|
|
|
}
|
|
|
Db::name('video')->where('id',$video['id'])->update(['buy_num'=>$video['buy_num']+1,'money'=>$video_money]);
|
|
|
}
|
|
|
$pic = Db::name('pic')->field('id,price,buy_num,money')->where('id',$v)->find();
|
|
|
$total_money = $pic['money'] + $pic['price'];
|
|
|
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1,'money'=>$total_money]);
|
|
|
}else{
|
|
|
//是会员的情况
|
|
|
//将购买次数加1
|
|
|
foreach ($video_id as $key => $val){
|
|
|
$video = Db::name('video')->field('id,buy_num,price,four_price,eight_price,money')->where('id',$val['id'])->find();
|
|
|
if($val['attr'] == 1){
|
|
|
$video_money = $video['money'] + ($video['price']*0.75);
|
|
|
}elseif ($val['attr'] == 2){
|
|
|
$video_money = $video['money'] + ($video['four_price']*0.75);
|
|
|
}else{
|
|
|
$video_money = $video['money'] + ($video['eight_price']*0.75);
|
|
|
}
|
|
|
Db::name('video')->where('id',$video['id'])->update(['buy_num'=>$video['buy_num']+1,'money'=>$video_money]);
|
|
|
}
|
|
|
//是会员
|
|
|
$pic = Db::name('pic')->field('id,price,buy_num,money')->where('id',$v)->find();
|
|
|
$total_money = $pic['money'] + ($pic['price']*0.75);
|
|
|
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1,'money'=>$total_money]);
|
|
|
}
|
|
|
|
|
|
//判断视频的属性
|
|
|
foreach ($video_id as &$val){
|
|
|
}
|
|
|
//拼接发送短信的内容
|
|
|
foreach ($pic_id as $key => $v){
|
|
|
$pic = Db::name('pic')->field('id,title,url,code')->where('id',$v)->find();
|
|
|
$str .= "图片标题:$pic[title],云盘地址:$pic[url],提取码:$pic[code],";
|
|
|
}
|
|
|
}
|
|
|
if(!empty($video_id)){
|
|
|
//判断是否为会员
|
|
|
if($user['is_vip'] == 0){
|
|
|
//不是会员的情况
|
|
|
//将购买次数加1
|
|
|
foreach ($video_id as $key => $val){
|
|
|
$video = Db::name('video')->field('id,buy_num,price,four_price,eight_price,money')->where('id',$val['id'])->find();
|
|
|
if($val['attr'] == 1){
|
|
|
$val['attr'] = '2k';
|
|
|
$video_money = $video['money'] + $video['price'];
|
|
|
}elseif ($val['attr'] == 2){
|
|
|
$val['attr'] = '4k';
|
|
|
$video_money = $video['money'] + $video['four_price'];
|
|
|
}else{
|
|
|
$val['attr'] = '8k';
|
|
|
$video_money = $video['money'] + $video['eight_price'];
|
|
|
}
|
|
|
Db::name('video')->where('id',$video['id'])->update(['buy_num'=>$video['buy_num']+1,'money'=>$video_money]);
|
|
|
}
|
|
|
//拼接发送短信的内容
|
|
|
foreach ($video_id as $k=>$v){
|
|
|
if($v['attr'] == '4k'){
|
|
|
$video = Db::name('video')->field('id,title,four_url,four_code')->where('id',$v['id'])->find();
|
|
|
$str .= "视频标题:$video[title],云盘地址:$video[four_url],提取码:$video[four_code]";
|
|
|
}elseif ($v['attr'] == '2k'){
|
|
|
$video = Db::name('video')->field('id,title,two_url,two_code')->where('id',$v['id'])->find();
|
|
|
$str .= "视频标题:$video[title],云盘地址:$video[two_url],提取码:$video[two_code]";
|
|
|
}elseif ($v['attr'] == '8k'){
|
|
|
$video = Db::name('video')->field('id,title,eight_url,eight_code')->where('id',$v['id'])->find();
|
|
|
$str .= "视频标题:$video[title],云盘地址:$video[eight_url],提取码:$video[eight_code]";
|
|
|
}else{
|
|
|
//是会员的情况
|
|
|
//将购买次数加1
|
|
|
foreach ($video_id as $key => $val){
|
|
|
$video = Db::name('video')->field('id,buy_num,price,four_price,eight_price,money')->where('id',$val['id'])->find();
|
|
|
if($val['attr'] == 1){
|
|
|
$video_money = $video['money'] + ($video['price']*0.75);
|
|
|
}elseif ($val['attr'] == 2){
|
|
|
$video_money = $video['money'] + ($video['four_price']*0.75);
|
|
|
}else{
|
|
|
$video_money = $video['money'] + ($video['eight_price']*0.75);
|
|
|
}
|
|
|
Db::name('video')->where('id',$video['id'])->update(['buy_num'=>$video['buy_num']+1,'money'=>$video_money]);
|
|
|
}
|
|
|
}
|
|
|
//发送短信
|
|
|
if(!empty($mobile)){
|
|
|
$result = $this->sms($mobile,$str);
|
|
|
|
|
|
//判断视频的属性
|
|
|
foreach ($video_id as &$val){
|
|
|
if($val['attr'] == 1){
|
|
|
$val['attr'] = '2k';
|
|
|
}elseif ($val['attr'] == 2){
|
|
|
$val['attr'] = '4k';
|
|
|
}else{
|
|
|
$val['attr'] = '8k';
|
|
|
}
|
|
|
}
|
|
|
//支付成功,更新订单状态
|
|
|
$toporder['status'] = 2;
|
|
|
$toporder['paytime'] = time();
|
|
|
$res = Db::name('order')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
if($res){
|
|
|
true;
|
|
|
//拼接发送短信的内容
|
|
|
foreach ($video_id as $k=>$v){
|
|
|
if($v['attr'] == '4k'){
|
|
|
$video = Db::name('video')->field('id,title,four_url,four_code')->where('id',$v['id'])->find();
|
|
|
$str .= "视频标题:$video[title],云盘地址:$video[four_url],提取码:$video[four_code]";
|
|
|
}elseif ($v['attr'] == '2k'){
|
|
|
$video = Db::name('video')->field('id,title,two_url,two_code')->where('id',$v['id'])->find();
|
|
|
$str .= "视频标题:$video[title],云盘地址:$video[two_url],提取码:$video[two_code]";
|
|
|
}elseif ($v['attr'] == '8k'){
|
|
|
$video = Db::name('video')->field('id,title,eight_url,eight_code')->where('id',$v['id'])->find();
|
|
|
$str .= "视频标题:$video[title],云盘地址:$video[eight_url],提取码:$video[eight_code]";
|
|
|
}
|
|
|
}
|
|
|
// 提交事务
|
|
|
Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
dump($e->getMessage());
|
|
|
// 回滚事务
|
|
|
Db::rollback();
|
|
|
$this->error('购买失败');
|
|
|
}
|
|
|
//发送短信
|
|
|
if(!empty($mobile)){
|
|
|
$result = $this->sms($mobile,$str);
|
|
|
}
|
|
|
//支付成功,更新订单状态
|
|
|
$toporder['status'] = 2;
|
|
|
$toporder['paytime'] = time();
|
|
|
Db::name('order')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
}else{
|
|
|
//支付失败
|
|
|
$toporder['status'] = 1;
|
...
|
...
|
|