From 1e922f35954f19e349e651a71d2d8ae78bce6c2f Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Thu, 25 Jan 2024 22:51:37 +0800 Subject: [PATCH] 1 --- app/common/enum/coupon/TypeCase.php | 31 +++++++++++++++++++++++++++++ app/common/model/Coupon.php | 15 ++++++++++++-- app/common/model/server/Server.php | 25 +++++++++++++++++++++++ app/store/controller/Server.php | 13 ++++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 app/common/enum/coupon/TypeCase.php diff --git a/app/common/enum/coupon/TypeCase.php b/app/common/enum/coupon/TypeCase.php new file mode 100644 index 00000000..bdc0ef58 --- /dev/null +++ b/app/common/enum/coupon/TypeCase.php @@ -0,0 +1,31 @@ + [ + 'name' => '商品券', + 'value' => self::SHOP + ], + self::SERVER => [ + 'name' => '服务券', + 'value' => self::SERVER + ] + ]; + } +} \ No newline at end of file diff --git a/app/common/model/Coupon.php b/app/common/model/Coupon.php index 7d8cfcf3..330c5760 100644 --- a/app/common/model/Coupon.php +++ b/app/common/model/Coupon.php @@ -12,8 +12,9 @@ declare (strict_types=1); namespace app\common\model; -use cores\BaseModel; +use app\common\enum\coupon\TypeCase; use app\common\library\helper; +use cores\BaseModel; /** * 优惠券模型 @@ -32,7 +33,7 @@ class Coupon extends BaseModel * 追加字段 * @var array */ - protected $append = ['state']; + protected $append = ['state', 'coupon_case_text']; /** * 优惠券状态 (是否可领取) @@ -54,6 +55,16 @@ class Coupon extends BaseModel return ['text' => '正常', 'value' => 1]; } + public function getCouponCaseTextAttr($value, $data) + { + // 订单状态 + $result = TypeCase::data(); + if (!empty($result[$data['coupon_case']]['name'])) { + return $result[$data['coupon_case']]['name']; + } + return '未知'; + } + /** * 获取器:格式化折扣率 * @param $value diff --git a/app/common/model/server/Server.php b/app/common/model/server/Server.php index 237b54c4..e2fe711f 100644 --- a/app/common/model/server/Server.php +++ b/app/common/model/server/Server.php @@ -74,6 +74,31 @@ class Server extends BaseModel ->paginate($listRows); } + /** + * 根据商品id集获取服务列表 + * @param array $serverIds + * @param null $status + * @return mixed + */ + public function getListByIds(array $serverIds, $status = null) + { + // 筛选条件 + $filter = [['server_id', 'in', $serverIds]]; + // 商品状态 + $status > 0 && $filter[] = ['status', '=', $status]; + // 获取商品列表数据 + $result = $this->withoutField(['content']) + ->with(['image']) + ->withJoin(['category' => ['category_id', 'name']]) + ->where($filter) + ->orderRaw('field(server_id, ' . implode(',', $serverIds) . ')') + ->select(); + if (!empty($result)) { + return $result->toArray(); + } + return []; + } + /** * 文章详情:HTML实体转换回普通字符 * @param $value diff --git a/app/store/controller/Server.php b/app/store/controller/Server.php index 687d88fd..066d3b4e 100644 --- a/app/store/controller/Server.php +++ b/app/store/controller/Server.php @@ -171,6 +171,19 @@ class Server extends Controller return $this->renderError('删除失败'); } + /** + * 根据服务ID集获取列表记录 + * @param $serverIds + * @return Json + */ + public function listByIds($serverIds): Json + { + // 获取列表记录 + $model = new ServerModel(); + $list = $model->getListByIds($serverIds); + return $this->renderSuccess(compact('list')); + } + /** * 修改服务状态(上下架) * @param array $serverIds 商品id集