优化统计逻辑

main
home.fengxinyhyl 8 months ago
parent 2841037b35
commit 222b624c6d
  1. 2
      app/common/repositories/store/product/ProductRepository.php
  2. 33
      app/common/repositories/user/UserAssetsLogRepository.php

@ -1325,7 +1325,7 @@ class ProductRepository extends BaseRepository
public function apiProductDetail($where, int $productType, ?int $activityId, $userInfo = null) public function apiProductDetail($where, int $productType, ?int $activityId, $userInfo = null)
{ {
$field = 'is_show,product_id,mer_id,image,slider_image,store_name,store_info,unit_name,price,cost,ot_price,stock,sales,video_link,is_hot,product_type,extension_type,old_product_id,rate,guarantee_template_id,temp_id,once_max_count,pay_limit,once_min_count,integral_rate,delivery_way,delivery_free,type,cate_id,svip_price_type,svip_price,mer_svip_status,mer_form_id,normal_intergal_one,normal_intergal_two,normal_diamond_one,normal_diamond_two,hot_intergal_one,hot_intergal_two,hot_diamond_one,hot_diamond_two,hot_intergal_rate,hot_intergal_total'; $field = 'is_show,product_id,mer_id,image,slider_image,store_name,store_info,unit_name,price,cost,ot_price,stock,sales,video_link,is_hot,product_type,extension_type,old_product_id,rate,guarantee_template_id,temp_id,once_max_count,pay_limit,once_min_count,integral_rate,delivery_way,delivery_free,type,cate_id,svip_price_type,svip_price,mer_svip_status,mer_form_id,normal_integral_one,normal_integral_two,normal_diamond_one,normal_diamond_two,hot_integral_one,hot_integral_two,hot_diamond_one,hot_diamond_two,hot_integral_rate,hot_integral_total';
$with = [ $with = [
'attr', 'attr',
'attrValue', 'attrValue',

@ -270,29 +270,36 @@ class UserAssetsLogRepository extends BaseRepository
continue; continue;
} }
// 先创建一条记录 $item = $hotRepository->getWhere(['product_id' => $productItem['product_id'], 'uid' => $order['uid']]);
$hotData = array( if($item){
'uid' => $order['uid'], $item['total'] += $product['hot_integral_total'] * $productItem['product_num'];
'order_id' => $order['order_id'], }else{
'product_id' => $productItem['product_id'], // 先创建一条记录
'create_time' => date('Y-m-d H:i:s') $hotData = array(
); 'uid' => $order['uid'],
$hotRepository->create($hotData); 'product_id' => $productItem['product_id'],
'total' => $product['hot_integral_total'] * $productItem['product_num'],
'create_time' => date('Y-m-d H:i:s')
);
$hotRepository->create($hotData);
}
// 计算每个购买当前爆单商品的积分数据 // 计算每个购买当前爆单商品的积分数据
$profit = $productItem['total_price'] - $productItem['cost']; $profit = $productItem['total_price'] - $productItem['cost'];
$list = $hotRepository->getList(['status' => 0, 'product_id' => $productItem['product_id']]); $where = array();
$where[] = array('product_id', '=', $productItem['product_id']);
$where[] = array('total', '>', 'current');
$list = $hotRepository->getList($where);
$max = $product['hot_integral_total'];
$logList = array(); $logList = array();
foreach ($list as $item){ foreach ($list as $item){
$tmp = array('integral' => $this->_getValue($profit * $product['hot_integral_rate'] / 100 / count($list))); $tmp = array('integral' => $this->_getValue($profit * $product['hot_integral_rate'] / 100 / count($list)));
if($max - $item['total'] < $tmp['integral']){ if($item['total'] - $item['current'] < $tmp['integral']){
$tmp['integral'] = $max - $item['total']; $tmp['integral'] = $item['total'] - $item['current'];
$item['status'] = 1; $item['status'] = 1;
} }
$this->userAssetsRepository->updateAssets($item['uid'], $tmp); $this->userAssetsRepository->updateAssets($item['uid'], $tmp);
$item['total'] += $tmp['integral']; $item['current'] += $tmp['integral'];
$item->save(); $item->save();
$logList[] = array( $logList[] = array(
'uid' => $item['uid'], 'uid' => $item['uid'],

Loading…
Cancel
Save