|
@@ -1,18 +1,18 @@
|
|
|
<?php
|
|
|
namespace app\service;
|
|
|
|
|
|
-use app\common\model\Area;
|
|
|
+use app\common\model\SysConfig;
|
|
|
use app\common\model\User;
|
|
|
use app\common\model\UserCoupon;
|
|
|
use app\common\model\UserOrder;
|
|
|
-use think\Exception;
|
|
|
|
|
|
class UserOrderService{
|
|
|
protected $order;
|
|
|
protected $user;
|
|
|
- /** @var UserCoupon[] */
|
|
|
protected $coupon;
|
|
|
protected $user_coupon=[];
|
|
|
+ protected $config=[];
|
|
|
+ protected $cage_spec;
|
|
|
|
|
|
/**
|
|
|
* @return UserCoupon[]
|
|
@@ -40,6 +40,7 @@ class UserOrderService{
|
|
|
public function __construct()
|
|
|
{
|
|
|
bcscale(2);
|
|
|
+ $this->config=SysConfig::look('price_config',config('process'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -95,10 +96,20 @@ class UserOrderService{
|
|
|
$this->order['to_latitude']=$this->order['to_addr']['latitude'];
|
|
|
}
|
|
|
|
|
|
+ protected function distance(){
|
|
|
+ $this->order['distance']=ll_distance(
|
|
|
+ $this->order['from_longitude'],
|
|
|
+ $this->order['from_latitude'],
|
|
|
+ $this->order['to_longitude'],
|
|
|
+ $this->order['to_latitude']
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
public function import(&$data){
|
|
|
list($data['agree_date'],$data['agree_time'])=explode(' ',$data['agree_time']);
|
|
|
$data['pet_category']=Pet::category()[$data['pet_category']]['name']??throw_user("宠物类目不存在");
|
|
|
- $data['spec']=Pet::spec()[$data['spec']]['name']??throw_user('宠具规格不存在');
|
|
|
+ $this->cage_spec=Pet::spec()[$data['spec']]??throw_user('宠具规格不存在');
|
|
|
+ $data['spec']=$this->cage_spec['name'];
|
|
|
if(!empty($data['protect_id'])) {
|
|
|
$protect=Pet::protect()[$data['protect_id']];
|
|
|
$data['protect_amount'] = $protect['price'];
|
|
@@ -108,6 +119,7 @@ class UserOrderService{
|
|
|
$data['real_amount']=0;
|
|
|
$this->order=$data;
|
|
|
$this->area();
|
|
|
+ $this->distance();
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
@@ -118,8 +130,8 @@ class UserOrderService{
|
|
|
$item=[
|
|
|
'type'=>$type,//类型
|
|
|
'price'=>0,#实付
|
|
|
- 'total_price'=>0,#总价
|
|
|
- 'coupon'=>[],
|
|
|
+ 'total_price'=>0,#单个类型支付总价
|
|
|
+ 'coupon'=>[],//可用的优惠券列表
|
|
|
];
|
|
|
$item['total_price']=$this->{$type}();
|
|
|
$item['price']=$item['total_price'];
|
|
@@ -158,8 +170,25 @@ class UserOrderService{
|
|
|
}
|
|
|
|
|
|
protected function fast(){
|
|
|
- $price=bcmul(bcmul(bcmul(2,$this->order['num']),$this->order['weight']),$this->order['piece']);
|
|
|
- return $price;
|
|
|
+ #距离
|
|
|
+ $distance=$this->order['distance'];
|
|
|
+ $start_kilo=$this->config['fast']['start_kilo'];
|
|
|
+ $start_amount=$this->config['fast']['start_amount'];
|
|
|
+ if($distance<=$start_kilo){
|
|
|
+ $distance_price=$start_amount;
|
|
|
+ }else{
|
|
|
+ $out_price=$start_amount;
|
|
|
+ foreach ($this->config['fast']['detail'] as $detail){
|
|
|
+ if($distance>=$detail['start_kilo'] && $distance<$detail['end_kilo']){
|
|
|
+ $out_price=bcadd($out_price,bcmul($detail['amount'],$distance));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $distance_price=$out_price;
|
|
|
+ }
|
|
|
+ #宠具
|
|
|
+ $cage_price=$this->cage();
|
|
|
+ return bcadd($distance_price,$cage_price);
|
|
|
}
|
|
|
protected function air(){
|
|
|
$price=bcmul(bcmul(bcmul(2,$this->order['num']),$this->order['weight']),$this->order['piece']);
|
|
@@ -167,8 +196,26 @@ class UserOrderService{
|
|
|
return $price;
|
|
|
}
|
|
|
protected function special(){
|
|
|
- $price=bcmul(bcmul(bcmul(2,$this->order['num']),$this->order['weight']),$this->order['piece']);
|
|
|
- $price=bcmul($price,2);
|
|
|
- return $price;
|
|
|
+ #距离
|
|
|
+ $distance=$this->order['distance'];
|
|
|
+ $start_kilo=$this->config['special']['start_kilo'];
|
|
|
+ $start_amount=$this->config['special']['start_amount'];
|
|
|
+ if($distance<=$start_kilo){
|
|
|
+ $distance_price=$start_amount;
|
|
|
+ }else{
|
|
|
+ $distance_price=bcmul(bcsub($distance,$start_kilo),$this->config['special']['out_amount']);
|
|
|
+ $distance_price=bcadd($start_amount,$distance_price);
|
|
|
+ }
|
|
|
+ #笼具
|
|
|
+ $cage_price=$this->cage();
|
|
|
+
|
|
|
+ return bcadd($distance_price,$cage_price);
|
|
|
+ }
|
|
|
+ protected function cage(){
|
|
|
+ if($this->order['has_cage']){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ $cage_num=$this->order['piece'];
|
|
|
+ return bcmul($cage_num,$this->cage_spec['amount']);
|
|
|
}
|
|
|
}
|