2024-06-01 17:22:46 +08:00
|
|
|
|
<?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\lists\ListsExtendInterface;
|
2024-06-25 10:18:33 +08:00
|
|
|
|
use app\common\model\Config;
|
2024-06-09 15:05:38 +08:00
|
|
|
|
use app\common\model\dict\DictType;
|
2024-08-28 15:21:55 +08:00
|
|
|
|
use app\common\model\store_product\StoreProduct;
|
2024-06-01 17:22:46 +08:00
|
|
|
|
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
2024-12-04 17:21:20 +08:00
|
|
|
|
use app\common\model\store_product_group_price\StoreProductGroupPrice;
|
2024-06-01 17:22:46 +08:00
|
|
|
|
use app\common\model\store_product_unit\StoreProductUnit;
|
2025-01-21 16:37:04 +08:00
|
|
|
|
use app\common\model\system_store\SystemStore;
|
2024-06-22 14:04:18 +08:00
|
|
|
|
use app\common\model\user\User;
|
2024-06-01 17:22:46 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 购物车列表
|
|
|
|
|
* Class RetailOrderList
|
|
|
|
|
* @package app\api\order
|
|
|
|
|
*/
|
|
|
|
|
class CartList extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
|
|
|
|
|
{
|
|
|
|
|
|
2024-06-09 15:05:38 +08:00
|
|
|
|
protected $total_price = 0;
|
2024-06-22 14:04:18 +08:00
|
|
|
|
protected $activity_price = 0;
|
2024-06-25 10:18:33 +08:00
|
|
|
|
protected $off_activity = 0;
|
2024-07-09 17:04:53 +08:00
|
|
|
|
protected $user_ship = 0;
|
2024-06-01 17:22:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 设置搜索条件
|
|
|
|
|
* @return \string[][]
|
|
|
|
|
* @author likeadmin
|
|
|
|
|
*/
|
|
|
|
|
public function setSearch(): array
|
|
|
|
|
{
|
2024-08-19 11:10:41 +08:00
|
|
|
|
return ['='=>['store_id']];
|
2024-06-01 17:22:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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 [];
|
2024-06-09 15:05:38 +08:00
|
|
|
|
$where = [
|
|
|
|
|
'uid' => $userId,
|
|
|
|
|
'is_pay' => 0
|
2024-06-01 17:22:46 +08:00
|
|
|
|
];
|
|
|
|
|
$list = Cart::where($this->searchWhere)->where($where)
|
|
|
|
|
->limit($this->limitOffset, $this->limitLength)
|
2024-06-04 11:58:51 +08:00
|
|
|
|
->order(['id' => 'desc'])
|
2024-06-01 17:22:46 +08:00
|
|
|
|
->select()->each(function ($item) {
|
|
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
|
})
|
|
|
|
|
->toArray();
|
2024-06-25 10:18:33 +08:00
|
|
|
|
$off_activity = Config::where('name', 'off_activity')->value('value');
|
2024-07-08 17:24:50 +08:00
|
|
|
|
$user_ship = User::where('id', $userId)->value('user_ship');
|
2024-08-28 15:21:55 +08:00
|
|
|
|
$field = 'id,id product_id,image,price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch';
|
2025-01-21 16:37:04 +08:00
|
|
|
|
if (in_array($user_ship, [4, 6, 7]) && !empty($this->params['store_id']) && !SystemStore::isSelfOperate($this->params['store_id'])) {
|
2024-08-28 15:21:55 +08:00
|
|
|
|
$field = 'id,id product_id,image,cost price,cost,store_name,unit,delete_time,vip_price,top_cate_id,batch';
|
2024-07-08 17:24:50 +08:00
|
|
|
|
}
|
2024-07-22 16:14:18 +08:00
|
|
|
|
$this->user_ship = $user_ship;
|
|
|
|
|
$this->off_activity = $off_activity;
|
2024-06-01 17:22:46 +08:00
|
|
|
|
foreach ($list as $key => &$item) {
|
2025-01-21 16:37:04 +08:00
|
|
|
|
$product = StoreProduct::where(['id' => $item['product_id']])
|
2024-07-20 14:22:36 +08:00
|
|
|
|
->field($field)
|
2024-06-01 17:22:46 +08:00
|
|
|
|
->find();
|
2025-01-21 16:37:04 +08:00
|
|
|
|
$product = StoreProductGroupPrice::resetStoreProductPrice($product, $user_ship, $this->params['store_id'] ?? 0);
|
|
|
|
|
if ($product) {
|
2024-07-22 16:14:18 +08:00
|
|
|
|
if ($off_activity == 1) {
|
2025-01-21 16:37:04 +08:00
|
|
|
|
$this->activity_price = bcadd(bcmul($product['cost'], $item['cart_num'], 2), $this->activity_price, 2);
|
2024-07-20 17:36:06 +08:00
|
|
|
|
}
|
2025-01-21 16:37:04 +08:00
|
|
|
|
if ($off_activity == 0 && $user_ship == 5 && $product['top_cate_id'] == 15189) {
|
|
|
|
|
$product['price'] = $product['cost'];
|
2024-06-24 14:15:22 +08:00
|
|
|
|
}
|
2025-04-02 16:12:02 +08:00
|
|
|
|
if ($user_ship == 4) {
|
|
|
|
|
$product['price'] = $product['cost'];
|
|
|
|
|
}
|
2025-01-21 16:37:04 +08:00
|
|
|
|
$item['goods_total_price'] = bcmul($item['cart_num'], $product['price'], 2);
|
2024-06-09 15:05:38 +08:00
|
|
|
|
$this->total_price = bcadd($this->total_price, $item['goods_total_price'], 2);
|
2025-01-21 16:37:04 +08:00
|
|
|
|
$item['batch'] = $product['batch'];
|
|
|
|
|
$item['imgs'] = $product['image'];
|
|
|
|
|
$item['price'] = $product['price'];
|
|
|
|
|
$item['cost'] = $product['cost'];
|
|
|
|
|
$item['goods_name'] = $product['store_name'];
|
|
|
|
|
$item['unit_name'] = StoreProductUnit::where('id', $product['unit'])->value('name');
|
2024-06-01 17:22:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @notes 购物车数量
|
|
|
|
|
* @return int
|
|
|
|
|
* @date 2024/04/27 11:26
|
|
|
|
|
*/
|
|
|
|
|
public function count(): int
|
|
|
|
|
{
|
|
|
|
|
$userId = $this->request->userId;
|
|
|
|
|
if (!$userId) return 0;
|
2024-06-09 15:05:38 +08:00
|
|
|
|
$where = [
|
|
|
|
|
'uid' => $userId,
|
|
|
|
|
'is_pay' => 0
|
2024-06-01 17:22:46 +08:00
|
|
|
|
];
|
|
|
|
|
return Cart::where($this->searchWhere)->where($where)->count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function extend()
|
|
|
|
|
{
|
2024-07-22 16:14:18 +08:00
|
|
|
|
$data = [
|
2024-06-25 10:18:33 +08:00
|
|
|
|
'off_activity' => $this->off_activity,
|
2024-06-22 14:04:18 +08:00
|
|
|
|
'total_price' => $this->total_price,
|
2024-07-09 17:04:53 +08:00
|
|
|
|
'msg' => '',
|
2024-06-26 15:12:00 +08:00
|
|
|
|
'pay_price' => $this->total_price
|
2024-06-22 14:04:18 +08:00
|
|
|
|
];
|
2024-07-22 16:14:18 +08:00
|
|
|
|
if ($this->user_ship == 0) {
|
|
|
|
|
if ($data['pay_price'] < 500) {
|
2024-07-22 17:13:38 +08:00
|
|
|
|
$data['msg'] = '还差' . bcsub(500, $data['pay_price'], 2) . '即可获得10%的品牌礼品兑换券,可到线下门店兑换礼品。';
|
2024-07-22 16:14:18 +08:00
|
|
|
|
} else {
|
2024-07-22 17:13:38 +08:00
|
|
|
|
$data['msg'] = '您已选购满500元,支付成功后即可获得' . bcmul($data['pay_price'], 0.1, 2) . '元品牌礼品兑换券,可到线下门店兑换礼品。';
|
2024-07-22 16:14:18 +08:00
|
|
|
|
}
|
2024-07-09 17:04:53 +08:00
|
|
|
|
}
|
2024-07-22 16:14:18 +08:00
|
|
|
|
if ($this->off_activity == 1) { //1
|
|
|
|
|
$data['pay_price'] = $this->activity_price;
|
|
|
|
|
if ($data['pay_price'] < 500) {
|
|
|
|
|
if ($this->user_ship == 0) {
|
|
|
|
|
$data['msg'] = '还差' . bcsub(500, $this->activity_price, 2) . '即可获得10%的品牌礼品兑换券,可到线下门店兑换礼品。';
|
2024-07-09 17:04:53 +08:00
|
|
|
|
}
|
2024-07-22 16:14:18 +08:00
|
|
|
|
} else {
|
|
|
|
|
if ($this->user_ship == 0) {
|
|
|
|
|
$data['msg'] = '您已选购满500元,支付成功后即可获得' . bcmul($this->activity_price, 0.1, 2) . '元品牌礼品兑换券,可到线下门店兑换礼品。';
|
2024-07-09 17:04:53 +08:00
|
|
|
|
}
|
2024-06-25 10:18:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $data;
|
2024-06-01 17:22:46 +08:00
|
|
|
|
}
|
|
|
|
|
}
|