From e7dd2388a14d4a4bdbf777325f36254e6d492293 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Mon, 29 Jan 2024 15:25:21 +0800 Subject: [PATCH] 1 --- app/common/enum/user/IdentityEnum.php | 33 +++++++++ app/common/model/User.php | 31 +++++++- app/common/model/user/Identity.php | 54 ++++++++++++++ app/store/controller/user/Identity.php | 97 ++++++++++++++++++++++++++ app/store/model/user/Identity.php | 60 ++++++++++++++++ 5 files changed, 272 insertions(+), 3 deletions(-) create mode 100644 app/common/enum/user/IdentityEnum.php create mode 100644 app/common/model/user/Identity.php create mode 100644 app/store/controller/user/Identity.php create mode 100644 app/store/model/user/Identity.php diff --git a/app/common/enum/user/IdentityEnum.php b/app/common/enum/user/IdentityEnum.php new file mode 100644 index 00000000..cafaa6c0 --- /dev/null +++ b/app/common/enum/user/IdentityEnum.php @@ -0,0 +1,33 @@ + [ + 'name' => 'PLUS会员', + 'value' => self::MEMBER, + ], + self::DEALER => [ + 'name' => '分销商', + 'value' => self::DEALER, + ], + ]; + } +} \ No newline at end of file diff --git a/app/common/model/User.php b/app/common/model/User.php index 1d42b490..c375ac52 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -12,11 +12,12 @@ declare (strict_types=1); namespace app\common\model; +use app\common\enum\user\UserTypeEnum; +use app\common\model\user\PointsLog as PointsLogModel; use cores\BaseModel; -use think\model\relation\HasOne; -use think\model\relation\HasMany; use think\model\relation\BelongsTo; -use app\common\model\user\PointsLog as PointsLogModel; +use think\model\relation\HasMany; +use think\model\relation\HasOne; /** * 用户模型类 @@ -34,6 +35,30 @@ class User extends BaseModel // 性别 private $gender = [0 => '未知', 1 => '男', 2 => '女']; + /** + * 追加字段 + * @var array + */ + protected $append = [ + 'user_type_text', //身份文字描述 + ]; + + /** + * 获取器:身份文字描述 + * @param $value + * @param $data + * @return string + */ + public function getUserTypeTextAttr($value, $data): string + { + // 身份 + $result = UserTypeEnum::data(); + if (!empty($result[$data['user_type']]['name'])) { + return $result[$data['user_type']]['name']; + } + return '未知'; + } + /** * 关联用户头像表 * @return HasOne diff --git a/app/common/model/user/Identity.php b/app/common/model/user/Identity.php new file mode 100644 index 00000000..21c59a72 --- /dev/null +++ b/app/common/model/user/Identity.php @@ -0,0 +1,54 @@ +request->post('type'); + if ($type) { + $where['type'] = $type; + } + $model = new IdentityModel(); + $list = $model->getList($where); + return $this->renderSuccess(compact('list')); + } + + /** + * @notes:新增 + * @return Json + * @author: wanghousheng + */ + public function add(): Json + { + $data = $this->postForm(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = new IdentityModel(); + if ($model->add($data)) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * @notes:编辑 + * @param int $identityId + * @return Json + * @author: wanghousheng + */ + public function edit(int $identityId): Json + { + $data = $this->postForm(); + if (!$data) { + return $this->renderError('缺少必要参数'); + } + $model = IdentityModel::detail($identityId); + if ($model->edit($data)) { + return $this->renderSuccess('编辑成功'); + } + return $this->renderError($model->getError() ?: '编辑失败'); + } + + /** + * @notes:删除 + * @param array $identityId + * @return Json + * @author: wanghousheng + */ + public function delete(array $identityId): Json + { + $model = new IdentityModel; + if ($model->remove($identityId)) { + return $this->renderSuccess('删除成功'); + } + return $this->renderError('删除失败'); + } + + /** + * @notes:身份值 + * @return Json + * @author: wanghousheng + */ + public function typeList(): Json + { + $list = array_values(IdentityEnum::data()); + return $this->renderSuccess(compact('list')); + } +} \ No newline at end of file diff --git a/app/store/model/user/Identity.php b/app/store/model/user/Identity.php new file mode 100644 index 00000000..fa7e91d3 --- /dev/null +++ b/app/store/model/user/Identity.php @@ -0,0 +1,60 @@ +where($where)->select(); + } + + /** + * @notes:新增 + * @param $data + * @return bool + * @author: wanghousheng + */ + public function add($data): bool + { + $data['store_id'] = self::$storeId; + return $this->save($data); + } + + /** + * @notes:编辑 + * @param $data + * @return bool + * @author: wanghousheng + */ + public function edit($data): bool + { + return $this->save($data) !== false; + } + + /** + * @notes:删除 + * @param array $IdentityId + * @return bool + * @author: wanghousheng + */ + public function remove(array $IdentityId): bool + { + return static::whereIn('identity_id', $IdentityId)->delete(); + } +} \ No newline at end of file