146 lines
4.9 KiB
PHP
146 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace app\store\lists\cart;
|
|
|
|
|
|
use app\admin\lists\BaseAdminDataLists;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\model\order\Cart;
|
|
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_group_price\StoreProductGroupPrice;
|
|
use app\common\model\store_product_unit\StoreProductUnit;
|
|
use app\common\model\system_store\SystemStoreStaff;
|
|
use app\common\model\user\User;
|
|
use app\common\lists\ListsExtendInterface;
|
|
use app\common\model\store_product\StoreProduct;
|
|
|
|
/**
|
|
* 购物车列表
|
|
* Class RetailOrderList
|
|
* @package app\store\cart
|
|
*/
|
|
class CartList extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
|
|
{
|
|
protected $total_price = 0;
|
|
protected $activity_price = 0;
|
|
protected $off_activity = 0;
|
|
protected $pay_price = 0;
|
|
/**
|
|
* @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
|
|
{
|
|
$where = [
|
|
'staff_id' => $this->adminId,
|
|
'is_pay' => 0
|
|
];
|
|
$list = Cart::where($this->searchWhere)->where($where)
|
|
->limit(100)
|
|
->order(['id' => 'desc'])
|
|
->select()->each(function ($item) {
|
|
|
|
return $item;
|
|
})
|
|
->toArray();
|
|
$storeId = SystemStoreStaff::where('id', $this->adminId)->value('store_id');
|
|
$off_activity = Config::where('name', 'off_activity')->value('value');
|
|
$off_activity = 0;
|
|
$this->off_activity = $off_activity;
|
|
$uid = 0;
|
|
if ($this->request->get('uid')) {
|
|
$uid = $this->request->get('uid');
|
|
}
|
|
$user_ship=0;
|
|
if ($uid > 0) {
|
|
$user_ship = User::where('id', $uid)->value('user_ship');
|
|
// if (in_array($user_ship, [4, 6, 7])) {
|
|
// $off_activity = 1;
|
|
// }
|
|
}
|
|
foreach ($list as $key => &$item) {
|
|
$product = StoreProduct::where(['id' => $item['product_id']])
|
|
->field('id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id')
|
|
->find();
|
|
if ($product) {
|
|
$product = StoreProductGroupPrice::resetStoreProductPrice($product, $user_ship, $storeId);
|
|
if ($off_activity == 1) {
|
|
$this->activity_price = bcadd(bcmul($product['cost'], $item['cart_num'], 2), $this->activity_price, 2);
|
|
$item['price'] = $product['cost'];
|
|
} else {
|
|
$item['price'] = $product['price'];
|
|
if ($user_ship==4) {
|
|
$item['price'] = $product['cost'];
|
|
}
|
|
}
|
|
$item['pay_price'] = bcmul($item['cart_num'], $item['price'], 2);
|
|
$item['total_price'] = bcmul($item['cart_num'], $product['price'], 2);
|
|
$this->total_price = bcadd($this->total_price, $item['total_price'], 2);
|
|
$this->pay_price = bcadd($this->pay_price, $item['pay_price'], 2);
|
|
$item['image'] = $product['image'];
|
|
$item['cost'] = $product['cost'];
|
|
$item['store_name'] = $product['store_name'];
|
|
$unit = StoreProductUnit::where('id', $product['unit'])->find();
|
|
if($unit){
|
|
$item['unit_name']=$unit['name'];
|
|
$item['is_bulk']=$unit['is_bulk'];
|
|
}else{
|
|
$item['unit_name']='';
|
|
$item['is_bulk']=0;
|
|
}
|
|
}
|
|
}
|
|
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()
|
|
{
|
|
$data = [
|
|
'off_activity' => $this->off_activity,
|
|
'total_price' => $this->total_price,
|
|
'msg' => '',
|
|
'pay_price' => $this->pay_price
|
|
];
|
|
if ($this->off_activity == 1) {
|
|
$data['pay_price'] = $this->activity_price;
|
|
if ($this->activity_price < 500) {
|
|
$data['msg'] = '还差' . bcsub(500, $this->activity_price, 2) . '元可获得10%品牌礼品券';
|
|
$data['pay_price'] = $this->activity_price;
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
}
|