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.
334 lines
11 KiB
334 lines
11 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author: CRMEB Team <admin@crmeb.com>
|
|
// +----------------------------------------------------------------------
|
|
namespace app\controller\api\v1\user;
|
|
|
|
use app\Request;
|
|
use app\services\product\product\StoreProductLogServices;
|
|
use app\services\user\UserServices;
|
|
use app\services\wechat\WechatUserServices;
|
|
|
|
|
|
/**
|
|
* 用户类
|
|
* Class User
|
|
* @package app\controller\api\store
|
|
*/
|
|
class User
|
|
{
|
|
protected $services = NUll;
|
|
|
|
/**
|
|
* User constructor.
|
|
* @param UserServices $services
|
|
*/
|
|
public function __construct(UserServices $services)
|
|
{
|
|
$this->services = $services;
|
|
}
|
|
|
|
/**
|
|
* 获取用户信息
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function userInfo(Request $request)
|
|
{
|
|
$info = $request->user()->toArray();
|
|
return app('json')->success($this->services->userInfo($info));
|
|
}
|
|
|
|
/**
|
|
* 用户资金统计
|
|
* @param Request $request
|
|
* @return mixed
|
|
* @throws \think\Exception
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function balance(Request $request)
|
|
{
|
|
$uid = (int)$request->uid();
|
|
return app('json')->successful($this->services->balance($uid));
|
|
}
|
|
|
|
/**
|
|
* 个人中心
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function user(Request $request)
|
|
{
|
|
$user = $request->user()->toArray();
|
|
return app('json')->success($this->services->personalHome($user, $request->tokenData()));
|
|
}
|
|
public function bindshangji(Request $request)
|
|
{
|
|
[$phone] = $request->postMore([
|
|
['phone', 0]
|
|
], true);
|
|
if(empty($phone)){
|
|
return app('json')->fail('请输入推广人手机号');
|
|
}
|
|
//根据手机号查询用户信息
|
|
$spreadUid = $this->services->getColumn(['phone'=>$phone]);
|
|
if(empty($spreadUid)) return app('json')->fail('请输入正确的推广人手机号');
|
|
$spuid = $spreadUid[0]['uid'];
|
|
$uid = (int)$request->uid();
|
|
if($spuid == $uid) return app('json')->fail('不能绑定自己');
|
|
if($this->services->spread($uid, (int)$spuid, '')) return app('json')->success('绑定成功');
|
|
return app('json')->fail('绑定失败');
|
|
}
|
|
|
|
/**
|
|
* 获取活动状态
|
|
* @return mixed
|
|
*/
|
|
public function activity()
|
|
{
|
|
return app('json')->successful($this->services->activity());
|
|
}
|
|
|
|
/**
|
|
* 用户修改信息
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function edit(Request $request)
|
|
{
|
|
[$avatar, $nickname, $extend_info] = $request->postMore([
|
|
['avatar', ''],
|
|
['nickname', ''],
|
|
['extend_info', []]
|
|
], true);
|
|
if (!$avatar && $nickname == '') {
|
|
return app('json')->fail('请输入昵称或者选择头像');
|
|
}
|
|
$uid = (int)$request->uid();
|
|
$this->services->saveExtendForm($uid, $extend_info, ['avatar' => $avatar, 'nickname' => $nickname], true);
|
|
return app('json')->success('修改成功');
|
|
}
|
|
|
|
/**
|
|
* 推广人排行
|
|
* @param Request $request
|
|
* @return mixed
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function rank(Request $request)
|
|
{
|
|
$data = $request->getMore([
|
|
['page', ''],
|
|
['limit', ''],
|
|
['type', '']
|
|
]);
|
|
$data['uid'] = $request->uid();
|
|
$info = $this->services->getRankList($data);
|
|
$info['avatar'] = $request->user()['avatar'];
|
|
$info['nickname'] = $request->user()['nickname'];
|
|
$info['uid'] = $request->uid();
|
|
return app('json')->success($info);
|
|
}
|
|
|
|
/**
|
|
* 添加访问记录
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function set_visit(Request $request)
|
|
{
|
|
$data = $request->postMore([
|
|
['url', ''],
|
|
['stay_time', 0]
|
|
]);
|
|
if ($data['url'] == '') return app('json')->fail('未获取页面路径');
|
|
$data['uid'] = (int)$request->uid();
|
|
$data['ip'] = $request->ip();
|
|
if ($this->services->setVisit($data)) {
|
|
return app('json')->success('添加访问记录成功');
|
|
} else {
|
|
return app('json')->fail('添加访问记录失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 静默绑定推广人
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function spread(Request $request)
|
|
{
|
|
[$spreadUid, $code] = $request->postMore([
|
|
['puid', 0],
|
|
['code', 0]
|
|
], true);
|
|
$uid = (int)$request->uid();
|
|
$this->services->spread($uid, (int)$spreadUid, $code);
|
|
return app('json')->success();
|
|
}
|
|
|
|
/**
|
|
* 推荐用户
|
|
* @param Request $request
|
|
* @return mixed
|
|
*
|
|
* grade == 0 获取一级推荐人
|
|
* grade == 1 获取二级推荐人
|
|
*
|
|
* keyword 会员名称查询
|
|
*
|
|
* sort childCount ASC/DESC 团队排序 numberCount ASC/DESC 金额排序 orderCount ASC/DESC 订单排序
|
|
*/
|
|
public function spread_people(Request $request)
|
|
{
|
|
$spreadInfo = $request->postMore([
|
|
['grade', 0],
|
|
['keyword', ''],
|
|
['sort', ''],
|
|
['start', 0],
|
|
['stop', 0],
|
|
]);
|
|
if (!in_array($spreadInfo['grade'], [0, 1])) {
|
|
return app('json')->fail('等级错误');
|
|
}
|
|
$spreadInfo['time'] = [$spreadInfo['start'], $spreadInfo['stop']];
|
|
$uid = $request->uid();
|
|
return app('json')->successful($this->services->getUserSpreadGrade($uid, $spreadInfo['grade'], $spreadInfo['sort'], $spreadInfo['keyword'], $spreadInfo['time']));
|
|
}
|
|
|
|
/**
|
|
* 是否关注
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function subscribe(Request $request)
|
|
{
|
|
if ($request->uid()) {
|
|
/** @var WechatUserServices $wechatUserService */
|
|
$wechatUserService = app()->make(WechatUserServices::class);
|
|
$subscribe = (bool)$wechatUserService->value(['uid' => $request->uid()], 'subscribe');
|
|
return app('json')->success(['subscribe' => $subscribe]);
|
|
} else {
|
|
return app('json')->success(['subscribe' => true]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户付款code
|
|
* @param Request $request
|
|
* @return mixed
|
|
*/
|
|
public function randCode(Request $request)
|
|
{
|
|
$uid = (int)$request->uid();
|
|
$code = $this->services->getRandCode((int)$uid);
|
|
return app('json')->success(['code' => $code]);
|
|
}
|
|
|
|
/**
|
|
* 商品浏览记录
|
|
* @param Request $request
|
|
* @param StoreProductLogServices $services
|
|
* @return mixed
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function visitList(Request $request, StoreProductLogServices $services)
|
|
{
|
|
$where['uid'] = (int)$request->uid();
|
|
$where['type'] = 'visit';
|
|
$result = $services->getList($where, 'product_id', 'id,product_id,max(add_time) as add_time');
|
|
$time_data = [];
|
|
if ($result['list']) {
|
|
foreach ($result['list'] as $key => &$item) {
|
|
$add_time = strtotime($item['add_time']);
|
|
if (date('Y') == date('Y', $add_time)) {//今年
|
|
$item['time_key'] = date('m月d日', $add_time);
|
|
} else {
|
|
$item['time_key'] = date('Y年m月d日', $add_time);
|
|
}
|
|
}
|
|
$time_data = array_merge(array_unique(array_column($result['list'], 'time_key')));
|
|
}
|
|
$result['time'] = $time_data;
|
|
return app('json')->success($result);
|
|
}
|
|
|
|
/**
|
|
* 商品浏览记录删除
|
|
* @param Request $request
|
|
* @param StoreProductLogServices $services
|
|
* @return mixed
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function visitDelete(Request $request, StoreProductLogServices $services)
|
|
{
|
|
$uid = (int)$request->uid();
|
|
[$ids] = $request->postMore([
|
|
['ids', []],
|
|
], true);
|
|
if ($ids) {
|
|
$where = ['uid' => $uid, 'product_id' => $ids];
|
|
$services->destroy($where);
|
|
}
|
|
return app('json')->success('删除成功');
|
|
}
|
|
/**
|
|
* 用户兑换积分
|
|
* @param Request $request
|
|
* @param $uid
|
|
* @return Response
|
|
*/
|
|
public function updatejifenduiyue(Request $request)
|
|
{
|
|
//获取用户信息
|
|
$data = $request->postMore([
|
|
['status', 0],
|
|
['number', 0],
|
|
['type', 2]//1余额 2积分
|
|
]);
|
|
$integral = sys_config('int_bili');
|
|
$uid = (int)$request->uid();
|
|
//查询用户信息
|
|
$userInfo = $this->services->getUserInfo($uid);
|
|
//判断余额是否满足兑换条件
|
|
if($data['number']>$userInfo['integral']) return app('json')->make(410010,"积分不足");
|
|
if (!$uid) return app('json')->make(410010,'数据不存在');
|
|
//记录是否积分是否满足兑换条件
|
|
if($data['number']>100) app('json')->make(410010,"兑换积分不足100");
|
|
// 计算可以兑换的积分
|
|
if($data['number']%100!=0){
|
|
$data['number'] = $data['number']-($data['number']%100);
|
|
}else{
|
|
$data['number'] = $data['number'];
|
|
}
|
|
$data['is_other'] = true;
|
|
$this->services->transaction(function () use ($data, $uid,$integral) {
|
|
$res = true;
|
|
$money = [];
|
|
$money['money'] = (int)$data['number']/$integral;
|
|
$money['money_status'] = 1;
|
|
$money['integration'] = (int)$data['number'];
|
|
$money['integration_status'] = 2;
|
|
$money['is_other'] = true;
|
|
$res = $this->services->updateInfo($uid, $money);
|
|
if (!$res) {
|
|
throw new ValidateException('积分兑换失败');
|
|
}
|
|
});
|
|
return app('json')->success('积分兑换成功');
|
|
}
|
|
}
|
|
|