Commit 7a949730 authored by hj's avatar hj

更新提交0

parent 495a26aa
......@@ -76,6 +76,16 @@ class OrdersDetailProperty
*/
public $siAmount;
/**
* @Property(
* type="number",
* description="代金券抵扣金额"
* )
*
* @var string
*/
public $siVamount;
/**
* @Property(
* type="string",
......
......@@ -85,4 +85,14 @@ class OrdersDispatchProperty
* @var string
*/
public $cas;
/**
* @Property(
* type="string",
* description="批次号"
* )
*
* @var string
*/
public $pstkNo;
}
......@@ -65,6 +65,7 @@ class OrderDetailTransformer extends TransformerAbstract
$tempItems['si_discount'] = $item['si_discount'];
$tempItems['si_num'] = $item['si_num'];
$tempItems['si_amount'] = $item['si_amount'];
$tempItems['si_vamount'] = $item['si_vamount'];
$tempItems['p_code'] = $item['p_code'];
$tempItems['p_cn_name'] = $item['p_cn_name'];
$tempItems['p_level'] = $item['p_level'];
......
......@@ -118,4 +118,34 @@ class RhawnCustomerRepositoryEloquent extends BaseRepository implements RhawnCus
}
return null;
}
public function getCustomerRebate($cusCode)
{
$customerCrStatus = RhawnCustomer::query()
->join('cusrebate','customers.cus_id','cusrebate.cus_id')
->where('customers.cus_no',$cusCode)
->get();
if($customerCrStatus){
$customerCrStatus = $customerCrStatus->toArray();
if(!empty($customerCrStatus) && current($customerCrStatus)['cr_status'] == 3){
return true;
}
}
return false;
}
public function getCustomerVoucherList($cusCode)
{
$customerVoucherList = RhawnCustomer::query()
->join('voucher','customers.cus_id','voucher.cus_id')
->where('customers.cus_no',$cusCode)
->where('voucher.so_id', 0)
->orderBy('voucher.v_amount','DESC')
->get();
if($customerVoucherList){
return $customerVoucherList->toArray();
}
return null;
}
}
......@@ -50,4 +50,18 @@ class RhawnCustomerService
}
return $customer;
}
/**
* 获取客户代金券信息
* @param $cusCode
* @return void|null
*/
public function getCustomerVoucherList($cusCode)
{
$customerRebate = $this->customerRepository->getCustomerRebate($cusCode);
if($customerRebate){
return null;
}
return $this->customerRepository->getCustomerVoucherList($cusCode);
}
}
......@@ -168,7 +168,7 @@ class RhawnOrdersService
$connection->table('soitems')->insert($soitems);
if($data['v_id'] != ''){
$orderId = $connection->table('voucher')
$connection->table('voucher')
->where('v_id',$data['v_id'])
->update([
'so_id' => $orderId
......
......@@ -201,7 +201,33 @@ class RhawnOrdersService
$data['express'] = $express;
$data['v_id'] = '';
$data['soitems'] = [];
//如果使用代金券
$equalVoucherList = [];
if(!empty($requestParams['use_voucher']) && $requestParams['use_voucher'] == 1){
$voucherList = $this->rhawnCustomerService->getCustomerVoucherList($customer['cus_no']);
//找到最合适的代金券
if($voucherList){
foreach($voucherList as $voucher){
if($data['sorders']['so_total'] >= $voucher['v_cond']){
if(empty($equalVoucherList[$voucher['v_cond']][$voucher['v_amount']])){
$equalVoucherList[$voucher['v_cond']][$voucher['v_amount']] = $voucher;
}
}
}
if(!empty($equalVoucherList)){
asort($equalVoucherList);
$equalVoucherList = current(current($equalVoucherList));
}
}
}
if(!empty($equalVoucherList)){
$v_amount = 0;
$num = count($orderItems['rows']);
$data['v_id'] = $equalVoucherList['v_id'];
}
foreach($orderItems['rows'] as $k => $v){
$soitem = [];
$soitem['p_id'] = $v['product_info']['p_id'];
$soitem['si_price'] = $v['product_info']['p_price'];
......@@ -219,8 +245,43 @@ class RhawnOrdersService
if(isset($v['si_molbase_pog'])){
$soitem['si_molbase_pog'] = $v['si_molbase_pog'];
}
if(!empty($equalVoucherList)){
if ($num == 1) {
$tmp_amount = $v['amount'] - $equalVoucherList['v_amount'];
$si_discount = bcdiv($tmp_amount, $v['num'], 1);//抵扣后的折后价
$si_amount = bcmul($si_discount,$v['num'],2);//抵扣后的小计
$this_v_amount = bcsub($v['amount'],$si_amount,2);//最终抵扣金额
} else {
if (($k + 1) != $num) {
$rate = bcdiv($v['amount'], $data['sorders']['so_total'], 3);
$this_v_amount = round(bcmul($rate, $equalVoucherList['v_amount']));//计算抵扣代金券总额的比例
$tmp_amount = $v['amount'] - $this_v_amount;
$si_discount = bcdiv($tmp_amount, $v['num'], 1);//抵扣后的折后价
$si_amount = bcmul($si_discount,$v['num'],2);//抵扣后的小计
$this_v_amount = bcsub($v['amount'],$si_amount,2);//最终抵扣金额
} else {
$this_v_amount = $equalVoucherList['v_amount'] - $v_amount;
$tmp_amount = $v['amount'] - $this_v_amount;
$si_discount = bcdiv($tmp_amount, $v['num'], 1);//抵扣后的折后价
$si_amount = bcmul($si_discount,$v['num'],2);//抵扣后的小计
$this_v_amount = bcsub($v['amount'],$si_amount,2);//最终抵扣金额
}
}
$v_amount += $this_v_amount;
$soitem['si_discount'] = $si_discount;
$soitem['si_amount'] = $si_amount;
$soitem['si_vamount'] = $this_v_amount;
//$data['sorders']['so_total'] = bcsub($data['sorders']['so_total'] , $v_amount , 2);
}
array_push($data['soitems'],$soitem);
}
if(!empty($data['v_id'])){
$data['sorders']['so_total'] = bcsub($data['sorders']['so_total'] , $v_amount , 2);
}
$orderId = $this->rhawnOrdersService->createOrders($data);
if($orderId){
......
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