Merge branch 'main' into feature/main20240421

# Conflicts:
#	app/api/controller/Controller.php
#	app/store/controller/Goods.php
feature/main20240421
lqmac 10 months ago
commit 63d6fa6dbf
  1. 2
      app/admin/controller/Goods.php
  2. 2
      app/admin/controller/goods/Import.php
  3. 7
      app/api/controller/Controller.php
  4. 22
      app/api/controller/Goods.php
  5. 21
      app/api/model/Goods.php
  6. 9
      app/api/model/Order.php
  7. 14
      app/api/model/dealer/Order.php
  8. 2
      app/api/service/Cart.php
  9. 26
      app/common/model/Goods.php
  10. 5
      app/job/service/goods/AdminImport.php
  11. 1
      app/job/service/goods/Collector.php
  12. 19
      app/job/service/goods/GoodsStoreImport.php
  13. 49
      app/store/controller/Goods.php
  14. 4
      app/store/model/Goods.php
  15. 1
      app/store/model/Store.php
  16. 4
      config/allowapi.php

@ -231,7 +231,7 @@ class Goods extends Controller
$categoryIds = $model->dealCategory($categoryIds);
\app\store\model\GoodsCategoryRel::updates($goodsId, $categoryIds);
}
$model->whereIn('goods_id', $goodsIds)->update(['cate_status'=>1]);
$model->whereIn('goods_id', $goodsIds)->update(['cate_status'=>1,'update_time' => time()]);
return $this->renderSuccess('操作成功');
}
/**

@ -35,7 +35,7 @@ class Import extends Controller
$params['store_id'] = 0;
$model = new ImportModel;
$platform = $this->getUserPlatform();
$params['channels'] = $platform ? array_column($platform->toArray(), "code") : [];
$params['channels'] = $this->admin['user']['role'] == 0 ? [] : ($platform ? array_column($platform->toArray(), "code") : []);
$list = $model->getList($params);
return $this->renderSuccess(compact('list'));
}

@ -32,6 +32,10 @@ class Controller extends BaseController
// 当前商城ID
protected int $storeId;
protected $storeInfo;
protected $user;
// 当前商户ID
protected int $merchantId = 0;
@ -50,7 +54,7 @@ class Controller extends BaseController
$this->checkStore();
// 验证当前客户端状态
$this->checkClient();
//$user = $this->getLoginUser();
$this->user = $this->getLoginUser(false);
// if ($user) {
// if ($user->user_type == 0 || $user->status == 0) {
// throwError('很抱歉,您没有权限进入系统');
@ -95,6 +99,7 @@ class Controller extends BaseController
if ($store['is_recycle'] || $store['is_delete']) {
throwError('很抱歉,当前商城已删除');
}
$this->storeInfo = $store;
}
/**

@ -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.($this->user ? $this->user->user_type : 0);
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'));
}
@ -405,7 +411,7 @@ class Goods extends Controller
$wxConfig = WxappSettingModel::getConfigBasic($store_id);
// 请求api获取短连接
$link_obj = new ShortLink($wxConfig['app_id'], $wxConfig['app_secret']);
$url = $link_obj->shortUrl($page_url, $page_title);
$url = $link_obj->shortUrl($page_url, "");
return $this->renderSuccess(['url' => $url]);
}

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

@ -80,9 +80,13 @@ class Order extends OrderModel
// 获取商品列表
$model = new GoodsModel;
$goodsList = $model->setEnableGradeMoney(false)->getListByIdsFromApi([$goodsId]);
if ($goodsList->isEmpty()) {
throwError('未找到商品信息');
}
// echo "<pre>";
// 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 "<pre>";
// print_r($goodsList->toArray());
// exit();
return $goodsList;
}

@ -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;
/**
@ -130,7 +130,9 @@ class Order extends DealerOrderModel
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;
}
// 计算订单分销佣金

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

@ -329,13 +329,36 @@ class Goods extends BaseModel
$query = $query->whereRaw('goods_name like ? or goods_no like ?', ["%{$val}%", "%{$val}%"]);
}
}
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);
@ -532,6 +555,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);
}
@ -566,7 +590,7 @@ class Goods extends BaseModel
protected function setGoodsData($goodsInfo, callable $callback = null)
{
$channel = Channel::withoutGlobalScope()->where('code', $goodsInfo['channel'])->find();
$goodsInfo['channel_name'] = $channel['name'] ?? "";
$goodsInfo['channel_name'] = $channel['alias'] ?? "";
$goodsInfo['goods_images'] = helper::getArrayColumn($goodsInfo['images'], 'file');
// 商品主图

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

@ -145,6 +145,7 @@ class Collector extends BaseService
{
try {
//var_dump($url);
// 采集第三方商品数据
$original = $this->collector($url, $storeId);
if ($original['spec_type'] == 20) {

@ -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++;
}
@ -201,9 +204,6 @@ class GoodsStoreImport extends BaseService
*/
public function createData(array $original, int $storeId): array
{
//$channel = Channel::where('name', $original["B"])->find();
//批量导入销售区域处理
$region = [];
$region_text = [];
@ -227,7 +227,8 @@ class GoodsStoreImport extends BaseService
foreach ($regions as $key => $value) {
$regionsnew[$value['pid']][] = $value;
}
// echo "<pre>";
// print_r($regionsnew);
foreach ($regionsnew as $pid => $value) {
$privince = Region::withoutGlobalScope()->where('id', $pid)->find();
$region_text[$pid]['name'] = $privince['name'] ?? "";
@ -239,6 +240,14 @@ class GoodsStoreImport extends BaseService
}
$region_text[$pid]['citys'] = $citys;
}
unset($pid);
foreach ($region_text as $pid => &$item) {
//如果传入的是整个省份
if (count($item['citys']) == Region::withoutGlobalScope()->whereIn('pid', $pid)->count()) {
$item['citys'] = [];
}
}
}
// echo "<pre>";
// print_r($region_text);

@ -25,6 +25,7 @@ use app\common\model\GoodsCategoryRel;
*/
class Goods extends Controller
{
private static $show_content = "***";
/**
* 商品列表
* @return Json
@ -35,9 +36,26 @@ class Goods extends Controller
// 获取列表记录
$model = new GoodsModel;
$params = $this->request->param();
$params['channel'] = 'zy';
//$params['channel'] = 'zy';
$params['merchantId'] = $this->merchantId;
$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'));
}
@ -68,6 +86,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'));
}
@ -120,8 +151,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 "<pre>";
// 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() ?: '更新失败');

@ -183,7 +183,7 @@ class Goods extends GoodsModel
public function setIsPool(array $goodsIds, int $is_pool): bool
{
// 批量更新记录
return static::updateBase(['is_pool' => $is_pool], [['goods_id', 'in', $goodsIds]]);
return static::updateBase(['is_pool' => $is_pool,'update_time' => time(),'sale_time' => time()], [['goods_id', 'in', $goodsIds]]);
}
/**
* 修改商品状态
@ -194,7 +194,7 @@ class Goods extends GoodsModel
public function setIsSale(array $goodsIds, int $is_sale): bool
{
// 批量更新记录
return static::updateBase(['is_sale' => $is_sale], [['goods_id', 'in', $goodsIds]]);
return static::updateBase(['is_sale' => $is_sale,'update_time' => time(),'sale_time' => time()], [['goods_id', 'in', $goodsIds]]);
}
/**
* 修改商品状态

@ -30,6 +30,7 @@ class Store extends StoreModel
{
// 是否删除图片
!isset($data['logo_image_id']) && $data['logo_image_id'] = 0;
$data['fliter_condition'] = isset($data['fliter_condition']) ? json_encode($data['fliter_condition'], JSON_UNESCAPED_UNICODE) : "";
return $this->save($data) !== false;
}
}

@ -0,0 +1,4 @@
<?php
return [
"/store/platformList"
];
Loading…
Cancel
Save