From d8d4f7f9def97f4a20731771b51c0c01268b30c8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 26 Jun 2024 13:56:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B4=AD=E7=89=A9=E8=BD=A6=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E7=89=B9=E6=9D=83?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E8=AE=A1=E7=AE=97=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/store/lists/cart/CartList.php | 89 +++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/app/store/lists/cart/CartList.php b/app/store/lists/cart/CartList.php index e16f45c1e..b4561de84 100644 --- a/app/store/lists/cart/CartList.php +++ b/app/store/lists/cart/CartList.php @@ -6,10 +6,12 @@ namespace app\store\lists\cart; 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\Config; 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; +use app\common\model\user\User; +use app\common\lists\ListsExtendInterface; /** * 购物车列表 @@ -18,10 +20,9 @@ use app\common\model\store_product_unit\StoreProductUnit; */ class CartList extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface { - protected $total_price = 0; - - + protected $activity_price = 0; + protected $off_activity = 0; /** * @notes 设置搜索条件 * @return \string[][] @@ -31,8 +32,6 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists { return []; } - - /** * @notes 购物车列表 * @return array @@ -43,27 +42,54 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists */ public function lists($where = []): array { - $this->searchWhere[]=['staff_id','=',$this->adminId]; - $this->searchWhere[]=['is_pay','=',0]; - $list = Cart::where($this->searchWhere) - ->field('id,product_id,cart_num,store_id') + $userId = $this->request->get('uid'); + $where = [ + 'staff_id' => $this->adminId, + 'is_pay' => 0 + ]; + $list = Cart::where($this->searchWhere)->where($where) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { - $find = StoreBranchProduct::where(['product_id' => $item['product_id'],'store_id'=>$item['store_id']]) - ->field('product_id,image,price,store_name,unit') - ->find(); - if ($find) { - $item['total_price'] = bcmul($item['cart_num'], $find['price'], 2); - $item['image'] = $find['image']; - $item['price'] = $find['price']; - $item['store_name'] = $find['store_name']; - $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); - } + return $item; }) ->toArray(); + $off_activity = Config::where('name', 'off_activity')->value('value'); + $this->off_activity = $off_activity; + $user = User::where('id', $userId)->find(); + foreach ($list as $key => &$item) { + $find = StoreBranchProduct::where(['product_id' => $item['product_id'], 'store_id' => $item['store_id']]) + ->field('product_id,image,price,cost,store_name,unit,delete_time,vip_price') + ->withTrashed() + ->find(); + + if ($find) { + if ($off_activity == 1) { + $this->activity_price = bcadd(bcmul($find['cost'], $item['cart_num'], 2), $this->activity_price, 2); + } else { + if ($user && $user['user_ship'] == 1) { + //更新 会员为1的时候原价减去会员价 + $deduction_price_count = bcmul(bcsub($find['price'], $find['vip_price'], 2), $item['cart_num'], 2); + $this->activity_price = bcadd($this->activity_price, $deduction_price_count, 2); + } elseif ($user && $user['user_ship'] == 4) { + //更新 为4商户的时候减去商户价格 + $deduction_price_count = bcmul(bcsub($find['price'], $find['cost'], 2), $item['cart_num'], 2); + $this->activity_price = bcadd($this->activity_price, $deduction_price_count, 2); + } else { + $this->activity_price = 0; + } + } + + $item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2); + $this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2); + $item['image'] = $find['image']; + $item['sell'] = $find['price']; + $item['store_name'] = $find['store_name']; + $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); + } + } return $list; } @@ -75,11 +101,30 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists */ public function count(): int { - return Cart::where($this->searchWhere)->count(); + $userId = $this->request->userId; + if (!$userId) return 0; + $where = [ + 'uid' => $userId, + 'is_pay' => 0 + ]; + return Cart::where($this->searchWhere)->where($where)->count(); } public function extend() { - // return ['total_price' => $this->total_price]; + $data = [ + 'off_activity' => $this->off_activity, + 'total_price' => $this->total_price, + 'msg' => '', + 'pay_price' => bcsub($this->total_price, $this->activity_price, 2) + ]; + if ($this->off_activity == 1) { + $data['pay_price'] = $this->activity_price; + if ($this->total_price < 500) { + $data['msg'] = '还差' . bcsub(500, $this->total_price, 2) . '元可获得10%品牌礼品券'; + $data['pay_price'] = $this->activity_price; + } + } + return $data; } }