修复:复购信息判断重构、返利明细判断错误导致显示错误、商品复购价格判断错误导致价格为0
This commit is contained in:
parent
99a443701e
commit
d57e84fc09
|
|
@ -602,44 +602,42 @@ class Privilege extends BaseModel
|
||||||
// 判断:是否开启消费返利
|
// 判断:是否开启消费返利
|
||||||
$goodsRebate = GoodsRebate::where('goods_id',$this->goods_id)->first();
|
$goodsRebate = GoodsRebate::where('goods_id',$this->goods_id)->first();
|
||||||
if($goodsRebate->is_open == 1){
|
if($goodsRebate->is_open == 1){
|
||||||
// 判断:当前返利记录是否已经失效 最后一条返利信息已失效或者已结算 则允许重新购买 状态:0=冻结中,1=待结算,2=已结算,3=已失效,4=已退款(失效)
|
// 判断:当前返利记录是否存在
|
||||||
$endTime = Rebate::where('uid', $member->uid)
|
$rebateInfo = Rebate::uniacid()
|
||||||
|
->selectRaw('max(reality_thaw_time) as last_reality_thaw_time,max(status) as max_status')
|
||||||
|
->where('uid', $member->uid)
|
||||||
->where('goods_id', $this->goods_id)
|
->where('goods_id', $this->goods_id)
|
||||||
->max('expect_thaw_time');
|
|
||||||
if(empty($endTime)) return false;
|
|
||||||
$endInfo = Rebate::where('uid', $member->uid)
|
|
||||||
->where('goods_id', $this->goods_id)
|
|
||||||
->where('expect_thaw_time', $endTime)
|
|
||||||
->first();
|
->first();
|
||||||
if(!$endInfo || in_array($endInfo->status,[2,3,4])) return false;
|
// 不存在返利记录,从未购买 允许购买
|
||||||
// 获取已经返利的 最大时间
|
if(empty($rebateInfo)) return;
|
||||||
$maxTime = Rebate::where('uid', $member->uid)
|
$rebateInfo = $rebateInfo->toArray();
|
||||||
|
// 判断:最大状态是否为1或者2 不是则失效,允许购买
|
||||||
|
if(!in_array($rebateInfo['max_status'],[1,2])) return;
|
||||||
|
// 判断:最后结算信息获取 并且判断是否需要复购,需要则返回复购价格
|
||||||
|
$endInfo = Rebate::uniacid()
|
||||||
|
->where('uid', $member->uid)
|
||||||
->where('goods_id', $this->goods_id)
|
->where('goods_id', $this->goods_id)
|
||||||
->where('status', 2)
|
->where('reality_thaw_time', $rebateInfo['last_reality_thaw_time'])
|
||||||
->max('reality_thaw_time');
|
|
||||||
if(empty($maxTime)) return false;
|
|
||||||
$lastInfo = Rebate::where('uid', $member->uid)
|
|
||||||
->where('goods_id', $this->goods_id)
|
|
||||||
->where('status', 2)
|
|
||||||
->where('reality_thaw_time', $maxTime)
|
|
||||||
->first();
|
->first();
|
||||||
if(!$lastInfo) return false;
|
// 是否需要复购 需要则判断是否已经复购,不需要则报错 未到复购时间
|
||||||
$lastInfo = $lastInfo->toArray();
|
if($endInfo->is_repurchase == 1){
|
||||||
if($lastInfo['is_repurchase'] != 1) throw new AppException('未到复购时间');
|
// 判断:需要复购 最后一次结算时间N天内
|
||||||
// 判断:需要复购 最后一次结算时间N天内
|
$set = Setting::get('plugin.rebate');
|
||||||
$set = Setting::get('plugin.rebate');
|
$repurchaseDay = $set['repurchase_day'] ?? 0;// 复购限制天数
|
||||||
$repurchase_day = $set['repurchase_day'] ?? 0;
|
$limitTime = strtotime(date("Y-m-d H:i:s",$rebateInfo['last_reality_thaw_time'])." +{$repurchaseDay} day");
|
||||||
$limitTime = strtotime(date("Y-m-d H:i:s",$maxTime)." +{$repurchase_day} day");
|
// 判断:最后复购时间 小于等于 当前时间,超出复购时间,禁止复购
|
||||||
// 判断:最后复购时间 小于等于 当前时间,超出复购时间,禁止复购
|
if($limitTime <= time()) throw new AppException('已超过复购时间');
|
||||||
if($limitTime <= time()) throw new AppException('已超过复购时间');
|
// 是否已经存在复购订单
|
||||||
// 是否已经存在复购订单
|
$isHas = (int)OrderGoods::where('is_rebate',1)
|
||||||
$isHas = (int)OrderGoods::where('is_rebate',1)
|
->where('created_at', '>', $rebateInfo['last_reality_thaw_time'])// 在最后一次返利后的订单
|
||||||
->where('created_at', '>', $maxTime)// 在最后一次返利后的订单
|
->where('created_at', '<=', $limitTime)// 在复购时间内的订单
|
||||||
->where('created_at', '<=', $limitTime)// 在复购时间内的订单
|
->where('goods_id', $this->goods_id)// 同一个商品
|
||||||
->where('goods_id', $this->goods_id)// 同一个商品
|
->where('uid', $member->uid)// 同一个用户
|
||||||
->where('uid', $member->uid)// 同一个用户
|
->value('id');
|
||||||
->value('id');
|
if($isHas > 0) throw new AppException('请勿重复复购!');
|
||||||
if($isHas > 0) throw new AppException('请勿重复复购!');
|
}else{
|
||||||
|
throw new AppException('未到复购时间');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,26 +107,29 @@ abstract class BaseOrderGoodsPrice extends OrderGoodsPrice
|
||||||
$this->price = $this->getGoodsPrice();
|
$this->price = $this->getGoodsPrice();
|
||||||
$this->price = max($this->price, 0);
|
$this->price = max($this->price, 0);
|
||||||
// 判断:是否开启消费返利
|
// 判断:是否开启消费返利
|
||||||
$goodsRebate = GoodsRebate::where('goods_id',$this->orderGoods->goods_id)->first();
|
$goodsRebate = GoodsRebate::uniacid()->where('goods_id',$this->orderGoods->goods_id)->first();
|
||||||
if($goodsRebate->is_open == 1){
|
if($goodsRebate->is_open == 1){
|
||||||
// 判断:当前返利记录是否已经失效
|
// 判断:当前返利记录是否存在
|
||||||
$endTime = Rebate::where('uid', $this->orderGoods->uid)
|
$rebateInfo = Rebate::uniacid()
|
||||||
|
->selectRaw('max(reality_thaw_time) as last_reality_thaw_time,max(status) as max_status')
|
||||||
|
->where('uid', $this->orderGoods->uid)
|
||||||
->where('goods_id', $this->orderGoods->goods_id)
|
->where('goods_id', $this->orderGoods->goods_id)
|
||||||
->max('reality_thaw_time');
|
|
||||||
// 不存在返利记录 原价购买
|
|
||||||
if(empty($endTime)) return $this->price;
|
|
||||||
// 存在返利记录 判断最后一条信息的状态
|
|
||||||
$endInfo = Rebate::where('uid', $this->orderGoods->uid)
|
|
||||||
->where('goods_id', $this->orderGoods->goods_id)
|
|
||||||
->where('reality_thaw_time', $endTime)
|
|
||||||
->first();
|
->first();
|
||||||
// 已失效 原价购买
|
// 不存在返利记录,从未购买 原价购买
|
||||||
if($endInfo->status == 2){
|
if(empty($rebateInfo)) return $this->price;
|
||||||
// 复购
|
$rebateInfo = $rebateInfo->toArray();
|
||||||
|
// 判断:最大状态是否为1或者2 不是则失效,原价购买
|
||||||
|
if(!in_array($rebateInfo['max_status'],[1,2])) return $this->price;
|
||||||
|
// 判断:最后结算信息获取 并且判断是否需要复购,需要则返回复购价格
|
||||||
|
$endInfo = Rebate::uniacid()
|
||||||
|
->where('uid', $this->orderGoods->uid)
|
||||||
|
->where('goods_id', $this->orderGoods->goods_id)
|
||||||
|
->where('reality_thaw_time', $rebateInfo['last_reality_thaw_time'])
|
||||||
|
->first();
|
||||||
|
// 是否需要复购 需要则返回复购价格,否则无操作
|
||||||
|
if($endInfo->is_repurchase == 1){
|
||||||
$endInfo = $endInfo->toArray();
|
$endInfo = $endInfo->toArray();
|
||||||
$goodsRebate = $goodsRebate->toArray();
|
$this->price = $endInfo['repurchase_money'] ?? $this->price;
|
||||||
$quarter = $goodsRebate['quarter_list'][$endInfo['quarter']];
|
|
||||||
$this->price = $quarter['repurchase_money'] ?? 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use app\common\facades\Setting;
|
||||||
use app\common\models\Goods;
|
use app\common\models\Goods;
|
||||||
use app\common\models\Income;
|
use app\common\models\Income;
|
||||||
use app\common\models\Member;
|
use app\common\models\Member;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Yunshop\Rebate\models\Rebate;
|
use Yunshop\Rebate\models\Rebate;
|
||||||
use Yunshop\TeamDividend\models\TeamDividendAgencyModel;
|
use Yunshop\TeamDividend\models\TeamDividendAgencyModel;
|
||||||
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
|
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
|
||||||
|
|
@ -76,12 +77,23 @@ class IndexController extends ApiController{
|
||||||
])->first();
|
])->first();
|
||||||
$isRepurchase = $lastSettlement->is_repurchase ?? 0;
|
$isRepurchase = $lastSettlement->is_repurchase ?? 0;
|
||||||
if($isRepurchase == 1){
|
if($isRepurchase == 1){
|
||||||
$good = Goods::where('id',$rebateInfo['goods_id'])
|
$set = Setting::get('plugin.rebate');
|
||||||
->select(['id','title','thumb'])
|
$repurchaseDay = $set['repurchase_day'] ?? 0;
|
||||||
->first();
|
$startTime = strtotime(date("Y-m-d H:i:s",time())." -{$repurchaseDay} day");
|
||||||
if($good) {
|
$isRepurchase = (int)Db::table('yz_order_goods')
|
||||||
$good->price = $lastSettlement['repurchase_money'];
|
->join('yz_order','yz_order.id','=','yz_order_goods.order_id')
|
||||||
$goods[] = $good->toArray();
|
->where('yz_order_goods.is_rebate',1)
|
||||||
|
->where('yz_order.pay_time','>',$startTime)
|
||||||
|
->where('yz_order.uid',$uid)
|
||||||
|
->value('yz_order_goods.id');
|
||||||
|
if($isRepurchase <= 0){
|
||||||
|
$good = Goods::where('id',$rebateInfo['goods_id'])
|
||||||
|
->select(['id','title','thumb'])
|
||||||
|
->first();
|
||||||
|
if($good) {
|
||||||
|
$good->price = $lastSettlement['repurchase_money'];
|
||||||
|
$goods[] = $good->toArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -126,8 +138,8 @@ class IndexController extends ApiController{
|
||||||
->sum('yz_member_income.amount');
|
->sum('yz_member_income.amount');
|
||||||
// 获取全部返利信息 并且循环处理
|
// 获取全部返利信息 并且循环处理
|
||||||
$set = Setting::get('plugin.rebate');
|
$set = Setting::get('plugin.rebate');
|
||||||
$repurchase_day = $set['repurchase_day'] ?? 0;
|
$repurchaseDay = $set['repurchase_day'] ?? 0;
|
||||||
$monthList = Rebate::select(['id','quarter','month','expect_thaw_time','money','status','is_repurchase','repurchase_money','reality_thaw_time'])
|
$monthList = Rebate::select(['id','quarter','month','expect_thaw_time','money','status','is_repurchase','repurchase_money','reality_thaw_time','goods_id'])
|
||||||
->where([
|
->where([
|
||||||
'uid' => $uid,
|
'uid' => $uid,
|
||||||
'order_id' => $lastRebateInfo['order_id'],
|
'order_id' => $lastRebateInfo['order_id'],
|
||||||
|
|
@ -135,31 +147,58 @@ class IndexController extends ApiController{
|
||||||
])
|
])
|
||||||
->get()
|
->get()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
// 循环每月信息 生成季度信息
|
||||||
foreach($monthList as $monthInfo){
|
foreach($monthList as $monthInfo){
|
||||||
|
// 时间
|
||||||
|
$monthInfo['expect_thaw_time'] = strtotime($monthInfo['expect_thaw_time']);
|
||||||
|
$monthInfo['reality_thaw_time'] = strtotime($monthInfo['reality_thaw_time']);
|
||||||
|
// 信息赋值及处理
|
||||||
$quarterList[$monthInfo['quarter']]['quarter'] = (int)$monthInfo['quarter'];
|
$quarterList[$monthInfo['quarter']]['quarter'] = (int)$monthInfo['quarter'];
|
||||||
$quarterList[$monthInfo['quarter']]['list'][$monthInfo['month']] = $monthInfo;
|
$quarterList[$monthInfo['quarter']]['list'][$monthInfo['month']] = $monthInfo;
|
||||||
// 复购信息
|
|
||||||
if($quarterList[$monthInfo['quarter']]['is_repurchase'] != 1) {
|
|
||||||
$quarterList[$monthInfo['quarter']]['is_repurchase'] = (int)$monthInfo['is_repurchase'];
|
|
||||||
$quarterList[$monthInfo['quarter']]['repurchase_money'] = (float)$monthInfo['repurchase_money'];
|
|
||||||
}
|
|
||||||
// 返利时间 开始 ~ 结束
|
// 返利时间 开始 ~ 结束
|
||||||
if($monthInfo['month'] == 1) $quarterList[$monthInfo['quarter']]['start_time'] = date("Y.m", strtotime($monthInfo['expect_thaw_time']));
|
if($monthInfo['month'] == 1) $quarterList[$monthInfo['quarter']]['start_time'] = date("Y.m", $monthInfo['expect_thaw_time']);
|
||||||
$quarterList[$monthInfo['quarter']]['end_time'] = date("Y.m", strtotime($monthInfo['expect_thaw_time']));
|
$quarterList[$monthInfo['quarter']]['end_time'] = date("Y.m", $monthInfo['expect_thaw_time']);
|
||||||
// 本季度总金额
|
// 本季度总金额
|
||||||
$quarterList[$monthInfo['quarter']]['total_money'] += (float)$monthInfo['money'];
|
$quarterList[$monthInfo['quarter']]['total_money'] += (float)$monthInfo['money'];
|
||||||
// 本季度是否在结算中 不是结算中 = 最新状态,是结算中 = 状态不变
|
|
||||||
if($quarterList[$monthInfo['quarter']]['status'] != 2) $quarterList[$monthInfo['quarter']]['status'] = (int)$monthInfo['status'];
|
|
||||||
// 当前记录最后一次结算时间
|
|
||||||
$reality_thaw_time = $monthInfo['reality_thaw_time'] ? strtotime($monthInfo['reality_thaw_time']) : 0;
|
|
||||||
if(!array_key_exists('last_reality_thaw_time',$quarterList[$monthInfo['quarter']])) $quarterList[$monthInfo['quarter']]['last_reality_thaw_time'] = 0;
|
|
||||||
if((int)$reality_thaw_time > 0) {
|
|
||||||
$quarterList[$monthInfo['quarter']]['last_reality_thaw_time'] = (int)$reality_thaw_time;
|
|
||||||
$quarterList[$monthInfo['quarter']]['repurchase_end_time'] = (int)strtotime(date("Y-m-d H:i:s",$reality_thaw_time)." +{$repurchase_day} day");;
|
|
||||||
}
|
|
||||||
// 最后一次预计结算时间
|
|
||||||
$quarterList[$monthInfo['quarter']]['last_expect_thaw_time'] = $monthInfo['expect_thaw_time'] ? strtotime($monthInfo['expect_thaw_time']) : 0;
|
|
||||||
}
|
}
|
||||||
|
// 循环处理季度信息
|
||||||
|
$upQuarter = [];
|
||||||
|
foreach($quarterList as &$quarterInfo){
|
||||||
|
$quarterInfo['goods_id'] = max(array_column($quarterInfo['list'], 'goods_id'));
|
||||||
|
// 获取本季度状态 状态值最高则为本季度最高状态
|
||||||
|
$quarterInfo['status'] = max(array_column($quarterInfo['list'], 'status'));
|
||||||
|
// 获取本季度最后预计结算时间
|
||||||
|
$quarterInfo['last_expect_thaw_time'] = (int)max(array_column($quarterInfo['list'], 'expect_thaw_time'));
|
||||||
|
// 获取本季度最后已结算时间
|
||||||
|
$quarterInfo['last_reality_thaw_time'] = (int)max(array_column($quarterInfo['list'], 'reality_thaw_time'));
|
||||||
|
// 复购信息:当前季度复购信息 = 上一个季度复购信息
|
||||||
|
$quarterInfo['is_repurchase'] = (int)max(array_column($upQuarter['list'], 'is_repurchase'));
|
||||||
|
$quarterInfo['repurchase_money'] = (float)max(array_column($upQuarter['list'], 'repurchase_money'));
|
||||||
|
// 判断:本季度最后结算时间=0;且上一个季度结束需要复购;进入复购判断流程
|
||||||
|
$quarterInfo['repurchase_type'] = 0;// 0=无复购;1=有复购,未到复购时间;2=有复购,未复购;3=有复购,已复购
|
||||||
|
if($quarterInfo['last_reality_thaw_time'] == 0 && $quarterInfo['is_repurchase'] == 1){
|
||||||
|
// 且上一个季最后结算时间大于等于上一个季度最后预计结算时间 已到复购时间内
|
||||||
|
if($upQuarter['last_reality_thaw_time'] >= $upQuarter['last_expect_thaw_time']){
|
||||||
|
$quarterInfo['repurchase_type'] = 2;// 有复购 未复购
|
||||||
|
$quarterInfo['repurchase_end_time'] = (int)strtotime(date("Y-m-d H:i:s",$realityThawTime)." +{$repurchaseDay} day");;
|
||||||
|
// 判断:N天内是否存在 该商品和用户的复购订单 存在则已复购
|
||||||
|
$startTime = strtotime(date("Y-m-d H:i:s",time())." -{$repurchaseDay} day");
|
||||||
|
$isRepurchase = (int)Db::table('yz_order_goods')
|
||||||
|
->join('yz_order','yz_order.id','=','yz_order_goods.order_id')
|
||||||
|
->where('yz_order_goods.is_rebate',1)
|
||||||
|
->where('yz_order.pay_time','>',$startTime)
|
||||||
|
->where('yz_order.uid',$uid)
|
||||||
|
->value('yz_order_goods.id');
|
||||||
|
if($isRepurchase > 0) $quarterInfo['repurchase_type'] = 3;// 有复购 已复购
|
||||||
|
}else{
|
||||||
|
$quarterInfo['repurchase_type'] = 1;// 有复购 未到复购时间
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新上一个季度信息
|
||||||
|
$upQuarter = $quarterInfo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->successJson('success',compact('statistics', 'quarterList', 'realityThawTime'));
|
return $this->successJson('success',compact('statistics', 'quarterList', 'realityThawTime'));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue