商品价格

pull/1/head
limu 10 months ago
parent bcc12d55ad
commit b8ae85799f
  1. 16
      app/api/controller/StoreKeeper.php
  2. 6
      app/common/model/Category.php
  3. 15
      app/common/model/Goods.php
  4. 48
      app/common/model/goods/GoodsPrice.php
  5. 129
      app/store/model/goods/GoodsPrice.php

@ -30,6 +30,7 @@ use app\store\model\Order as OrderModel;
use app\store\model\OrderRefund as OrderRefundModel;
use app\store\model\dealer\Order as DealerOrderModel;
use app\store\model\Article as ArticleModel;
use app\store\model\goods\GoodsPrice as GoodsPriceModel;
/**
* 店主管理
@ -500,4 +501,19 @@ class StoreKeeper extends Controller
}
//会员、分销价格配置
/**
* 配置列表
* @return Json
* @throws \think\db\exception\DbException
*/
public function priceList(): Json
{
$model = new GoodsPriceModel;
$list = $model->getAll($this->request->param());
return $this->renderSuccess(compact('list'));
}
}

@ -14,6 +14,7 @@ namespace app\common\model;
use cores\BaseModel;
use think\model\relation\HasOne;
use think\model\relation\HasMany;
/**
* 商品分类模型
@ -37,6 +38,11 @@ class Category extends BaseModel
return $this->hasOne('UploadFile', 'file_id', 'image_id');
}
public function price(): HasMany
{
$model = "app\\common\\model\\goods\\GoodsPrice";
return $this->HasMany($model, 'cat_id', 'category_id');
}
/**
* 分类详情
* @param int|array $where

@ -13,6 +13,7 @@ declare (strict_types=1);
namespace app\common\model;
use app\api\service\User as UserService;
use cores\BaseModel;
use think\db\BaseQuery;
use think\db\exception\DbException;
@ -356,11 +357,25 @@ class Goods extends BaseModel
$goodsInfo['goods_image'] = current($goodsInfo['goods_images'])['preview_url'];
// 商品销量(实际显示=初始虚拟销量+实际销量)
$goodsInfo['goods_sales'] = $goodsInfo['sales_initial'] + $goodsInfo['sales_actual'];
//商品价格判断
if (UserService::isLogin()) {
if (UserService::isStore()) {//店主
$goodsInfo['goods_price_min_plus'] = 0;
$goodsInfo['goods_price_min_dealer'] = 0;
} elseif (UserService::isDealerMember()) { //分销商
$goodsInfo['goods_price_min_dealer'] = 0;
} elseif (UserService::isPlusMember()) {//升级会员
$goodsInfo['goods_price_min_plus'] = 0;
}
}
// 回调函数
is_callable($callback) && call_user_func($callback, $goodsInfo);
return $goodsInfo;
}
/**
* 根据商品id集获取商品列表
* @param array $goodsIds

@ -0,0 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model\goods;
use cores\BaseModel;
use think\model\relation\HasOne;
/**
* 商品服务与承诺模型
* Class Service
*/
class GoodsPrice extends BaseModel
{
// 定义表名
protected $name = 'goods_price';
// 定义主键
protected $pk = 'id';
/**
* 帮助详情
* @param int $helpId
* @return static|array|null
*/
public static function detail(int $helpId)
{
return self::get($helpId);
}
/**
* 分类图片
* @return HasOne
*/
public function cat(): HasOne
{
$model = "app\\common\\model\\Category";
return $this->hasOne($model, 'category_id', 'cat_id');
}
}

@ -0,0 +1,129 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\store\model\goods;
use think\Paginator;
use think\Collection;
use app\common\model\goods\GoodsPrice as GoodsPriceModel;
use app\common\model\Category as CategoryModel;
/**
* 商品价格配比
* Class Service
*/
class GoodsPrice extends GoodsPriceModel
{
/**
* 获取全部记录
* @param array $param
* @return Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAll($params)
{
$catFids = CategoryModel::where(['parent_id' => 0])->column('category_id');
$catList = CategoryModel::with(['price'])->whereIn('parent_id', $catFids)->select()->toArray();
$all = [];
foreach ($catList as $k => $v) {
$temp = [];
if (!empty($v['price'])) {
foreach ($v['price'] as $pk => $pv) {
if (!empty($params['type'])) {
if ($pv['type'] == $params['type']) {
$temp[] = $pv;
}
} else {
if ($pv['type'] == 1) {
$temp[] = $pv;
}
}
}
}
$all[] = [
'category_id' => $v['category_id'],
'name' => $v['name'],
'price' => $temp
];
}
return $all;
}
/**
* 获取列表记录
* @param array $param
* @return Paginator
* @throws \think\db\exception\DbException
*/
public function getList(array $param = []): Paginator
{
return $this->where($this->getFilter($param))
->where('is_delete', '=', 0)
->order(['sort', $this->getPk()])
->paginate();
}
/**
* 获取查询条件
* @param array $param
* @return array
*/
private function getFilter(array $param = []): array
{
// 默认查询参数
$params = $this->setQueryDefaultValue($param, ['search' => '']);
// 检索查询条件
$filter = [];
!empty($params['search']) && $filter[] = ['name', 'like', "%{$params['search']}%"];
return $filter;
}
/**
* 新增记录
* @param array $data
* @return bool|false
*/
public function add(array $data): bool
{
$data['store_id'] = self::$storeId;
return $this->save($data);
}
/**
* 更新记录
* @param array $data
* @return bool
*/
public function edit(array $data): bool
{
return $this->save($data) !== false;
}
/**
* 删除记录(软删除)
* @return bool
* @throws \Exception
*/
public function remove(): bool
{
// 判断该服务是否被商品引用
$goodsCount = ServiceRelModel::getCountByServiceId($this['service_id']);
if ($goodsCount > 0) {
$this->error = "该记录被{$goodsCount}个商品引用,不允许删除";
return false;
}
return $this->save(['is_delete' => 1]) !== false;
}
}
Loading…
Cancel
Save