From b8ae85799fdb9ead604cf3b80b5daf04b4205e44 Mon Sep 17 00:00:00 2001 From: limu Date: Thu, 1 Feb 2024 18:29:10 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=95=86=E5=93=81=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/StoreKeeper.php | 16 ++++ app/common/model/Category.php | 6 ++ app/common/model/Goods.php | 15 +++ app/common/model/goods/GoodsPrice.php | 48 ++++++++++ app/store/model/goods/GoodsPrice.php | 129 ++++++++++++++++++++++++++ 5 files changed, 214 insertions(+) create mode 100644 app/common/model/goods/GoodsPrice.php create mode 100644 app/store/model/goods/GoodsPrice.php diff --git a/app/api/controller/StoreKeeper.php b/app/api/controller/StoreKeeper.php index ce257ac9..82fd0876 100644 --- a/app/api/controller/StoreKeeper.php +++ b/app/api/controller/StoreKeeper.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')); + } + + } \ No newline at end of file diff --git a/app/common/model/Category.php b/app/common/model/Category.php index dc09acaf..861d47fa 100644 --- a/app/common/model/Category.php +++ b/app/common/model/Category.php @@ -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 diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 24e277ab..ac356c7f 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -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 diff --git a/app/common/model/goods/GoodsPrice.php b/app/common/model/goods/GoodsPrice.php new file mode 100644 index 00000000..8ea60710 --- /dev/null +++ b/app/common/model/goods/GoodsPrice.php @@ -0,0 +1,48 @@ + +// +---------------------------------------------------------------------- +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'); + } +} diff --git a/app/store/model/goods/GoodsPrice.php b/app/store/model/goods/GoodsPrice.php new file mode 100644 index 00000000..7a47906a --- /dev/null +++ b/app/store/model/goods/GoodsPrice.php @@ -0,0 +1,129 @@ + +// +---------------------------------------------------------------------- +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; + } +} From 701d9f8230b7c54875efe091f56ebc5fa4c0825e Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 2 Feb 2024 00:42:42 +0800 Subject: [PATCH 2/9] 1 --- app/common/model/Goods.php | 37 +++++++++++++++------------------ app/store/controller/Server.php | 6 ++++-- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index ac356c7f..1438607e 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -13,19 +13,18 @@ declare (strict_types=1); namespace app\common\model; -use app\api\service\User as UserService; +use app\common\enum\goods\Status as GoodsStatusEnum; +use app\common\enum\order\DeliveryType as DeliveryTypeEnum; +use app\common\library\helper; +use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel; use cores\BaseModel; use think\db\BaseQuery; use think\db\exception\DbException; +use think\model\Collection; use think\model\relation\BelongsTo; use think\model\relation\HasMany; -use think\Paginator; -use think\model\Collection; use think\model\relation\HasOne; -use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel; -use app\common\library\helper; -use app\common\enum\goods\Status as GoodsStatusEnum; -use app\common\enum\order\DeliveryType as DeliveryTypeEnum; +use think\Paginator; /** * 商品模型 @@ -357,25 +356,23 @@ 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; - } - } +// //商品价格判断 +// 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 diff --git a/app/store/controller/Server.php b/app/store/controller/Server.php index 066d3b4e..57a477fe 100644 --- a/app/store/controller/Server.php +++ b/app/store/controller/Server.php @@ -212,7 +212,7 @@ class Server extends Controller $order_status = intval($this->request->post('order_status')); $where = []; if (!empty($server_name)) { - $where[] = ['a.server_name', 'like', `%$server_name%`]; + $where[] = ['a.server_name', 'like', "%$server_name%"]; } if (!empty($order_no)) { $where[] = ['a.order_no', '=', $order_no]; @@ -229,7 +229,9 @@ class Server extends Controller $where[] = ['b.nick_name', 'like', "%$server_name%"]; } $list = $model->getList($where); - return $this->renderSuccess(compact('list')); + $data['list'] = $list->items(); + $data['total'] = $list->total(); + return $this->renderSuccess($data); } /** From dd79cf3b7d50a59cc398c898dc4a0342db852eeb Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Fri, 2 Feb 2024 00:50:51 +0800 Subject: [PATCH 3/9] 1 --- app/common/model/UploadFile.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/common/model/UploadFile.php b/app/common/model/UploadFile.php index 940c3ea0..7a2f1be5 100644 --- a/app/common/model/UploadFile.php +++ b/app/common/model/UploadFile.php @@ -12,10 +12,10 @@ declare (strict_types=1); namespace app\common\model; +use app\common\enum\file\FileType as FileTypeEnum; +use app\common\enum\file\Storage as StorageEnum; use cores\BaseModel; use think\model\relation\BelongsTo; -use app\common\enum\file\Storage as StorageEnum; -use app\common\enum\file\FileType as FileTypeEnum; /** * 文件库模型 @@ -73,6 +73,8 @@ class UploadFile extends BaseModel // 存储方式本地:拼接当前域名 if ($data['storage'] === StorageEnum::LOCAL) { $data['domain'] = rtrim(uploads_url(), '/'); + } elseif ($data['storage'] === StorageEnum::EXTERNAL) { + return "{$data['file_path']}"; } return "{$data['domain']}/{$data['file_path']}"; } From f994e3a56c14f2339aa1239ab09c655176f48919 Mon Sep 17 00:00:00 2001 From: limu Date: Fri, 2 Feb 2024 10:57:03 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/StoreKeeper.php | 9 ++++++ app/store/model/goods/GoodsPrice.php | 47 ++++++++++------------------ 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/app/api/controller/StoreKeeper.php b/app/api/controller/StoreKeeper.php index 82fd0876..6ff987ac 100644 --- a/app/api/controller/StoreKeeper.php +++ b/app/api/controller/StoreKeeper.php @@ -515,5 +515,14 @@ class StoreKeeper extends Controller return $this->renderSuccess(compact('list')); } + public function addPrice(): Json + { + $model = new GoodsPriceModel; + if (!$model->add($this->request->param())) { + return $this->renderError($model->getError() ?: '添加失败'); + } + return $this->renderSuccess('添加成功'); + } + } \ No newline at end of file diff --git a/app/store/model/goods/GoodsPrice.php b/app/store/model/goods/GoodsPrice.php index 7a47906a..3dfabca6 100644 --- a/app/store/model/goods/GoodsPrice.php +++ b/app/store/model/goods/GoodsPrice.php @@ -26,7 +26,7 @@ class GoodsPrice extends GoodsPriceModel /** * 获取全部记录 * @param array $param - * @return Collection + * @return array|Collection * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException @@ -40,6 +40,8 @@ class GoodsPrice extends GoodsPriceModel $temp = []; if (!empty($v['price'])) { foreach ($v['price'] as $pk => $pv) { + $pv['profit_min'] = round($pv['min_price'] * $pv['markup_rate'] / 100, 2); + $pv['profit_max'] = round($pv['max_price'] * $pv['markup_rate'] / 100, 2); if (!empty($params['type'])) { if ($pv['type'] == $params['type']) { $temp[] = $pv; @@ -51,7 +53,6 @@ class GoodsPrice extends GoodsPriceModel } } } - $all[] = [ 'category_id' => $v['category_id'], 'name' => $v['name'], @@ -61,34 +62,6 @@ class GoodsPrice extends GoodsPriceModel 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; - } /** * 新增记录 @@ -97,6 +70,20 @@ class GoodsPrice extends GoodsPriceModel */ public function add(array $data): bool { + if (empty($data['type']) || empty($data['max_price']) || empty($data['cat_id']) || empty($data['markup_rate'])) { + $this->error = "请补全信息"; + return false; + } + //校验是否有冲突的区间 + $catList = $this->where(['cat_id' => $data['cat_id'], 'type' => $data['type']])->select(); + if (!empty($catList)) { + foreach ($catList as $k => $v) { + if ($v->max_price <= $data['min_price'] || $v->min_price >= $data['max_price']) { + $this->error = "该分类价格区间冲突,请重新设置价格"; + return false; + } + } + } $data['store_id'] = self::$storeId; return $this->save($data); } From 799eb79db0106c638548fbce9562fa8238bdba4b Mon Sep 17 00:00:00 2001 From: limu Date: Fri, 2 Feb 2024 11:17:35 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/StoreKeeper.php | 9 +++++++++ app/store/model/goods/GoodsPrice.php | 25 ++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/api/controller/StoreKeeper.php b/app/api/controller/StoreKeeper.php index 6ff987ac..34a30951 100644 --- a/app/api/controller/StoreKeeper.php +++ b/app/api/controller/StoreKeeper.php @@ -524,5 +524,14 @@ class StoreKeeper extends Controller return $this->renderSuccess('添加成功'); } + public function editPrice(): Json + { + $model = new GoodsPriceModel; + if (!$model->edit($this->request->param())) { + return $this->renderError($model->getError() ?: '添加失败'); + } + return $this->renderSuccess('添加成功'); + } + } \ No newline at end of file diff --git a/app/store/model/goods/GoodsPrice.php b/app/store/model/goods/GoodsPrice.php index 3dfabca6..1e0a16d2 100644 --- a/app/store/model/goods/GoodsPrice.php +++ b/app/store/model/goods/GoodsPrice.php @@ -77,8 +77,13 @@ class GoodsPrice extends GoodsPriceModel //校验是否有冲突的区间 $catList = $this->where(['cat_id' => $data['cat_id'], 'type' => $data['type']])->select(); if (!empty($catList)) { + foreach ($catList as $k => $v) { - if ($v->max_price <= $data['min_price'] || $v->min_price >= $data['max_price']) { + if ($data['min_price'] >= $v->min_price && $data['min_price'] <= $v->max_price ) { + $this->error = "该分类价格区间冲突,请重新设置价格"; + return false; + } + if ( $data['max_price'] <= $v->max_price && $data['max_price'] >= $v->min_price ) { $this->error = "该分类价格区间冲突,请重新设置价格"; return false; } @@ -95,6 +100,24 @@ class GoodsPrice extends GoodsPriceModel */ public function edit(array $data): bool { + if (empty($data['type']) || empty($data['max_price']) || empty($data['cat_id']) || empty($data['markup_rate']) || empty($data['id'])) { + $this->error = "请补全信息"; + return false; + } + //校验是否有冲突的区间 + $catList = $this->where(['cat_id' => $data['cat_id'], 'type' => $data['type']])->where('id','<>',$data['id'])->select(); + if (!empty($catList)) { + foreach ($catList as $k => $v) { + if ($data['min_price'] >= $v->min_price && $data['min_price'] <= $v->max_price ) { + $this->error = "该分类价格区间冲突,请重新设置价格"; + return false; + } + if ( $data['max_price'] <= $v->max_price && $data['max_price'] >= $v->min_price ) { + $this->error = "该分类价格区间冲突,请重新设置价格"; + return false; + } + } + } return $this->save($data) !== false; } From 3cf067705727f7a866024bffb2fd31c9aae38245 Mon Sep 17 00:00:00 2001 From: limu Date: Fri, 2 Feb 2024 11:30:14 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/StoreKeeper.php | 13 +++++++++-- app/store/model/goods/GoodsPrice.php | 33 +++++++++++++++++----------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/api/controller/StoreKeeper.php b/app/api/controller/StoreKeeper.php index 34a30951..6903219e 100644 --- a/app/api/controller/StoreKeeper.php +++ b/app/api/controller/StoreKeeper.php @@ -528,9 +528,18 @@ class StoreKeeper extends Controller { $model = new GoodsPriceModel; if (!$model->edit($this->request->param())) { - return $this->renderError($model->getError() ?: '添加失败'); + return $this->renderError($model->getError() ?: '编辑失败'); } - return $this->renderSuccess('添加成功'); + return $this->renderSuccess('编辑成功'); + } + + public function delPrice(): Json + { + $model = new GoodsPriceModel; + if (!$model->del($this->request->param())) { + return $this->renderError($model->getError() ?: '删除失败'); + } + return $this->renderSuccess('删除成功'); } diff --git a/app/store/model/goods/GoodsPrice.php b/app/store/model/goods/GoodsPrice.php index 1e0a16d2..3f934127 100644 --- a/app/store/model/goods/GoodsPrice.php +++ b/app/store/model/goods/GoodsPrice.php @@ -40,8 +40,6 @@ class GoodsPrice extends GoodsPriceModel $temp = []; if (!empty($v['price'])) { foreach ($v['price'] as $pk => $pv) { - $pv['profit_min'] = round($pv['min_price'] * $pv['markup_rate'] / 100, 2); - $pv['profit_max'] = round($pv['max_price'] * $pv['markup_rate'] / 100, 2); if (!empty($params['type'])) { if ($pv['type'] == $params['type']) { $temp[] = $pv; @@ -79,16 +77,18 @@ class GoodsPrice extends GoodsPriceModel if (!empty($catList)) { foreach ($catList as $k => $v) { - if ($data['min_price'] >= $v->min_price && $data['min_price'] <= $v->max_price ) { + if ($data['min_price'] >= $v->min_price && $data['min_price'] <= $v->max_price) { $this->error = "该分类价格区间冲突,请重新设置价格"; return false; } - if ( $data['max_price'] <= $v->max_price && $data['max_price'] >= $v->min_price ) { + if ($data['max_price'] <= $v->max_price && $data['max_price'] >= $v->min_price) { $this->error = "该分类价格区间冲突,请重新设置价格"; return false; } } } + $data['profit_min'] = round($data['min_price'] * $data['markup_rate'] / 100, 2); + $data['profit_max'] = round($data['max_price'] * $data['markup_rate'] / 100, 2); $data['store_id'] = self::$storeId; return $this->save($data); } @@ -104,21 +104,28 @@ class GoodsPrice extends GoodsPriceModel $this->error = "请补全信息"; return false; } + $detail = $this->where('id', '=', $data['id'])->find(); + if ($detail->isEmpty()) { + $this->error = "异常数据"; + return false; + } //校验是否有冲突的区间 - $catList = $this->where(['cat_id' => $data['cat_id'], 'type' => $data['type']])->where('id','<>',$data['id'])->select(); + $catList = $this->where(['cat_id' => $data['cat_id'], 'type' => $data['type']])->where('id', '<>', $data['id'])->select(); if (!empty($catList)) { foreach ($catList as $k => $v) { - if ($data['min_price'] >= $v->min_price && $data['min_price'] <= $v->max_price ) { + if ($data['min_price'] >= $v->min_price && $data['min_price'] <= $v->max_price) { $this->error = "该分类价格区间冲突,请重新设置价格"; return false; } - if ( $data['max_price'] <= $v->max_price && $data['max_price'] >= $v->min_price ) { + if ($data['max_price'] <= $v->max_price && $data['max_price'] >= $v->min_price) { $this->error = "该分类价格区间冲突,请重新设置价格"; return false; } } } - return $this->save($data) !== false; + $data['profit_min'] = round($data['min_price'] * $data['markup_rate'] / 100, 2); + $data['profit_max'] = round($data['max_price'] * $data['markup_rate'] / 100, 2); + return $detail->save($data) !== false; } /** @@ -126,14 +133,14 @@ class GoodsPrice extends GoodsPriceModel * @return bool * @throws \Exception */ - public function remove(): bool + public function del($data): bool { // 判断该服务是否被商品引用 - $goodsCount = ServiceRelModel::getCountByServiceId($this['service_id']); - if ($goodsCount > 0) { - $this->error = "该记录被{$goodsCount}个商品引用,不允许删除"; + $detail = $this->where('id', '=', $data['id'])->find(); + if ($detail->isEmpty()) { + $this->error = "异常数据"; return false; } - return $this->save(['is_delete' => 1]) !== false; + return $detail->delete() !== false; } } From 250a660114d60acee58288e8302d0709eccfab0d Mon Sep 17 00:00:00 2001 From: limu Date: Fri, 2 Feb 2024 14:17:45 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E5=95=86=E5=93=81=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/model/Goods.php | 43 ++++++++++++++++++++++++++++ app/store/model/goods/GoodsPrice.php | 26 +++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index d6ce4147..ac029482 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -26,6 +26,7 @@ use cores\exception\BaseException; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use app\store\model\goods\GoodsPrice as GoodsPriceModel; /** * 商品模型 @@ -346,9 +347,51 @@ class Goods extends GoodsModel return $this->setGoodsData($goodsInfo, function ($goods) { // 计算并设置商品会员价 $this->getEnableGradeMoney() && $this->setGoodsGradeMoney($goods); + //计算plus 分销价格 + $this->setGoodsMoney($goods); }); } + /** + * 设置商品plus 分销价格 + * @param Goods $goods + * @throws BaseException + */ + private function setGoodsMoney(self $goods) + { + // 判断是否登录 + if (!UserService::isLogin()) { + return; + } + $catService = new \app\store\model\GoodsCategoryRel(); + $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); + //读取分类集 + $price_list_plus = $price_list_dealer = []; + foreach ($catIds as $k => $v) { + $price_list_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['goods_price_min']); + $price_list_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['goods_price_min']); + } + //价格判断 + if (UserService::isstore()) { + $goods['goods_price_min_plus'] = min($price_list_plus); + $goods['goods_price_min_dealer'] = min($price_list_dealer); + } elseif (UserService::isPlusMember()) { + $goods['goods_price_min_plus'] = min($price_list_plus); + } elseif (UserService::isDealerMember()) { + $goods['goods_price_min_dealer'] = min($price_list_dealer); + } + // 会员折扣价: 商品sku列表 + if ($goods->getRelation('skuList')) { + foreach ($goods['skuList'] as &$skuItem) { + $skuItem['goods_price'] = $skuItem['goods_price']; + } + } + // 会员折扣价: 已选择的商品sku(用于购物车) + if ($goods->getAttr('skuInfo')) { + $goods['skuInfo']['goods_price'] = $goods['skuInfo']['goods_price']; + } + } + /** * 设置商品的会员价 * @param Goods $goods diff --git a/app/store/model/goods/GoodsPrice.php b/app/store/model/goods/GoodsPrice.php index 3f934127..910ac2bf 100644 --- a/app/store/model/goods/GoodsPrice.php +++ b/app/store/model/goods/GoodsPrice.php @@ -12,6 +12,7 @@ declare (strict_types=1); namespace app\store\model\goods; +use app\common\library\helper; use think\Paginator; use think\Collection; use app\common\model\goods\GoodsPrice as GoodsPriceModel; @@ -143,4 +144,29 @@ class GoodsPrice extends GoodsPriceModel } return $detail->delete() !== false; } + + + /** + * 获取和计算折扣后的价格 + * @param $catId + * @param $type + * @param $originalPrice + * @return string + */ + public static function getDiscountPrice($catId, $type = 1, $originalPrice): string + { + $info = self::where(['cat_id' => $catId, 'type' => $type]) + ->where('min_price', '<=', $originalPrice) + ->order('min_price desc') + ->find(); + //没有配置返回原价 + if (!$info) { + return $originalPrice; + } + // 使用高精度方法计算等级折扣; + $discountPrice = helper::bcmul($originalPrice, $info->markup_rate / 100, 2); + //取优惠后的价格 + $lastPrice = bcsub($originalPrice, $discountPrice, 2); + return helper::number2($lastPrice, true); + } } From 742b791cc2fac3abea3e402a9a431a3969bfcd41 Mon Sep 17 00:00:00 2001 From: limu Date: Fri, 2 Feb 2024 14:40:44 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/model/Goods.php | 33 ++++++++++++++++++++++++++++++--- app/api/service/Goods.php | 31 ++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index ac029482..7a0a37f0 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -383,12 +383,39 @@ class Goods extends GoodsModel // 会员折扣价: 商品sku列表 if ($goods->getRelation('skuList')) { foreach ($goods['skuList'] as &$skuItem) { - $skuItem['goods_price'] = $skuItem['goods_price']; + $temp_price_plus = $temp_price_dealer = []; + foreach ($catIds as $k => $v) { + $temp_price_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $skuItem['goods_price']); + $temp_price_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $skuItem['goods_price']); + } + //价格判断 + if (UserService::isstore()) { + $skuItem['goods_price_plus'] = min($temp_price_plus); + $skuItem['goods_price_dealer'] = min($temp_price_dealer); + } elseif (UserService::isPlusMember()) { + $skuItem['goods_price_plus'] = min($temp_price_plus); + } elseif (UserService::isDealerMember()) { + $skuItem['goods_price_dealer'] = min($temp_price_dealer); + } + } } - // 会员折扣价: 已选择的商品sku(用于购物车) + // 折扣价: 已选择的商品sku(用于购物车) if ($goods->getAttr('skuInfo')) { - $goods['skuInfo']['goods_price'] = $goods['skuInfo']['goods_price']; + if (UserService::isPlusMember()) { + $sku_price_plus = []; + foreach ($catIds as $k => $v) { + $sku_price_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['skuInfo']['goods_price']); + } + $goods['skuInfo']['goods_price'] = min($sku_price_plus); + } elseif (UserService::isDealerMember()) { + $sku_price_dealer = []; + foreach ($catIds as $k => $v) { + $sku_price_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['skuInfo']['goods_price']); + } + $goods['skuInfo']['goods_price'] = min($sku_price_dealer); + } + } } diff --git a/app/api/service/Goods.php b/app/api/service/Goods.php index bffafc63..0eca5075 100644 --- a/app/api/service/Goods.php +++ b/app/api/service/Goods.php @@ -16,6 +16,7 @@ use app\api\model\Goods as GoodsModel; use app\api\model\Setting as SettingModel; use app\api\model\GoodsSku as GoodsSkuModel; use app\api\model\Category as CategoryModel; +use app\api\service\User as UserService; use app\common\model\store\Shop as ShopModel; use app\api\service\sharp\Active as ActiveService; use app\common\enum\Setting as SettingEnum; @@ -23,6 +24,7 @@ use app\common\service\Goods as GoodsService; use app\api\model\sharp\Active as SharpActiveModel; use app\api\model\sharp\ActiveTime as ActiveTimeModel; use app\api\controller\sharp\Goods as miaosha; +use app\store\model\goods\GoodsPrice as GoodsPriceModel; /** * 商品服务类 @@ -52,19 +54,19 @@ class Goods extends GoodsService switch (request()->get('type')) { case 1: - $data['imgurl']= 'https://www.saas.njrenzhou.com/uploads/10001/20240131/bdc5f17f3ff8c53ce0853177bc4f1917.png'; + $data['imgurl'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240131/bdc5f17f3ff8c53ce0853177bc4f1917.png'; return $data; break; case 2: - $data['imgurl']= 'https://www.saas.njrenzhou.com/uploads/10001/20240131/e8e10653875e779bc72dbee65b8072c0.png'; + $data['imgurl'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240131/e8e10653875e779bc72dbee65b8072c0.png'; return $data; break; case 3: - $data['imgurl']= 'https://www.saas.njrenzhou.com/uploads/10001/20240131/5c4ec6ffeb23223936295e290dc3d1f9.png'; + $data['imgurl'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240131/5c4ec6ffeb23223936295e290dc3d1f9.png'; return $data; break; case 4: - $data['imgurl']= [ + $data['imgurl'] = [ 'https://www.saas.njrenzhou.com/uploads/10001/20240131/5c4ec6ffeb23223936295e290dc3d1f9.png', ]; return $data; @@ -278,7 +280,7 @@ class Goods extends GoodsService { $data = []; foreach ($goodsList as $goods) { - $data[] = [ + $temp = [ 'goods_id' => $goods['goods_id'], 'goods_name' => $goods['goods_name'], 'selling_point' => $goods['selling_point'], @@ -290,6 +292,25 @@ class Goods extends GoodsService 'goods_sales' => $goods['goods_sales'], 'remaizhishu' => $goods['remaizhishu'], ]; + if (UserService::isLogin()) { + $catService = new \app\store\model\GoodsCategoryRel(); + $catIds = $catService->where(['goods_id' => $goods['goods_id']])->column('category_id'); + $price_list_plus = $price_list_dealer = []; + foreach ($catIds as $k => $v) { + $price_list_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['goods_price_min']); + $price_list_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['goods_price_min']); + } + //价格判断 + if (UserService::isstore()) { + $temp['goods_price_min_plus'] = min($price_list_plus); + $temp['goods_price_min_dealer'] = min($price_list_dealer); + } elseif (UserService::isPlusMember()) { + $temp['goods_price_min_plus'] = min($price_list_plus); + } elseif (UserService::isDealerMember()) { + $temp['goods_price_min_dealer'] = min($price_list_dealer); + } + } + $data[] = $temp; } return $data; } From 72975a1614dd37df6182de3edb4a6d520b1fb2ab Mon Sep 17 00:00:00 2001 From: limu Date: Fri, 2 Feb 2024 15:34:51 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/test.php | 28 ++++++++++++++++++++++++++++ config/console.php | 2 ++ 2 files changed, 30 insertions(+) create mode 100644 app/command/test.php diff --git a/app/command/test.php b/app/command/test.php new file mode 100644 index 00000000..9406e9d4 --- /dev/null +++ b/app/command/test.php @@ -0,0 +1,28 @@ +setName('test') + ->setDescription('测试demo'); + } + + protected function execute(Input $input, Output $output) + { + echo date('Y-m-d H:i:s') . '完成'; + } + + +} diff --git a/config/console.php b/config/console.php index f6008bfe..dbaa6db4 100644 --- a/config/console.php +++ b/config/console.php @@ -7,5 +7,7 @@ return [ 'commands' => [ // 定时任务 'timer' => \app\timer\command\Timer::class, + //test脚本 + 'test' => 'app\command\test', ], ];