Files
juipphp/script/test/user_level.php

61 lines
1.7 KiB
PHP
Raw Normal View History

2021-04-20 15:25:00 +08:00
<?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();
//根据等级
2021-04-20 15:48:48 +08:00
$i=1;
2021-04-20 15:25:00 +08:00
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'],
];
2021-04-20 16:06:13 +08:00
if ($info['money']>=200 && $info['money']<500){
2021-04-20 15:25:00 +08:00
$temp['discount_id'] = 1;
2021-04-20 16:06:13 +08:00
} elseif($info['money']>=500 && $info['money']<1500) {
2021-04-20 15:25:00 +08:00
$temp['discount_id'] = 2;
2021-04-20 16:06:13 +08:00
} elseif($info['money']>=1500 && $info['money']<3000) {
2021-04-20 15:25:00 +08:00
$temp['discount_id'] = 4;
2021-04-20 16:06:13 +08:00
} elseif($info['money']>=3000 && $info['money']<6000) {
2021-04-20 15:25:00 +08:00
$temp['discount_id'] = 5;
2021-04-20 16:06:13 +08:00
} elseif($info['money']>=6000) {
2021-04-20 15:25:00 +08:00
$temp['discount_id'] = 6;
}
$user_model->updateOne(['Id'=>$info['UserId'],'agent_id'=>0],$temp);
2021-04-20 15:48:48 +08:00
echo $i."\r";
$i++;
2021-04-20 15:25:00 +08:00
}