代理商
This commit is contained in:
235
app/agent/controller/Agent.php
Normal file
235
app/agent/controller/Agent.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
|
||||
namespace app\agent\controller;
|
||||
|
||||
use fastphp\base\Controller;
|
||||
use app\agent\model\AgentUser;
|
||||
use app\agent\model\User as UserModel;
|
||||
use app\agent\model\Product as PoductModel;
|
||||
use app\agent\model\ProductPackage as PoductPackageModel;
|
||||
use app\agent\model\AgentPrice as AgentPriceModel;
|
||||
use app\agent\model\AgentScore as AgentScoreModel;
|
||||
|
||||
class Agent extends Controller
|
||||
{
|
||||
//代理商列表
|
||||
public function getList ()
|
||||
{
|
||||
$page = 0;
|
||||
if (isset($_GET['PageIndex'])) {
|
||||
$page = ($_GET['PageIndex'] - 1) * 50;
|
||||
}
|
||||
$where = [];
|
||||
if(!empty($_GET['keyWord'])){
|
||||
$where['username'] = $_GET['keyWord'];
|
||||
}
|
||||
$agent_user_model = new AgentUser;
|
||||
$user_model = new UserModel;
|
||||
$user_list = $agent_user_model->getListPage($where, '*', 'id desc', "$page,50");
|
||||
|
||||
//获取代理商下的用户数
|
||||
$agent_ids = [];
|
||||
$list = [];
|
||||
foreach ($user_list as &$info){
|
||||
$info['password'] = '';
|
||||
$agent_ids[] = $info['id'];
|
||||
$list[$info['id']] = $info;
|
||||
}
|
||||
$agent_user_num = $user_model->getAgentUser(['agent_id'=>['in',$agent_ids]]);
|
||||
foreach ($agent_user_num as $info){
|
||||
$list[$info['agent_id']]['user_num'] = $info['num'];
|
||||
}
|
||||
$list = array_merge($list);
|
||||
|
||||
$data = [
|
||||
'Code' => 10000,
|
||||
'Data' => $list,
|
||||
'Message' => '',
|
||||
'TotalCount' => (int)$agent_user_model->getCount($where)['count'],
|
||||
];
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
//设置代理商最低价格价格表
|
||||
public function price()
|
||||
{
|
||||
$id = $_GET['userId'];
|
||||
$list = [];
|
||||
$product_model = new PoductModel;
|
||||
$package_model = new PoductPackageModel;
|
||||
$price_model = new AgentPriceModel;
|
||||
$product = $product_model->getList(['OnLine'=>1,'Id'=>['<>',11]], '*', 'Sort asc');
|
||||
$package = $package_model->getList([], '*', 'TenantId asc');
|
||||
$price = $price_model->getList(['agent_id'=>$id], '*');
|
||||
|
||||
//按照套餐整理价格
|
||||
$price_list = [];
|
||||
foreach($price as $info){
|
||||
$price_list[$info['package_id']] = $info;
|
||||
}
|
||||
|
||||
|
||||
//按照产品整理价格
|
||||
$package_list = [];
|
||||
foreach($package as $info){
|
||||
$package_list[$info['ProductId']][] = $info;
|
||||
}
|
||||
|
||||
//处理数据
|
||||
foreach ($product as $p_info){
|
||||
$temp = [];
|
||||
$temp['Product'] = $p_info;
|
||||
$package_temp = [];
|
||||
|
||||
//套餐分离
|
||||
foreach ($package_list[$p_info['Id']] as $pack_info){
|
||||
$pack_temp = [];
|
||||
$pack_temp['Package'] = $pack_info;
|
||||
//若没有价格 默认价格
|
||||
if(empty($price_list[$pack_info['Id']])){
|
||||
$price_list[$pack_info['Id']]['refund'] = $p_info['RefundDayPrice'];
|
||||
$price_list[$pack_info['Id']]['price'] = $pack_info['Price'];
|
||||
}
|
||||
$pack_temp['UserPrice'] = $price_list[$pack_info['Id']];
|
||||
$package_temp[] = $pack_temp;
|
||||
}
|
||||
$temp['PackageUserPrices'] = $package_temp;
|
||||
|
||||
$list[] = $temp;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'Code' => 10000,
|
||||
'Data' => $list,
|
||||
'Message' => '',
|
||||
];
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
//设置最低价
|
||||
public function setPrice()
|
||||
{
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$price_model = new AgentPriceModel;
|
||||
|
||||
$update_data = [
|
||||
'product_id' => $data['ProductId'],
|
||||
'package_id' => $data['PackageId'],
|
||||
'agent_id' => $data['UserId'],
|
||||
'price' => $data['UserPrice'],
|
||||
'refund' => $data['RefundDayPrice'],
|
||||
];
|
||||
|
||||
$where = [
|
||||
'package_id' => $data['PackageId'],
|
||||
'agent_id' => $data['UserId']
|
||||
];
|
||||
|
||||
$agent_price = $price_model->getOne($where);
|
||||
|
||||
if(empty($agent_price)){
|
||||
$price_model->add($update_data);
|
||||
} else {
|
||||
$price_model->updateOne($where,$update_data);
|
||||
}
|
||||
|
||||
$retuen_data = [
|
||||
'Code' => 10000,
|
||||
'Message' => '',
|
||||
];
|
||||
echo json_encode($retuen_data);
|
||||
}
|
||||
|
||||
//是否启用修改后的价格
|
||||
public function setPriceStatus()
|
||||
{
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$price_model = new AgentPriceModel;
|
||||
$id = $data['id'];
|
||||
$update_data['status'] = $data['status'];
|
||||
|
||||
$where = ['id'=>$id];
|
||||
if($price_model->updateOne($where,$update_data)){
|
||||
$retuen_data = [
|
||||
'Code' => 10000,
|
||||
'Message' => '',
|
||||
];
|
||||
echo json_encode($retuen_data);
|
||||
die;
|
||||
} else {
|
||||
$retuen_data = [
|
||||
'Code' => -10000,
|
||||
'Message' => '操作失败',
|
||||
];
|
||||
echo json_encode($retuen_data);
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
//添加代理商
|
||||
public function addAgent()
|
||||
{
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
$data['password'] = cToMd5($data['password']);
|
||||
$agent_user_model = new AgentUser;
|
||||
|
||||
$agent_user_model->add($data);
|
||||
|
||||
$retuen_data = [
|
||||
'Code' => 10000,
|
||||
'Message' => '操作成功',
|
||||
];
|
||||
echo json_encode($retuen_data);
|
||||
die;
|
||||
}
|
||||
|
||||
//代理商充值扣款
|
||||
public function account()
|
||||
{
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
$agent_user_model = new AgentUser;
|
||||
$score_model = new AgentScoreModel;
|
||||
|
||||
$update_data = [];
|
||||
$score = [];
|
||||
$id = $data['id'];
|
||||
|
||||
$agent = $agent_user_model->getOne(['id'=>$id]);
|
||||
if($data['opAmountType'] == 1){
|
||||
$update_data['account'] = $data['rest'] + $data['amount'];
|
||||
$score['agent_id'] = $id;
|
||||
$score['order_id'] = 0;
|
||||
$score['score_type'] = 3;
|
||||
$score['score_value'] = $data['amount'];
|
||||
$score['agent_name'] = $agent['username'];
|
||||
$score['op_user'] = $this->userinfo['LoginName'];
|
||||
$score['rest_amount1'] = $agent['account'];
|
||||
$score['rest_amount2'] = $update_data['account'];
|
||||
$score['remark'] = $data['attchInfo'];
|
||||
} else {
|
||||
$update_data['account'] = $data['rest'] - $data['amount'];
|
||||
$score['agent_id'] = $id;
|
||||
$score['order_id'] = 0;
|
||||
$score['score_type'] = 4;
|
||||
$score['score_value'] = $data['amount'];
|
||||
$score['agent_name'] = $agent['username'];
|
||||
$score['op_user'] = $this->userinfo['LoginName'];
|
||||
$score['rest_amount1'] = $agent['account'];
|
||||
$score['rest_amount2'] = $update_data['account'];
|
||||
$score['remark'] = $data['attchInfo'];
|
||||
}
|
||||
|
||||
|
||||
if($agent_user_model->updateOne(['id'=>$id],$update_data)){
|
||||
|
||||
$score_model->add($score);
|
||||
|
||||
$retuen_data = [
|
||||
'Code' => 10000,
|
||||
'Message' => '操作成功',
|
||||
];
|
||||
echo json_encode($retuen_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user