10
This commit is contained in:
@@ -43,6 +43,7 @@ class BalanceLogController extends BaseController{
|
||||
}
|
||||
$item->_type= $item->type;
|
||||
$item->type= $BalanceTypeList[$item->type];
|
||||
return $item;
|
||||
});
|
||||
return $this->success(__('successful'),$list);
|
||||
}
|
||||
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
use app\model\User as UserModel;
|
||||
use app\model\UserRemark as UserRemarkModel;
|
||||
use app\model\GroupRemark as GroupRemarkModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use taoser\facade\Validate;
|
||||
use support\think\Db;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
/**
|
||||
* 通讯录
|
||||
*/
|
||||
class ContactController extends BaseController{
|
||||
/**
|
||||
* 不需要鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedAuth = ['*'];
|
||||
|
||||
/**
|
||||
* 无需登录及鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedLogin = [];
|
||||
/**
|
||||
* @Apidoc\Title("获取用户好友列表")
|
||||
* @Apidoc\Method("GET")
|
||||
*/
|
||||
function get_friend_list(Request $request): Response
|
||||
{
|
||||
$current_user = \support\Jwt::getUser();
|
||||
$user_id = $current_user->id;
|
||||
$userID = idEncode($user_id);
|
||||
$res = $request->IM->friend()->getFriendList($userID,1,10000);
|
||||
return $this->success('ok',$res['data']['friendsInfo']);
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("好友信息")
|
||||
* @Apidoc\Method("GET")
|
||||
* @Apidoc\Param("userID", type="string",require=true, desc="用户ID")
|
||||
*/
|
||||
function get_friend_info(Request $request): Response
|
||||
{
|
||||
$userID = Input('userID');
|
||||
if(!$userID){
|
||||
return $this->error('UserID is Empty');
|
||||
}
|
||||
$userID = idDecode($userID);
|
||||
$res = \app\model\User::where('id',$userID)->find();
|
||||
return $this->success('ok',$res);
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("批量查询好友信息")
|
||||
* @Apidoc\Method("GET")
|
||||
* @Apidoc\Param("userIDs", type="string",require=true, desc="用户ID列表,逗号分隔")
|
||||
*/
|
||||
function get_friends_info(Request $request): Response
|
||||
{
|
||||
$userIDs = Input('userIDs');
|
||||
if(!$userIDs){
|
||||
return $this->error('UserID is Empty');
|
||||
}
|
||||
//$userIDs = explode(',',$userIDs);
|
||||
//$userIDs = idDecode($userIDs);
|
||||
//$current_user = \support\Jwt::getUser();
|
||||
//$user_id = $current_user->id;
|
||||
//$userID = idEncode($user_id);
|
||||
$res = \app\model\User::whereIn('userID',$userIDs)->select();
|
||||
return $this->success('ok',$res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("批量查询好友信息")
|
||||
* @Apidoc\Method("GET")
|
||||
* @Apidoc\Param("userIDs", type="string",require=true, desc="用户ID列表,逗号分隔")
|
||||
*/
|
||||
function get_friends_roles(Request $request): Response
|
||||
{
|
||||
$userIDs = Input('userIDs');
|
||||
if(!$userIDs){
|
||||
return $this->error('UserID is Empty');
|
||||
}
|
||||
$res = Db::name('user')->whereIn('userID',$userIDs)->column('role_id','userID');
|
||||
return $this->success('ok',$res);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,8 @@ use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 我的产品
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class ProductOrderController extends BaseController{
|
||||
/**
|
||||
|
||||
@@ -1,253 +0,0 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\model\WorkRecord as WorkRecordModel;
|
||||
use app\model\Questionnaire as QuestionnaireModel;
|
||||
use app\model\Product as ProductModel;
|
||||
use app\model\ProductOrder as ProductOrderModel;
|
||||
use app\model\BalanceLog;
|
||||
use support\think\Db;
|
||||
use taoser\facade\Validate;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 问卷
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class QuestionnaireController extends BaseController{
|
||||
/**
|
||||
* 不需要鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedAuth = ['*'];
|
||||
public $noNeedLogin = [];
|
||||
/**
|
||||
* 简介
|
||||
* @Apidoc\Method("GET")
|
||||
*/
|
||||
public function info(){
|
||||
$user = \support\Jwt::getUser();
|
||||
return $this->success(__('successful'),[
|
||||
'success_count' => WorkRecordModel::where('status',\app\enum\ServerStatus::COMPLETE->value)
|
||||
->where('user_id',$user->id)
|
||||
->count('id'),
|
||||
'audit_count' => WorkRecordModel::where('status',\app\enum\ServerStatus::AUDITING->value)
|
||||
->where('user_id',$user->id)
|
||||
->count('id'),
|
||||
]);
|
||||
|
||||
}
|
||||
/**
|
||||
* 列表
|
||||
* @Apidoc\Query("kw", type="string", require=false, desc="搜索关键字")
|
||||
* @Apidoc\Query("country", type="string", require=false, desc="国家,i18n编码")
|
||||
* @Apidoc\Query("category_id", type="int", require=false, desc="分类")
|
||||
* @Apidoc\Query("page", type="int", require=true, desc="页码",default=1)
|
||||
* @Apidoc\Query("limit", type="int", require=true, desc="分页大小",default=10)
|
||||
*/
|
||||
public function list(){
|
||||
$limit = (int)input('limit',10);
|
||||
$model = QuestionnaireModel::with(['category'])->where('status',1);
|
||||
if($category_id = input('category_id')){
|
||||
$model = $model->where('category_id', $category_id);
|
||||
}
|
||||
if($country = input('country')){
|
||||
$model = $model->where('country', $country);
|
||||
}
|
||||
$list = $model->order('id desc')->paginate($limit);
|
||||
$list = $list->toArray();
|
||||
foreach($list['data'] as $k=>$item){
|
||||
$list['data'][$k]['id'] = idEncode($item['id']);
|
||||
}
|
||||
return $this->success(__('successful'),$list);
|
||||
|
||||
}
|
||||
/**
|
||||
* 问卷详情
|
||||
* @Apidoc\Query("id", type="int", require=true, desc="ID")
|
||||
*/
|
||||
public function detail(){
|
||||
try{
|
||||
$user = \support\Jwt::getUser();
|
||||
}catch(\Exception $e){
|
||||
$user = ['id'=>0,'role_id'=>0];
|
||||
}
|
||||
$appid = input('id');
|
||||
if(!$appid){
|
||||
return $this->error(__("Product does not exist"));
|
||||
}
|
||||
/** @var ProductModel $product */
|
||||
$product = ProductModel::where('id',$appid)->find();
|
||||
//->cache(true,86400,'product_detail')
|
||||
if(!$product) {
|
||||
return $this->error(__("Product does not exist"));
|
||||
}
|
||||
if($user['id']){
|
||||
$total_quantity_user = ProductOrderModel::where('product_id',$product->id)->where('user_id',$user['id'])->sum('quantity');
|
||||
|
||||
$total_quantity_system = $product->user_quantity ?: 99999999;
|
||||
$max_quantity = $total_quantity_system-$total_quantity_user;
|
||||
$max_quantity= $max_quantity < 0 ? 0: $max_quantity;
|
||||
$product->max_quantity = $max_quantity;
|
||||
$product->total_quantity_user = $total_quantity_user;
|
||||
}else{
|
||||
$product->total_quantity_user = 0;
|
||||
$product->max_quantity = 0;
|
||||
}
|
||||
return $this->success(__('successful'),$product->toArray());
|
||||
}
|
||||
/**
|
||||
* 领取问卷
|
||||
* @Apidoc\Method("GET")
|
||||
*/
|
||||
function claim(){
|
||||
$user = \support\Jwt::getUser();
|
||||
//判断是否有问卷可领取
|
||||
if($user->currency6<=0){
|
||||
return $this->success(__('successful'));
|
||||
}
|
||||
//产生工作记录
|
||||
$datas = [];
|
||||
$questionnaire_ids = QuestionnaireModel::where('status',1)
|
||||
->whereTime('start_time','<',time())
|
||||
->whereTime('end_time','>',time())
|
||||
->column('id');
|
||||
$time = time();
|
||||
for ($i=0; $i < $user->currency6; $i++) {
|
||||
//随机选取一份问卷
|
||||
$questionnaire_id = $questionnaire_ids[array_rand($questionnaire_ids)];
|
||||
/** @var QuestionnaireModel $questionnaire */
|
||||
$questionnaire = QuestionnaireModel::field('id,score')->find($questionnaire_id);
|
||||
array_push($datas,[
|
||||
"user_id" => $user->id,
|
||||
"product_id" => null,
|
||||
"questionnaire_id" => $questionnaire->id,
|
||||
"order_id" => null,
|
||||
"income" => $questionnaire->score,
|
||||
"start_time" => 0,
|
||||
"end_time" => 0,
|
||||
"status" => 0, //自动开始
|
||||
"created_at" => $time,
|
||||
]);
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
(new WorkRecordModel)->saveAll($datas);
|
||||
//领取完成,待领取清0;
|
||||
$logData = [
|
||||
'user_id' => $user->id.'',
|
||||
'currency' => 'currency6',
|
||||
'amount' => (0-$user->currency6).'',
|
||||
'before' => $user->currency6.'',
|
||||
'after' => '0',
|
||||
'type' => \app\enum\BalanceType::CLAIM->value,
|
||||
'created_at' => $time.'',
|
||||
'memo' => ''
|
||||
];
|
||||
|
||||
// 写入日志
|
||||
BalanceLog::create($logData);
|
||||
$user->currency6 = 0;
|
||||
$user->save();
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
return $this->success(__('successful'));
|
||||
}
|
||||
/**
|
||||
* 用户参与的问卷列表
|
||||
* @Apidoc\Query("order_id", type="string", require=false, desc="订单号")
|
||||
* @Apidoc\Query("step", type="string", require=false, desc="类型,progress,done")
|
||||
* @Apidoc\Query("page", type="int", require=true, desc="页码",default=1)
|
||||
* @Apidoc\Query("limit", type="int", require=true, desc="分页大小",default=10)
|
||||
*/
|
||||
public function record(){
|
||||
$limit = (int)input('limit',10);
|
||||
$type = input('type','all');
|
||||
$user_id = \support\Jwt\JwtToken::getCurrentId();
|
||||
$step = input('step');
|
||||
$order_id = input('order_id');
|
||||
$model = WorkRecordModel::withJoin([
|
||||
'questionnaire' => function($query) {
|
||||
$query->field('title,category_id,country');
|
||||
},
|
||||
// 'product' => function($query) {
|
||||
// $query->field('title');
|
||||
// }
|
||||
])->where('work_record.user_id',$user_id);
|
||||
|
||||
if($type && $type !='all'){
|
||||
$model = $model->where('work_record.status', $type);
|
||||
}
|
||||
if($order_id){
|
||||
$model = $model->where('work_record.order_id',$order_id);
|
||||
}
|
||||
|
||||
if($step){
|
||||
if($step=='done'){
|
||||
$model = $model->where('work_record.status',\app\enum\ServerStatus::COMPLETE->value);
|
||||
}
|
||||
if($step=='progress'){
|
||||
$model = $model->whereBetween('work_record.status',[1,\app\enum\ServerStatus::AUDITING->value,\app\enum\ServerStatus::SETTLEMENT->value]);
|
||||
}
|
||||
}
|
||||
$list = $model->order('work_record.id desc')
|
||||
->paginate($limit);
|
||||
$list->each(function($item){
|
||||
$item->questionnaire->country = Config('site.questionnaire_country')[$item->questionnaire->country];
|
||||
$item->category = Db::name('category')->where('id',$item->questionnaire->category_id)->value('name');
|
||||
return $item;
|
||||
});
|
||||
return $this->success(__('successful'),$list->toArray());
|
||||
}
|
||||
/**
|
||||
* 开始任务
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("server_id", type="string", require=true, desc="产品ID")
|
||||
*/
|
||||
public function start()
|
||||
{
|
||||
$server_id = input('server_id');
|
||||
$user = \support\Jwt::getUser();
|
||||
if(!$server_id){
|
||||
return $this->error(__('Incorrect parameter'));
|
||||
}
|
||||
if($server_id === 'all'){
|
||||
$work_records = WorkRecordModel::where('user_id',$user->id)
|
||||
->where('status',\app\enum\ServerStatus::WAITING->value)
|
||||
->select();
|
||||
}else{
|
||||
$work_records = WorkRecordModel::where('user_id',$user->id)
|
||||
->where('status',\app\enum\ServerStatus::WAITING->value)
|
||||
->where('id',$server_id)->select();
|
||||
if(count($work_records) === 0){
|
||||
return $this->error(__('Server is not exist'));
|
||||
}
|
||||
}
|
||||
/** @var WorkRecordModel $server */
|
||||
foreach($work_records as $server){
|
||||
$server->start();
|
||||
}
|
||||
return $this->success(__('successful'));
|
||||
}
|
||||
/**
|
||||
* 用户参与的问卷详情
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("server_id", type="string", require=true, desc="产品ID")
|
||||
*/
|
||||
function progress(){
|
||||
$server_id = (int)input('server_id',1);
|
||||
$user = \support\Jwt::getUser();
|
||||
/** @var WorkRecordModel $work_record */
|
||||
$work_record = WorkRecordModel::with(['questionnaire'])->where('id',$server_id)->find();
|
||||
if(!$work_record){
|
||||
return $this->error(__('Server is not exist %sadds_f%',["%sadds_f%"=>'']));
|
||||
}
|
||||
$work_record->step_text = $work_record->getStep();
|
||||
|
||||
return $this->success(__('successful'),$work_record->toArray());
|
||||
}
|
||||
}
|
||||
@@ -324,8 +324,8 @@ class RechargeController extends BaseController{
|
||||
UserModel::money($vo->user_id,$money,\app\enum\BalanceType::RECHARGE,$vo->id);
|
||||
Hook('recharge.success',$vo);
|
||||
}catch(\Exception $e){
|
||||
log_write('充值回调失败:'.$e->getMessage());
|
||||
log_write($data);
|
||||
log_alert('充值回调失败:'.$e->getMessage());
|
||||
log_alert($data);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@@ -363,8 +363,8 @@ class RechargeController extends BaseController{
|
||||
UserModel::money($vo->user_id,$money,\app\enum\BalanceType::RECHARGE,$vo->id);
|
||||
Hook('recharge.success',$vo);
|
||||
}catch(\Exception $e){
|
||||
log_write('充值回调失败:'.$e->getMessage());
|
||||
log_write($data);
|
||||
log_alert('充值回调失败:'.$e->getMessage());
|
||||
log_alert($data);
|
||||
return response("FAIL");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,9 @@ use support\think\Db;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* 用户角色
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
* VIP
|
||||
*/
|
||||
class RoleController extends BaseController{
|
||||
class ThaliController extends BaseController{
|
||||
/**
|
||||
* 不需要鉴权的方法
|
||||
* @var array
|
||||
@@ -20,17 +18,8 @@ class RoleController extends BaseController{
|
||||
* 无需登录及鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedLogin = ['recent'];
|
||||
public $noNeedLogin = ['recent','list'];
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("当前角色信息")
|
||||
* @Apidoc\Method("GET")
|
||||
*/
|
||||
function detail(){
|
||||
$user = \support\Jwt::getUser();
|
||||
$data = \app\model\UserRole::where('id',$user->role_id)->field('name,id,price')->find();
|
||||
return $this->success(__('successful'),$data);
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("列表")
|
||||
* @Apidoc\Method("GET")
|
||||
@@ -38,13 +27,10 @@ class RoleController extends BaseController{
|
||||
* @Apidoc\Param("limit", type="int",require=false, desc="分页大小")
|
||||
*/
|
||||
public function list(Request $request){
|
||||
$user = \support\Jwt::getUser();
|
||||
$limit = $request->get('limit',10);
|
||||
$page = $request->get('page',1);
|
||||
$kw = $request->get('kw');
|
||||
|
||||
$model = \app\model\UserRole::where('id','>',0)->field('id,name,price')
|
||||
->order('id asc');
|
||||
$model = \app\model\Thali::with(['Role'])->where('status',1)->order('id asc');
|
||||
|
||||
if($limit == 'all' || $limit >= 999999){
|
||||
$result = $model->select();
|
||||
@@ -54,14 +40,29 @@ class RoleController extends BaseController{
|
||||
}
|
||||
return $this->success(__('successful'),$result);
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("当前角色信息")
|
||||
* @Apidoc\Method("GET")
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
function detail(){
|
||||
$user = \support\Jwt::getUser();
|
||||
$data = \app\model\UserRole::where('id',$user->role_id)->field('name,id,price')->find();
|
||||
return $this->success(__('successful'),$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("最近购买列表")
|
||||
* @Apidoc\Method("GET")
|
||||
*/
|
||||
public function recent(Request $request){
|
||||
$list = (new \app\model\BalanceLog)->setSuffix('_money')->where('type',\app\enum\BalanceType::PURCHASE_ROLE->value)
|
||||
->order('created_at','desc')->limit(0,10)->field('user_id,created_at,memo')->select();
|
||||
$list = (new \app\model\BalanceLog)->setSuffix('_score')
|
||||
->where('type',\app\enum\BalanceType::PURCHASE_ROLE->value)
|
||||
->order('created_at','desc')
|
||||
->limit(0,10)
|
||||
->field('user_id,created_at,memo')
|
||||
->select();
|
||||
$list = $list->toArray();
|
||||
$data = [];
|
||||
$role_list = \app\model\UserRole::where('id', '>',1)
|
||||
@@ -81,44 +82,61 @@ class RoleController extends BaseController{
|
||||
/**
|
||||
* @Apidoc\Title("购买")
|
||||
* @Apidoc\Method("POST")
|
||||
* @Apidoc\Param("role_id", type="string",require=true, desc="要购买的角色ID")
|
||||
* @Apidoc\Param("id", type="string",require=true, desc="要购买的ID")
|
||||
* @Apidoc\Param("quantity", type="string",require=true, desc="要购买的数量(单位月)")
|
||||
* @Apidoc\Param("trade_password", type="string",require=true, desc="交易密码")
|
||||
*/
|
||||
function buy(Request $request): Response{
|
||||
$user = \support\Jwt::getUser();
|
||||
$role_id = (int)$request->post('role_id');
|
||||
if($user->role_id > $role_id){
|
||||
return $this->fail(__('Your level is too high to purchase this character'));
|
||||
}
|
||||
if(abs($role_id - $user->role_id) !== 1 && $role_id !==6){
|
||||
return $this->fail(__('Your level is too high to purchase this character'));
|
||||
}
|
||||
$role = \app\model\UserRole::where('id',$role_id)->find();
|
||||
if(!$role){
|
||||
$id = (int)$request->post('id');
|
||||
//数量
|
||||
$quantity = (int)$request->post('quantity',1);
|
||||
/**
|
||||
* @var \app\model\Thali $thali
|
||||
*/
|
||||
$thali = \app\model\Thali::where('id',$id)->find();
|
||||
if(!$thali){
|
||||
return $this->fail(__('Role does not exist'));
|
||||
}
|
||||
if($role->price <=0){
|
||||
$role_id = $thali->role_id;
|
||||
if($user->role_id >= $role_id){
|
||||
return $this->fail(__('Your level is too high to purchase this character'));
|
||||
}
|
||||
$price = $thali->price;
|
||||
if($quantity == 1){
|
||||
$price = $thali->month_price;
|
||||
}
|
||||
if($quantity == 3){
|
||||
$price = $thali->quarter_price;
|
||||
}
|
||||
if($quantity == 12){
|
||||
$price = $thali->year_price;
|
||||
}
|
||||
$amount = $price * $quantity;
|
||||
if($amount <=0){
|
||||
return $this->fail(__('This character group is not allowed to be sold'));
|
||||
}
|
||||
if($user->money < $role->price){
|
||||
if($user->score < $amount){
|
||||
return $this->fail(__('Insufficient balance'));
|
||||
}
|
||||
\support\Jwt::verify_trade_password($request->post('trade_password'));
|
||||
$amount = $role->price;
|
||||
$power = bcmul($amount,config('site.suanli_rate'),4);
|
||||
\app\model\User::where('id',$user->id)->save(['role_id'=>$role_id]);
|
||||
\app\model\User::money($user->id,-$amount,\app\enum\BalanceType::PURCHASE_ROLE,'购买用户组:'.$role_id);
|
||||
\app\model\User::score($user->id,$power,\app\enum\BalanceType::POWER_ADD,'购买用户组:'.$role_id);
|
||||
|
||||
cache_add('user_power_total_'.$user->id,$power);
|
||||
Hook('user.roleup', $user);
|
||||
$data = [
|
||||
'role_id' => $role_id,
|
||||
'user_id' => $user->id,
|
||||
'parent_id' => $user->parent_id,
|
||||
'amount' => $amount,
|
||||
];
|
||||
Hook('role.buy', $data);
|
||||
return $this->success(__('successful'));
|
||||
$user = \support\Jwt::getUser();
|
||||
$user->role_id = $role_id;
|
||||
$user->expire_at = ($user->expire_at>time() ? $user->expire_at : time())+86400* $quantity * 30;
|
||||
$user->save();
|
||||
cache('user_role_'.$user->userID,[
|
||||
'role_id'=>$role_id,'expire_at'=>$user->expire_at
|
||||
],$user->expire_at-time());
|
||||
|
||||
\app\model\User::score($user->id,-$amount,\app\enum\BalanceType::PURCHASE_ROLE,$role_id);
|
||||
//Hook('user.roleup', $user);
|
||||
// $data = [
|
||||
// 'role_id' => $role_id,
|
||||
// 'user_id' => $user->id,
|
||||
// 'parent_id' => $user->parent_id,
|
||||
// 'amount' => $amount,
|
||||
// ];
|
||||
// Hook('role.buy', $data);
|
||||
return $this->success(__('successful'),$user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user