|
|
@@ -9,6 +9,8 @@ use bizHd\custom\classes\CustomClass;
|
|
|
use bizHd\custom\classes\HdClass;
|
|
|
use bizHd\member\classes\MemberLevelClass;
|
|
|
use bizHd\purchase\classes\PurchaseClass;
|
|
|
+use bizHd\shop\models\Shop;
|
|
|
+use common\components\dict;
|
|
|
use common\components\noticeUtil;
|
|
|
use common\components\util;
|
|
|
use bizHd\user\classes\UserClass;
|
|
|
@@ -148,76 +150,82 @@ class CustomController extends Controller
|
|
|
// 把所有客户的累计消费和成长值、积分都刷新一下
|
|
|
public function actionRefreshCustomData()
|
|
|
{
|
|
|
-
|
|
|
- ini_set('memory_limit', '2045M');
|
|
|
- set_time_limit(0);
|
|
|
-
|
|
|
- $redisKey = 'refresh_custom_data_processed_shops';
|
|
|
-
|
|
|
- // 1. 查询 xhShop 表,获取所有 ptStyle = 1 的门店数据,每次取出500个进行处理
|
|
|
- $query = \bizHd\shop\models\Shop::find()
|
|
|
- ->select('id, mainId')
|
|
|
- ->where(['ptStyle' => 1])
|
|
|
- ->orderBy('id DESC')
|
|
|
- ->asArray();
|
|
|
-
|
|
|
- // 2. 把每个门店下的所有用户进行遍历,刷新他们的累计消费和成长值、积分
|
|
|
- foreach ($query->batch(500) as $allShops) {
|
|
|
- if (!empty($allShops)) {
|
|
|
- foreach ($allShops as $shop) {
|
|
|
- $shopId = $shop['id'];
|
|
|
- $mainId = $shop['mainId'];
|
|
|
-
|
|
|
- // 判断是否已经执行过,执行过则跳过
|
|
|
- $hasProcessed = Yii::$app->redis->executeCommand('SISMEMBER', [$redisKey, $shopId]);
|
|
|
- if ($hasProcessed) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- $customs = CustomClass::getAllByCondition(['shopId' => $shopId], null, 'id, userId, buyAmount, growth, member, memberName', null, true);
|
|
|
- $levelDatas = MemberLevelClass::getAllByCondition(['mainId' => $mainId], 'amount DESC', 'id, name, level, amount');
|
|
|
- if (!empty($customs) && !empty($levelDatas)) {
|
|
|
- foreach ($customs as $c) {
|
|
|
- $buyAmount = 0;
|
|
|
- // 获取所有零售订单,计算消费金额
|
|
|
- $orderList = \bizHd\order\classes\OrderClass::getAllByCondition(['customId' => $c->id], null, 'id, forward, actPrice');
|
|
|
- if (!empty($orderList)) {
|
|
|
- foreach ($orderList as $order) {
|
|
|
- if ($order['forward'] == 0) { //0 常规订单
|
|
|
- $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
|
|
|
- } elseif ($order['forward'] == 1) { //1 售后付款单(红冲)
|
|
|
- $buyAmount = bcsub($buyAmount, $order['actPrice'], 2);
|
|
|
- } else {
|
|
|
- Yii::info('订单类型不存在,订单ID:' . $order['id']);
|
|
|
- continue;
|
|
|
+ try {
|
|
|
+ ini_set('memory_limit', '2045M');
|
|
|
+ set_time_limit(0);
|
|
|
+
|
|
|
+ // 1. 查询 xhShop 表,获取所有 ptStyle = 1 的门店数据,每次取出500个进行处理
|
|
|
+ $query = Shop::find()
|
|
|
+ ->select('id, mainId')
|
|
|
+ ->where(['ptStyle' => 1])
|
|
|
+ ->orderBy('id DESC')
|
|
|
+ ->asArray();
|
|
|
+
|
|
|
+ // 2. 把每个门店下的所有用户进行遍历,刷新他们的累计消费和成长值、积分
|
|
|
+ foreach ($query->batch(500) as $allShops) {
|
|
|
+ if (!empty($allShops)) {
|
|
|
+ foreach ($allShops as $shop) {
|
|
|
+ $shopId = $shop['id'];
|
|
|
+ $mainId = $shop['mainId'];
|
|
|
+
|
|
|
+ echo '门店id:' . $shopId;
|
|
|
+
|
|
|
+ $customList = CustomClass::getAllByCondition(['shopId' => $shopId], null, 'id, userId, balance, buyAmount, growth, integral, member, memberName', null, true);
|
|
|
+ $levelData = MemberLevelClass::getAllByCondition(['mainId' => $mainId], 'amount DESC', 'id, name, level, amount');
|
|
|
+ if (!empty($customList)) {
|
|
|
+ foreach ($customList as $custom) {
|
|
|
+ $buyAmount = 0;
|
|
|
+ // 获取所有零售订单,计算消费金额
|
|
|
+ $orderList = \bizHd\order\classes\OrderClass::getAllByCondition(['customId' => $custom->id, 'payStatus' => 1], null, 'id, forward, actPrice, payWay');
|
|
|
+ if (!empty($orderList)) {
|
|
|
+ foreach ($orderList as $order) {
|
|
|
+ if ($order['forward'] == 0) { //0 常规订单
|
|
|
+ $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
|
|
|
+ } else { //1 红冲
|
|
|
+ $buyAmount = bcsub($buyAmount, $order['actPrice'], 2);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ $custom->buyAmount = $buyAmount;
|
|
|
+ $balance = $custom->balance ?? 0;
|
|
|
+ if ($balance > 0) {
|
|
|
+ $total = bcadd($balance, $buyAmount, 2);
|
|
|
+ } else {
|
|
|
+ $total = $buyAmount;
|
|
|
+ }
|
|
|
+ $custom->growth = $total;
|
|
|
+ $custom->integral = $total;
|
|
|
+//echo " customId:" . $custom->id;
|
|
|
+ // 根据 growth 设置等级
|
|
|
+ $memberData = CustomClass::getCustomExpenseLevel($custom->growth, $mainId, $levelData); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
|
|
|
+//echo "--+--- ";
|
|
|
+ $level = $memberData['level'] ?? 0;
|
|
|
+ $level = trim($level);
|
|
|
+ $level = floatval($level);
|
|
|
+ $memberName = $memberData['name'] ?? '';
|
|
|
+ $memberName = trim($memberName);
|
|
|
+//echo $level."+".$memberName;
|
|
|
+ $custom->member = $level;
|
|
|
+ $custom->memberName = $memberName;
|
|
|
+ //$custom->listend = false; //关闭对 xhCustom 的 buyAmount 变动监听
|
|
|
+ $custom->save();
|
|
|
+//echo " 0000 \n";
|
|
|
+ // 更新客户所对应花店的消费金额
|
|
|
+ $hdId = $custom->hdId;
|
|
|
+ if (!empty($hdId)) {
|
|
|
+ HdClass::updateById($hdId, ['expendAmount' => $buyAmount]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- $c->buyAmount = $buyAmount;
|
|
|
- $c->growth = $buyAmount;
|
|
|
- $c->integral = $buyAmount;
|
|
|
-
|
|
|
- // 根据 growth 设置等级
|
|
|
- $memberData = CustomClass::getCustomExpenseLevel($c->growth, $mainId, $levelDatas); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
|
|
|
- $c->member = $memberData['level'];
|
|
|
- $c->memberName = $memberData['name'];
|
|
|
- $c->listend = false; //关闭对 xhCustom 的 buyAmount 变动监听
|
|
|
- $c->save();
|
|
|
-
|
|
|
- // 更新客户所对应花店的消费金额
|
|
|
- HdClass::updateByCondition(['shopId' => $shopId, 'userId' => $c->userId], ['expendAmount' => $buyAmount]);
|
|
|
}
|
|
|
+//echo "\n";
|
|
|
}
|
|
|
-
|
|
|
- // 记录该 shopId 已经执行完成
|
|
|
- Yii::$app->redis->executeCommand('SADD', [$redisKey, $shopId]);
|
|
|
}
|
|
|
+ echo "end\n";
|
|
|
}
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Yii::error('把所有客户的累计消费和成长值、积分都刷新一下脚本执行失败,原因:' . $e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
- // 脚本执行完之后,清除缓存
|
|
|
- Yii::$app->redis->executeCommand('DEL', [$redisKey]);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//批量创建客户
|