From f662b4fa8d9f13475b597a68a80383f86769dbfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Wed, 24 Mar 2021 18:39:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8A=98=E6=89=A3=E6=96=B9?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/controller/api/auth/Order.php | 17 ++--------------- app/data/service/OrderService.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/data/controller/api/auth/Order.php b/app/data/controller/api/auth/Order.php index 2efb0eec1..704dc56d4 100644 --- a/app/data/controller/api/auth/Order.php +++ b/app/data/controller/api/auth/Order.php @@ -100,15 +100,7 @@ class Order extends Auth $allowPayments = $_allowPayments; } // 商品折扣处理 - [$discountId, $discountRate] = [0, 100.00]; - if ($goodsInfo['discount_id'] > 0) { - $map = ['status' => 1, 'deleted' => 0, 'id' => $goodsInfo['discount_id']]; - if ($discount = $this->app->db->name('DataUserDiscount')->where($map)->value('items')) { - foreach (json_decode($discount, true) as $vo) if ($vo['level'] == $this->user['vip_code']) { - [$discountId, $discountRate] = [$goodsInfo['discount_id'], $vo['discount']]; - } - } - } + [$discountId, $discountRate] = OrderService::instance()->discount($goodsInfo['discount_id'], $this->user['vip_code']); // 订单详情处理 $items[] = [ 'uid' => $order['uid'], @@ -200,12 +192,7 @@ class Order extends Auth public function discount() { $data = $this->_vali(['discount.require' => '折扣编号不能为空!']); - [$map, $rate] = [['status' => 1, 'deleted' => 0, 'id' => $data['discount']], 100.00]; - if ($discount = $this->app->db->name('DataUserDiscount')->where($map)->value('items')) { - foreach (json_decode($discount, true) as $vo) if ($vo['level'] == $this->user['vip_code']) { - $rate = round($vo['discount']); - } - } + [, $rate] = OrderService::instance()->discount(intval($data['discount']), $this->user['vip_code']); $this->success('获取用户折扣', ['rate' => $rate]); } diff --git a/app/data/service/OrderService.php b/app/data/service/OrderService.php index f87e3a029..08d194ec8 100644 --- a/app/data/service/OrderService.php +++ b/app/data/service/OrderService.php @@ -95,6 +95,23 @@ class OrderService extends Service return $buyVipEntry; } + /** + * 获取级别折扣比例 + * @param integer $disId 折扣方案ID + * @param integer $vipCode 等级序号 + * @return array [方案ID, 等级序号] + */ + public function discount(int $disId, int $vipCode): array + { + [$map, $rate] = ['id' => $disId, ['status' => 1, 'deleted' => 0], 100.00]; + if ($discount = $this->app->db->name('DataUserDiscount')->where($map)->value('items')) { + foreach (json_decode($discount, true) as $vo) if ($vo['level'] == $vipCode) { + $rate = round($vo['discount']); + } + } + return [$disId, $rate]; + } + /** * 绑定订单详情数据 * @param array $data