初始化项目:添加后端代码、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,71 @@
<?php
namespace app\admin\controller\app\agent;
use app\common\controller\Backend;
/**
* 分销配置
*/
class Config extends Backend
{
/**
* AttachmentGroup模型对象
* @var \app\admin\model\attachment\AttachmentGroup
*/
protected $model = null;
protected $configName = 'agent';
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config',$this->configName);
}
/**
* 获取配置
* @return mixed
*/
public function getConfig(){
$data = \app\common\model\app\Config::getConfig($this->configName);
foreach ($data['levelPlan'] as &$item){
$item['saved'] = true;
}
return $this->success("获取成功",$data);
}
/**
* 获取配置
* @return mixed
*/
public function setConfig(){
$row = $this->request->post("row/a", [], 'trim');
$data = \app\common\model\app\Config::setConfig($this->configName,$row);
return $this->success("保存成功",$data);
}
/**
* 删除等级中的level
* @return void
*/
public function delLevel(){
$index = $this->request->post("index");
$data = \app\common\model\app\Config::getConfig($this->configName);
if(isset($data['levelPlan'][$index])){
unset($data['levelPlan'][$index]);
}
$data = \app\common\model\app\Config::setConfig($this->configName,$data);
//重置受影响的level
\app\common\model\app\agent\Level::delLevelConfigReset();
return $this->success("保存成功",$data);
}
}
@@ -0,0 +1,236 @@
<?php
namespace app\admin\controller\app\agent;
use app\common\controller\Backend;
use think\Request;
/**
* 分销商品
*
* @icon fa fa-circle-o
*/
class Goods extends Backend
{
/**
* Goods模型对象
* @var \app\admin\model\app\agent\Goods
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\admin\model\app\agent\Goods;
$this->courseModel = new \app\admin\model\course\Course;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
//创建时间搜索格式转换
$filterParams = json_decode(input('filter'),true);
if(isset($filterParams['goods.createtime']) && $filterParams['goods.createtime']){
$createtimeParams = explode(" - ",$filterParams['goods.createtime']);
if($createtimeParams && count($createtimeParams) == 2){
$createtimeParams[0] = strtotime($createtimeParams[0]);
$createtimeParams[1] = strtotime($createtimeParams[1]);
//合并$createtimeParams
$createtimeParams = implode(" - ",$createtimeParams);
$filterParams['goods.createtime'] = $createtimeParams;
Request::instance()->post(['filter'=>json_encode($filterParams)]);
}
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = \app\common\model\goods\Handle::getGoodsQuery()
->join("app_agent_goods prop","goods.id = prop.goods_id","LEFT")
->order("goods.createtime", "desc")
->field(["goods.*","prop.goods_id","prop.goods_type","prop.status","prop.mode","prop.prop_rule"])
->field("CONCAT_WS('_', goods.id,goods.type) as id_type")
->group("CONCAT_WS('_', goods.id,goods.type)")
->where($where)
->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(['goods.pay_type'=>'pay'])
->paginate($limit);
if($list){
$list = $list->toArray();
foreach ($list['data'] as &$row) {
$extendInfo = \app\common\model\goods\Handle::parseGoodsExtendInfo($row['id'],$row['type']);
if($extendInfo){
$row = array_merge($row,$extendInfo);
}
if(!$row['goods_id']){
$row = array_merge($row,\app\common\model\app\ConfigDefault::$goodsProp);
$row['goods_id'] = $row['id'];
}
if($row['pay_type'] != 'pay'){
$row['disabled'] = true;
}
$row['prop'] = \app\common\model\app\agent\Goods::getGoodsAllProp($row['goods_id'],$this->getGoodsType($row['type']));
// if(!isset($row['goods_id']) || !$row['goods_id']){
// $row['goods_id'] = $row['id'];
// }
//
// if($row['pay_type'] != 'pay'){
// $row['disabled'] = true;
// }
//
// $prop = \app\common\model\app\agent\Goods::getGoodsAllProp($row['goods_id'],$row['type']);
// if($prop){
// $row = array_merge($prop['goods'],$row);
// $row['prop'] = $prop;
// }else{
// $row = array_merge($row,\app\common\model\app\ConfigDefault::$goodsProp);
// }
}
}
$result = array("total" => $list['total'], "rows" => $list['data'],'attr'=>[
'statusList'=>$this->model->getStatusList(),
'modeList'=>$this->model->getModeList(),
'goodsTypeList'=> array_merge([
'column'=>__('Column'),
'video'=>__('Video'),
'audio'=>__('Audio'),
'article'=>__('Article'),
'live'=>__('Live'),
'vipcard' => __('Vipcard'),
'activity' => __('Activity'),
'exercises' => __('Exercises'),
'physical' => __('Physical')
], \app\admin\library\project\App::isInstall('composite') ? ['composite' => '组合商品'] : [])
]);
return $this->success("获取成功",$result);
}
/**
* 获取比例详情
* @return void
*/
public function getPropDetail(){
$goodsId = $this->request->post("goods_id/a");
$goodsType = $this->request->post("goods_type/a");
if(count($goodsId) > 1){
$goodsId = 0;
$goodsType = 'article';
}else{
$goodsId = $goodsId[0];
$goodsType = $goodsType[0];
}
$data = \app\common\model\app\agent\Goods::getGoodsAllProp($goodsId,$this->getGoodsType($goodsType));
return $this->success("获取成功",$data);
}
/**
* 设置商品佣金
* @return void
*/
public function setGoodsProp()
{
$goodsIds = $this->request->post("goods_id/a");
$goodsTypes = $this->request->post("goods_type/a");
$row = $this->request->post("row/a");
if(!is_array($goodsIds)){
$goodsIds = [$goodsIds];
}
if(!is_array($goodsTypes)){
$goodsTypes = [$goodsTypes];
}
$row['prop_rule'] = json_encode($row['prop_rule'],true);
//过滤字段
$fields = ['prop_rule','status','mode'];
foreach ($row as $index => $item){
if(!in_array($index,$fields)){
unset($row[$index]);
}
}
$count = 0;
foreach ($goodsIds as $index => $goodsId){
$detail = $this->model->where([
'goods_id'=>$goodsId,
'goods_type'=>$this->getGoodsType($goodsTypes[$index])
])->find();
if(!$detail){
$row['uniacid'] = UNIACID;
$row['goods_id'] = $goodsId;
$row['goods_type'] = $this->getGoodsType($goodsTypes[$index]);
$row['createtime'] = time();
$ret = $this->model->insert($row);
}else{
$ret = $this->model->where([
'goods_id'=>$goodsId,
'goods_type'=>$this->getGoodsType($goodsTypes[$index])
])->update($row);
}
if($ret){
$count++;
}
}
return $this->success("已变更{$count}条数据");
}
public function getGoodsType($type){
if($type == 'video' || $type == 'column' || $type == 'audio' || $type == 'article' || $type == 'live'){
$type = 'course';
}
return $type;
}
}
@@ -0,0 +1,39 @@
<?php
namespace app\admin\controller\app\agent;
use app\common\controller\Backend;
/**
* 分销等级
*
* @icon fa fa-circle-o
*/
class Level extends Backend
{
/**
* Goods模型对象
* @var \app\admin\model\app\agent\Goods
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\common\model\app\agent\Level;
\app\common\model\fill\Handle::check('app_config','agent');
}
/**
* 获取等级列表
* @return mixed
*/
public function getLevel(){
$data = $this->model->getLevelList();
return $this->success("获取成功",$data);
}
}
@@ -0,0 +1,221 @@
<?php
namespace app\admin\controller\app\agent;
use app\common\controller\Backend;
use app\admin\model\app\agent\Relation as RelationModel;
use think\Db;
/**
* 分销成员
*
* @icon fa fa-circle-o
*/
class Member extends Backend
{
/**
* Member模型对象
* @var \app\admin\model\app\agent\Member
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\admin\model\app\agent\Member;
}
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$orderModel = new \app\admin\model\order\Order();
$parentWhere = [];
$relationusername = input('relationusername');
if($relationusername){
//获取符合规则的上级用户ID集合
$userIds = \app\admin\model\User::where([
'username'=>['like',"%{$relationusername}%"]
])->field("id")->select();
if($userIds){
foreach ($userIds as $id){
$ids[] = $id['id'];
}
$parentWhere['relation.parent_id'] = ['in',$ids];
}
}
$list = $this->model
->with(['user','relation'])
->where($where)
->where($parentWhere)
->order($sort, $order)
->paginate($limit);
$memberCommonModel = (new \app\common\model\app\agent\Member);
foreach ($list as &$row) {
if($row->relation){
$row->relation->parent = \app\admin\model\User::where([
'id'=>$row->relation->parent_id
])->find();
}
$row->getRelation('user')->visible(\app\admin\model\User::$listShowField);
$row->condition = $orderModel->getTransactionStatistic($row->user_id);
$row->statistics = $memberCommonModel->getMemberStatistics($row->user_id);
}
$result = array("total" => $list->total(), "rows" => $list->items());
$result['attr'] = [
'auditList'=>$this->model->getAuditList(),
'level'=>(new \app\common\model\app\agent\Level)->getLevelList()
];
return $this->success("获取成功",$result);
}
/**
* 获取分销员详情
* @return mixed
*/
public function getDetail(){
$id = $this->request->post("id");
$data = $this->model->with(['user','relation.parent'])->where([
'member.id'=>$id
])->find();
if(!$data){
return $this->error("获取信息失败,请刷新重试");
}
if($data['level'] == 0){
$data['level'] = intval($data['level']);
}
$memberCommonModel = (new \app\common\model\app\agent\Member);
$data['statistics'] = $memberCommonModel->getMemberStatistics($data['user_id']);
return $this->success("获取成功",$data);
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$parent_id = 0;
if(isset($params['parent_id'])){
$parent_id = $params['parent_id'];
unset($params['parent_id']);
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
//修改上级用户ID
(new RelationModel)->setRalation($params['user_id'],$parent_id);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success("提交成功");
}
/**
* 分销员审核
* @return void
*/
public function audit(){
$ids = $this->request->post("ids/a");
$audit = $this->request->post("audit");
if(!is_array($ids)){
$ids = [$ids];
}
$count = 0;
foreach ($ids as $id){
$data = $this->model->where([
'id'=>$id
])->find();
if(!$data){
continue;
}
if($audit == 1){
//通过申请
$data->status = 1;
$data->audit = 1;
}else{
//驳回
$data->audit = 3;
}
$ret = $data->save();
if($ret){
$count++;
}
}
return $this->success("已变更{$count}条数据");
}
}
@@ -0,0 +1,84 @@
<?php
namespace app\admin\controller\app\agent;
use app\common\controller\Backend;
/**
* 分销订单
*
* @icon fa fa-circle-o
*/
class Order extends Backend
{
/**
* Order模型对象
* @var \app\admin\model\app\agent\Order
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\admin\model\app\agent\Order;
$this->view->assign("typeList", $this->model->getTypeList());
$this->view->assign("statusList", $this->model->getStatusList());
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['orderuser','beneficiaryuser','item','ordersource'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as &$row) {
$row->item->snapshoot = json_decode($row->item->snapshoot,true);
$row->is_channels = false;
if(\app\admin\library\project\App::isInstall('channels')){
$row->is_channels = (new \app\admin\model\app\channels\Order)->checkIsChannelsOrder($row->order_no);
}
}
$result = array("total" => $list->total(), "rows" => $list->items(),'attr'=>[
'type'=>$this->model->getTypeList(),
'status'=>$this->model->getStatusList(),
'mode'=>$this->model->getModeList(),
'paytype'=>(new \app\admin\model\order\Order())->getPayTypeList()
]);
return $this->success("获取成功",$result);
}
}
@@ -0,0 +1,117 @@
<?php
namespace app\admin\controller\app\agent;
use app\common\controller\Backend;
/**
* 提现管理
*
* @icon fa fa-circle-o
*/
class Withdraw extends Backend
{
/**
* Withdraw模型对象
* @var \app\admin\model\app\agent\Withdraw
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
\app\common\model\fill\Handle::check('app_config','agent');
$this->model = new \app\admin\model\app\agent\Withdraw;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['user','member'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
$row->getRelation('user')->visible(\app\admin\model\User::$listShowField);
}
$result = array("total" => $list->total(), "rows" => $list->items(),'attr'=>[
'status'=>$this->model->getStatusList()
]);
return $this->success("获取成功",$result);
}
/**
* 审批提现
* @return void
*/
public function audit(){
$id = $this->request->post("id");
$status = $this->request->post("status");
$remark = $this->request->post("remark");
$status = $status == 1 ? 'success' : 'refuse';
$data = $this->model->where([
'id'=>$id
])->find();
if(!$data){
$this->error("获取提现记录异常,请重试");
}
if($data['status'] != 'waiting'){
$this->error("该记录已经处理过了");
}
if($remark){
$data->remark = $remark;
}
if($status == 'success'){
//通过 移除冻结资金
\app\api\model\app\agent\Money::changeMoney($data['user_id'],'money_freeze', ($data['money'] * -1),false,'提现成功,移除冻结资金');
//增加提现金额
\app\api\model\app\agent\Money::changeMoney($data['user_id'],'money_withdraw',$data['money'],false,false);
}else{
//拒绝 返还冻结资金
\app\api\model\app\agent\Money::changeMoney($data['user_id'],'money',$data['money'],true,'提现驳回,返回冻结资金');
}
$data->status = $status;
$data->updatetime = time();
$data->save();
return $this->success("操作成功");
}
}