451 lines
16 KiB
PHP
Executable File
451 lines
16 KiB
PHP
Executable File
<?php
|
|
namespace app\api\controller;
|
|
|
|
use app\common\basics\Api;
|
|
use app\api\logic\UserLogic;
|
|
use app\common\enum\NoticeEnum;
|
|
use app\common\server\JsonServer;
|
|
use app\api\validate\UpdateUserValidate;
|
|
use app\api\validate\SetWechatUserValidate;
|
|
use app\api\validate\WechatMobileValidate;
|
|
use app\api\validate\ChangeMobileValidate;
|
|
use app\common\server\WeChatServer;
|
|
use think\exception\ValidateException;
|
|
use app\common\server\UrlServer;
|
|
use think\facade\Db;
|
|
use Requests;
|
|
use think\facade\Request;
|
|
|
|
class User extends Api
|
|
{
|
|
/***
|
|
* 个人中心
|
|
*/
|
|
public function center()
|
|
{
|
|
$config = UserLogic::center($this->user_id);
|
|
return JsonServer::success('', $config);
|
|
}
|
|
|
|
/**
|
|
* 用户信息
|
|
*/
|
|
public function info()
|
|
{
|
|
return JsonServer::success('', UserLogic::getUserInfo($this->user_id));
|
|
}
|
|
|
|
/**
|
|
* Notes:设置用户信息
|
|
*/
|
|
public function setInfo()
|
|
{
|
|
try{
|
|
$post = $this->request->post();
|
|
$post['user_id'] = $this->user_id;
|
|
validate(UpdateUserValidate::class)->scene('set')->check($post);
|
|
}catch(ValidateException $e) {
|
|
return JsonServer::error($e->getError());
|
|
}
|
|
|
|
if ($post['ugc']) {
|
|
$config = WeChatServer::getMnpConfig();
|
|
$appid = $config['app_id'];
|
|
$secret = $config['secret'];
|
|
$result = Requests::get('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret);
|
|
$response = json_decode($result->body, true);
|
|
if (!empty($response['errcode'])) {
|
|
return JsonServer::error('信息获取错误');
|
|
} else {
|
|
$userAuth = Db::name('user_auth')->where('user_id', $this->user_id)->find();
|
|
if($userAuth) {
|
|
$data = [
|
|
'content' => $post['value'],
|
|
'version' => 2,
|
|
'scene' => 1,
|
|
'openid' => $userAuth['openid']
|
|
];
|
|
|
|
$url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=' . $response['access_token']; // 目标URL
|
|
$data_json = json_encode($data, JSON_UNESCAPED_UNICODE); // 将数据编码为JSON
|
|
|
|
$ch = curl_init($url); // 初始化cURL会话
|
|
curl_setopt($ch, CURLOPT_POST, true); // 设置为POST请求
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json); // 设置POST数据
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); // 设置头部信息
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 将响应作为字符串返回
|
|
|
|
$response = curl_exec($ch); // 执行cURL请求
|
|
curl_close($ch); // 关闭cURL会话
|
|
|
|
$res = json_decode($response, true);
|
|
if (!empty($res['errcode'])) {
|
|
return JsonServer::error('信息获取错误');
|
|
} else if ($res['result']['label'] != 100) {
|
|
return JsonServer::error('您的昵称含有非法字符,请重新设置');
|
|
}
|
|
} else {
|
|
return JsonServer::error('暂无授权信息');
|
|
}
|
|
}
|
|
}
|
|
|
|
$result = UserLogic::setUserInfo($post);
|
|
if($result === true) {
|
|
return JsonServer::success('设置成功');
|
|
}
|
|
return JsonServer::error(UserLogic::getError());
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 财户流水
|
|
*/
|
|
public function accountLog(){
|
|
// 来源类型 1-余额 2-积分 3-成长值
|
|
$source = $this->request->get('source', '');
|
|
if(empty($source)) {
|
|
return JsonServer::error('请传入来源类型');
|
|
}
|
|
// 变动类型
|
|
$type = $this->request->get('type');
|
|
$data = UserLogic::accountLog($this->user_id, $source,$type, $this->page_no, $this->page_size);
|
|
return JsonServer::success('', $data);
|
|
}
|
|
|
|
/***
|
|
* 会员中心 - 会员等级
|
|
*/
|
|
public function getUserLevelInfo() {
|
|
$data = UserLogic::getUserLevelInfo($this->user_id);
|
|
return JsonServer::success('', $data);
|
|
}
|
|
|
|
/**
|
|
* 成长值记录
|
|
*/
|
|
public function getGrowthList()
|
|
{
|
|
$get = $this->request->get();
|
|
$get['page_no'] = $this->page_no;
|
|
$get['page_size'] = $this->page_size;
|
|
$get['user_id'] = $this->user_id;
|
|
$data = UserLogic::getGrowthList($get);
|
|
return JsonServer::success('', $data);
|
|
}
|
|
|
|
/**
|
|
* 我的钱包
|
|
*/
|
|
public function myWallet(){
|
|
$result = UserLogic::myWallet($this->user_id);
|
|
if($result === false) {
|
|
return JsonServer::error(UserLogic::getError());
|
|
}
|
|
return JsonServer::success('获取成功', $result);
|
|
}
|
|
|
|
/**
|
|
* Notes: 更新微信的用户信息
|
|
*/
|
|
public function setWechatInfo()
|
|
{
|
|
$data = $this->request->post();
|
|
try{
|
|
validate(SetWechatUserValidate::class)->check($data);
|
|
}catch(ValidateException $e) {
|
|
return JsonServer::error($e->getError());
|
|
}
|
|
$result = UserLogic::updateWechatInfo($this->user_id, $data);
|
|
if($result === true) {
|
|
return JsonServer::success('更新成功');
|
|
}
|
|
return JsonServer::error(UserLogic::getError());
|
|
}
|
|
|
|
//获取微信手机号
|
|
public function getMobile()
|
|
{
|
|
try{
|
|
$post = $this->request->post();
|
|
$post['user_id'] = $this->user_id;
|
|
validate(WechatMobileValidate::class)->check($post);
|
|
}catch(ValidateException $e) {
|
|
return JsonServer::error($e->getError());
|
|
}
|
|
$result = UserLogic::getMobileByMnp($post);
|
|
if($result === false) {
|
|
return JsonServer::error(UserLogic::getError());
|
|
}
|
|
return JsonServer::success('操作成功', [],1,1);
|
|
}
|
|
// checkReal
|
|
public function checkRealUser(){
|
|
$user_id = $this->user_id;
|
|
$result = UserLogic::checkRealUserMsg($user_id);
|
|
if($result){
|
|
$data['check'] = 1;
|
|
return JsonServer::success("验证通过",$data);
|
|
}else{
|
|
$data['check'] = 0;
|
|
return JsonServer::success("需要实名认证",$data);
|
|
}
|
|
}
|
|
|
|
public function updateRealUser(){
|
|
$user_id = $this->user_id;
|
|
$post = $this->request->post();
|
|
$result = UserLogic::updateRealUserMsg($user_id,$post);
|
|
if($result){
|
|
if($result === -1){
|
|
return JsonServer::error("身份证号码已被实名");
|
|
}
|
|
return JsonServer::success("保存成功");
|
|
}else{
|
|
return JsonServer::error("保存失败");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Notes: 更换手机号 / 绑定手机号
|
|
* @author 段誉(2021/6/23)
|
|
* @return \think\response\Json
|
|
*/
|
|
public function changeMobile()
|
|
{
|
|
$data = $this->request->post();
|
|
$data['client'] = $this->client;
|
|
$data['user_id'] = $this->user_id;
|
|
if(isset($data['action']) && 'change' == $data['action']) {
|
|
//变更手机号码
|
|
$data['message_key'] = NoticeEnum::CHANGE_MOBILE_NOTICE;
|
|
(new ChangeMobileValidate())->goCheck('', $data);
|
|
} else {
|
|
//绑定手机号码
|
|
$data['message_key'] = NoticeEnum::BIND_MOBILE_NOTICE;
|
|
(new ChangeMobileValidate())->goCheck('binding', $data);
|
|
}
|
|
$result = UserLogic::changeMobile($this->user_id, $data);
|
|
if(false === $result) {
|
|
return JsonServer::error(UserLogic::getError());
|
|
}
|
|
if(is_object($result)){
|
|
$result = $result->toArray();
|
|
}
|
|
return JsonServer::success('操作成功',$result);
|
|
}
|
|
|
|
//我的粉丝
|
|
public function fans()
|
|
{
|
|
$get = $this->request->get();
|
|
$page = $this->request->get('page_no', $this->page_no);
|
|
$size = $this->request->get('page_size', $this->page_size);
|
|
return JsonServer::success('', UserLogic::fans($this->user_id, $get, $page, $size));
|
|
}
|
|
|
|
//我的推荐店铺(废弃)
|
|
public function shops()
|
|
{
|
|
$get = $this->request->get();
|
|
$page = $this->request->get('page_no', $this->page_no);
|
|
$size = $this->request->get('page_size', $this->page_size);
|
|
$user_id = $this->user_id;
|
|
$where[] = ['u.reference_user_id', '=', $user_id];
|
|
if (isset($get['keyword']) && $get['keyword'] != ''){
|
|
$where[] = ['u.name','like','%'.$get['keyword'].'%'];
|
|
}
|
|
|
|
//查询条件
|
|
|
|
$field = 'u.logo as avatar,u.name as nickname, u.mobile, u.create_time, d.order_num as fans_order,
|
|
d.order_amount as fans_money, d.fans as fans_team';
|
|
|
|
$count = \app\common\model\shop\Shop::alias('u')
|
|
->field($field)
|
|
->leftJoin('user_shop_distribution d', 'd.shop_id = u.id')
|
|
->where($where)
|
|
->count();
|
|
|
|
$lists = \app\common\model\shop\Shop::alias('u')
|
|
->field($field)
|
|
->leftJoin('user_shop_distribution d', 'd.shop_id = u.id')
|
|
->where($where)
|
|
->page($page, $size)
|
|
->select();
|
|
|
|
foreach ($lists as &$item) {
|
|
$item['avatar'] = UrlServer::getFileUrl($item['avatar']);
|
|
$item['fans_team'] = $item['fans_team'] ?? 0;
|
|
$item['fans_order'] = $item['fans_order'] ?? 0;
|
|
$item['fans_money'] = $item['fans_money'] ?? 0;
|
|
unset($item['fans'], $item['distribution_order_num'], $item['distribution_money']);
|
|
}
|
|
|
|
$data = [
|
|
'list' => $lists,
|
|
'page' => $page,
|
|
'size' => $size,
|
|
'count' => $count,
|
|
'more' => is_more($count, $page, $size)
|
|
];
|
|
return JsonServer::success('', $data);
|
|
}
|
|
|
|
public function newShops()
|
|
{
|
|
$page = $this->request->get('page_no', $this->page_no);
|
|
$size = $this->request->get('page_size', $this->page_size);
|
|
$type = $this->request->get('type');
|
|
$user_id = $this->user_id;
|
|
$pa = $page-1;
|
|
$p = $pa*$size;
|
|
//查询条件
|
|
if($type == 1){
|
|
$sql = "SELECT * FROM ls_user a,ls_shop b WHERE a.id = b.reference_user_id and
|
|
a.id = $user_id and a.disable = 0 and a.del = 0 and b.del=0
|
|
limit ".$p.",".$size;
|
|
// var_dump($sql);
|
|
$lists = Db::query($sql);
|
|
// $sql = "SELECT count(*) as cont FROM ls_user a,ls_shop_apply b WHERE a.id = b.user_id and
|
|
// a.first_leader = '.$user_id.' and a.disable = 0 and a.del = 0 and b.del=0
|
|
// and b.audit_status = 2 group by a.first_leader";
|
|
$count = $qy_count = Db::name("shop_apply")
|
|
->alias("a")
|
|
->join("user b","a.user_id = b.id","left")
|
|
->where("b.id",$user_id)
|
|
->where("b.disable",0)
|
|
->where("b.del",0)
|
|
->where("a.del",0)
|
|
->count();
|
|
// $count = Db::query($sql);
|
|
// $count = $count[0]['cont'];
|
|
$local_count = Db::name("local_store")
|
|
->alias("a")
|
|
->join("user b","a.user_id = b.id","left")
|
|
->where("b.id",$user_id)
|
|
->where("b.disable",0)
|
|
->where("b.del",0)
|
|
->where("a.is_delete",0)
|
|
->where("a.store_state",1)
|
|
->count();
|
|
}else{
|
|
$sql = "SELECT * FROM ls_user a,ls_local_store b WHERE a.id = b.user_id and
|
|
a.id = $user_id and a.disable = 0 and a.del = 0 and b.is_delete=0
|
|
and b.store_state = 1 limit ".$p.",".$size;
|
|
$lists = Db::query($sql);
|
|
// $sql = "SELECT count(*) as cont FROM ls_user a,ls_local_store b WHERE a.id = b.user_id and
|
|
// a.first_leader = '.$user_id.' and a.disable = 0 and a.del = 0 and b.is_delete=0
|
|
// and b.store_state = 1 group by a.first_leader";
|
|
// $count = Db::query($sql);
|
|
// $count = $count[0]['cont'];
|
|
$count = $local_count = Db::name("local_store")
|
|
->alias("a")
|
|
->join("user b","a.user_id = b.id","left")
|
|
->where("b.id",$user_id)
|
|
->where("b.disable",0)
|
|
->where("b.del",0)
|
|
->where("a.is_delete",0)
|
|
->where("a.store_state",1)
|
|
->count();
|
|
$qy_count = Db::name("shop_apply")
|
|
->alias("a")
|
|
->join("user b","a.user_id = b.id","left")
|
|
->where("b.id",$user_id)
|
|
->where("b.disable",0)
|
|
->where("b.del",0)
|
|
->where("a.del",0)
|
|
->where("a.audit_status",2)
|
|
->count();
|
|
}
|
|
foreach($lists as $key=>$value){
|
|
if ($value['avatar']) {
|
|
$lists[$key]['avatar'] = UrlServer::getFileUrl($value['avatar']);
|
|
}
|
|
}
|
|
$data = [
|
|
'list' => $lists,
|
|
'page' => $page,
|
|
'size' => $size,
|
|
'qy_count' => $qy_count,
|
|
'local_count' => $local_count,
|
|
'count'=>$count,
|
|
'more' => is_more($count, $page, $size)
|
|
];
|
|
return JsonServer::success('', $data);
|
|
}
|
|
// 推广店铺收益明细
|
|
public function shopDetails(){
|
|
$page = $this->request->get('page_no', $this->page_no);
|
|
$size = $this->request->get('page_size', $this->page_size);
|
|
$type = $this->request->get('type');
|
|
$shop_id = $this->request->get('shop_id');
|
|
$start_time = $this->request->get('start_time',date("Y-m-d 00:00:00"));
|
|
$end_time = $this->request->get('end_time',date("Y-m-d 23:59:59"));
|
|
$start_time = strtotime($start_time);
|
|
$end_time = strtotime($end_time);
|
|
$pa = $page-1;
|
|
$p = $pa*$size;
|
|
if($type == 1){
|
|
|
|
}else{
|
|
$all_total = Db::name("account_log")
|
|
->where("source_type",409)
|
|
->where("change_type",1)
|
|
->where("shop_id",$shop_id)
|
|
->sum("change_amount");
|
|
$day_total = Db::name("account_log")
|
|
->where([['create_time', 'between', [$start_time, $end_time]]])
|
|
->where("source_type",409)
|
|
->where("change_type",1)
|
|
->where("shop_id",$shop_id)
|
|
->sum("change_amount");
|
|
$sql = "SELECT *,DATE_FORMAT(FROM_UNIXTIME(create_time), '%Y-%m-%d %H:%i:%s') AS dtime FROM ls_account_log WHERE source_type = 409 and
|
|
change_type = 1 and shop_id = ".$shop_id." and create_time between
|
|
$start_time and $end_time
|
|
limit ".$p.",".$size;
|
|
$lists = Db::query($sql);
|
|
$count = Db::name("account_log")
|
|
->where("source_type",409)
|
|
->where("change_type",1)
|
|
->where("shop_id",$shop_id)
|
|
->where([['create_time', 'between', [$start_time, $end_time]]])
|
|
->count();
|
|
$data = [
|
|
'list' => $lists,
|
|
'page' => $page,
|
|
'size' => $size,
|
|
'all_total' => $all_total,
|
|
'day_total' => $day_total,
|
|
'count'=>$count,
|
|
'more' => is_more($count, $page, $size)
|
|
];
|
|
return JsonServer::success('', $data);
|
|
}
|
|
}
|
|
/**
|
|
* @notes 用户聊天记录
|
|
* @return \think\response\Json
|
|
* @author 段誉
|
|
* @date 2021/12/20 11:29
|
|
*/
|
|
public function chatRecord()
|
|
{
|
|
$shop_id = $this->request->get('shop_id/d', 0);
|
|
$result = UserLogic::getChatRecord($this->user_id, $shop_id, $this->page_no, $this->page_size);
|
|
return JsonServer::success('', $result);
|
|
}
|
|
|
|
// 校验支付密码
|
|
public function checkPayPassword()
|
|
{
|
|
$post = $this->request->post();
|
|
$result = UserLogic::checkPayPassword($post, $this->user_id);
|
|
if ($result) {
|
|
return JsonServer::success('密码正确');
|
|
}
|
|
|
|
return JsonServer::error('密码错误');
|
|
}
|
|
} |