feat(CartList): 修改购物车列表逻辑,支持商品成本计算与库存管理

This commit is contained in:
mkm 2024-06-09 15:05:38 +08:00
parent 5527ec60dd
commit 1fd77a396b

View File

@ -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];
}
}