diff --git a/app/api/controller/Controller.php b/app/api/controller/Controller.php index 67127e6a..828292ed 100644 --- a/app/api/controller/Controller.php +++ b/app/api/controller/Controller.php @@ -32,6 +32,8 @@ class Controller extends BaseController // 当前商城ID protected int $storeId; + protected $storeInfo; + /** * API基类初始化 * @throws BaseException @@ -82,6 +84,7 @@ class Controller extends BaseController if ($store['is_recycle'] || $store['is_delete']) { throwError('很抱歉,当前商城已删除'); } + $this->storeInfo = $store; } /** diff --git a/app/api/controller/Goods.php b/app/api/controller/Goods.php index de318ad0..d94d3570 100644 --- a/app/api/controller/Goods.php +++ b/app/api/controller/Goods.php @@ -24,6 +24,7 @@ use cores\exception\BaseException; use think\db\exception\DbException; use think\response\Json; use app\common\enum\goods\GoodsDeliveryTime; +use think\facade\Cache; /** * 商品控制器 * Class Goods @@ -38,9 +39,14 @@ class Goods extends Controller */ public function list(): Json { + // 获取列表数据 $model = new GoodsModel; $param = $this->request->param(); + //限制过滤条件-渠道 + $param['channels'] = $this->storeInfo['open_channel'] ? array_merge(['zy'], explode(",", $this->storeInfo['open_channel'])) : []; + //分类利润-利润率 + $param['fliter_condition'] = $this->storeInfo['fliter_condition']; $list = $model->getList($param); return $this->renderSuccess(compact('list')); } @@ -142,7 +148,7 @@ class Goods extends Controller ]; break; default: - if ($goods->stock_total > ($value['num'] ?? 1)) { + if ($goods->stock_total >= ($value['num'] ?? 1)) { $res = "有货"; } $data = [ @@ -288,13 +294,13 @@ class Goods extends Controller public function recommended(): Json { $service = new GoodsService; -// $cache_key = "goods_recommended".$this->storeId; -// if(Cache::has($cache_key)) { -// $goodsList = Cache::get($cache_key); -// return $this->renderSuccess(compact('goodsList')); -// } + $cache_key = "goods_recommended".$this->storeId; + if(Cache::has($cache_key)) { + $goodsList = Cache::get($cache_key); + return $this->renderSuccess(compact('goodsList')); + } $goodsList = $service->recommended(); -// Cache::set($cache_key, $goodsList, 60*60); + Cache::set($cache_key, $goodsList, 60*60); return $this->renderSuccess(compact('goodsList')); } diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index 7094877f..d60de044 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -583,12 +583,25 @@ class Goods extends GoodsModel * @return \app\common\model\GoodsSku|array|null * @throws BaseException */ - public static function getSkuInfo($goodsInfo, string $goodsSkuId, bool $enableGradeMoney = true) + public static function getSkuInfo($goods, string $goodsSkuId, bool $enableGradeMoney = true) { - $goodsInfo['skuInfo'] = GoodsService::getSkuInfo($goodsInfo['goods_id'], $goodsSkuId); + $goods['skuInfo'] = GoodsService::getSkuInfo($goods['goods_id'], $goodsSkuId); //$enableGradeMoney && (new static)->setGoodsGradeMoney($goodsInfo); - (new static)->setGoodsMoney($goodsInfo); - return $goodsInfo['skuInfo']; + + $catService = new GoodsCategoryRel(); + $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); + if ($goods->getAttr('skuInfo')) { + if (UserService::isPlusMember()) { + $goods['skuInfo']['goods_price'] = \app\common\model\PriceSet::membershipPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds); + + } elseif (UserService::isDealerMember()) { + $priceArr = \app\common\model\PriceSet::distributionPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds); + $goods['skuInfo']['goods_price'] = $priceArr['distributionPrice']; + } + + } + //(new static)->setGoodsMoney($goodsInfo); + return $goods['skuInfo']; } /** diff --git a/app/api/model/Order.php b/app/api/model/Order.php index 079bcf70..2b187e09 100644 --- a/app/api/model/Order.php +++ b/app/api/model/Order.php @@ -80,9 +80,13 @@ class Order extends OrderModel // 获取商品列表 $model = new GoodsModel; $goodsList = $model->setEnableGradeMoney(false)->getListByIdsFromApi([$goodsId]); + if ($goodsList->isEmpty()) { throwError('未找到商品信息'); } + // echo "
"; + // print_r($goodsList->toArray()); + // exit(); // 隐藏冗余的属性 $goodsList->hidden(GoodsModel::getHidden(['content', 'goods_images', 'images'])); foreach ($goodsList as &$item) { @@ -92,7 +96,7 @@ class Order extends OrderModel $item['goods_image'] = $item['skuInfo']['goods_image'] ?: $item['goods_image']; // 商品单价 - $item['goods_price'] = \app\api\service\Goods::getGoodsPrice($item['goods_id'], $item['skuInfo']['goods_price'], $item['skuInfo']['cost_price']); + $item['goods_price'] = $item['skuInfo']['goods_price'];//\app\api\service\Goods::getGoodsPrice($item['goods_id'], $item['skuInfo']['goods_price'], $item['skuInfo']['cost_price']); // 商品购买数量 $item['total_num'] = $goodsNum; // 商品SKU索引 @@ -100,6 +104,9 @@ class Order extends OrderModel // 商品购买总金额 $item['total_price'] = helper::bcmul($item['goods_price'], $goodsNum); } + // echo ""; + // print_r($goodsList->toArray()); + // exit(); return $goodsList; } diff --git a/app/api/model/dealer/Order.php b/app/api/model/dealer/Order.php index 43ebd092..2f0d1a92 100644 --- a/app/api/model/dealer/Order.php +++ b/app/api/model/dealer/Order.php @@ -12,17 +12,17 @@ declare (strict_types=1); namespace app\api\model\dealer; +use app\api\model\Order as OrderApiModel; +use app\api\model\User as UserApiModel; use app\api\service\User as UserService; use app\common\enum\dealer\DealerUserEnum; +use app\common\enum\order\PayStatus as PayStatusEnum; use app\common\enum\ServerEnum; -use app\common\model\Order as OrderModel; +use app\common\enum\user\UserTypeEnum; use app\common\model\dealer\Order as DealerOrderModel; -use app\api\model\Order as OrderApiModel; -use app\common\enum\order\PayStatus as PayStatusEnum; +use app\common\model\Order as OrderModel; use app\common\model\UserAddress as UserAddessModel; use cores\exception\BaseException; -use app\api\model\User as UserApiModel; -use app\common\enum\user\UserTypeEnum; /** @@ -64,11 +64,11 @@ class Order extends DealerOrderModel ->paginate(15); // 数据整理 foreach ($list as &$item) { - $with = ['goods' => ['image'],'user','address']; + $with = ['goods' => ['image'], 'user', 'address']; $where = ['order_id' => $item['order_id']]; // 查询订单记录 $order_goods = OrderApiModel::detail($where, $with); - $address = UserAddessModel::where('address_id',$item['user']->address_id)->find(); + $address = UserAddessModel::where('address_id', $item['user']->address_id)->find(); // 我的佣金 $money = [ $item['first_user_id'] => $item['first_money'], @@ -76,7 +76,7 @@ class Order extends DealerOrderModel $item['third_user_id'] => $item['third_money'], ]; $item['goods'] = $order_goods['goods'] ?? []; - $item['address_name'] =$address['name']; + $item['address_name'] = $address['name']; $item['order_no'] = $item['order']['order_no'] ?? ""; $item['my_money'] = $money[$userId]; } @@ -126,11 +126,13 @@ class Order extends DealerOrderModel return false; } //如果上级已经不是分销商 - if(!User::isDealerUser($dealerUser['first_user_id'])){ + if (!User::isDealerUser($dealerUser['first_user_id'])) { return false; } //如果上级已经不是分销商 - if(!UserApiModel::where('user_id',$dealerUser['first_user_id'])->value('user_type') !== UserTypeEnum::DEALER){ + $userModel = new UserApiModel; + $user_type = $userModel->where('user_id', $dealerUser['first_user_id'])->value('user_type'); + if ($user_type && $user_type != UserTypeEnum::DEALER) { return false; } // 计算订单分销佣金 diff --git a/app/api/service/Cart.php b/app/api/service/Cart.php index 89770cbc..2f8475f2 100644 --- a/app/api/service/Cart.php +++ b/app/api/service/Cart.php @@ -80,7 +80,7 @@ class Cart extends BaseService // 商品记录 $goods = $item['goods']; // 商品单价 - $goods['goods_price'] = \app\api\service\Goods::getGoodsPrice($item['goods_id'], $goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price']); + $goods['goods_price'] = $goods['skuInfo']['goods_price'];//\app\api\service\Goods::getGoodsPrice($item['goods_id'], $goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price']); //$goods['goods_price'] = $goods['skuInfo']['goods_price']; // 商品购买数量 $goods['total_num'] = $item['goods_num']; diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 271ca05d..880bbc3b 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -329,13 +329,36 @@ class Goods extends BaseModel $query = $query->whereRaw('goods_name like ? or goods_no like ?', ["%{$val}%", "%{$val}%"]); } } - // 执行查询 - $list = $query->with(['images.file']) - ->alias($this->name) - ->field($field) - ->where('is_delete', '=', 0) - ->order($sort) - ->paginate($listRows); + if (isset($param['fliter_condition']) && $param['fliter_condition']) { + $fliter_condition = json_decode($param['fliter_condition'], true); + + $str = ""; + foreach ($fliter_condition as $value) { + $strConditon = "("; + $strConditon .= "goods_category_rel.category_id in (".implode(",", $value['category']).")"; + $strConditon .= " and goods.profit >= ".$value['profit']; + $strConditon .= " and goods.profit_rate >= ".$value['profit_rate'] . ") or "; + $str .= $strConditon; + } + $str = trim($str, "or "); + // 执行查询 + $list = $query->with(['images.file']) + ->alias($this->name) + ->field($field) + ->where('is_delete', '=', 0) + ->where($str) + ->order($sort) + ->paginate($listRows); + } else { + // 执行查询 + $list = $query->with(['images.file']) + ->alias($this->name) + ->field($field) + ->where('is_delete', '=', 0) + ->order($sort) + ->paginate($listRows); + } + // 整理列表数据并返回 return $this->setGoodsListData($list); @@ -526,6 +549,7 @@ class Goods extends BaseModel if (isset($param['is_has_detail']) && $param['is_has_detail'] !== '') { $filter[] = ['goods.is_has_detail', '=', $params['is_has_detail']]; } + // 实例化新查询对象 return $query->where($filter); } diff --git a/app/job/service/goods/AdminImport.php b/app/job/service/goods/AdminImport.php index a4c769bc..784cda48 100644 --- a/app/job/service/goods/AdminImport.php +++ b/app/job/service/goods/AdminImport.php @@ -110,7 +110,10 @@ class AdminImport extends BaseService continue; } $data = $this->createData($item, $storeId); - $service->single($item['D'], $data, $storeId); + $ret = $service->single($item['D'], $data, $storeId); + if ($ret == false) { + continue; + } // 记录导入成功 $this->successCount++; } diff --git a/app/job/service/goods/Collector.php b/app/job/service/goods/Collector.php index 0760b7d6..b59078f1 100644 --- a/app/job/service/goods/Collector.php +++ b/app/job/service/goods/Collector.php @@ -145,6 +145,7 @@ class Collector extends BaseService { try { + //var_dump($url); // 采集第三方商品数据 $original = $this->collector($url, $storeId); if ($original['spec_type'] == 20) { diff --git a/app/job/service/goods/GoodsStoreImport.php b/app/job/service/goods/GoodsStoreImport.php index e5c46f93..d8e9dd38 100644 --- a/app/job/service/goods/GoodsStoreImport.php +++ b/app/job/service/goods/GoodsStoreImport.php @@ -110,7 +110,10 @@ class GoodsStoreImport extends BaseService continue; } $data = $this->createData($item, $storeId); - $service->single($item['D'], $data, $storeId); + $ret = $service->single($item['D'], $data, $storeId); + if ($ret == false) { + continue; + } // 记录导入成功 $this->successCount++; } diff --git a/app/store/controller/Goods.php b/app/store/controller/Goods.php index 194130b5..03d3c89c 100644 --- a/app/store/controller/Goods.php +++ b/app/store/controller/Goods.php @@ -25,6 +25,7 @@ use app\common\model\GoodsCategoryRel; */ class Goods extends Controller { + private static $show_content = "***"; /** * 商品列表 * @return Json @@ -35,8 +36,25 @@ class Goods extends Controller // 获取列表记录 $model = new GoodsModel; $params = $this->request->param(); - $params['channel'] = 'zy'; - $list= $model->getList($params, (int)$this->request->param('pageSize', 15)); + //$params['channel'] = 'zy'; + $list = $model->getList($params, (int)$this->request->param('pageSize', 15)); + if ($list->isEmpty()) { + return $this->renderSuccess(compact('list')); + } + $list = $list->toArray(); + + foreach ($list['data'] as &$value) { + if (!in_array($value['channel'], ['zy'])) { + $value['goods_price_min'] = self::$show_content; + $value['goods_price_max'] = self::$show_content; + $value['line_price_max'] = self::$show_content; + $value['line_price_min'] = self::$show_content; + $value['cost_price_min'] = self::$show_content; + $value['goods_no'] = self::$show_content; + } + + } + return $this->renderSuccess(compact('list')); } @@ -67,6 +85,19 @@ class Goods extends Controller // 获取商品详情 $model = new GoodsModel; $goodsInfo = $model->getDetail($goodsId); + if (!in_array($goodsInfo['channel'], ['zy'])) { + $goodsInfo['goods_price_min'] = self::$show_content; + $goodsInfo['goods_price_max'] = self::$show_content; + $goodsInfo['line_price_max'] = self::$show_content; + $goodsInfo['line_price_min'] = self::$show_content; + $goodsInfo['cost_price_min'] = self::$show_content; + $goodsInfo['goods_no'] = self::$show_content; + foreach ($goodsInfo['skuList'] as $key => &$value) { + $value['goods_price'] = self::$show_content; + $value['cost_price'] = self::$show_content; + } + + } return $this->renderSuccess(compact('goodsInfo')); } @@ -117,8 +148,22 @@ class Goods extends Controller { // 商品详情 $model = GoodsModel::detail($goodsId); + $params = $this->postForm(); + if ($model->isEmpty()) { + return $this->renderError("该商品已不存在!"); + } + if (!in_array($model->channel, ['zy'])) { + $params['goods_price'] = $model->goods_price_min; + $params['cost_price'] = $model->cost_price_min; + $params['goods_no'] = $model->goods_no; + } + + // echo ""; + // print_r($params); + // print_r($model->toArray()); + // exit(); // 更新记录 - if ($model->edit($this->postForm())) { + if ($model->edit($params)) { return $this->renderSuccess('更新成功'); } return $this->renderError($model->getError() ?: '更新失败');