...
|
...
|
@@ -688,16 +688,14 @@ class Pay extends Api |
|
|
|
|
|
//图片支付订单结果通知(无需调用)
|
|
|
public function picOrderNotify(){
|
|
|
Log::info('11111111');
|
|
|
$config = config('verify.wx_pay');
|
|
|
$app = Factory::payment($config);
|
|
|
$response = $app->handlePaidNotify(function($message, $fail){
|
|
|
//return_code 表示通信状态
|
|
|
if ($message['return_code'] === 'SUCCESS') {
|
|
|
if ($message['result_code'] === 'SUCCESS') {
|
|
|
//支付成功,更新订单状态
|
|
|
$toporder['status'] = 2;
|
|
|
$toporder['paytime'] = time();
|
|
|
|
|
|
Log::info($message);
|
|
|
//找到该订单信息
|
|
|
$data = Db::name('order')->where('id',$message['out_trade_no'])->find();
|
|
|
$pic_id = explode(',',$data['pic_id']);
|
...
|
...
|
@@ -706,61 +704,113 @@ class Pay extends Api |
|
|
$user = Db::name('user')->where('id',$data['user_id'])->find();
|
|
|
$mobile = $user['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();
|
|
|
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1,'money'=>$pic['money']+$pic['price']]);
|
|
|
}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($pic_id)){
|
|
|
foreach ($pic_id as $key => $v){
|
|
|
//非会员
|
|
|
if(!empty($video_id)){
|
|
|
//判断是否为会员
|
|
|
if($user['is_vip'] == 0){
|
|
|
$pic = Db::name('pic')->field('id,price,buy_num,money')->where('id',$v)->find();
|
|
|
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1,'money'=>$pic['money']+$pic['price']]);
|
|
|
//不是会员的情况
|
|
|
//将购买次数加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]);
|
|
|
}
|
|
|
}else{
|
|
|
//是会员
|
|
|
$pic = Db::name('pic')->field('id,price,buy_num,money')->where('id',$v)->find();
|
|
|
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1,'money'=>$pic['money']+$pic['price']]);
|
|
|
//是会员的情况
|
|
|
//将购买次数加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]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
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)){
|
|
|
foreach ($video_id as &$val){
|
|
|
if($val['attr'] == 1){
|
|
|
$val['attr'] = '2k';
|
|
|
}elseif ($val['attr'] == 2){
|
|
|
$val['attr'] = '4k';
|
|
|
}else{
|
|
|
$val['attr'] = '8k';
|
|
|
|
|
|
//判断视频的属性
|
|
|
foreach ($video_id as &$val){
|
|
|
if($val['attr'] == 1){
|
|
|
$val['attr'] = '2k';
|
|
|
}elseif ($val['attr'] == 2){
|
|
|
$val['attr'] = '4k';
|
|
|
}else{
|
|
|
$val['attr'] = '8k';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
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]";
|
|
|
//拼接发送短信的内容
|
|
|
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]";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//发送短信
|
|
|
if(!empty($mobile)){
|
|
|
$result = $this->sms($mobile,$str);
|
|
|
//发送短信
|
|
|
if(!empty($mobile)){
|
|
|
$result = $this->sms($mobile,$str);
|
|
|
}
|
|
|
//支付成功,更新订单状态
|
|
|
$toporder['status'] = 2;
|
|
|
$toporder['paytime'] = time();
|
|
|
$res = Db::name('order')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
if($res){
|
|
|
true;
|
|
|
}
|
|
|
// 提交事务
|
|
|
Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
dump($e->getMessage());
|
|
|
// 回滚事务
|
|
|
Db::rollback();
|
|
|
$this->error('购买失败');
|
|
|
}
|
|
|
}else{
|
|
|
//支付失败
|
|
|
$toporder['status'] = 1;
|
|
|
Db::name('order')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
}
|
|
|
}else{
|
|
|
return $fail('通信失败,请稍后再通知我');
|
|
|
}
|
|
|
Db::name('order')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
return true; // 返回处理完成
|
|
|
});
|
|
|
$response->send();
|
|
|
}
|
...
|
...
|
@@ -773,78 +823,119 @@ class Pay extends Api |
|
|
//return_code 表示通信状态
|
|
|
if ($message['return_code'] === 'SUCCESS') {
|
|
|
if ($message['result_code'] === 'SUCCESS') {
|
|
|
//支付成功,更新订单状态
|
|
|
$toporder['status'] = 2;
|
|
|
$toporder['paytime'] = time();
|
|
|
$data = Db::name('order')->where('id',$message['out_trade_no'])->find();
|
|
|
$pic_id = explode(',',$data['pic_id']);
|
|
|
$video_id = unserialize($data['video_id']);
|
|
|
|
|
|
$user = Db::name('user')->where('id',$data['user_id'])->find();
|
|
|
$mobile = $user['mobile'];
|
|
|
$str = "【仁甲看见】";
|
|
|
|
|
|
//判断用户是否为会员
|
|
|
$login = Db::name('user')
|
|
|
->where('id',$data['user_id'])
|
|
|
->field('id,is_vip')
|
|
|
->find();
|
|
|
|
|
|
if(!empty($pic_id)){
|
|
|
foreach ($pic_id as $key => $v){
|
|
|
//非会员
|
|
|
if($login['is_vip'] == 0){
|
|
|
$pic = Db::name('pic')->field('id,price,buy_num,money')->where('id',$v)->find();
|
|
|
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1,'money'=>$pic['money']+$pic['price']]);
|
|
|
}else{
|
|
|
//是会员
|
|
|
$pic = Db::name('pic')->field('id,price,buy_num,money')->where('id',$v)->find();
|
|
|
Db::name('pic')->where('id',$pic['id'])->update(['buy_num'=>$pic['buy_num']+1,'money'=>$pic['money']+$pic['price']]);
|
|
|
// 启动事务
|
|
|
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],";
|
|
|
}
|
|
|
}
|
|
|
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)){
|
|
|
foreach ($video_id as $key => $val){
|
|
|
$video = Db::name('video')->field('id,buy_num')->where('id',$val['id'])->find();
|
|
|
Db::name('video')->where('id',$video['id'])->update(['buy_num'=>$video['buy_num']+1]);
|
|
|
}
|
|
|
foreach ($video_id as &$val){
|
|
|
if($val['attr'] == 1){
|
|
|
$val['attr'] = '2k';
|
|
|
}elseif ($val['attr'] == 2){
|
|
|
$val['attr'] = '4k';
|
|
|
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){
|
|
|
$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]);
|
|
|
}
|
|
|
}else{
|
|
|
$val['attr'] = '8k';
|
|
|
//是会员的情况
|
|
|
//将购买次数加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]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
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]";
|
|
|
|
|
|
//判断视频的属性
|
|
|
foreach ($video_id as &$val){
|
|
|
if($val['attr'] == 1){
|
|
|
$val['attr'] = '2k';
|
|
|
}elseif ($val['attr'] == 2){
|
|
|
$val['attr'] = '4k';
|
|
|
}else{
|
|
|
$val['attr'] = '8k';
|
|
|
}
|
|
|
}
|
|
|
//拼接发送短信的内容
|
|
|
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]";
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(!empty($mobile)){
|
|
|
$result = $this->sms($mobile,$str);
|
|
|
//发送短信
|
|
|
if(!empty($mobile)){
|
|
|
$result = $this->sms($mobile,$str);
|
|
|
}
|
|
|
//支付成功,更新订单状态
|
|
|
$toporder['status'] = 2;
|
|
|
$toporder['paytime'] = time();
|
|
|
$res = Db::name('order')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
if($res){
|
|
|
true;
|
|
|
}
|
|
|
// 提交事务
|
|
|
Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
dump($e->getMessage());
|
|
|
// 回滚事务
|
|
|
Db::rollback();
|
|
|
$this->error('购买失败');
|
|
|
}
|
|
|
}else{
|
|
|
//支付失败
|
|
|
$toporder['status'] = 1;
|
|
|
Db::name('vorder')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
}
|
|
|
}else{
|
|
|
return $fail('通信失败,请稍后再通知我');
|
|
|
}
|
|
|
Db::name('vorder')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
return true; // 返回处理完成
|
|
|
});
|
|
|
$response->send();
|
...
|
...
|
|