初始化项目:添加后端代码、ThinkPHP框架、前端资源

This commit is contained in:
amb
2026-09-03 12:42:39 +08:00
commit 482bece22e
3726 changed files with 416708 additions and 0 deletions
@@ -0,0 +1,43 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
/**
* 配置
*/
class Config extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\common\model\app\agent\Member();
}
/**
* 获取分销配置
* @return void
*/
public function getConfig(){
$config = \app\common\model\app\Config::getConfig('agent');
$config['member_recruit_poster'] = \addons\alivod\library\Alivod::parseContentAliovdTag($config['member_recruit_poster']);
$config['channels'] = false;
if(\app\admin\library\project\App::isInstall('channels')){
$config['channels'] = true;
}
$this->success('获取成功',$config);
}
}
@@ -0,0 +1,96 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
/**
* 下级
*/
class Customer extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\api\model\app\agent\Relation();
$this->orderModel = new \app\api\model\app\agent\Order();
}
/**
* 获取下级列表
* @return void
*/
public function getCustomerList(){
$limit = input('limit',10);
$page = input('page',1);
$order = input('order','desc');
$name = input('name','');
$where = [
'parent_id'=>$this->auth->id
];
if($name){
$where['user.nickname'] = ['like',"%{$name}%"];
}
$list = $this->model
->with(['user'])
->where($where)
->limit($limit)
->page($page)
->order('relation.createtime',$order)
->select();
if(!empty($list)){
foreach ($list as $item){
$item->user->visible(['nickname','avatar','id']);
$item->order = $this->orderModel->getChildUserOrder($item->user_id);
}
}
$this->success('获取成功', $list);
}
/**
* 获取客户详情
* @return void
*/
public function getCustomerDetail(){
$userId = input('user_id');
$where = [
'parent_id'=>$this->auth->id,
'user_id'=>$userId
];
$detail = $this->model
->with(['user'])
->where($where)
->find();
if(!$detail){
$this->error('暂时无法查看,请刷新重试');
}
$detail->user->visible(['nickname','avatar','id']);
$detail['order'] = $this->orderModel->getChildUserOrder($userId);
$this->success('获取成功', $detail);
}
}
@@ -0,0 +1,114 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
/**
* 分销商品
*/
class Goods extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\api\model\app\agent\Goods();
}
/**
* 获取分销商品列表
* @return void
*/
public function getGoodsList(){
$limit = input('limit',10);
$page = input('page',1);
$type = input('type','');
$name = input('name','');
$sort = input('sort','time');
$order = input('order','desc');
$where = [];
if($type){
$where['goods.type'] = $type;
}
if($name){
$where['goods.name'] = ['like',"%{$name}%"];
}
$where['goods.pay_type'] = ['=','pay'];
switch ($sort){
case 'time':
$sort = 'goods.createtime';
break;
case 'price':
$sort = 'goods.price';
break;
default:
$sort = 'goods.createtime';
break;
}
$list = \app\common\model\goods\Handle::getGoodsQuery()
->join(\app\api\model\app\agent\Goods::getTable() ." prop","goods.id = prop.goods_id","left")
->field(["goods.*","prop.goods_id","prop.goods_type","prop.status","prop.mode","prop.prop_rule"])
->where('goods.type', '<>', 'test')
->where('goods.sales_type', 'like', '%alone%')
->where(function ($query) {
// 部分商品的实际价格依赖关联表或历史同步结果,不能只靠 goods.price 过滤
$query->where('goods.price', '>', 0)
->whereOr('goods.type', 'vipcard')
->whereOr('goods.type', 'activity');
})
->where($where)
->where(function ($query) {
$query->where('prop.status', '<>', 2)
->whereNull('prop.status', 'OR');
})
->limit($limit)
->page($page)
->order($sort,$order)
->select();
if($list){
foreach ($list as $index => &$row) {
try{
$extendInfo = \app\common\model\goods\Handle::parseGoodsExtendInfo($row['id'],$row['type']);
if($extendInfo){
$row = array_merge($row,$extendInfo);
}
if(!isset($row['goods_id']) || !$row['goods_id']){
$row['goods_id'] = $row['id'];
}
$row['prop'] = \app\common\model\app\agent\Goods::getUserGoodsProp($this->auth->id,$row['goods_id'],$row['type'],$row['price']);
if(!isset($row['prop']) || !$row['prop']){
$row['prop'] = [
'price'=>[
'goods'=>0
]
];
}
}catch(\Exception $e){
unset($list[$index]);
}
}
}
$this->success('获取成功', $list);
}
}
@@ -0,0 +1,55 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
/**
* 配置
*/
class Level extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\common\model\app\agent\Member();
}
/**
* 获取等级列表
* @return void
*/
public function getLevelList(){
$levelList = \app\common\model\app\agent\Level::getLevelList();
$member = $this->model->getMember($this->auth->id);
$data = [
'list'=>[],
'user'=>0
];
$levelIndex = 0;
foreach ($levelList as $item){
$data['list'][] = $item;
if( isset($item['id']) && $member['level'] == $item['id']){
$data['user'] = $levelIndex;
}
$levelIndex++;
}
$this->success('获取成功', $data);
}
}
@@ -0,0 +1,44 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
/**
* 成员
*/
class Member extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\common\model\app\agent\Member();
}
public function getMember(){
$data = $this->model->getMember($this->auth->id);
$this->success('获取成功',$data);
}
/**
* 获取用户统计数据
* @return void
*/
public function getMemberTotal(){
$data = (new \app\common\model\app\agent\Member)->getMemberStatistics($this->auth->id);
$this->success('获取成功',$data);
}
}
@@ -0,0 +1,98 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
/**
* 订单
*/
class Order extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\api\model\app\agent\Order();
}
/**
* 获取统计数据
* @return void
*/
public function getTotal(){
$type = $this->request->post('type','');
$data = $this->model->getTotal($this->auth->id,$type);
$this->success("获取成功",$data);
}
/**
* 获取订单列表
* @return void
*/
public function getOrderList(){
$limit = input('limit',10);
$page = input('page',1);
$type = input('type','');
$status = input('status',0);
$uid = input('uid','');
$where = [
'beneficiary_user_id'=>$this->auth->id
];
if($uid){
$time = input('time',time());
$startOfMonth = strtotime(date('Y-m-01',$time)); // 获取当前月份的第一天的时间戳
$endOfMonth = strtotime(date('Y-m-t 23:59:59',$time)); // 获取当前月份的最后一天的时间戳
$where['order.createtime'] = ['BETWEEN',[$startOfMonth, $endOfMonth]];
$where['order_user_id'] = $uid;
}
if($type){
$where['order.type'] = $type;
}
$status--;
if($status >= 0){
$where['order.status'] = $status;
}
$list = $this->model
->with(['item','user'])
->where($where)
->limit($limit)
->page($page)
->order('createtime','desc')
->select();
if(!empty($list)){
foreach ($list as &$item){
$item->user->visible(['nickname','avatar','id']);
$item->item->visible(['item_name','item_id','total_price','count','real_price']);
$item->item->total_price = $item->item->real_price;
$item->is_channels = false;
if(\app\admin\library\project\App::isInstall('channels')){
$item->is_channels = (new \app\admin\model\app\channels\Order)->checkIsChannelsOrder($item->order_no);
}
}
}
$this->success('获取成功', $list);
}
}
@@ -0,0 +1,109 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
/**
* 分销员招募
*/
class Recruit extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\common\model\app\agent\Member();
}
/**
* 获取当前申请状态
* @return void
*/
public function getStatus(){
$code = $this->model->getAuditStatus($this->auth->id);
$this->success("获取成功",$code);
}
/**
* 获取用户列表
* @return void
*/
public function getUserCondition(){
$data = (new \app\admin\model\order\Order())->getTransactionStatistic($this->auth->id);
$this->success("获取成功",$data);
}
/**
* 提交申请
* @return void
*/
public function apply()
{
$config = \app\common\model\app\Config::getConfig('agent');
if($config['member_recruit_status'] != 1){
$this->error("当前申请通道已经关闭");
}
$code = $this->model->getAuditStatus($this->auth->id);
if($code == 2){
$this->error("已经提交过了,请耐心等待审核");
}
if($code == 1){
$this->error("审核已通过,请刷新页面");
}
//判断加入条件
$recruitModal = new \app\common\model\app\agent\Recruit();
//检查加入条件
if(!$recruitModal->checkCondition($this->auth->id)){
$this->error("不满足加入条件");
}
if($code == 4){
//创建分销员记录
$insertData = [
'uniacid'=>UNIACID,
'user_id'=>$this->auth->id,
'createtime'=>time()
];
if($config['member_recruit_audit'] ==1){
//人工审核
$insertData['status'] = 2;
$insertData['audit'] = 2;
}else{
$insertData['status'] = 1;
$insertData['audit'] = 1;
}
$this->model->insert($insertData);
}else{
//重新申请
$this->model->where([
'user_id'=>$this->auth->id
])->delete();
$this->success("撤销成功,请重新提交");
}
$this->success("提交成功");
}
}
@@ -0,0 +1,72 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
use think\Db;
/**
* 钱包
*/
class Wallet extends Api
{
//如果$noNeedLogin为空表示所有接口都需要登录才能请求
//如果$noNeedRight为空表示所有接口都需要验证权限才能请求
//如果接口已经设置无需登录,那也就无需鉴权了
//
// 无需登录的接口,*表示全部
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function getMoney(){
}
/**
* 获取资产信息
* @return void
*/
public function getMoneyLog(){
$limit = input('limit',10);
$page = input('page',1);
$mode = input('mode',0);
$time = input('time',time());
$type = input('type','money');
$where = [
'user_id'=>$this->auth->id
];
$startOfMonth = strtotime(date('Y-m-01',$time)); // 获取当前月份的第一天的时间戳
$endOfMonth = strtotime(date('Y-m-t 23:59:59',$time)); // 获取当前月份的最后一天的时间戳
$rows = new \app\api\model\app\agent\Money();
if($mode == 1){
$rows->where('before', 'exp', Db::raw('> `after`'));
}else if($mode == 2){
$rows->where('before', 'exp', Db::raw('< `after`'));
}
$list = $rows
->where($where)
->limit($limit)->page($page)
->where('createtime', 'BETWEEN', [$startOfMonth, $endOfMonth])
->order('createtime','desc')
->select();
$data = [];
if(!empty($list)){
foreach ($list as $item){
$item['value'] = $type=='money' ? $item['money'] : $item['score'];
$item['value'] = $item['value'] > 0 ? '+'.$item['value'] : $item['value'];
}
}
$this->success('获取成功', $list);
}
}
@@ -0,0 +1,168 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
use think\Db;
/**
* 提现
*/
class Withdraw extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->withdrawCardModel = new \app\api\model\app\agent\WithdrawCard();
$this->memberModel = new \app\common\model\app\agent\Member();
$this->withdrawModel = new \app\api\model\app\agent\Withdraw();
}
/**
* 提交申请
* @return void
*/
public function submit(){
$money = $this->request->post('money');
$this->check($money);
$cardDetail = $this->withdrawCardModel->getCard($this->auth->id);
Db::startTrans();
try {
$changeRet = \app\api\model\app\agent\Money::changeMoney($this->auth->id,'money',($money * -1),true,'用户提现,冻结资金');
if(!$changeRet){
$this->error("余额变更失败,请刷新重试");
}
$data = [
'user_id' => $this->auth->id,
'money' => $money,
'status' => 'waiting',
'uniacid'=>UNIACID,
'createtime' => time(),
'card_name'=>$cardDetail['name'],
'card_no'=>$cardDetail['card_no'],
'card_address'=>$cardDetail['address']
];
$ret = $this->withdrawModel->create($data);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$ret){
$this->error("可提现金额不足");
}
$this->success("提现申请已提交,请等待处理");
}
/**
* 检查
* @param $money
* @return void
*/
public function check($money){
$config = \app\common\model\app\Config::getConfig('agent');
if($config['withdraw_status'] != '1'){
$this->error("提现功能暂时关闭");
}
if($config['withdraw_minmoney'] && $money < $config['withdraw_minmoney']){
$this->error("提现最小金额为:{$config['withdraw_minmoney']}");
}
//每月可提现次数
if($config['withdraw_monthlimit']){
$monthTime = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
$monthTime = strtotime($monthTime);
$withdrawCount = $this->withdrawModel->where([
'user_id'=>$this->auth->id,
'createtime'=>['>',$monthTime]
])->count();
if($withdrawCount >= $config['withdraw_monthlimit']){
$this->error("已超出每月可提现次数{$config['withdraw_monthlimit']}次,请下月再提现");
}
}
$waiting = $this->withdrawModel->where([
'user_id' => $this->auth->id,
'status'=>'waiting'
])->field('id')->find();
if($waiting){
$this->error("尚有未处理的提现申请,请等待处理完毕后再提交");
}
$cardDetail = $this->withdrawCardModel->getCard($this->auth->id);
if(!$cardDetail){
$this->error("请完善提现银行卡信息");
}
$memberInfo = $this->memberModel->getMember($this->auth->id);
if($money > $memberInfo['money']){
$this->error("可提现金额不足");
}
}
/**
* 获取提现记录
* @return void
*/
public function getLog(){
$limit = input('limit',10);
$page = input('page',1);
$mode = input('mode',0);
$time = input('time',time());
$where = [
'user_id'=>$this->auth->id
];
$startOfMonth = strtotime(date('Y-m-01',$time)); // 获取当前月份的第一天的时间戳
$endOfMonth = strtotime(date('Y-m-t 23:59:59',$time)); // 获取当前月份的最后一天的时间戳
switch ($mode){
case 1:
$where['status'] = 'waiting';
break;
case 2:
$where['status'] = 'success';
break;
case 3:
$where['status'] = 'refuse';
break;
}
$list = $this->withdrawModel
->where($where)
->limit($limit)->page($page)
->where('createtime', 'BETWEEN', [$startOfMonth, $endOfMonth])
->order('createtime','desc')
->select();
if(!empty($list)){
foreach ($list as $item){
$item['status'] = __($item['status']);
}
}
$this->success('获取成功', $list);
}
}
@@ -0,0 +1,71 @@
<?php
namespace app\api\controller\app\agent;
use app\common\controller\Api;
/**
* 提现银行卡
*/
class WithdrawCard extends Api
{
protected $noNeedLogin = [];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\api\model\app\agent\WithdrawCard();
}
/**
* 获取银行卡信息
* @return void
*/
public function getCard(){
$data = $this->model->getCard($this->auth->id);
$this->success('获取成功', $data);
}
/**
* 设置银行卡信息
* @return void
*/
public function setCard(){
$params = [];
$params['name'] = $this->request->post('name');
$params['card_no'] = $this->request->post('card_no');
$params['address'] = $this->request->post('address');
if(in_array("",$params)){
$this->error("请完善表单后再提交");
}
$params['updatetime'] = time();
$data = $this->model->getCard($this->auth->id);
if($data){
$ret = $this->model->where([
'user_id'=>$this->auth->id
])->update($params);
}else{
$params['user_id'] = $this->auth->id;
$params['uniacid'] = UNIACID;
$ret = $this->model->insert($params);
}
if($ret){
$this->success('设置成功');
}
$this->error('设置失败,请重试');
}
}