100 lines
2.5 KiB
PHP
100 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace app\api\lists\order;
|
|
|
|
|
|
use app\admin\lists\BaseAdminDataLists;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\model\order\Cart;
|
|
use app\common\model\retail\Cashierclass;
|
|
use app\common\lists\ListsExtendInterface;
|
|
use app\common\model\goods\Goods;
|
|
use app\common\model\goods\Unit;
|
|
|
|
/**
|
|
* 购物车列表
|
|
* Class RetailOrderList
|
|
* @package app\api\order
|
|
*/
|
|
class CartList extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
|
|
{
|
|
|
|
protected $total_price;
|
|
|
|
|
|
/**
|
|
* @notes 设置搜索条件
|
|
* @return \string[][]
|
|
* @author likeadmin
|
|
*/
|
|
public function setSearch(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 购物车列表
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @date 2024/04/27 11:26
|
|
*/
|
|
public function lists($where = []): array
|
|
{
|
|
$userId = $this->request->userId;
|
|
if (!$userId) return [];
|
|
$where=[
|
|
'uid'=>$userId,
|
|
'is_pay'=>0
|
|
];
|
|
$list = Cart::where($this->searchWhere)->where($where)
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->order(['cart_id' => 'desc'])
|
|
->select()->each(function ($item) {
|
|
|
|
return $item;
|
|
})
|
|
->toArray();
|
|
|
|
$total_price = 0;
|
|
foreach ($list as $key => &$item) {
|
|
$find = Goods::where(['id' => $item['goods_id']])->field('name,imgs,unit,sell')->find();
|
|
if($find){
|
|
$item['goods_total_price'] = bcmul($item['cart_num'], $find['sell'], 2);
|
|
$total_price += $item['goods_total_price'];
|
|
$item['goods_name'] = $find['name'];
|
|
$item['imgs'] = $find['imgs'];
|
|
$item['sell'] = $find['sell'];
|
|
$item['unit_name'] = Unit::where('id',$find['unit'])->value('name');
|
|
}
|
|
|
|
}
|
|
$this->total_price=$total_price;
|
|
return $list;
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 购物车数量
|
|
* @return int
|
|
* @date 2024/04/27 11:26
|
|
*/
|
|
public function count(): int
|
|
{
|
|
$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];
|
|
}
|
|
}
|