代理商

This commit is contained in:
“wanyongkang”
2021-02-21 18:18:26 +08:00
parent 41e1742f82
commit a53ec5cf96
14 changed files with 732 additions and 1 deletions

View File

@@ -4,6 +4,8 @@ namespace app\agent\controller;
use fastphp\base\Controller;
use app\agent\model\AgentUser;
use app\agent\model\ProductUserPrice;
use app\agent\model\AgentPrice as AgentPriceModel;
use app\agent\model\User as UserModel;
class Userinfo extends Controller
@@ -23,6 +25,57 @@ class Userinfo extends Controller
echo json_encode($info);
}
//代理商修改密码
public function updatePass()
{
$data = json_decode(file_get_contents("php://input"), true);
$agent_user_model = new AgentUser;
$userinfo = $agent_user_model->getOne(['id'=>$this->userinfo['OperaterID']]);
if($userinfo['password'] != cToMd5($data['old_pass'])){
$info = [
'Code' => -10000,
'Message' => '旧密码错误',
];
echo json_encode($info);
die;
}
$update = [
'password' => cToMd5($data['new_pass'])
];
if($agent_user_model->updateOne(['id'=>$this->userinfo['OperaterID']],$update)){
$info = [
'Code' => 10000,
'Message' => '更新成功',
];
echo json_encode($info);
die;
} else {
$info = [
'Code' => -10000,
'Message' => '更新失败',
];
echo json_encode($info);
}
}
//验证是否是该代理的用户
public function verify()
{
$data = json_decode(file_get_contents("php://input"), true);
$user_id = $data['user_id'];
$agent_id = $this->userinfo['OperaterID'];
$user_model = new UserModel;
$userinfo = $user_model->getOne(['Id'=>$user_id]);
if($userinfo['agent_id'] != $agent_id){
die;
}
$info = [
'Code' => 20000,
'Message' => '请正确操作',
];
echo json_encode($info);
}
//代理商下的用户
public function getList ()
{
@@ -56,4 +109,85 @@ class Userinfo extends Controller
];
echo json_encode($data);
}
//获取代理最低价
public function getAgentPrice()
{
$data = json_decode(file_get_contents("php://input"), true);
$agent_price_model = new AgentPriceModel;
$agent_id = $this->userinfo['OperaterID'];
$where = [
'agent_id' => $agent_id,
'package_id' => $data['Id']
];
$price = $agent_price_model->getOne($where);
$retuen_data = [
'Code' => 30000,
'Data' => $price,
'Message' => '',
];
echo json_encode($retuen_data);
}
//设置价格
public function setPrice()
{
$data = json_decode(file_get_contents("php://input"), true);
$price_model = new ProductUserPrice;
$agent_price_model = new AgentPriceModel;
$agent_id = $this->userinfo['OperaterID'];
$where = [
'agent_id' => $agent_id,
'package_id' => $data['PackageId']
];
$agent_price = $agent_price_model->getOne($where);
if($data['UserPrice']<$agent_price['price'] || $data['RefundDayPrice']<$agent_price['refund']){
$retuen_data = [
'Code' => -10000,
'Message' => '低于最低价格',
];
echo json_encode($retuen_data);
die;
}
$update_data = [
'TenantId' => 0,
'ProductId' => $data['ProductId'],
'PackageId' => $data['PackageId'],
'UserId' => $data['UserId'],
'UserPrice' => $data['UserPrice'],
'RefundDayPrice' => $data['RefundDayPrice'],
'Status' => 1,
'DeleteTag' => 0
];
$where = [
'PackageId' => $data['PackageId'],
'UserId' => $data['UserId']
];
$user_price = $price_model->getOne($where);
if(empty($user_price)){
$price_model->add($update_data);
} else {
$price_model->updateOne($where,$update_data);
}
$retuen_data = [
'Code' => 10000,
'Message' => '',
];
echo json_encode($retuen_data);
}
}