设置价格 折扣
This commit is contained in:
@@ -11,6 +11,7 @@ use app\agent\model\AgentPrice as AgentPriceModel;
|
||||
use app\agent\model\AgentScore as AgentScoreModel;
|
||||
use app\agent\model\ProductPriceDiscount as ProductPriceDiscountModel;
|
||||
use app\agent\model\ProductOrder as ProductOrderModel;
|
||||
use app\agent\model\ProductPriceScheme;
|
||||
|
||||
class Agent extends Controller
|
||||
{
|
||||
@@ -28,16 +29,27 @@ class Agent extends Controller
|
||||
$agent_user_model = new AgentUser;
|
||||
$user_model = new UserModel;
|
||||
$order_model = new ProductOrderModel;
|
||||
$discount_model = new ProductPriceScheme;
|
||||
|
||||
$user_list = $agent_user_model->getListPage($where, '*', 'id desc', "$page,50");
|
||||
|
||||
//折扣列表
|
||||
$discount_data = $discount_model->getList();
|
||||
$discount_list = [];
|
||||
$discount_list[0] = '原价';
|
||||
foreach($discount_data as $info) {
|
||||
$discount_list[$info['Id']] = $info['Name'];
|
||||
}
|
||||
|
||||
//获取代理商下的用户数
|
||||
$agent_ids = [];
|
||||
$list = [];
|
||||
foreach ($user_list as &$info){
|
||||
$info['password'] = '';
|
||||
$agent_ids[] = $info['id'];
|
||||
$info['discount'] = $discount_list[$info['discount_id']];
|
||||
$list[$info['id']] = $info;
|
||||
|
||||
}
|
||||
|
||||
$last_month_cost_money = $order_model->getLastMonthCost($agent_ids);
|
||||
@@ -359,4 +371,29 @@ class Agent extends Controller
|
||||
echo json_encode($retuen_data);
|
||||
}
|
||||
}
|
||||
|
||||
//代理折扣
|
||||
public function setUserDiscount()
|
||||
{
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
// dump($data);
|
||||
|
||||
if(!isset($data['schemeId'])){
|
||||
die;
|
||||
}
|
||||
|
||||
$agent_user_model = new AgentUser;
|
||||
|
||||
$discount_data = [
|
||||
'discount_id' => $data['schemeId']
|
||||
];
|
||||
|
||||
$agent_user_model->updateOne(['id'=>$data['userId']],$discount_data);
|
||||
$info = [
|
||||
'Code' => 10000,
|
||||
'Data' => '',
|
||||
'Message' => '',
|
||||
];
|
||||
echo json_encode($info);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use app\agent\model\ProductUserPrice;
|
||||
use app\agent\model\AgentPrice as AgentPriceModel;
|
||||
use app\agent\model\User as UserModel;
|
||||
use app\agent\model\AgentScore as AgentScoreModel;
|
||||
use app\user\model\ProductPriceScheme;
|
||||
use app\agent\model\CashOut as CashOutModel;
|
||||
|
||||
class Userinfo extends Controller
|
||||
@@ -17,8 +18,10 @@ class Userinfo extends Controller
|
||||
{
|
||||
|
||||
$agent_user_model = new AgentUser;
|
||||
$discount_model = new ProductPriceScheme;
|
||||
$userinfo = $agent_user_model->getOne(['id'=>$this->userinfo['OperaterID']]);
|
||||
$userinfo['id'] = base64_encode($userinfo['id']);
|
||||
$userinfo['discount'] = $discount_model->getOne(['Id'=>$userinfo['discount_id']])['Name'];
|
||||
|
||||
$info = [
|
||||
'Code'=>10000,
|
||||
@@ -131,8 +134,18 @@ class Userinfo extends Controller
|
||||
}
|
||||
$where['agent_id'] = $this->userinfo['OperaterID'];
|
||||
$user_model = new UserModel;
|
||||
$discount_model = new ProductPriceScheme;
|
||||
$user_list = $user_model->getListPage($where, '*', 'id desc', "$page,50");
|
||||
|
||||
|
||||
//折扣列表
|
||||
$discount_data = $discount_model->getList();
|
||||
$discount_list = [];
|
||||
$discount_list[0] = '原价';
|
||||
foreach($discount_data as $info) {
|
||||
$discount_list[$info['Id']] = $info['Name'];
|
||||
}
|
||||
|
||||
foreach ($user_list as &$info){
|
||||
$info['Password'] = '';
|
||||
if(empty($info['id_code'])){
|
||||
@@ -141,7 +154,8 @@ class Userinfo extends Controller
|
||||
$info['id_code'] = substr($info['id_code'], 0, 6) . '***';
|
||||
$info['is_verify'] = $info['is_verify']?'认证成功':'认证失败';
|
||||
}
|
||||
|
||||
$info['discount'] = $discount_list[$info['discount_id']];
|
||||
|
||||
}
|
||||
$data = [
|
||||
'Code' => 10000,
|
||||
@@ -232,4 +246,52 @@ class Userinfo extends Controller
|
||||
];
|
||||
echo json_encode($retuen_data);
|
||||
}
|
||||
|
||||
//代理折扣
|
||||
public function setUserDiscount()
|
||||
{
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
// dump($data);
|
||||
|
||||
if(!isset($data['schemeId'])){
|
||||
die;
|
||||
}
|
||||
|
||||
$user_model = new UserModel;
|
||||
$agent_user_model = new AgentUser;
|
||||
$discount_model = new ProductPriceScheme;
|
||||
|
||||
$agent_id = $this->userinfo['OperaterID'];
|
||||
$agent_info = $agent_user_model->getOne(['id'=>$agent_id]);
|
||||
//原始折扣
|
||||
$discount_old = $discount_model->getList(['Id'=>['in',[$data['schemeId'],$agent_info['discount_id']]]],'Id,discount');
|
||||
|
||||
$discount_list = [];
|
||||
foreach($discount_old as $info){
|
||||
$discount_list[$info['Id']] = $info["discount"];
|
||||
}
|
||||
|
||||
if($discount_list[$data['schemeId']]<=$discount_list[$agent_info['discount_id']]){
|
||||
$info = [
|
||||
'Code' => -10000,
|
||||
'Data' => '',
|
||||
'Message' => '不能低于您的折扣!',
|
||||
];
|
||||
echo json_encode($info);
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
$discount_data = [
|
||||
'discount_id' => $data['schemeId']
|
||||
];
|
||||
|
||||
$user_model->updateOne(['Id'=>$data['userId']],$discount_data);
|
||||
$info = [
|
||||
'Code' => 10000,
|
||||
'Data' => '',
|
||||
'Message' => '',
|
||||
];
|
||||
echo json_encode($info);
|
||||
}
|
||||
}
|
||||
21
app/agent/model/ProductPriceScheme.php
Normal file
21
app/agent/model/ProductPriceScheme.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: kangkang
|
||||
* @Date: 2020-10-15 17:31:30
|
||||
* @LastEditors: kangkang
|
||||
* @LastEditTime: 2020-10-15 17:32:22
|
||||
*/
|
||||
|
||||
namespace app\agent\model;
|
||||
|
||||
use fastphp\base\Model;
|
||||
|
||||
class ProductPriceScheme extends Model
|
||||
{
|
||||
protected $table = 'product_price_scheme';
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use app\user\model\User as UserModel;
|
||||
use app\user\model\AgentUser as AgentUser;
|
||||
use app\user\model\UserScore as UserScore;
|
||||
use app\user\model\SellCouponUserOrgin;
|
||||
use app\user\model\ProductPriceScheme;
|
||||
use fastphp\base\Controller;
|
||||
|
||||
class User extends Controller
|
||||
@@ -23,8 +24,17 @@ class User extends Controller
|
||||
$where = "LoginCode like '%".$_GET['keyWord']."%' or Phone like '%".$_GET['keyWord']."%'";
|
||||
}
|
||||
$user_model = new UserModel;
|
||||
$discount_model = new ProductPriceScheme;
|
||||
$user_list = $user_model->getUserListPage($where, '*', 'id desc', "$page,50");
|
||||
|
||||
//折扣列表
|
||||
$discount_data = $discount_model->getList();
|
||||
$discount_list = [];
|
||||
$discount_list[0] = '原价';
|
||||
foreach($discount_data as $info) {
|
||||
$discount_list[$info['Id']] = $info['Name'];
|
||||
}
|
||||
|
||||
foreach ($user_list as &$info){
|
||||
$info['Password'] = '';
|
||||
if(empty($info['id_code'])){
|
||||
@@ -34,6 +44,8 @@ class User extends Controller
|
||||
$info['is_verify'] = $info['is_verify']?'认证成功':'认证失败';
|
||||
}
|
||||
|
||||
$info['discount'] = $discount_list[$info['discount_id']];
|
||||
|
||||
if($info['CreateType'] == 4){
|
||||
$agent = new AgentUser;
|
||||
$agent_info = $agent->getOne(['id'=>$info['agent_id']]);
|
||||
@@ -269,4 +281,52 @@ class User extends Controller
|
||||
];
|
||||
echo json_encode($info);
|
||||
}
|
||||
|
||||
//设置用户的折扣价
|
||||
public function setUserDiscount()
|
||||
{
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
// dump($data);
|
||||
|
||||
if(!isset($data['schemeId'])){
|
||||
die;
|
||||
}
|
||||
|
||||
$user_model = new UserModel;
|
||||
$discount_model = new ProductPriceScheme;
|
||||
|
||||
$user_info = $user_model->getOne(['Id'=>$data['userId']]);
|
||||
//原始折扣
|
||||
$discount_old = $discount_model->getList(['Id'=>['in',[$data['schemeId'],$user_info['discount_id']]]],'Id,discount');
|
||||
|
||||
$discount_list = [];
|
||||
foreach($discount_old as $info){
|
||||
$discount_list[$info['Id']] = $info["discount"];
|
||||
}
|
||||
|
||||
if($user_info['discount_id'] != 0){
|
||||
if($discount_list[$data['schemeId']]>$discount_list[$user_info['discount_id']]){
|
||||
$info = [
|
||||
'Code' => -10000,
|
||||
'Data' => '折扣无法调高!',
|
||||
'Message' => '折扣无法调高!',
|
||||
];
|
||||
echo json_encode($info);
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$discount_data = [
|
||||
'discount_id' => $data['schemeId']
|
||||
];
|
||||
|
||||
$user_model->updateOne(['Id'=>$data['userId']],$discount_data);
|
||||
$info = [
|
||||
'Code' => 10000,
|
||||
'Data' => '',
|
||||
'Message' => '',
|
||||
];
|
||||
echo json_encode($info);
|
||||
}
|
||||
}
|
||||
|
||||
21
app/user/model/ProductPriceScheme.php
Normal file
21
app/user/model/ProductPriceScheme.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: kangkang
|
||||
* @Date: 2020-10-15 17:31:30
|
||||
* @LastEditors: kangkang
|
||||
* @LastEditTime: 2020-10-15 17:32:22
|
||||
*/
|
||||
|
||||
namespace app\user\model;
|
||||
|
||||
use fastphp\base\Model;
|
||||
|
||||
class ProductPriceScheme extends Model
|
||||
{
|
||||
protected $table = 'product_price_scheme';
|
||||
|
||||
|
||||
|
||||
}
|
||||
21
app/user/model/ProductUserPrice.php
Normal file
21
app/user/model/ProductUserPrice.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/*
|
||||
* @Descripttion:
|
||||
* @version:
|
||||
* @Author: kangkang
|
||||
* @Date: 2020-10-15 17:31:30
|
||||
* @LastEditors: kangkang
|
||||
* @LastEditTime: 2020-10-15 17:32:22
|
||||
*/
|
||||
|
||||
namespace app\user\model;
|
||||
|
||||
use fastphp\base\Model;
|
||||
|
||||
class ProductUserPrice extends Model
|
||||
{
|
||||
protected $table = 'product_user_price';
|
||||
|
||||
|
||||
|
||||
}
|
||||
57
script/test/user_level.php
Normal file
57
script/test/user_level.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
$is_script = 1;
|
||||
include_once __DIR__ . '/../../index.php';
|
||||
|
||||
|
||||
use app\api\model\User as UserModel;
|
||||
use app\api\model\ProductOrder as ProductOrderModel;
|
||||
use enum\order\ProductOrder as ProductOrderEnum;
|
||||
|
||||
$user_model = new UserModel;
|
||||
$product_order_model = new ProductOrderModel;
|
||||
|
||||
//分批操作,每次1000条
|
||||
|
||||
$order_refund_list = [];
|
||||
|
||||
//退款金额
|
||||
$order_refund_list_db = $product_order_model->field('UserId,sum(RefundAmount) as money')
|
||||
->where(['OrderState' => ['in', ProductOrderEnum::$Refunds]])
|
||||
->group(['UserId'])
|
||||
->fetchAll();
|
||||
|
||||
foreach ($order_refund_list_db as $info){
|
||||
$order_refund_list[$info['UserId']] = $info['money'];
|
||||
}
|
||||
//支付金额
|
||||
$order_pay_list_db = $product_order_model->field('UserId,sum(PaymentAmount) as money')
|
||||
->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete]])
|
||||
->group(['UserId'])
|
||||
->fetchAll();
|
||||
|
||||
|
||||
//根据等级
|
||||
foreach ($order_pay_list_db as $info){
|
||||
//如果有退款,先减去退款
|
||||
if(isset( $order_refund_list[$info['UserId']])){
|
||||
$info['money'] -= $order_refund_list[$info['UserId']];
|
||||
}
|
||||
$temp = [];
|
||||
$temp = [
|
||||
'ConsumeAmount' => $info['money'],
|
||||
];
|
||||
if ($info['money']>=500 && $info['money']<1000){
|
||||
$temp['discount_id'] = 1;
|
||||
} elseif($info['money']>=1000 && $info['money']<3000) {
|
||||
$temp['discount_id'] = 2;
|
||||
} elseif($info['money']>=3000 && $info['money']<6000) {
|
||||
$temp['discount_id'] = 4;
|
||||
} elseif($info['money']>=6000 && $info['money']<10000) {
|
||||
$temp['discount_id'] = 5;
|
||||
} elseif($info['money']>=10000) {
|
||||
$temp['discount_id'] = 6;
|
||||
}
|
||||
|
||||
$user_model->updateOne(['Id'=>$info['UserId'],'agent_id'=>0],$temp);
|
||||
}
|
||||
Reference in New Issue
Block a user