jh-admin/app/api/controller/Memberaccount.php

171 lines
6.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Index.php
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
* =========================================================
* Copy right 2023-2033 成都SAAS云科技有限公司, 保留所有权利。
* ----------------------------------------------
* 官方网址: https://www.gobuysaas.com
* =========================================================
* @author : small
* @date : 2022.8.8
* @version : v5.0.0.1
*/
namespace app\api\controller;
use app\model\account\Account as accountModel;
use app\model\member\MemberAccount as MemberAccountModel;
use app\model\member\Member as MemberModel;
class Memberaccount extends BaseApi
{
/**
* 基础信息
*/
public function info()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$account_type = isset($this->params[ 'account_type' ]) ? $this->params[ 'account_type' ] : 'balance,balance_money'; //账户类型 余额:balance积分:point
if (!in_array($account_type, [ 'point', 'balance', 'balance,balance_money' ])) return $this->response($this->error('', 'INVALID_PARAMETER'));
$member_model = new MemberModel();
$info = $member_model->getMemberInfo([ [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ] ], $account_type);
return $this->response($info);
}
/**
* 列表信息
*/
public function page()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
$page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
$account_type = isset($this->params[ 'account_type' ]) ? $this->params[ 'account_type' ] : 'balance,balance_money';//账户类型 余额:balance积分:point
$start_time = empty($this->params[ 'date' ]) ? strtotime(date('Y-m', strtotime("today"))) : strtotime($this->params[ 'date' ]);
$end_time = strtotime("+1 month", $start_time);
$from_type = isset($this->params[ 'from_type' ]) ? $this->params[ 'from_type' ] : '';
$related_id = isset($this->params[ 'related_id' ]) ? $this->params[ 'related_id' ] : 0;
if (!in_array($account_type, [ 'point', 'balance', 'balance,balance_money' ])) return $this->response($this->error('', 'INVALID_PARAMETER'));
$condition[] = [ 'account_type', 'in', $account_type ];
$condition[] = [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ];
if ($this->params['app_type'] != 'pc') {
$condition[] = [ 'create_time', 'between', [ $start_time, $end_time ] ];
}
if (!empty($from_type)) {
$condition[] = [ 'from_type', '=', $from_type ];
}
if (!empty($related_id)) {
$condition[] = [ 'related_id', '=', $related_id ];
}
$member_account_model = new MemberAccountModel();
$list = $member_account_model->getMemberAccountPageList($condition, $page, $page_size);
return $this->response($list);
}
/**
* 获取类型
* @return false|string
*/
public function fromType()
{
$member_account_model = new MemberAccountModel();
$lists = $member_account_model->getFromType();
return $this->response($lists);
}
/**
* 获取账户总额
*/
public function sum()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$account_type = $this->params[ 'account_type' ] ?? 'point'; // 账户类型 余额:balance积分:point
$from_type = $this->params[ 'from_type' ] ?? '';
$query_type = $this->params[ 'query_type' ] ?? ''; // 查询类型 收入income 支出pay
$start_time = $this->params[ 'start_time' ] ?? 0;
$end_time = $this->params[ 'end_time' ] ?? 0;
if (!in_array($account_type, [ 'point', 'balance', 'balance_money', 'growth' ])) return $this->response($this->error('', 'INVALID_PARAMETER'));
$member_account_model = new MemberAccountModel();
$condition = [
[ 'member_id', '=', $this->member_id ],
[ 'site_id', '=', $this->site_id ],
[ 'account_type', '=', $account_type ]
];
if (!empty($from_type)) $condition[] = [ 'from_type', '=', $from_type ];
if ($query_type == 'income') $condition[] = [ 'account_data', '>', 0 ];
if ($query_type == 'pay') $condition[] = [ 'account_data', '<', 0 ];
if ($start_time && $end_time) $condition[] = [ 'create_time', 'between', [ $start_time, $end_time ] ];
$data = $member_account_model->getMemberAccountSum($condition, 'account_data');
return $this->response($data);
}
/**
* 获取用户可用余额
* @return false|string
*/
public function usableBalance()
{
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$data = ( new MemberModel() )->getMemberUsableBalance($this->site_id, $this->member_id);
return $this->response($data);
}
public function withdraw(){
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$set = (new accountModel())->getPointConfig($this->site_id);
$member_model = new MemberModel();
$info = $member_model->getMemberInfo([ [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ] ]);
$set['member_point'] = $info['data']['point'];
return $this->response($set);
}
public function search(){
$search = $this->params[ 'search' ];
if($search){
$member_model = new MemberModel();
$condition = [
['member_id|mobile', '=' ,$search]
];
$info = $member_model->getMemberInfo($condition,'member_id,nickname');
if($info['data']){
return $this->response($this->success($info['data']));
}else{
return $this->response($this->error($search,'未找到此用户'));
}
}else{
return $this->response($this->error($search,'请输入需要转赠的用户信息'));
}
}
public function give(){
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
$give_id = $this->params[ 'give_id' ];
$point = $this->params[ 'point' ];
if($give_id && $point){
$member_model = new MemberAccountModel();
$res = $member_model->giveMemberPoint($give_id,$token[ 'data' ][ 'member_id' ],$point,$this->site_id);
return $this->response($res);
}else{
return $this->response($this->error([$give_id,$point],'请输入需要转赠的用户信息'));
}
}
}