You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/controller/User.php

415 lines
14 KiB

11 months ago
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\api\controller;
9 months ago
use app\api\model\Agreement as AgreementModel;
9 months ago
use app\api\model\Invite\InviteLog;
8 months ago
use app\api\model\User as UserModel;
10 months ago
use app\api\model\user\BalanceLog;
use app\api\model\user\GoodSource as GoodsSourceModel;
use app\api\model\user\InvoiceOrder;
use app\api\model\user\UserCoupon;
9 months ago
use app\api\model\user\UserInvoice;
11 months ago
use app\api\model\UserCoupon as UserCouponModel;
10 months ago
use app\api\service\Feedback;
11 months ago
use app\api\service\User as UserService;
8 months ago
use app\common\model\dealer\Order as DealerOrderModel;
use app\common\model\Order as OrderModel;
9 months ago
use app\common\service\qrcode\InviteUser;
8 months ago
use app\store\model\MaintenanceCategory as MaintenanceCategoryModel;
use app\store\model\User as StoreUserModel;
11 months ago
use cores\exception\BaseException;
9 months ago
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
10 months ago
use think\response\Json;
10 months ago
11 months ago
/**
* 用户管理
* Class User
* @package app\api\controller
*/
class User extends Controller
{
9 months ago
/**
* 注销账号
* [delete description]
* @return [type] [description]
*/
9 months ago
public function delete()
{
9 months ago
$user_id = UserService::getCurrentLoginUserId();
9 months ago
UserModel::where('user_id', $user_id)->update(['is_delete' => 1, 'update_time' => time()]);
9 months ago
}
9 months ago
11 months ago
/**
* 当前用户详情
* @return Json
* @throws BaseException
*/
public function info(): Json
{
// 当前用户信息
$userInfo = UserService::getCurrentLoginUser(true);
// 获取用户头像和会员等级
$userInfo = UserModel::related($userInfo, ['avatar', 'grade']);
10 months ago
//获取提现次数
10 months ago
$userInfo['finace_count'] = BalanceLog::where(['user_id' => $userInfo->user_id, 'scene' => 50])->count() ?? 0;
10 months ago
//获取用户收入
$userInfo['income'] = BalanceLog::where(['user_id' => $userInfo->user_id])
10 months ago
->whereIn('scene', [10, 30, 40, 60])
->where('money', '>', 0)
->sum('money') ?? 0;
10 months ago
11 months ago
return $this->renderSuccess(compact('userInfo'));
}
10 months ago
/**
* @notes:编辑用户信息
* @return Json|void
* @throws BaseException
* @author: wanghousheng
*/
public function editUser()
{
$userId = UserService::getCurrentLoginUserId();
$data = [];
$avatar_id = intval($this->request->post('avatar_id'));
if ($avatar_id) {
$data['avatar_id'] = $avatar_id;
}
$nick_name = $this->request->post('nick_name');
if ($nick_name) {
$data['nick_name'] = $nick_name;
}
$gender = intval($this->request->post('gender'));
if ($gender) {
$data['gender'] = $gender;
}
if ($data) {
$model = new UserModel();
$model->where(['user_id' => $userId])->save($data);
return $this->renderSuccess('操作成功');
}
$this->renderError('操作失败');
}
11 months ago
/**
* 账户资产
* @return Json
* @throws BaseException
*/
public function assets(): Json
{
// 当前用户信息
$userInfo = UserService::getCurrentLoginUser(true);
// 用户优惠券模型
$model = new UserCouponModel;
// 返回数据
return $this->renderSuccess([
'assets' => [
'balance' => $userInfo['balance'], // 账户余额
'points' => $userInfo['points'], // 会员积分
'coupon' => $model->getCount($userInfo['user_id']), // 优惠券数量(可用)
]
]);
}
/**
* 手机号绑定
* @return Json
* @throws BaseException
*/
public function bindMobile(): Json
{
$model = new UserModel;
if (!$model->bindMobile($this->postForm())) {
return $this->renderSuccess($model->getError() ?: '操作失败');
}
return $this->renderSuccess('恭喜您,手机号绑定成功');
}
/**
* 修改个人信息(头像昵称)
* @return Json
* @throws BaseException
*/
public function personal(): Json
{
$model = new UserModel;
if (!$model->personal($this->postForm())) {
return $this->renderSuccess($model->getError() ?: '操作失败');
}
return $this->renderSuccess('恭喜您,信息修改成功');
}
10 months ago
/**
* 提交反馈
*/
public function addFeedback(): Json
{
// 当前用户信息
$userInfo = UserService::getCurrentLoginUser(true);
$params = $this->request->param();
10 months ago
if (empty($params['content']) || (empty($params['shop_id']) && $params['object_type'] != 1) || empty($params['type'])) {
10 months ago
return $this->renderError('请补全信息');
}
$userData = [
'user_id' => $userInfo->user_id,
'user_name' => $params['user_name'] ?? $userInfo->nick_name,
9 months ago
'mobile' => $params['mobile'] ? hide_mobile($params['mobile']) : $userInfo->mobile,
10 months ago
];
$service = new Feedback();
$res = $service->addFeedback($params, $userData);
if ($res) {
return $this->renderSuccess('提交成功,请耐心等待');
} else {
return $this->renderError('提交失败');
}
}
//获取反馈列表
public function getFeedBack(): Json
{
$params = $this->request->param();
// 当前用户信息
if (!empty($params['is_my'])) {
$userInfo = UserService::getCurrentLoginUser(true);
$params['user_id'] = $userInfo->user_id;
}
$service = new Feedback();
$list = $service->getFeedback($params);
return $this->renderSuccess(compact('list'));
}
10 months ago
//我要货源
public function addGoodsSource(): Json
{
$model = new GoodsSourceModel();
10 months ago
if (!$model->addSource($this->request->param())) {
10 months ago
return $this->renderSuccess($model->getError() ?: '操作失败');
}
return $this->renderSuccess('提交成功,请耐心等待');
}
10 months ago
//发票抬头列表
public function myInvoicing(): Json
{
$service = new UserInvoice();
$list = $service->getList($this->request->param());
return $this->renderSuccess(compact('list'));
}
//发票抬头添加
public function addInvoicing(): Json
{
$service = new UserInvoice();
if (!$service->add($this->request->param())) {
return $this->renderSuccess($service->getError() ?: '操作失败');
}
10 months ago
return $this->renderSuccess('添加成功');
}
//发票抬头编辑
10 months ago
public function editInvoicing(): Json
{
$service = new UserInvoice();
if (!$service->edit($this->request->param())) {
return $this->renderSuccess($service->getError() ?: '操作失败');
}
10 months ago
return $this->renderSuccess('修改成功');
}
9 months ago
//发票抬头删除
public function delInvoicing(): Json
{
$service = new UserInvoice();
9 months ago
if (!$service->del($this->request->param())) {
9 months ago
return $this->renderSuccess($service->getError() ?: '操作失败');
}
return $this->renderSuccess('删除成功·');
}
10 months ago
//开票记录
public function invoicingLog(): Json
{
$service = new InvoiceOrder();
$list = $service->getList($this->request->param());
return $this->renderSuccess(compact('list'));
}
10 months ago
//开票记录
public function invoicingDetail(): Json
{
$service = new InvoiceOrder();
$data = $service->getDetail($this->request->param('id'));
return $this->renderSuccess(compact('data'));
}
//订单开票
public function invoicingAdd(): Json
{
$service = new InvoiceOrder();
if (!$service->invoicingAdd($this->request->param())) {
return $this->renderSuccess($service->getError() ?: '操作失败');
}
return $this->renderSuccess('提交成功,请耐心等待');
}
//订单开票
public function invoicingEdit(): Json
{
$service = new InvoiceOrder();
if (!$service->invoicingEdit($this->request->param())) {
return $this->renderSuccess($service->getError() ?: '操作失败');
}
return $this->renderSuccess('提交成功,请耐心等待');
}
/**
* 个人中心协议
*/
9 months ago
public function getAgreement(): Json
{
$params = $this->request->param();
if (empty($params['type'])) {
return $this->renderSuccess("参数错误");
}
$detail = AgreementModel::detail(['type' => $params['type']]);
return $this->renderSuccess(compact('detail'), 'success');
}
/**
* 添加用户浏览记录
*/
9 months ago
public function addView(): Json
{
$goods_id = $this->request->param('goods_id');
$user_id = UserService::getCurrentLoginUserId();
$userView = new UserCoupon();
if ($userView->add(['user_id' => $user_id, 'goods_id' => $goods_id, 'store_id' => $this->storeId])) {
return $this->renderSuccess('记录成功');
}
return $this->renderSuccess($userView->getError() ?: '记录失败');
}
9 months ago
/**
* @notes:邀请好友海报
* @return Json
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function InviteUserPoster(): Json
{
$userInfo = UserService::getCurrentLoginUser(true);
8 months ago
$type = intval($this->request->post('type'), 1);
9 months ago
// 生成二维码
8 months ago
$Qrcode = new InviteUser($userInfo, 'MP-WEIXIN', $type);
return $this->renderSuccess(['imageUrl' => $Qrcode->getImage()]);
9 months ago
}
10 months ago
9 months ago
/**
* 用户列表
* @return Json
* @throws \think\db\exception\DbException
*/
public function list(): Json
{
// 用户列表
$model = new StoreUserModel;
$list = $model->getList($this->request->param());
9 months ago
if (!$list) {
return $this->renderSuccess(compact('list'));
}
$list = $list->toArray();
// echo "<pre>";
// print_r($list);
// exit();
foreach ($list['data'] as $key => &$value) {
$log = InviteLog::where('invitee_user_id', $value['user_id'])->find();
$user = UserModel::where('user_id', $log['user_id'] ?? 0)->field('user_id,nick_name,mobile')->find();
$value['inviter'] = $user;
9 months ago
$value['order_num'] = 0;
if ($value['user_type'] == 10 || $value['user_type'] == 20) {
$value['order_num'] = OrderModel::where('user_id', $value['user_id'])->count();
} elseif ($value['user_type'] == 30) {
$value['order_num'] = DealerOrderModel::where('first_user_id|second_user_id|third_user_id', '=', $value['user_id'])->count();
}
10 months ago
9 months ago
}
10 months ago
9 months ago
return $this->renderSuccess(compact('list'));
}
10 months ago
9 months ago
public function updateUser(): Json
{
$params = $this->request->param();
$user_id = $params['user_id'] ?? 0;
unset($params['user_id']);
UserModel::where('user_id', $user_id)->update($params);
return $this->renderSuccess('ok');
}
10 months ago
9 months ago
/**
* 生成会员码
* [getMembershipInviteQrcode description]
* @return [type] [description]
*/
10 months ago
public function getMembershipInviteQrcode()
{
9 months ago
$user_id = $userInfo = UserService::getCurrentLoginUserId(true);
$obj = new \app\common\service\qrcode\BaseQRcode();
// 小程序码参数
$scene = "refereeId:" . $user_id;
$storeId = request()->header()['storeid'];
// 下载小程序码
$page = 'pages/login/index';
$qrcode = $obj->getQrcode((int)$storeId, $scene, $page, 'MP-WEIXIN');
10 months ago
return $this->renderSuccess(str_replace(root_path() . "public/", base_url(), $qrcode));
9 months ago
}
10 months ago
9 months ago
/**
* 生成分销商码
* [getDealerInviteQrcode description]
* @return [type] [description]
*/
10 months ago
public function getDealerInviteQrcode()
{
9 months ago
$storeId = request()->header()['storeid'];
$user_id = $userInfo = UserService::getCurrentLoginUserId(true);
$obj = new \app\common\service\qrcode\BaseQRcode();
$scene = 'uid:' . $user_id;
$qrcode = $obj->getQrcode((int)$storeId, $scene, null, 'MP-WEIXIN');
10 months ago
return $this->renderSuccess(str_replace(root_path() . "public/", base_url(), $qrcode));
9 months ago
}
9 months ago
8 months ago
/**
* @throws ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
*/
10 months ago
public function maintenance()
9 months ago
{
10 months ago
$storeId = request()->header()['storeid'];
8 months ago
$model = new MaintenanceCategoryModel;
$list = $model->getList(['store_id' => $storeId])->toArray();
9 months ago
9 months ago
return $this->renderSuccess($list);
}
11 months ago
}