Wayne 11 months ago
commit 7f671b4c57
  1. 14
      app/api/controller/Recovery.php
  2. 51
      app/api/controller/Store.php
  3. 4
      app/api/model/dealer/Order.php
  4. 69
      app/common/model/PriceSet.php

@ -134,11 +134,17 @@ class Recovery extends Controller
if (empty($params['order_id']) || empty($params['recovery_id']) || empty($params['status'])) { if (empty($params['order_id']) || empty($params['recovery_id']) || empty($params['status'])) {
return $this->renderError('缺少必要参数'); return $this->renderError('缺少必要参数');
} }
$model = new RecoveryOrder();
$res = $model->save(['order_status' => $params['status']]); $model = (new RecoveryOrder())::detail($params['order_id']);
if ($res) { if ($model) {
return $this->renderSuccess('更新成功'); if($params['status'] == RecoveryStatusEnum::ALREADY || $params['status'] == RecoveryStatusEnum::FINISN) {
$res = $model->save(['order_status' => $params['status']]);
if ($res) {
return $this->renderSuccess('更新成功');
}
}
} }
return $this->renderError('更新失败'); return $this->renderError('更新失败');
} }

@ -139,20 +139,25 @@ class Store extends Controller
PriceSet::where('store_id', $storeid)->where('type', $params['type']??0)->delete(); PriceSet::where('store_id', $storeid)->where('type', $params['type']??0)->delete();
$inDatas = []; $inDatas = [];
foreach ($params['list'] as $value) { foreach ($params['list'] as $value) {
foreach ($value['price_list'] as $price) { $categorys = explode(",", $value['category']);
$temp = [ foreach ($categorys as $category) {
'category' => $value['category'], foreach ($value['price_list'] as $price) {
'store_id' => $storeid, $temp = [
'type' => $params['type'], 'category' => $value['category'],
'min' => $price['min'], 'code' => $category,
'max' => $price['max'], 'store_id' => $storeid,
'add_price_rate' => $price['add_price_rate'], 'type' => $params['type'],
'create_time' => time(), 'min' => $price['min'],
'update_time' => time(), 'max' => $price['max'],
]; 'add_price_rate' => $price['add_price_rate'],
$inDatas[] = $temp; 'create_time' => time(),
'update_time' => time(),
];
$inDatas[] = $temp;
}
} }
} }
// echo "<pre>"; // echo "<pre>";
// print_r($inDatas); // print_r($inDatas);
@ -165,7 +170,7 @@ class Store extends Controller
public function getStorePriceInfo(int $type): Json public function getStorePriceInfo(int $type): Json
{ {
$storeid = request()->header()['storeid']; $storeid = request()->header()['storeid'];
$list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,min,max,add_price_rate')->select()->toArray(); $list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,code,min,max,add_price_rate')->group("category, min")->select()->toArray();
$data = []; $data = [];
$arr = []; $arr = [];
foreach ($list as $value) { foreach ($list as $value) {
@ -185,20 +190,12 @@ class Store extends Controller
public function test(int $type): Json public function test(int $type): Json
{ {
$storeid = request()->header()['storeid']; $storeid = request()->header()['storeid'];
$list = PriceSet::where('store_id',$storeid)->where('type', $params['type'] ?? 0)->field('category,min,max,add_price_rate')->select()->toArray();
$data = []; $categoryIds = [1001,1002];
$arr = []; $list = PriceSet::distributionPrice(90, 50, $categoryIds);
foreach ($list as $value) {
$arr[$value['category']][] = $value;
} return $this->renderSuccess($list);
foreach ($arr as $key => $item) {
$data['list'][] = [
'category' => $key,
'price_list' => $item,
];
}
$data['type'] = $type;
return $this->renderSuccess($data);
} }

@ -75,9 +75,9 @@ class Order extends DealerOrderModel
$item['second_user_id'] => $item['second_money'], $item['second_user_id'] => $item['second_money'],
$item['third_user_id'] => $item['third_money'], $item['third_user_id'] => $item['third_money'],
]; ];
$item['goods'] = $order_goods['goods']; $item['goods'] = $order_goods['goods'] ?? [];
$item['address_name'] =$address['name']; $item['address_name'] =$address['name'];
$item['order_no'] = $item['order']['order_no']; $item['order_no'] = $item['order']['order_no'] ?? "";
$item['my_money'] = $money[$userId]; $item['my_money'] = $money[$userId];
} }
return $list; return $list;

@ -28,4 +28,73 @@ class PriceSet extends BaseModel
// 定义主键 // 定义主键
protected $pk = 'id'; protected $pk = 'id';
/**
* 会员价
* [membershipPrice description]
* @param [type] $market_price [description]
* @param [type] $cost_price [description]
* @param [type] $category_ids [description]
* @return [type] [description]
*/
public static function membershipPrice($market_price, $cost_price, $category_ids){
$addPriceRate = self::getAddPriceRate(0, $category_ids, $cost_price);
$membershipPrice = $cost_price * (1 + $addPriceRate * 0.01);
//当加价率生效后,会员价高于市场价
if ($membershipPrice > $market_price) {
$membershipPrice = ($market_price - $cost_price) * $addPriceRate * 0.01 + $cost_price;
}
return sprintf("%.2f", $membershipPrice);
}
/**
* 分销价
* [distributionPrice description]
* @param [type] $market_price [description]
* @param [type] $cost_price [description]
* @param [type] $type [description]
* @param [type] $category_ids [description]
* @return [type] [description]
*/
public static function distributionPrice($market_price, $cost_price, $category_ids){
//会员价
$membershipPrice = self::membershipPrice($market_price, $cost_price, $category_ids);
//分销价
$addPriceRate = self::getAddPriceRate(1, $category_ids, $cost_price);
$distributionPrice = $cost_price * (1 + $addPriceRate * 0.01);
$price = $distributionPrice;
//当加价率生效后,分销价高于市场价
if ($distributionPrice > $market_price) {
$price = ($market_price - $cost_price) * $addPriceRate * 0.01 + $cost_price;
}
//当加价率生效后,分销价高于会员价
if ($distributionPrice > $membershipPrice) {
$price = ($membershipPrice - $cost_price) * $addPriceRate * 0.01 + $cost_price;
}
return sprintf("%.2f", $price);
}
/**
* 获取商品加价率
* [getAddPriceRate description]
* @param [type] $store_id [description]
* @param [type] $type [description]
* @param [type] $category_ids [description]
* @param [type] $goods_price [description]
* @return [type] [description]
*/
public static function getAddPriceRate($type, $category_ids, $cost_price){
$info = static::where('type',$type)
->whereIn('code', $category_ids)
->where('min', '<=', $cost_price)
->where('max', '>', $cost_price)
->order('id desc')
->column('add_price_rate');
if (!$info) {
return 0;
}
return $info[0];
}
} }

Loading…
Cancel
Save