From 1fd77a396b76f29f8cef4ba4f7223a54862360d5 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sun, 9 Jun 2024 15:05:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(CartList):=20=E4=BF=AE=E6=94=B9=E8=B4=AD?= =?UTF-8?q?=E7=89=A9=E8=BD=A6=E5=88=97=E8=A1=A8=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=95=86=E5=93=81=E6=88=90=E6=9C=AC=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E4=B8=8E=E5=BA=93=E5=AD=98=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/order/CartList.php | 33 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php index 4c410c28b..3990c14e7 100644 --- a/app/api/lists/order/CartList.php +++ b/app/api/lists/order/CartList.php @@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists; use app\common\lists\ListsSearchInterface; use app\common\model\order\Cart; use app\common\lists\ListsExtendInterface; +use app\common\model\dict\DictType; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_product_attr_value\StoreProductAttrValue; use app\common\model\store_product_unit\StoreProductUnit; @@ -19,7 +20,7 @@ use app\common\model\store_product_unit\StoreProductUnit; class CartList extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface { - protected $total_price=0; + protected $total_price = 0; /** @@ -45,9 +46,9 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists { $userId = $this->request->userId; if (!$userId) return []; - $where=[ - 'uid'=>$userId, - 'is_pay'=>0 + $where = [ + 'uid' => $userId, + 'is_pay' => 0 ]; $list = Cart::where($this->searchWhere)->where($where) ->limit($this->limitOffset, $this->limitLength) @@ -57,21 +58,23 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists return $item; }) ->toArray(); + $check = DictType::where('type', 'activities')->find(); foreach ($list as $key => &$item) { - $find = StoreBranchProduct::where(['id'=>$item['product_id']]) - ->field('product_id,image,price,store_name,unit') + $find = StoreBranchProduct::where(['id' => $item['product_id']]) + ->field('product_id,image,price,cost,store_name,unit') ->find(); - if($find){ + if (isset($check) && $check['status'] == 1) { + $find['price'] = $find['cost']; + } + if ($find) { $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); - $this->total_price=bcadd($this->total_price,$item['goods_total_price'],2); + $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); $item['imgs'] = $find['image']; $item['sell'] = $find['price']; $item['goods_name'] = $find['store_name']; - $item['unit_name'] = StoreProductUnit::where('id',$find['unit'])->value('name'); - + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); } - } return $list; } @@ -86,15 +89,15 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists { $userId = $this->request->userId; if (!$userId) return 0; - $where=[ - 'uid'=>$userId, - 'is_pay'=>0 + $where = [ + 'uid' => $userId, + 'is_pay' => 0 ]; return Cart::where($this->searchWhere)->where($where)->count(); } public function extend() { - return ['total_price'=>$this->total_price]; + return ['total_price' => $this->total_price]; } }