迁移代码(用户相关,商品分类)

This commit is contained in:
liu 2024-06-01 13:32:43 +08:00
parent f0537ea234
commit 2ef90f9403
16 changed files with 824 additions and 5 deletions

View File

@ -3,7 +3,7 @@
namespace app\api\controller;
use app\api\logic\LoginLogic;
use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate};
use app\api\validate\{LoginAccountValidate, WechatLoginValidate};
use app\common\model\user\UserAuth;
class LoginController extends BaseApiController
@ -35,7 +35,7 @@ class LoginController extends BaseApiController
/**
* @notes 小程序-登录接口
* @return \think\response\Json
* @return
* @author 段誉
* @date 2022/9/20 19:48
*/
@ -52,7 +52,7 @@ class LoginController extends BaseApiController
/**
* @notes 小程序绑定微信
* @return \think\response\Json
* @return
* @author 段誉
* @date 2022/9/20 19:48
*/
@ -69,7 +69,7 @@ class LoginController extends BaseApiController
/**
* @notes 更新用户头像昵称
* @return \think\response\Json
* @return
* @author 段誉
* @date 2023/2/22 11:15
*/

View File

@ -0,0 +1,29 @@
<?php
namespace app\api\controller\goods;
use app\api\controller\BaseApiController;
use app\api\lists\goods\GoodsclassLists;
/**
* 商品分类控制器
* Class GoodsclassController
* @package app\admin\controller\goods
*/
class GoodsclassController extends BaseApiController
{
public $notNeedLogin = ['lists'];
/**
* @notes 获取商品分类列表
* @return
* @author likeadmin
* @date 2024/04/23 10:27
*/
public function lists()
{
return $this->dataLists(new GoodsclassLists());
}
}

View File

@ -0,0 +1,99 @@
<?php
namespace app\api\controller\user;
use app\api\controller\BaseApiController;
use app\api\lists\user\UserAddressList;
use app\api\logic\user\AddressLogic;
use app\api\validate\UserAddressValidate;
use app\common\model\retail\Cashierclass;
class AddressController extends BaseApiController
{
public function lists(){
return $this->dataLists(new UserAddressList());
}
/**
* @notes 添加地址
* @return \think\response\Json
* @author likeadmin
* @date 2024/4/24 10:37
*/
public function create()
{
$params = (new UserAddressValidate())->post()->goCheck('add');
$params['uid'] = $this->request->userId;
$res=AddressLogic::add($params);
if(AddressLogic::hasError()){
return $this->fail(AddressLogic::getError());
}else{
return $this->success('添加成功');
}
}
/**
* 商户给用户添加地址
*/
public function merchant_create()
{
$params = $this->request->post();
if($params['order_id'] && $params['order_id']!=0){
$uid=Cashierclass::where('id',$params['order_id'])->value('uid');
if(!$uid || $uid<=0){
return $this->fail('订单不存在');
}
}
$params['uid'] = $uid;
$res=AddressLogic::add($params);
if(AddressLogic::hasError()){
return $this->fail(AddressLogic::getError());
}else{
// Cashierclass::where('id',$params['order_id'])->update(['address_id'=>$res,'real_name'=>$params['real_name'],'user_phone'=>$params['phone'],'user_address'=>$params['detail']]);
return $this->success('添加成功');
}
}
/**
* @notes 编辑地址
* @return \think\response\Json
* @author likeadmin
* @date 2024/4/24 10:37
*/
public function edit()
{
$params = (new UserAddressValidate())->post()->goCheck('edit');
$params['uid'] = $this->request->userId;
if(AddressLogic::edit($params)){
return $this->success('编辑成功');
}else{
return $this->fail(AddressLogic::getError());
}
}
/**
* @notes 删除地址
* @return \think\response\Json
* @author likeadmin
* @date 2024/4/24 10:37
*/
public function delete()
{
$params = (new UserAddressValidate())->post()->goCheck('delete');
if(AddressLogic::delete($params)){
return $this->success('删除成功');
}else{
return $this->fail(AddressLogic::getError());
}
}
/**
* @notes 获取地址详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/4/24 10:37
*/
public function detail()
{
$params = (new UserAddressValidate())->goCheck('detail');
return $this->success('获取成功',AddressLogic::detail($params));
}
}

View File

@ -19,7 +19,7 @@ class UserController extends BaseApiController
/**
* @notes 获取小程序手机号
* @return \think\response\Json
* @return
* @author 段誉
* @date 2022/9/21 16:46
*/

View File

@ -0,0 +1,34 @@
<?php
namespace app\api\controller\user;
use app\api\lists\user\UserFeedbackLists;
use app\api\logic\user\UserFeedbackLogic;
use app\admin\validate\user\UserFeedbackValidate;
use app\api\controller\BaseApiController;
class UserFeedbackController extends BaseApiController
{
/**
* @notes 获取用户反馈表列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/05/13 16:56
*/
public function lists()
{
return $this->dataLists(new UserFeedbackLists());
}
public function add()
{
$params = (new UserFeedbackValidate())->post()->goCheck('add');
$result = UserFeedbackLogic::add($params,$this->request->userInfo['user_id']);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(UserFeedbackLogic::getError());
}
}

View File

@ -0,0 +1,102 @@
<?php
namespace app\api\lists\goods;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\goods\Goodsclass;
use app\common\lists\ListsSearchInterface;
use app\Request;
/**
* 商品分类列表
* Class GoodsclassLists
* @package app\admin\listsgoods
*/
class GoodsclassLists extends BaseAdminDataLists implements ListsSearchInterface
{
protected $where;
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/04/23 10:27
*/
public function setSearch(): array
{
return [
'=' => ['pid', 'name', 'data', 'pic', 'sort'],
];
}
/**
* @notes 获取商品分类列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/04/23 10:27
*/
public function lists(): array
{
$pid=Request()->get('pid',0);
if($pid==0){
$lists = Goodsclass::where($this->searchWhere)
->where('pid', 0)
->where('children','<>',null)
->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])
->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc','id' => 'desc'])
->select()->toArray();
}else{
$three=Request()->get('three',0);
if($three==0){
$where[]=['children','<>',''];
$this->where=$where;
}
$lists = Goodsclass::where($this->searchWhere)
->where($this->where)
->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])
->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc','id' => 'desc'])
->select()->toArray();
}
// ->each(function ($item) {
// $a = Goodsclass::where('pid', $item['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select();
// $item['children'] = $a;
// foreach ($a as $k => &$v) {
// $b = Goodsclass::where('pid', $v['id'])->field(['id', 'pid', 'name', 'data', 'pic', 'sort'])->select();
// $v['children'] = $b;
// }
// })->toArray();
return $lists;
// return linear_to_tree($lists, 'children');
}
/**
* @notes 获取商品分类数量
* @return int
* @author likeadmin
* @date 2024/04/23 10:27
*/
public function count(): int
{
$pid=Request()->get('pid',0);
if($pid==0){
return Goodsclass::where($this->searchWhere)->where('pid', 0)
->where('children','<>',null)
->count();
}else{
return Goodsclass::where($this->searchWhere)
->where($this->where)
->count();
}
}
}

View File

@ -0,0 +1,63 @@
<?php
namespace app\api\lists\user;
use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\user\UserAddress;
/**
* 地址列表
* Class OpurchaseclassLists
* @package app\api\operation
*/
class UserAddressList extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
*/
public function setSearch(): array
{
return [
];
}
/**
* @notes 获取地址列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @date 2024/04/27 11:26
*/
public function lists(): array
{
$user_id=$this->request->userId;
if(!$user_id) return [];
return UserAddress::where($this->searchWhere)->where('uid',$user_id)
->field('address_id,real_name,detail,phone,is_default')
->limit($this->limitOffset, $this->limitLength)
->order(['address_id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取地址数量
* @return int
* @date 2024/04/27 11:26
*/
public function count(): int
{
$user_id=$this->request->userId;
return UserAddress::where($this->searchWhere)->where('uid',$user_id)->count();
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace app\api\lists\user;
use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\user\User;
use app\common\model\user\UserFeedback;
class UserFeedbackLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/05/13 16:56
*/
public function setSearch(): array
{
return [
'=' => ['uid'],
'%like%' => ['name', 'contact'],
];
}
/**
* @notes 获取用户反馈表列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/05/13 16:56
*/
public function lists(): array
{
$uid = $this->request->userInfo['user_id'];
return UserFeedback::where($this->searchWhere)->where('uid',$uid)
->field(['id', 'uid', 'content', 'images', 'name', 'contact','create_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($data){
$user = User::field('nickname')->where('id',$data['uid'])->findOrEmpty();
$data['user_name'] = !$user->isEmpty() ? $user['nickname'] : '';
})
->toArray();
}
/**
* @notes 获取用户反馈表数量
* @return int
* @author likeadmin
* @date 2024/05/13 16:56
*/
public function count(): int
{
return UserFeedback::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,106 @@
<?php
namespace app\api\logic\user;
use app\common\logic\BaseLogic;
use app\common\model\user\UserAddress;
use think\facade\Db;
/**
* 地址逻辑
* Class OrderLogic
* @package app\api\logic\order
*/
class AddressLogic extends BaseLogic
{
/**
* @notes 添加地址表
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/04/24 10:37
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
if(isset($params['is_default'])&&$params['is_default']==1){
UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]);
}else{
$params['is_default']=1;
}
$id=UserAddress::insertGetId([
'uid' => $params['uid'],
'real_name' => $params['real_name'],
'phone' => $params['phone'],
'detail' => $params['detail'],
'is_default' => $params['is_default'],
]);
Db::commit();
return $id;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑地址表
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/04/24 10:37
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
if($params['is_default']==1){
UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]);
}
$data = [
'real_name' => $params['real_name'],
'phone' => $params['phone'],
'detail' => $params['detail'],
'is_default' => $params['is_default'],
];
UserAddress::where('uid', $params['uid'])->where('address_id', $params['address_id'])->update($data);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除地址表
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/04/24 10:37
*/
public static function delete(array $params): bool
{
return UserAddress::destroy($params['address_id']);
}
/**
* @notes 获取购物车表详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/04/24 10:37
*/
public static function detail($params): array
{
return UserAddress::field('address_id,real_name,phone,detail,is_default')->findOrEmpty($params['address_id'])->toArray();
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace app\api\logic\user;
use app\common\logic\BaseLogic;
use app\common\model\user\UserFeedback;
use think\facade\Db;
class UserFeedbackLogic extends BaseLogic
{
/**
* @notes 添加用户反馈表
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/05/13 16:56
*/
public static function add(array $params,$uid): bool
{
Db::startTrans();
try {
UserFeedback::create([
'uid' => $uid,
'content' => $params['content'],
'images' => $params['images'] ? json_encode($params['images']) : null,
'name' => $params['name'],
'contact' => $params['contact'],
'create_time' => time(),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace app\api\logic\user;
use app\common\{
logic\BaseLogic,
model\user\User,
service\wechat\WeChatMnpService};
/**
* 会员逻辑层
* Class UserLogic
* @package app\shopapi\logic
*/
class UserLogic extends BaseLogic
{
/**
* @notes 获取小程序手机号
* @param array $params
* @return bool
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
* @author 段誉
* @date 2023/2/27 11:49
*/
public static function getMobileByMnp(array $params)
{
try {
$response = (new WeChatMnpService())->getUserPhoneNumber($params['code']);
$phoneNumber = $response['phone_info']['purePhoneNumber'] ?? '';
if (empty($phoneNumber)) {
throw new \Exception('获取手机号码失败');
}
$user = User::where([
['mobile', '=', $phoneNumber],
['id', '<>', $params['user_id']]
])->findOrEmpty();
if (!$user->isEmpty()) {
throw new \Exception('手机号已被其他账号绑定');
}
// 绑定手机号
User::update([
'id' => $params['user_id'],
'mobile' => $phoneNumber
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace app\api\validate;
use app\common\enum\PayEnum;
use app\common\validate\BaseValidate;
/**
* 支付验证
* Class PayValidate
* @package app\api\validate
*/
class PayValidate extends BaseValidate
{
protected $rule = [
'from' => 'require',
'pay_way' => 'require|in:' . PayEnum::BALANCE_PAY . ',' . PayEnum::WECHAT_PAY . ',' . PayEnum::ALIPAY,
'order_id' => 'require'
];
protected $message = [
'from.require' => '参数缺失',
'pay_way.require' => '支付方式参数缺失',
'pay_way.in' => '支付方式参数错误',
'order_id.require' => '订单参数缺失'
];
/**
* @notes 支付方式场景
* @return PayValidate
* @author 段誉
* @date 2023/2/24 17:43
*/
public function scenePayway()
{
return $this->only(['from', 'order_id']);
}
/**
* @notes 支付状态
* @return PayValidate
* @author 段誉
* @date 2023/3/1 16:17
*/
public function sceneStatus()
{
return $this->only(['from', 'order_id']);
}
}

View File

@ -0,0 +1,93 @@
<?php
namespace app\api\validate;
use app\common\validate\BaseValidate;
/**
* UserAddress验证器
* Class UserAddressValidate
* @package app\admin\validate
*/
class UserAddressValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'real_name' => 'require',
'phone' => 'require',
'detail' => 'require',
'address_id' => 'require',
"is_default"=>"require|in:0,1"
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'real_name' => '收货人姓名',
'phone' => '收货人电话',
'detail' => '收货人详细地址',
'address_id' => '地址id',
"is_default"=>"默认地址"
];
/**
* @notes 添加场景
* @return UserAddressValidate
* @author likeadmin
* @date 2024/04/28 17:28
*/
public function sceneAdd()
{
return $this->only(['real_name','phone','detail']);
}
/**
* @notes 编辑场景
* @return UserAddressValidate
* @author likeadmin
* @date 2024/04/28 17:28
*/
public function sceneEdit()
{
return $this->only(['real_name','phone','detail','address_id']);
}
/**
* @notes 删除场景
* @return UserAddressValidate
* @author likeadmin
* @date 2024/04/28 17:28
*/
public function sceneDelete()
{
return $this->only(['address_id']);
}
/**
* @notes 详情场景
* @return UserAddressValidate
* @author likeadmin
* @date 2024/04/28 17:28
*/
public function sceneDetail()
{
return $this->only(['address_id']);
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace app\common\model\goods;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 商品分类模型
* Class Goodsclass
* @package app\common\model\goods
*/
class Goodsclass extends BaseModel
{
use SoftDelete;
protected $name = 'store_category';
protected $deleteTime = 'delete_time';
public function getChildrenAttr($value)
{
if($value){
return json_decode($value, true);
}else{
return [];
}
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace app\common\model\merchant;
use app\common\model\BaseModel;
use app\common\model\user\User;
use think\model\concern\SoftDelete;
/**
* 商户列表模型
* Class Merchant
* @package app\common\model\merchant
*/
class Merchant extends BaseModel
{
use SoftDelete;
protected $ok = 'mer_id';
protected $name = 'merchant';
protected $deleteTime = 'delete_time';
public function realName()
{
return $this->hasOne(User::class,'id','uid')->bind(['mer_real_name'=>'real_name']);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\user;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 用户地址表
* Class UserAddress
* @package app\common\model
*/
class UserAddress extends BaseModel
{
use SoftDelete;
protected $pk = 'address_id';
protected $deleteTime = 'delete_time';
}