9
This commit is contained in:
@@ -8,6 +8,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 提现地址
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class AddressController extends BaseController{
|
||||
/**
|
||||
|
||||
@@ -56,13 +56,9 @@ class BaseController
|
||||
{
|
||||
return $this->json(1,$msg, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("上传")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
function upload(Request $request)
|
||||
protected function _upload($request)
|
||||
{
|
||||
|
||||
try{
|
||||
$user = \support\Jwt::getUser();
|
||||
}catch(\Exception $e){
|
||||
@@ -72,7 +68,7 @@ class BaseController
|
||||
$validate = Validate::rule('savePath', 'alphaNum');
|
||||
$data = ['savePath' => $savePath];
|
||||
if (!$validate->check($data)) {
|
||||
return $this->fail( '参数错误:'.$validate->getError());
|
||||
return '参数错误:'.$validate->getError();
|
||||
}
|
||||
$savePath = trim($savePath,'/');
|
||||
//$savePath = 'upload/'.$savePath.'/'.$user['id'];
|
||||
@@ -82,35 +78,43 @@ class BaseController
|
||||
$maxsize = Config('site.upload_maxsize')*1024*1024;
|
||||
//多文件上传
|
||||
$files = $request->file();
|
||||
try {
|
||||
$result = Storage::adapter('oss')
|
||||
->path($savePath)
|
||||
->size($maxsize)
|
||||
->extYes($mimetype)
|
||||
->uploads($files,0,$maxsize * count($files),false);
|
||||
$save_datas = [];
|
||||
foreach($result as $k=>$fileinfo){
|
||||
$save_datas[] = [
|
||||
'user_id' => $user['id'],
|
||||
'category' => 'default',
|
||||
'adapter' => $fileinfo->adapter,
|
||||
'origin_name' => $fileinfo->origin_name,
|
||||
'file_name' => $fileinfo->file_name,
|
||||
'size' => $fileinfo->size,
|
||||
'mime_type' => $fileinfo->mime_type,
|
||||
'extension' => $fileinfo->extension,
|
||||
'file_height' => $fileinfo->file_height,
|
||||
'file_width' => $fileinfo->file_width,
|
||||
'file_url' => $fileinfo->file_url,
|
||||
'sha1' => $fileinfo->storage_key ?:sha1_file(public_path($fileinfo->file_name)),
|
||||
'use_count' => 0,
|
||||
];
|
||||
}
|
||||
\app\model\Files::insertAll($save_datas);
|
||||
return $this->success(__('successful'),$result);
|
||||
}catch (\Exception $e){
|
||||
return $this->error($e->getMessage());
|
||||
$result = Storage::adapter('oss')
|
||||
->path($savePath)
|
||||
->size($maxsize)
|
||||
->extYes($mimetype)
|
||||
->uploads($files,0,$maxsize * count($files),false);
|
||||
$save_datas = [];
|
||||
foreach($result as $k=>$fileinfo){
|
||||
$save_datas[] = [
|
||||
'user_id' => $user['id'],
|
||||
'category' => 'default',
|
||||
'adapter' => $fileinfo->adapter,
|
||||
'origin_name' => $fileinfo->origin_name,
|
||||
'file_name' => $fileinfo->file_name,
|
||||
'size' => $fileinfo->size,
|
||||
'mime_type' => $fileinfo->mime_type,
|
||||
'extension' => $fileinfo->extension,
|
||||
'file_height' => $fileinfo->file_height,
|
||||
'file_width' => $fileinfo->file_width,
|
||||
'file_url' => $fileinfo->file_url,
|
||||
'sha1' => $fileinfo->storage_key ?:sha1_file(public_path($fileinfo->file_name)),
|
||||
'use_count' => 0,
|
||||
];
|
||||
}
|
||||
$res = \app\model\Files::saveAll($save_datas);
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("上传")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
function upload(Request $request,$return = false)
|
||||
{
|
||||
$res = $this->_upload($request);
|
||||
if(is_string($res)){
|
||||
return $this->fail( $res);
|
||||
}
|
||||
return $this->success(__('successful'),$res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 卡密模块
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class CardController extends BaseController{
|
||||
/**
|
||||
|
||||
@@ -46,7 +46,7 @@ class CommonController extends BaseController{
|
||||
'attachment_category','categorytype','cdkey_category','configgroup','flagtype',
|
||||
'languages','forbiddenip','fixedpage','admin_login_captcha',
|
||||
'upload_mimetype','upload_multipart','upload_multiple','upload_thumbstyle','upload_previewtpl','upload_timeout','upload_maxsize',
|
||||
'yeji_jicha_reward','suanli_rate','agent_expirs_retention','allow_currencys','allow_balance_log',
|
||||
'yeji_jicha_reward','suanli_rate','agent_expirs_retention','allow_currencys','allow_currency_logs',
|
||||
'agent_commission_total_rate','agent_commission_layer_rate','differential_commission_total_rate'
|
||||
];
|
||||
$config = array_diff_key($config, array_flip($disallowFields));
|
||||
@@ -153,7 +153,7 @@ class CommonController extends BaseController{
|
||||
'group_id' => 0,
|
||||
'region' => '86',
|
||||
'nickname' => input('nickname'),
|
||||
'avatar' => '/static/img/avatar.png',
|
||||
'avatar' => '/static/avatar/'.rand(0,17).'.png',
|
||||
];
|
||||
if ($invite_code) {
|
||||
if(strlen($invite_code) == 12){
|
||||
@@ -211,7 +211,7 @@ class CommonController extends BaseController{
|
||||
$mobile = input('mobile');
|
||||
$email = input('email');
|
||||
$password = input('password');
|
||||
$type = input(param: 'type');
|
||||
$type = input('type');
|
||||
if($type == 'mobile'){
|
||||
if (!$mobile ) {
|
||||
return $this->fail(__('Invalid username or password'));
|
||||
|
||||
@@ -34,26 +34,40 @@ class FriendCircleController extends BaseController{
|
||||
* @return void
|
||||
*/
|
||||
function info(Request $request): Response{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
$user_id = Input('user_id');
|
||||
if($user_id){
|
||||
$user_id = idDecode($user_id);
|
||||
$json= [
|
||||
'top_unread_items' =>[],
|
||||
'unread_item_ids' =>[],
|
||||
'unread_count' =>0,
|
||||
'settings' => Db::name('friend_circle_setting')->where('user_id',$user_id)->order('id','desc')->findOrEmpty()
|
||||
];
|
||||
return $this->success('ok',$json);
|
||||
}else{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
$user_id = $user->id;
|
||||
$res = $this->newcount($request);
|
||||
$response = $res->rawBody();
|
||||
$json = json_decode($response,true);
|
||||
$json['data']['settings'] = Db::name('friend_circle_setting')->where('user_id',$user_id)->order('id','desc')->findOrEmpty();
|
||||
// [
|
||||
// 'bg' => '',
|
||||
// ];
|
||||
$top_unread_items = FriendCircleModel::whereIn('id',$json['data']['unread_item_ids'])
|
||||
->with(['user' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}])
|
||||
->order('id', 'desc')
|
||||
->limit(0,3)
|
||||
->select();
|
||||
$json['data']['top_unread_items'] = $top_unread_items ?: [];
|
||||
$res->withBody(json_encode($json));
|
||||
return $res;
|
||||
}
|
||||
$res = $this->newcount($request);
|
||||
$response = $res->rawBody();
|
||||
$json = json_decode($response,true);
|
||||
$json['data']['settings'] = [
|
||||
'bg' => '',
|
||||
];
|
||||
$top_unread_items = FriendCircleModel::whereIn('id',$json['data']['unread_item_ids'])
|
||||
->with(['user' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}])
|
||||
->order('id', 'desc')
|
||||
->limit(0,3)
|
||||
->select();
|
||||
$json['data']['top_unread_items'] = $top_unread_items ?: [];
|
||||
$res->withBody(json_encode($json));
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("列表")
|
||||
@@ -66,9 +80,12 @@ class FriendCircleController extends BaseController{
|
||||
{
|
||||
$current_user = \support\Jwt::getUser();
|
||||
$current_user_id = $current_user ? $current_user->id : 0;
|
||||
$page = (int)$request->get('page', 1);
|
||||
$limit = (int)$request->get('limit', 10);
|
||||
$user_id = $request->get('user_id', 0);
|
||||
$page = (int)Input('page', 1);
|
||||
$limit = (int)Input('limit', 10);
|
||||
$user_id = Input('user_id', 0);
|
||||
if($user_id){
|
||||
$user_id = idDecode($user_id);
|
||||
}
|
||||
|
||||
$query = FriendCircleModel::where('status', 1)
|
||||
->whereIn('user_id',$this->getFriendUserIds($current_user_id))
|
||||
@@ -86,16 +103,18 @@ class FriendCircleController extends BaseController{
|
||||
'list_rows' => $limit,
|
||||
'page' => $page,
|
||||
]);
|
||||
cache('circle_last_read_id',$list[0]['id']);
|
||||
if(!$user_id){
|
||||
cache('circle_last_read_id_'.$current_user_id,$list[0]['id']);
|
||||
}
|
||||
|
||||
|
||||
// 处理每条朋友圈数据
|
||||
$items = $list->items();
|
||||
$list->each(function($item) use ($current_user_id){
|
||||
// 获取点赞列表
|
||||
$likes = Db::name('friend_circle')->alias('f')
|
||||
$likes = Db::name('friend_circle_like')->alias('f')
|
||||
->join('user u','u.id=f.user_id')
|
||||
->where('f.id', $item->id)
|
||||
->where('f.circle_id', $item->id)
|
||||
->field('f.*,u.avatar,u.nickname')
|
||||
->order('f.created_at', 'desc')
|
||||
->limit(20)
|
||||
@@ -182,11 +201,11 @@ class FriendCircleController extends BaseController{
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
|
||||
$circle_last_read_id = cache('circle_last_read_id') ?: 0;
|
||||
$user_id = $user->id;
|
||||
$circle_last_read_id = cache('circle_last_read_id_'.$user_id) ?: 0;
|
||||
// 统计从上次查看时间到现在新增的朋友圈数量
|
||||
$unread_item_ids = FriendCircleModel::where('status', 1)
|
||||
->whereIn('user_id',$this->getFriendUserIds($user->id))
|
||||
->whereIn('user_id',$this->getFriendUserIds($user_id))
|
||||
->where('id', '>', $circle_last_read_id)
|
||||
->order('id', 'desc')
|
||||
->column('id');
|
||||
@@ -250,7 +269,7 @@ class FriendCircleController extends BaseController{
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
return $this->success('发布成功', ['id' => $circle->id]);
|
||||
return $this->success('发布成功', ['id' => $circle->id,'data' => $circle]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,15 +390,56 @@ class FriendCircleController extends BaseController{
|
||||
if (!$user_id) {
|
||||
return [];
|
||||
}
|
||||
$result = cache('friend_id_list') ?: [];
|
||||
$cache_key = 'friend_id_list_'.$user_id;
|
||||
$result = cache($cache_key) ?: [];
|
||||
if(count($result) === 0){
|
||||
$res = request()->IM->friend->getFriendList($user_id.'');
|
||||
$res = request()->IM->friend->getFriendList(idEncode($user_id));
|
||||
$friendsInfo = $res['friendsInfo'];
|
||||
foreach($friendsInfo as $k=>$v){
|
||||
array_push($result,$v['friendUser']['userID']);
|
||||
}
|
||||
cache('friend_id_list',$result,3600);
|
||||
cache($cache_key,$result,3600);
|
||||
}
|
||||
$result[] = $user_id;
|
||||
return $result;
|
||||
}
|
||||
function delete(Request $request): Response{
|
||||
$id = $request->post('id');
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
if($id){
|
||||
FriendCircleModel::where('id',$id)->where('user_id',$user->id)->delete();
|
||||
}
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
|
||||
function upload_bg(Request $request){
|
||||
try {
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
$res = $this->_upload($request);
|
||||
if(is_string($res)){
|
||||
return $this->fail( $res);
|
||||
}
|
||||
|
||||
Db::name('friend_circle_setting')->replace()->insert([
|
||||
'user_id' => $user->id,
|
||||
'bg' => $res[0]['file_name'],
|
||||
'allow_days'=>0,
|
||||
'created_at'=>0
|
||||
]);
|
||||
//$result->ss = cdnurl($result->url);
|
||||
//P($result);
|
||||
return $this->success(__('successful'),[
|
||||
'url'=>$res[0]['file_name']
|
||||
]);
|
||||
}catch (\Exception $e){
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 礼品模块
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class GiftController extends BaseController{
|
||||
/**
|
||||
|
||||
Executable
+129
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
use app\model\User;
|
||||
use app\model\Album as AlbumModel;
|
||||
|
||||
/**
|
||||
* 群组管理
|
||||
*/
|
||||
class GroupController extends BaseController
|
||||
{
|
||||
public $noNeedAuth = ['*'];
|
||||
public $noNeedLogin = [];
|
||||
/**
|
||||
* @Apidoc\Title("群相片列表")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("group_id", type="string", require=true, desc="群ID")
|
||||
* @Apidoc\Param("page", type="int", require=true, desc="页码",default=1)
|
||||
* @Apidoc\Param("limit", type="int", require=true, desc="分页大小",default=10)
|
||||
*/
|
||||
function album_list(Request $request): Response
|
||||
{
|
||||
$user = \support\Jwt::getUser();
|
||||
$limit = $request->post('limit',10);
|
||||
$offset = $request->post('offset',0);
|
||||
$group_id = $request->post('groupID') ?:$request->post('group_id');
|
||||
//$ls = $this->get_user_in_group($group_id);
|
||||
//log_alert($ls);
|
||||
log_alert([$offset,$group_id,$limit]);
|
||||
$list = AlbumModel::where('group_id',$group_id)
|
||||
->where('id','<',$offset)
|
||||
->order('id','desc')
|
||||
->limit(0,$limit)
|
||||
->select();
|
||||
return $this->success('ok',$list);
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("上传相片")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("group_id", type="string", require=true, desc="群ID")
|
||||
* @Apidoc\Param("title", type="string", require=true, desc="标题")
|
||||
* @Apidoc\Param("url", type="string", require=true, desc="图片")
|
||||
*/
|
||||
function album_create(Request $request): Response
|
||||
{
|
||||
$user_id = \support\Jwt\JwtToken::getCurrentId();
|
||||
$res = $this->_upload($request);
|
||||
if(is_string($res)){
|
||||
return $this->fail( $res);
|
||||
}
|
||||
$groupID = $request->post('groupID');
|
||||
$insert_data = [];
|
||||
foreach($res as $item){
|
||||
$insert_data[] = [
|
||||
'user_id' => $user_id,
|
||||
'group_id' => $groupID,
|
||||
'title' => $item['origin_name'],
|
||||
'url' => $item['file_name'],
|
||||
];
|
||||
}
|
||||
$result = AlbumModel::saveAll($insert_data);
|
||||
return $this->success('ok',$result[0]);
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("更新相片")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("id", type="string", require=true, desc="ID")
|
||||
* @Apidoc\Param("title", type="string", require=true, desc="标题")
|
||||
* @Apidoc\Param("url", type="string", require=true, desc="图片")
|
||||
*/
|
||||
function album_update(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id');
|
||||
$data = $request->input('data');
|
||||
$album = AlbumModel::find($id);
|
||||
$album->update($data);
|
||||
return $this->success('ok',$album);
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("删除相片")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("id", type="string", require=true, desc="ID")
|
||||
*/
|
||||
function album_delete(Request $request): Response
|
||||
{
|
||||
$ids = Input('ids');
|
||||
//$album = AlbumModel::whereIn('id',condition: $ids)->select();
|
||||
//$album->delete();
|
||||
AlbumModel::whereIn('id',condition: $ids)->delete();
|
||||
return $this->success('ok');
|
||||
}
|
||||
/**
|
||||
* 获取再群里的角色
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
private function get_user_in_group($group_id='',$user_id='')
|
||||
{
|
||||
$list = request()->IM->group->getGroupMemberList($group_id,$user_id);
|
||||
return $list;
|
||||
}
|
||||
/**
|
||||
* 头像上传
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("file", type="File", require=true, desc="文件")
|
||||
*/
|
||||
public function avatar(Request $request)
|
||||
{
|
||||
//单文件上传
|
||||
$groupID = $request->post('groupID');
|
||||
if(!$groupID){
|
||||
return $this->fail(__('参数错误'));
|
||||
}
|
||||
$res = $this->_upload($request);
|
||||
if(is_string($res)){
|
||||
return $this->fail( $res);
|
||||
}
|
||||
$data = [
|
||||
'groupID' => $groupID,
|
||||
'faceURL' => $res[0]['file_name'],
|
||||
];
|
||||
$list = request()->IM->group->setGroupInfo($data);
|
||||
return $this->success(__('successful'),$data);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 消息控制器
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class MessageController extends BaseController{
|
||||
/**
|
||||
@@ -20,7 +22,7 @@ class MessageController extends BaseController{
|
||||
*/
|
||||
function delete(Request $request):Response{
|
||||
$im = $request->IM;
|
||||
$data = $im->message->sendBusinessNotification('system',100007,[
|
||||
$data = $im->message->sendBusinessNotification('system',idEncode(100007),[
|
||||
'contentType' => 101,
|
||||
'textElem' => [
|
||||
'content' => '欢迎使用4'.Config('site.name')
|
||||
|
||||
@@ -9,6 +9,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 产品模块
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class ProductController extends BaseController{
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 问卷
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class QuestionnaireController extends BaseController{
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 充值模块
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class RechargeController extends BaseController{
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 用户角色
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class RoleController extends BaseController{
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,8 @@ use Shopwwi\WebmanFilesystem\Facade\Storage;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
/**
|
||||
* 签到模块
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
|
||||
class SigninController extends BaseController
|
||||
@@ -275,7 +277,7 @@ class SigninController extends BaseController
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("file", type="string",require=true, desc="文件")
|
||||
*/
|
||||
function upload(Request $request)
|
||||
function upload(Request $request,$return = false)
|
||||
{
|
||||
//多文件上传
|
||||
$files = $request->file();
|
||||
|
||||
@@ -159,12 +159,8 @@ class TeamController extends BaseController{
|
||||
//$result['data'][$k]['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
|
||||
$result['data'][$k]['total_count'] = UserTeamModel::where('ancestor_id',$item['id'])->where('status',1)->where('depth','>',0)->count('descendant_id');
|
||||
$result['data'][$k]['direct_total'] = cache('team_direct_total_'.$item['id'])??0;
|
||||
$performance = get_performance($item['id']);
|
||||
$result['data'][$k]['performance_large'] = $performance[0];
|
||||
$result['data'][$k]['performance_small'] = $performance[1];
|
||||
$result['data'][$k]['role'] = isset($role_arr[$item['role_id']]) ? $role_arr[$item['role_id']] : __('普通用户');
|
||||
$result['data'][$k]['level'] = get_user_level($item['id'],$item['performance_small']);
|
||||
$result['data'][$k]['questionnaire_count'] = WorkRecordModel::where('user_id',$item['id'])->count('id');
|
||||
//$result['data'][$k]['questionnaire_count'] = WorkRecordModel::where('user_id',$item['id'])->count('id');
|
||||
$result['data'][$k]['id'] = idEncode($item['id']);
|
||||
//return $item;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ class UserController extends BaseController{
|
||||
$gender = input('gender',null);
|
||||
$faceURL = input('faceURL',null);
|
||||
$birth = input('birth',null);
|
||||
$bio = input('bio',null);
|
||||
$save_data =[];
|
||||
if($nickname){
|
||||
$save_data['nickname'] = $nickname;
|
||||
@@ -46,7 +47,10 @@ class UserController extends BaseController{
|
||||
$save_data['sex'] = $gender;
|
||||
}
|
||||
if($faceURL){
|
||||
$save_data['avatar'] = $faceURL;
|
||||
$save_data['faceURL'] = $faceURL;
|
||||
}
|
||||
if($bio){
|
||||
$save_data['bio'] = $bio;
|
||||
}
|
||||
if($birth){
|
||||
$save_data['birthday'] = datetime($birth/1000,'Y-m-d');
|
||||
@@ -133,21 +137,15 @@ class UserController extends BaseController{
|
||||
public function avatar(Request $request)
|
||||
{
|
||||
//单文件上传
|
||||
$file = $request->file('file0');
|
||||
try {
|
||||
$result = Storage::adapter('public')->path('upload/avatar')->size(1024*1024*5)->extYes(['image/jpeg','image/png'])->processUpload($file,function ($image){
|
||||
$image->resize(200,200);
|
||||
return $image;
|
||||
},true);
|
||||
\support\Jwt::getUser()->save([
|
||||
'avatar' => '/'.$result->file_name,
|
||||
]);
|
||||
//$result->ss = cdnurl($result->url);
|
||||
//P($result);
|
||||
return $this->success(__('successful'),$result);
|
||||
}catch (\Exception $e){
|
||||
return $this->error($e->getMessage());
|
||||
$res = $this->_upload($request);
|
||||
if(is_string($res)){
|
||||
return $this->fail( $res);
|
||||
}
|
||||
$data = [
|
||||
'avatar' => $res[0]['file_name'],
|
||||
];
|
||||
\support\Jwt::getUser()->save($data);
|
||||
return $this->success(__('successful'),$data);
|
||||
}
|
||||
function realname(Request $request): Response
|
||||
{
|
||||
@@ -198,7 +196,11 @@ class UserController extends BaseController{
|
||||
*/
|
||||
function find(Request $request): Response
|
||||
{
|
||||
$userIDs = Input('userIDs');
|
||||
$ids = Input('userIDs');
|
||||
if(is_string($ids)){
|
||||
$ids = explode(',',$ids);
|
||||
}
|
||||
$userIDs = array_map('idDecode',$ids);
|
||||
//$res = $request->IM->user->getUsersInfo($userIDs);
|
||||
$list = Db::name('user')->
|
||||
whereIn('id',$userIDs)
|
||||
@@ -240,12 +242,18 @@ class UserController extends BaseController{
|
||||
$searchtype = Input('searchtype');
|
||||
$fields = 'id,avatar,username,nickname,avatar,sex,email,mobile,birthday,bio';
|
||||
$model = Db::name('user')->field($fields)->where('status',1);
|
||||
if($searchtype =='id'){
|
||||
$model = $model->where('id',$keyword);
|
||||
}else{
|
||||
$model = $model->whereLike('username','%'.$keyword.'%');
|
||||
}
|
||||
$model = $model->where('id',idDecode($keyword));
|
||||
// if($searchtype =='id'){
|
||||
// $model = $model->where('id',$keyword);
|
||||
// }else{
|
||||
// $model = $model->whereLike('username|id','%'.$keyword.'%');
|
||||
// }
|
||||
$list = $model->paginate(Input('limit',10));
|
||||
$list->each(function ($item){
|
||||
$item['id'] = idEncode($item['id']);
|
||||
return $item;
|
||||
});
|
||||
//log_alert($list->toArray());
|
||||
return $this->success('ok',$list);
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,11 @@ class WalletController extends BaseController{
|
||||
*/
|
||||
public $noNeedLogin = [];
|
||||
/**
|
||||
* 用户调研币兑换问卷指标
|
||||
* 用户货币互换
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("currency", type="string",require=true, desc="货币money_to_score")
|
||||
* @Apidoc\Param("sendAmount", type="string",require=true, desc="调研币兑换数量")
|
||||
* @Apidoc\Param("receiveAmount", type="string",require=true, desc="问卷指标兑换数量")
|
||||
* @Apidoc\Param("sendAmount", type="string",require=true, desc="money兑换数量")
|
||||
* @Apidoc\Param("receiveAmount", type="string",require=true, desc="score兑换数量")
|
||||
* @Apidoc\Param("trade_password", type="string",require=true, desc="交易密码")
|
||||
* @Apidoc\Param("code", type="string",require=true, desc="图形验证码(event=exchange)")
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 提现模块
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class WithdrawlController extends BaseController{
|
||||
/**
|
||||
|
||||
+33
-39
@@ -19,14 +19,14 @@ class Auth implements MiddlewareInterface
|
||||
*/
|
||||
public function process(Request $request, callable $next): Response
|
||||
{
|
||||
$headers = [
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Allow-Origin' => $request->header('origin', '*'),
|
||||
'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'),
|
||||
'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'),
|
||||
];
|
||||
if($request->method() == 'OPTIONS'){
|
||||
$headers = [
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Allow-Origin' => $request->header('origin', '*'),
|
||||
'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'),
|
||||
'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'),
|
||||
];
|
||||
$response = response('200',200,$headers);
|
||||
$response = response('',204,$headers);
|
||||
return $response;
|
||||
}
|
||||
$lang = $request->input('lang','zh-Hans');
|
||||
@@ -49,28 +49,29 @@ class Auth implements MiddlewareInterface
|
||||
//检测是否登录
|
||||
try {
|
||||
if (!\support\Jwt::isLogin()) {
|
||||
return json([
|
||||
return new Response(401,$headers,json_encode([
|
||||
"code"=>401,
|
||||
"data"=>[],
|
||||
"msg"=>__('Please login first')
|
||||
]);
|
||||
]));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
return new Response(401,$headers,json_encode([
|
||||
"code"=>401,
|
||||
"data"=>[],
|
||||
"msg"=>__('Please login first')
|
||||
]);
|
||||
]));
|
||||
}
|
||||
$user = \support\Jwt\JwtToken::getUser();
|
||||
if(!$user['status']){
|
||||
return json([
|
||||
return new Response(403,$headers,json_encode([
|
||||
"code"=>403,
|
||||
"data"=>[],
|
||||
"msg"=>__('Account is locked')
|
||||
]);
|
||||
]));
|
||||
}
|
||||
|
||||
|
||||
// $key = "debounce_" . $request->path() . "_" . ($user->id ?? 'guest');
|
||||
// $ttl = 1; // 防抖时间(秒)
|
||||
// $redishandler = new \Redis;
|
||||
@@ -91,27 +92,27 @@ class Auth implements MiddlewareInterface
|
||||
$actionname = strtolower(get_action_name());
|
||||
$path = str_replace('.', '/', $controllername) . '/' . $actionname;
|
||||
if (!\support\Jwt::check($path)) {
|
||||
return json([
|
||||
return new Response(405,$headers,json_encode([
|
||||
"code"=>405,
|
||||
"data"=>[],
|
||||
"msg"=>__('You have no permission')
|
||||
]);
|
||||
"msg"=>__('have no permission')
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($request->client!='web'){
|
||||
$data = $request->post('data');
|
||||
if($data){
|
||||
$data = str_replace('%3D','=',$data);
|
||||
$data = str_replace(' ','+',$data);
|
||||
//var_dump($data);
|
||||
$data = aesdecode($data);
|
||||
$data = json_decode($data,true);
|
||||
//var_dump($data);
|
||||
$request->withBody($data);
|
||||
}
|
||||
}
|
||||
// if($request->client!='web'){
|
||||
// $data = $request->post('data');
|
||||
// if($data){
|
||||
// $data = str_replace('%3D','=',$data);
|
||||
// $data = str_replace(' ','+',$data);
|
||||
// //var_dump($data);
|
||||
// $data = aesdecode($data);
|
||||
// $data = json_decode($data,true);
|
||||
// //var_dump($data);
|
||||
// $request->withBody($data);
|
||||
// }
|
||||
// }
|
||||
$config = Config('site');
|
||||
$config['debug'] = config('app.debug');
|
||||
$config['controller'] = $request->controller_name;
|
||||
@@ -126,13 +127,6 @@ class Auth implements MiddlewareInterface
|
||||
]);
|
||||
$request->IM = $IM;
|
||||
$response = $next($request);
|
||||
$headers = [
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Allow-Origin' => $request->header('origin', '*'),
|
||||
'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'),
|
||||
'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'),
|
||||
];
|
||||
$response->withHeaders($headers);
|
||||
//cp('auth');
|
||||
//\support\Log::alert('auth');
|
||||
$body = str_replace([
|
||||
@@ -140,10 +134,10 @@ class Auth implements MiddlewareInterface
|
||||
],[
|
||||
request()->path()
|
||||
],$response->rawBody());
|
||||
if($request->app=="api" && $request->client!='web'){
|
||||
$body = aesencode($body);
|
||||
}
|
||||
$response->withBody($body)->getStatusCode();
|
||||
// if($request->app=="api" && $request->client!='web'){
|
||||
// $body = aesencode($body);
|
||||
// }
|
||||
$response->withHeaders($headers)->withBody($body)->getStatusCode();
|
||||
$time = microtime() - $request->start_time;
|
||||
//echo("响应时间:".$request->uri().':'.$time.PHP_EOL);
|
||||
//$response = $next($request);
|
||||
|
||||
@@ -45,7 +45,7 @@ class OpenIm extends Command
|
||||
'host' => 'http://127.0.0.1:10002', // OpenIM API地址
|
||||
'secret' => 'n1e5a6s6m7', // OpenIM密钥
|
||||
]);
|
||||
$data = $im->user->updateUserInfo('100001',['userInfo'=>['userId'=>'wx100001']]);
|
||||
$data = $im->user->updateUserInfo(idEncode('100006'),['userInfo'=>['userId'=>'wx100001']]);
|
||||
cp($data);
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use support\think\Db;
|
||||
use isszz\hashids\facade\Hashids;
|
||||
use function GuzzleHttp\json_encode;
|
||||
|
||||
class User extends Command
|
||||
{
|
||||
protected static $defaultName = 'User';
|
||||
protected static $defaultDescription = '用户';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->addOption('user_id','u', InputArgument::OPTIONAL, 'user_id');
|
||||
$this->addOption('action','a', InputArgument::OPTIONAL, '操作类型');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InputInterface $input
|
||||
* @param OutputInterface $output
|
||||
* @return int
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$action = $input->getOption('action','login');
|
||||
if($action == 'login'){
|
||||
$IM = new \support\OpenImSdk\Client([
|
||||
'host' => 'http://127.0.0.1:10002', // OpenIM API地址
|
||||
'secret' => 'n1e5a6s6m7', // OpenIM密钥
|
||||
]);
|
||||
$user_id = $input->getOption('user_id');
|
||||
if(!$user_id){
|
||||
return false;
|
||||
}
|
||||
$user = \support\Jwt::direct($user_id);
|
||||
$imToken = $IM->auth->getUserToken(idEncode($user['id']),2);
|
||||
cp('userID:' . $user['id']);
|
||||
cp('nickname:' . $user['nickname']);
|
||||
cp('token:' . $user['token']);
|
||||
cp('imToken:' . $imToken['token']);
|
||||
return 0;
|
||||
}
|
||||
cp('action not exist');
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,17 +23,27 @@ class HookController{
|
||||
{
|
||||
$userID= Input('userID');
|
||||
$nickname= Input('nickname');
|
||||
|
||||
$users = Input('users');
|
||||
$im = new \support\OpenImSdk\Client([
|
||||
'host' => 'http://127.0.0.1:10002', // OpenIM API地址
|
||||
'secret' => 'n1e5a6s6m7', // OpenIM密钥
|
||||
]);
|
||||
$im->message->sendBusinessNotification('official_team',$userID,[
|
||||
'contentType' => 101,
|
||||
'textElem' => [
|
||||
'content' => '欢迎使用'.Config('site.name')
|
||||
]
|
||||
]);
|
||||
foreach($users as $k=>$v){
|
||||
|
||||
// 'userID' => '0EO9K107ON',
|
||||
// 'nickname' => '坏蛋',
|
||||
// 'faceURL' => '/static/img/avatar.png',
|
||||
// 'ex' => '',
|
||||
// 'createTime' => 0,
|
||||
// 'appMangerLevel' => 0,
|
||||
// 'globalRecvMsgOpt' => 0,
|
||||
$im->message->sendBusinessNotification('official_team',idEncode($v['userID']),[
|
||||
'contentType' => 101,
|
||||
'textElem' => [
|
||||
'content' => '欢迎使用'.Config('site.name')
|
||||
]
|
||||
]);
|
||||
}
|
||||
return json([
|
||||
"actionCode" => 0,
|
||||
"errCode" => 0,
|
||||
@@ -266,4 +276,32 @@ class HookController{
|
||||
"nextCode"=> 0
|
||||
]);
|
||||
}
|
||||
function callbackAfterDeleteFriendCommand() : Response {
|
||||
$friendUserID = Input('friendUserID');
|
||||
$ownerUserID = Input('ownerUserID');
|
||||
$sdk = $this->getSdk();
|
||||
$relation = $sdk->friend->isFriend($friendUserID,$ownerUserID);
|
||||
if($relation){
|
||||
if($relation['inUser1Friends']){
|
||||
$this->getSdk()->friend->deleteFriend($friendUserID,$ownerUserID);
|
||||
}
|
||||
if($relation['inUser2Friends']){
|
||||
$this->getSdk()->friend->deleteFriend($ownerUserID,$friendUserID);
|
||||
}
|
||||
}
|
||||
return json([
|
||||
"actionCode" => 0,
|
||||
"errCode" => 0,
|
||||
"errMsg" => "",
|
||||
"errDlt" => "",
|
||||
"nextCode"=> 0
|
||||
]);
|
||||
}
|
||||
function getSdk(){
|
||||
$IM = new \support\OpenImSdk\Client([
|
||||
'host' => 'http://127.0.0.1:10002', // OpenIM API地址
|
||||
'secret' => 'n1e5a6s6m7', // OpenIM密钥
|
||||
]);
|
||||
return $IM;
|
||||
}
|
||||
}
|
||||
+4
-5
@@ -14,7 +14,7 @@ class User{
|
||||
if($user->parent_id){
|
||||
parent_info( $user->id,[
|
||||
'id' => $user->parent_id,
|
||||
'username' => Db::name('user')->where('id',op: $user->parent_id)->value('username')
|
||||
'username' => Db::name('user')->where('id',$user->parent_id)->value('username')
|
||||
]);
|
||||
//管理直推人数
|
||||
cache_add('team_direct_total_'.$user->parent_id,1);
|
||||
@@ -64,16 +64,15 @@ class User{
|
||||
$data['avatar'] = $data['avatar']?:"/static/img/avatar.png";
|
||||
$data['role'] = isset($role_arr[$data['role_id']]) ? $role_arr[$data['role_id']] : __('普通用户');//\app\model\UserRole::where('id',$data['role_id'])->value('name');
|
||||
|
||||
$data['level'] = get_user_level($data['id']);
|
||||
/**
|
||||
* @var \support\OpenImSdk\Client $IM
|
||||
*/
|
||||
$IM = request()->IM;
|
||||
$imToken = $IM->auth->getUserToken($data['id'],Input('platform'));
|
||||
$imToken = $IM->auth->getUserToken(idEncode($data['id']),Input('platform'));
|
||||
$data['imToken'] = $imToken['token'];
|
||||
$data['userID'] = $data['id'] ;
|
||||
$data['id'] = idEncode($data['id']);
|
||||
$last_see = $last_see ?? cache('last_see_'.$data['id']);
|
||||
$data['id'] = idEncode($data['id']);
|
||||
$data['userID'] = $data['id'] ;
|
||||
$count = 0;
|
||||
$data['friend_settings'] = [
|
||||
'unread_count' => $count ??0,
|
||||
|
||||
+19
-127
@@ -236,26 +236,29 @@ if (!function_exists('abort')) {
|
||||
if (!function_exists('idEncode')) {
|
||||
function idEncode($id = '')
|
||||
{
|
||||
return \isszz\hashids\facade\Hashids::mode('bilibili')->encode($id);
|
||||
if($id<=100234){return $id.'';}
|
||||
return id_encode($id);
|
||||
}
|
||||
}
|
||||
if (!function_exists('idDecode')) {
|
||||
function idDecode($id = '')
|
||||
{
|
||||
return \isszz\hashids\facade\Hashids::mode('bilibili')->decode($id);
|
||||
$_id= intval($id);
|
||||
if($_id == $id){return $id;}
|
||||
return id_decode($id);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 生成可逆的邀请码(8位,含校验位)
|
||||
* @param int $user_id 用户ID(需≥1000)
|
||||
* @param int $id 用户ID(需≥1000)
|
||||
* @return string 大写字母+数字组合
|
||||
*/
|
||||
|
||||
if (!function_exists('base62Encode')) {
|
||||
function base62Encode(int $user_id,$secret='your_secret_salt'): string {
|
||||
function base62Encode(int $id,$secret='your_secret_salt'): string {
|
||||
// 添加校验位(防止篡改)
|
||||
$hash = crc32($user_id . $secret) % 1000;
|
||||
$code_num = $user_id * 1000 + $hash;
|
||||
$hash = crc32($id . $secret) % 1000;
|
||||
$code_num = $id * 1000 + $hash;
|
||||
|
||||
// Base62 编码(0-9A-Za-z)
|
||||
$base62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
@@ -271,7 +274,7 @@ if (!function_exists('base62Encode')) {
|
||||
}
|
||||
/**
|
||||
* 从邀请码解析用户ID
|
||||
* @return int|false 成功返回user_id,失败返回false
|
||||
* @return int|false 成功返回id,失败返回false
|
||||
*/
|
||||
if (!function_exists('base62Decode')) {
|
||||
function base62Decode(string $code,$secret='your_secret_salt'): int|false {
|
||||
@@ -286,15 +289,15 @@ if (!function_exists('base62Decode')) {
|
||||
}
|
||||
|
||||
// 分离校验位
|
||||
$user_id = (int)($code_num / 1000);
|
||||
$id = (int)($code_num / 1000);
|
||||
$hash = $code_num % 1000;
|
||||
|
||||
// 校验
|
||||
if (crc32($user_id . $secret) % 1000 != $hash) {
|
||||
if (crc32($id . $secret) % 1000 != $hash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user_id;
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,26 +663,6 @@ if (!function_exists('parent_info')) {
|
||||
return $info;
|
||||
}
|
||||
}
|
||||
if (!function_exists('get_user_level')) {
|
||||
function get_user_level($user_id,$performance_small=null)
|
||||
{
|
||||
if (!$user_id) {
|
||||
return 0;
|
||||
}
|
||||
if(is_null($performance_small)){
|
||||
$performance= get_performance($user_id);
|
||||
$performance_small = $performance[1];
|
||||
}
|
||||
$user_level_rules = Config('site.user_level_rules');
|
||||
$level = 0;
|
||||
foreach ($user_level_rules as $_level => $score) {
|
||||
if($performance_small>$score){
|
||||
$level = $_level;
|
||||
}
|
||||
}
|
||||
return $level;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('datetime')){
|
||||
function datetime($timestamp=0,$format='Y-m-d H:i:s'){
|
||||
@@ -700,20 +683,6 @@ if(!function_exists('datetime')){
|
||||
return $timestamp;
|
||||
}
|
||||
}
|
||||
if(!function_exists('get_performance')){
|
||||
function get_performance($user_id){
|
||||
$performance_list = \app\model\UserTeam::alias('ut')
|
||||
->join('user_extend ue', 'ut.descendant_id = ue.user_id')
|
||||
->where('ut.ancestor_id', $user_id)
|
||||
->order('ue.sales desc')->column('ue.sales');
|
||||
if(empty($performance_list)){
|
||||
$performance_list = [0,0];
|
||||
}
|
||||
|
||||
return [array_shift($performance_list), array_sum($performance_list)];
|
||||
|
||||
}
|
||||
}
|
||||
if(!function_exists('log_alert')){
|
||||
function log_alert($data='',$channel='default'){
|
||||
if(!is_string($data)){
|
||||
@@ -743,84 +712,6 @@ if(!function_exists('enum_dir')){
|
||||
return $list ;
|
||||
}
|
||||
}
|
||||
if(!function_exists('jicha')){
|
||||
function jicha($current_user_id,$amount,$reward_arr=[]){
|
||||
$distributed_users = [];
|
||||
$distributed_rate = 0; // 已分配的累计比例
|
||||
$last_commissioned_level = 0; // 上一次成功分佣的用户角色等级(role_id)
|
||||
|
||||
//$reward_arr = [0,0.02,0.04,0.06,0.08,0.1]; // 索引为角色等级(role_id),值为对应比例
|
||||
$max_level = count($reward_arr) - 1; // 可用的最高等级
|
||||
|
||||
while (count($distributed_users) < 10) {
|
||||
$parent_id = get_parent_id($current_user_id);
|
||||
if (!$parent_id) {
|
||||
// cp(sprintf("用户ID:%s\t级别:%s\t父级:%s\t%s\t%s\n\n",
|
||||
// $parent_id.'',
|
||||
// '-',
|
||||
// '-',
|
||||
// "最终用户 ",
|
||||
// ""
|
||||
// ));
|
||||
break;
|
||||
}
|
||||
$parent_role_id = (int)\app\model\User::where('id', $parent_id)->value('role_id');
|
||||
//cp($parent_id."\t".$parent_role_id."\t".$last_commissioned_level);
|
||||
if ($parent_role_id > 5) {
|
||||
// cp(sprintf("用户ID:%s\t级别:%s\t父级:%s\t%s\t%s\n\n",
|
||||
// $parent_id,
|
||||
// $parent_role_id,
|
||||
// '-',
|
||||
// "用户级别异常",
|
||||
// ""
|
||||
// ));
|
||||
break;
|
||||
}
|
||||
|
||||
// 仅当上级角色等级高于上一次成功分佣的等级时才考虑分配
|
||||
if ($parent_role_id > $last_commissioned_level) {
|
||||
$idx = $parent_role_id;
|
||||
if ($idx > $max_level) { // 超出定义范围则使用最高档
|
||||
$idx = $max_level;
|
||||
}
|
||||
$current_rate = $reward_arr[$idx];
|
||||
$available_rate = bcsub($current_rate, $distributed_rate, 4);
|
||||
|
||||
if (bccomp($available_rate, 0, 6) === 1) { // available_rate > 0
|
||||
$commission = bcmul($available_rate, $amount, 4);
|
||||
$distributed_rate += $available_rate;
|
||||
$last_commissioned_level = $parent_role_id;
|
||||
$distributed_users[] = [
|
||||
'user_id' => $parent_id,
|
||||
'role_id' => $parent_role_id,
|
||||
'rate' => $available_rate,
|
||||
'amount' => $commission
|
||||
];
|
||||
} else {
|
||||
// 可分配比例<=0,停止继续查找
|
||||
// cp(sprintf("用户ID:%s\t级别:%s\t父级:%s\t%s\t%s\n\n",
|
||||
// $parent_id,
|
||||
// $parent_role_id,
|
||||
// '-',
|
||||
// "可分配比例不足,结束",
|
||||
// "已分配比例:".$distributed_rate
|
||||
// ));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// cp(sprintf("用户ID:%s\t级别:%s\t父级:%s\t%s\t%s\n\n",
|
||||
// $parent_id,
|
||||
// $parent_role_id,
|
||||
// '-',
|
||||
// "用户等级不够高",
|
||||
// "最后分佣等级:".$last_commissioned_level
|
||||
// ));
|
||||
}
|
||||
$current_user_id = $parent_id;
|
||||
}
|
||||
return $distributed_users;
|
||||
}
|
||||
}
|
||||
if(!function_exists('generateShortUniqueID')){
|
||||
function generateShortUniqueID($length = 8) {
|
||||
// 生成指定长度的随机字节,转为 Base64 编码并去除不必要字符
|
||||
@@ -836,14 +727,15 @@ if(!function_exists('get_user_rights')){
|
||||
// 'max_group_join_count' => 999999999999,
|
||||
// 'max_gourp_create_count' => 999999999999
|
||||
// ];
|
||||
$user_id = idDecode($user_id);
|
||||
$key = 'user_rights_'.$user_id;
|
||||
$result = cache($key);
|
||||
if(!$result){
|
||||
log_alert(\think\facade\Db::name('user_role')->alias('ur')
|
||||
->join('user u','ur.id = u.role_id')
|
||||
->where('u.id',$user_id)
|
||||
->field('ur.name,ur.max_send_msg_count,ur.max_friend_count,ur.max_group_join_count,ur.max_gourp_create_count')
|
||||
->buildSql());
|
||||
// log_alert(\think\facade\Db::name('user_role')->alias('ur')
|
||||
// ->join('user u','ur.id = u.role_id')
|
||||
// ->where('u.id',$user_id)
|
||||
// ->field('ur.name,ur.max_send_msg_count,ur.max_friend_count,ur.max_group_join_count,ur.max_gourp_create_count')
|
||||
// ->buildSql());
|
||||
$result = \think\facade\Db::name('user_role')->alias('ur')
|
||||
->join('user u','ur.id = u.role_id')
|
||||
->where('u.id',$user_id)
|
||||
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 相册模型
|
||||
* @property integer $id 主键(ID)
|
||||
* @property integer $user_id 用户ID
|
||||
* @property integer $group_id 内容
|
||||
* @property string $url 图片
|
||||
* @property string $title 标题
|
||||
* @property integer $created_at 创建时间
|
||||
* @property integer $updated_at 更新时间
|
||||
* @property integer $status 状态(0:隐藏 1:正常)
|
||||
*/
|
||||
class Album extends Base
|
||||
{
|
||||
protected $name = 'album';
|
||||
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return array_merge(parent::getOptions(), [
|
||||
'insert' => [
|
||||
'status' => 1,
|
||||
],
|
||||
]);
|
||||
}
|
||||
public static function onAfterInsert($row){
|
||||
$changeData = $row->getChangedData();
|
||||
if(isset($changeData['url'])) {
|
||||
Files::where('path',$changeData['url'])->inc('use_count');
|
||||
};
|
||||
}
|
||||
|
||||
public static function onAfterUpdate($row){
|
||||
$OrgData = $row->getOrigin();
|
||||
$changeData = $row->getChangedData();
|
||||
if(isset($OrgData['url']) && $OrgData['url']) {
|
||||
\support\Log::info('OrgData string');
|
||||
Files::where('path',$OrgData['url'])->dec('use_count');
|
||||
};
|
||||
if(isset($changeData['url']) && $changeData['url']) {
|
||||
\support\Log::info('changeData string');
|
||||
Files::where('path',$changeData['url'])->inc('use_count');
|
||||
};
|
||||
}
|
||||
|
||||
public static function onAfterDelete($row){
|
||||
Files::where('path',$row->url)->dec('use_count');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class BalanceLog extends Base
|
||||
{
|
||||
$model = new static();
|
||||
if(isset($data['currency'])){
|
||||
if(in_array($data['currency'],Config('site.allow_balance_log'))){
|
||||
if(in_array($data['currency'],Config('site.allow_currency_logs'))){
|
||||
$data['status']=isset($data['status']) ? $data['status']:1;
|
||||
$data['user_id'] = intval($data['user_id']);
|
||||
$data['amount'] = floatval($data['amount']);
|
||||
@@ -56,8 +56,8 @@ class BalanceLog extends Base
|
||||
public static function createAllIndexes(): array
|
||||
{
|
||||
$results = [];
|
||||
$allow_balance_log = Config('site.allow_balance_log');
|
||||
foreach ($allow_balance_log as $currency) {
|
||||
$allow_currency_logs = Config('site.allow_currency_logs');
|
||||
foreach ($allow_currency_logs as $currency) {
|
||||
$results[$currency] = self::createTableIndexes($currency);
|
||||
}
|
||||
return $results;
|
||||
@@ -115,8 +115,8 @@ class BalanceLog extends Base
|
||||
public static function archiveData(int $days = 3): array
|
||||
{
|
||||
$results = [];
|
||||
$allow_balance_log = Config('site.allow_balance_log');
|
||||
foreach ($allow_balance_log as $currency) {
|
||||
$allow_currency_logs = Config('site.allow_currency_logs');
|
||||
foreach ($allow_currency_logs as $currency) {
|
||||
$results[$currency] = self::archiveCurrencyData($currency, $days);
|
||||
}
|
||||
return $results;
|
||||
@@ -175,17 +175,7 @@ class BalanceLog extends Base
|
||||
->order('created_at', 'desc');
|
||||
|
||||
if ($type) {
|
||||
if($type == '99999'){
|
||||
$query->whereIn('type', [
|
||||
\app\enum\BalanceType::OUTPUT_REWARD->value,
|
||||
\app\enum\BalanceType::WITHDRAW_REWARD->value,
|
||||
\app\enum\BalanceType::PRODUCT_INCOME->value,
|
||||
\app\enum\BalanceType::AGENT_COMMISSION->value,
|
||||
\app\enum\BalanceType::DIFFERENTIAL_COMMISSION->value
|
||||
]);
|
||||
}else{
|
||||
$query->where('type', intval($type));
|
||||
}
|
||||
$query->whereIn('type', $type);
|
||||
}
|
||||
|
||||
if ($startTime) {
|
||||
|
||||
@@ -57,6 +57,12 @@ class FriendCircle extends Base
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static function onAfterDelete($row){
|
||||
FriendCircleLike::whereIn('circle_id',$row->id)->delete();
|
||||
FriendCircleComment::whereIn('circle_id',$row->id)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联用户
|
||||
*/
|
||||
|
||||
+6
-7
@@ -75,9 +75,9 @@ use support\think\Db;
|
||||
*/
|
||||
class User extends Base
|
||||
{
|
||||
use \think\model\concern\SoftDelete;
|
||||
//use \think\model\concern\SoftDelete;
|
||||
public static function onAfterInsert($row){
|
||||
$res = request()->IM->user->userRegister($row->id,$row->nickname,cdnurl($row->avatar));
|
||||
$res = request()->IM->user->userRegister(idEncode($row->id),$row->nickname,cdnurl($row->avatar));
|
||||
}
|
||||
public static function onAfterUpdate($row){
|
||||
$changeData = $row->getChangedData();
|
||||
@@ -87,25 +87,24 @@ class User extends Base
|
||||
'nickname' => $row->nickname,
|
||||
'faceURL' => cdnurl($row->avatar)
|
||||
];
|
||||
request()->IM->user->updateUserInfo($row->id,$sdata);
|
||||
request()->IM->user->updateUserInfo(idEncode($row->id),$sdata);
|
||||
}
|
||||
if(isset($changeData['status']) || $changeData['status'] == '0'){
|
||||
request()->IM->user->forceLogout($row->id);
|
||||
request()->IM->user->forceLogout(idEncode($row->id));
|
||||
}
|
||||
}
|
||||
public static function onAfterDelete($row)
|
||||
{
|
||||
Db::name('address')->where('user_id',$row->id)->delete();
|
||||
Db::name('recharge')->where('user_id',$row->id)->delete();
|
||||
Db::name('record')->where('user_id',$row->id)->delete();
|
||||
//Db::name('record')->where('user_id',$row->id)->delete();
|
||||
Db::name('withdrawl')->where('user_id',$row->id)->delete();
|
||||
Db::name('user_extend')->where('user_id',$row->id)->delete();
|
||||
Db::name('user_team')->where('descendant_id|ancestor_id','=',$row->id)->delete();
|
||||
Db::name('withdrawl')->where('user_id',$row->id)->delete();
|
||||
foreach(Config('site.allow_currencys') as $currency){
|
||||
(new \app\model\BalanceLog)->setSuffix('_'.$currency)->where('user_id',(int)$row->id)->delete();
|
||||
}
|
||||
request()->IM->user->forceLogout($row->id);
|
||||
request()->IM->user->forceLogout(idEncode($row->id));
|
||||
}
|
||||
public function role()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user