pull/1/head
wanghousheng 12 months ago
parent bf95dd00de
commit e7dd2388a1
  1. 33
      app/common/enum/user/IdentityEnum.php
  2. 31
      app/common/model/User.php
  3. 54
      app/common/model/user/Identity.php
  4. 97
      app/store/controller/user/Identity.php
  5. 60
      app/store/model/user/Identity.php

@ -0,0 +1,33 @@
<?php
namespace app\common\enum\user;
use app\common\enum\EnumBasics;
class IdentityEnum extends EnumBasics
{
// 分销商
const DEALER = 20;
// 会员用户
const MEMBER = 10;
/**
* 获取用户身份值
* @return array
*/
public static function data(): array
{
return [
self::MEMBER => [
'name' => 'PLUS会员',
'value' => self::MEMBER,
],
self::DEALER => [
'name' => '分销商',
'value' => self::DEALER,
],
];
}
}

@ -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

@ -0,0 +1,54 @@
<?php
namespace app\common\model\user;
use app\common\enum\user\IdentityEnum;
use cores\BaseModel;
class Identity extends BaseModel
{
// 定义表名
protected $name = 'user_identity_price';
// 定义主键
protected $pk = 'identity_id';
protected $updateTime = false;
/**
* 追加字段
* @var array
*/
protected $append = [
'type_text', //身份文字描述
];
/**
* 获取器:身份文字描述
* @param $value
* @param $data
* @return string
*/
public function getTypeTextAttr($value, $data): string
{
// 身份
$result = IdentityEnum::data();
if (!empty($result[$data['type']]['name'])) {
return $result[$data['type']]['name'];
}
return '未知';
}
/**
* @notes:详情
* @param $where
* @param array $with
* @return static|array|null
* @author: wanghousheng
*/
public static function detail($where, array $with = [])
{
return static::get($where, $with);
}
}

@ -0,0 +1,97 @@
<?php
namespace app\store\controller\user;
use app\admin\controller\Controller;
use app\common\enum\user\IdentityEnum;
use app\store\model\user\Identity as IdentityModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
class Identity extends Controller
{
/**
* @notes:列表
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function list(): Json
{
$where = [];
$type = $this->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'));
}
}

@ -0,0 +1,60 @@
<?php
namespace app\store\model\user;
use app\common\model\user\Identity as BaseIdentity;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class Identity extends BaseIdentity
{
/**
* @notes:获取全部记录
* @param array $where
* @return Identity[]|array|Collection
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function getList(array $where)
{
return $this->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();
}
}
Loading…
Cancel
Save