作者 王智

文档修改

... ... @@ -170,74 +170,97 @@ class Pay extends Api
//是否首次下单
$FirstPay = Db::name('order')->where('OrderSn', 'NEQ', $PayOrderInfo['OrderSn'])->where('status', 'IN', '1,2,3,4,5')->find();
if (empty($FirstPay)) {
Db::name('pay_order')->where('PayOrder', $data['out_trade_no'])->update(
[
'is_new' => 1,
]
);
//查询用户积分
$FirstPayUserinfo = Db::name('user')->where('id', $PayOrderInfo['user_id'])->find();
//更改用户积分
$UpdateFirstPay = Db::name('user')->where('id', $PayOrderInfo['user_id'])->update(['num' => $FirstPayUserinfo['num'] + (floor($OrderInfo['total']) * 2)]);
if (!$UpdateFirstPay) {
$this->error('更改用户积分失败失败', 0);
die;
}
//添加用户积分记录
$InserNumSql = [
'user_id' => $PayOrderInfo['user_id'],
'status' => 1,
'type' => 5,
'num' => floor($OrderInfo['total']) * 2,
'up_num' => $FirstPayUserinfo['num'] + (floor($OrderInfo['total']) * 2),
'createtime' => time()
];
Db::name('num')->insert($InserNumSql);
}
//是否升级
//已消费金额 $Consumed
$Consumed = $this->YiXiaofeiMoney($PayOrderInfo['user_id']);
$Level = Db::name('user')->where('id', $PayOrderInfo['user_id'])->value('level');
$LevelSql = Db::name('level')->where('type', $Level + 1)->find();
if ($Consumed > $LevelSql['price'] && $Consumed == $LevelSql['price']) {
$LevelUserInfo = Db::name('user')->where('id', $PayOrderInfo['user_id'])->find();
//更改用户积分
$UpdateLevelUserInfo = Db::name('user')->where('id', $PayOrderInfo['user_id'])->update(['num' => $LevelUserInfo['num'] + $LevelSql['num']]);
if (!$UpdateLevelUserInfo) {
$this->error('更改用户积分失败失败2', 0);
die;
//新用户首次下单双倍积分
// Db::name('pay_order')->where('PayOrder', $data['out_trade_no'])->update(
// [
// 'is_new' => 1,
// ]
// );
// //查询用户积分
// $FirstPayUserinfo = Db::name('user')->where('id', $PayOrderInfo['user_id'])->find();
// //更改用户积分
// $UpdateFirstPay = Db::name('user')->where('id', $PayOrderInfo['user_id'])->update(['num' => $FirstPayUserinfo['num'] + (floor($OrderInfo['total']) * 2)]);
// if (!$UpdateFirstPay) {
// $this->error('更改用户积分失败失败', 0);
// die;
// }
// //添加用户积分记录
// $InserNumSql = [
// 'user_id' => $PayOrderInfo['user_id'],
// 'status' => 1,
// 'type' => 5,
// 'num' => floor($OrderInfo['total']) * 2,
// 'up_num' => $FirstPayUserinfo['num'] + (floor($OrderInfo['total']) * 2),
// 'createtime' => time()
// ];
// Db::name('num')->insert($InserNumSql);
//新用户消费 上级增加积分
$Fuser_id = Db::name('group')->where('user_id', $PayOrderInfo['user_id'])->value('fuser_id');
if (!empty($Fuser_id)) {
$FuserInfo = Db::name('user')->where('id', $Fuser_id)->find();
Db::name('user')->where('id', $Fuser_id)->update(
[
'num' => $FuserInfo['num'] + floor($OrderInfo['total'])
]
);
//添加用户积分记录
$Fuser_idSql2 = [
'user_id' => $PayOrderInfo['user_id'],
'status' => 1,
'type' => 9,
'num' => floor($OrderInfo['total']),
'up_num' => $FuserInfo['num'] + floor($OrderInfo['total']),
'createtime' => time()
];
Db::name('num')->insert($Fuser_idSql2);
}
//添加用户积分记录
$InserNumSql2 = [
'user_id' => $PayOrderInfo['user_id'],
'status' => 1,
'type' => 6,
'num' => $LevelSql['num'],
'up_num' => $LevelUserInfo['num'] + $LevelSql['num'],
'createtime' => time()
];
Db::name('num')->insert($InserNumSql2);
}
// //是否升级
// //已消费金额 $Consumed
// $Consumed = $this->YiXiaofeiMoney($PayOrderInfo['user_id']);
// $Level = Db::name('user')->where('id', $PayOrderInfo['user_id'])->value('level');
// $LevelSql = Db::name('level')->where('type', $Level + 1)->find();
// if ($Consumed > $LevelSql['price'] && $Consumed == $LevelSql['price']) {
// $LevelUserInfo = Db::name('user')->where('id', $PayOrderInfo['user_id'])->find();
// //更改用户积分
// $UpdateLevelUserInfo = Db::name('user')->where('id', $PayOrderInfo['user_id'])->update(['num' => $LevelUserInfo['num'] + $LevelSql['num']]);
// if (!$UpdateLevelUserInfo) {
// $this->error('更改用户积分失败失败2', 0);
// die;
// }
// //添加用户积分记录
// $InserNumSql2 = [
// 'user_id' => $PayOrderInfo['user_id'],
// 'status' => 1,
// 'type' => 6,
// 'num' => $LevelSql['num'],
// 'up_num' => $LevelUserInfo['num'] + $LevelSql['num'],
// 'createtime' => time()
// ];
// Db::name('num')->insert($InserNumSql2);
// }
//好友下单奖励
$Fuser_id = Db::name('group')->where('user_id', $PayOrderInfo['user_id'])->value('fuser_id');
if (!empty($Fuser_id)) {
$FuserInfo = Db::name('user')->where('id', $Fuser_id)->find();
Db::name('user')->where('id', $Fuser_id)->update(
[
'num' => $FuserInfo['num'] + 300
]
);
//添加用户积分记录
$Fuser_idSql2 = [
'user_id' => $PayOrderInfo['user_id'],
'status' => 1,
'type' => 9,
'num' => 300,
'up_num' => $FuserInfo['num'] + 300,
'createtime' => time()
];
Db::name('num')->insert($Fuser_idSql2);
}
// $Fuser_id = Db::name('group')->where('user_id', $PayOrderInfo['user_id'])->value('fuser_id');
// if (!empty($Fuser_id)) {
// $FuserInfo = Db::name('user')->where('id', $Fuser_id)->find();
// Db::name('user')->where('id', $Fuser_id)->update(
// [
// 'num' => $FuserInfo['num'] + 300
// ]
// );
// //添加用户积分记录
// $Fuser_idSql2 = [
// 'user_id' => $PayOrderInfo['user_id'],
// 'status' => 1,
// 'type' => 9,
// 'num' => 300,
// 'up_num' => $FuserInfo['num'] + 300,
// 'createtime' => time()
// ];
// Db::name('num')->insert($Fuser_idSql2);
// }
//活动逻辑 单笔订单满100元,额外奖励5元。单笔订单满399,额外奖励50元,单笔订单满699元,额外奖励100元;(下级下单)奖励到活动收益表
$Part = Db::name('huodong')->find();
$i = 0;
... ...