Commit be330efd authored by hangjun83's avatar hangjun83

修复bug

parent 5ea9a62a
......@@ -16,8 +16,11 @@ use App\Repositories\Contracts\BhPordersRepository;
use App\Repositories\Contracts\BhSoitemsRepository;
use App\Repositories\Contracts\BhSorderRefundRepository;
use App\Repositories\Contracts\BhSordersRepository;
use App\Repositories\Contracts\SysLogRepository;
use App\Repositories\Contracts\ToolsTaskRepository;
use App\Repositories\Criteria\BhPordersCriteria;
use App\Repositories\Criteria\BhSorderRefundCriteria;
use App\Repositories\Criteria\BhSorderRefundTaskLogCriteria;
use App\Repositories\Enums\ResponseCodeEnum;
use App\Repositories\Models\AdminUsers;
use App\Repositories\Models\BhPorders;
......@@ -237,7 +240,14 @@ class BhOrdersService
throw new \LogicException('退货数量大于购买数量',500);
}
if($orderitem['si_num'] == $refundInfo->refund_nums){
// 统计有多少数量
$sum = $dbConnect->table('soitems')
->where('so_id',$orderitem['so_id'])
->where('si_id',$orderitem['si_id'])
->sum('si_num');
// 如果是全部退货并且没有手续费的情况
if($sum == $refundInfo->refund_nums && $refundInfo->handle_fee == 0){
throw new \LogicException('本功能不支持全部退货,如果需要全部退货请移步百化系统后台进行操作!',500);
}
......@@ -322,6 +332,7 @@ class BhOrdersService
throw new \LogicException('手续费异常,处理失败!',500);
}
}
/*If(isset($refundInfo->handle_fee) && $refundInfo->handle_fee > 0){
$updateArr['si_amount'] = bcadd($updateArr['si_amount'] , $refundInfo->handle_fee,2);
}
......@@ -379,7 +390,7 @@ class BhOrdersService
$updatedItem['total'] = $currentAmount;
//修改配货单记录
//修改配货单记录
if($dpdetail){
$maxRecord = $minRecord = [];
$needUpdate = null;
......@@ -417,31 +428,47 @@ class BhOrdersService
// 如果退货数量跟此明细数量相同,不需要拆分的情况下
if(!is_null($needUpdate)){
$dpUpdateArr = [];
$dpUpdateArr['si_id'] = $updatedItem['create']['si_id'];
// 如果有手续费,对价格进行更新
if($refundInfo->handle_fee > 0){
// 如果有手续费,将价格进行修改
foreach($dpdetail as $detail){
if($detail->dpd_id != $needUpdate['dpd_id']){
$otherUpdate = [];
$otherUpdate['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $detail->dpd_num, 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$detail->dpd_id)
->update($otherUpdate);
}
// 如果是全部退货
if($refundInfo->refund_nums == $needUpdate['dpd_num'] && count($dpdetail) == 1){
// 如果有手续费,将价格进行修改
foreach($dpdetail as $detail){
$otherUpdate = [];
$otherUpdate['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $detail->dpd_num, 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$detail->dpd_id)
->update($otherUpdate);
}
}else{
// 如果有手续费,将价格进行修改
foreach($dpdetail as $detail){
if($detail->dpd_id != $needUpdate['dpd_id']){
$otherUpdate = [];
$otherUpdate['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $detail->dpd_num, 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$detail->dpd_id)
->update($otherUpdate);
}
}
$dpUpdateArr['si_id'] = $updatedItem['create']['si_id'];
//将取消的记录价格进行更新
$dpUpdateArr['dpd_amount'] = bcmul($updatedItem['create']['si_discount'], $needUpdate['dpd_num'], 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$needUpdate['dpd_id'])
->update($dpUpdateArr);
}
//将取消的记录价格进行更新
$dpUpdateArr['dpd_amount'] = bcmul($updatedItem['create']['si_discount'], $needUpdate['dpd_num'], 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$needUpdate['dpd_id'])
->update($dpUpdateArr);
} // 如果没有手续费,不对价格进行更新
else{
/*else{
echo "<pre>";
print_r($needUpdate);
exit;
$dbConnect->table('dpdetail')
->where('dpd_id',$needUpdate['dpd_id'])
->update($dpUpdateArr);
}
}*/
}else{
asort($maxRecord);
......@@ -452,8 +479,24 @@ class BhOrdersService
// minrecord有值,只有退货数量大于此条记录的数量时
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$minRecord,$updatedItem,$refundInfo,'asort'));
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$maxRecord,$updatedItem,$refundInfo,'arsort'));
}
// 判断是否这次是全部取消
$dpCount = $dbConnect->table('dpdetail')
->where('si_id',$orderitem['si_id'])
->whereIn('dpd_id',$cancelRecord)->sum('dpd_num');
if($dpCount == 0 && $sum == $refundInfo->refund_nums){
$infos = $dbConnect->table('dpdetail')
->whereIn('dpd_id',$cancelRecord)->get();
foreach($infos->toArray() as $info){
$update = [];
$update['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $info->dpd_num, 2);
$update['si_id'] = $orderitem['si_id'];
$dbConnect->table('dpdetail')
->where('dpd_id',$info->dpd_id)
->update($update);
}
}
}
// 更新除了取消的记录以外的记录的价格
if(count($cancelRecord) > 0){
$dpdetailInfo = $dbConnect->table('dpdetail')
......@@ -639,7 +682,6 @@ class BhOrdersService
$dpCreateArr['dpd_amount'] = bcmul($updatedItem['create']['si_discount'], $num, 2);
$dpCreateArr['si_id'] = $updatedItem['create']['si_id'];
$dpId = $dbConnect->table('dpdetail')->insertGetId($dpCreateArr);
$num = 0;
$cancelRecord[] = $dpId;
}
......@@ -975,19 +1017,14 @@ class BhOrdersService
{
$params = $this->formatKeysfromArray($request->all(),'toUnderScore');
$this->bhPordersRepository->pushCriteria(new BhPordersCriteria($request));
$pOrdersList = $this->bhPordersRepository->paginate($params['page_size']);
$returnRecord = [];
if($pOrdersList){
$record = $this->procOrderResponseData($pOrdersList->items());
if(!isset($params['type']) || empty($params['type'])){
$params['type'] = 'sorder_refund';
}
// 获取当前角色的所有权限
$returnRecord['data'] = $this->formatKeysfromArray($record);
$returnRecord['current_page'] = $pOrdersList->currentPage();
$returnRecord['total'] = $pOrdersList->total();
return $returnRecord; }
$taskService = app(ToolsTaskRepository::class);
$taskLogsList = $taskService->getTaskLogsFromType($params['type'],$params['task_id']);
return $taskLogsList;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment