main
fengxinyhyl 10 months ago
parent 023f290e1e
commit 25a6e4d538
  1. 5
      app/common/repositories/store/order/StoreOrderHotRepository.php
  2. 78
      app/common/repositories/user/UserAssetsLogRepository.php
  3. 4
      app/controller/api/Auth.php

@ -36,4 +36,9 @@ class StoreOrderHotRepository extends BaseRepository
$this->dao->create($data); $this->dao->create($data);
} }
public function getList($where){
return $this->dao->selectWhere($where);
}
} }

@ -22,6 +22,7 @@ use app\common\repositories\system\groupData\GroupDataRepository;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\facade\Cache;
use think\facade\Log; use think\facade\Log;
/** /**
@ -52,7 +53,10 @@ class UserAssetsLogRepository extends BaseRepository
const STATUS_WITHDRAW = 3; // 提现 const STATUS_WITHDRAW = 3; // 提现
public function __construct(UserAssetsLogDao $dao, UserAssetsRepository $userAssetsRepository, ProductRepository $productRepository, GroupDataRepository $groupRepository) public function __construct(UserAssetsLogDao $dao, UserAssetsRepository $userAssetsRepository,
ProductRepository $productRepository, GroupDataRepository $groupRepository,
UserRepository $userRepository
)
{ {
$this->dao = $dao; $this->dao = $dao;
/** /**
@ -64,6 +68,11 @@ class UserAssetsLogRepository extends BaseRepository
*/ */
$this->productRepository = $productRepository; $this->productRepository = $productRepository;
$this->groupDataRepository = $groupRepository; $this->groupDataRepository = $groupRepository;
/**
* @var UserRepository $userRepository
*/
$this->userRepository = $userRepository;
} }
/** /**
@ -133,28 +142,57 @@ class UserAssetsLogRepository extends BaseRepository
$orderRepository = app(StoreOrderRepository::class); $orderRepository = app(StoreOrderRepository::class);
/** /**
* @var StoreOrderHotRepository * @var StoreOrderHotRepository $hotRepository
*/ */
$hotRepository = app(StoreOrderHotRepository::class); $hotRepository = app(StoreOrderHotRepository::class);
$order = $orderRepository->getDetail($orderItem['order_id']); $order = $orderRepository->getDetail($orderItem['order_id']);
// Log::info("order is".json_encode($order));
foreach ($order['orderProduct'] as $productItem){ foreach ($order['orderProduct'] as $productItem){
$product = $this->productRepository->get($productItem['product_id']); $product = $this->productRepository->get($productItem['product_id']);
Log::info("product is". json_encode($product)); Log::info("product is". json_encode($product));
if($product['is_hot']){
$hotData = array( if(empty($product['is_hot'])){
'uid' => $order['uid'], continue;
'order_id' => $order['order_id'], }
// 先创建一条记录
$hotData = array(
'uid' => $order['uid'],
'order_id' => $order['order_id'],
'product_id' => $productItem['product_id'],
'create_time' => date('Y-m-d H:i:s')
);
$hotRepository->create($hotData);
// 计算每个购买当前爆单商品的积分数据
$profit = $productItem['total_price'] - $productItem['cost'];
$list = $hotRepository->getList(['status' => 0, 'product_id' => $productItem['product_id']]);
$max = $product['hot_integral_total'];
$logList = array();
foreach ($list as $item){
$tmp = array('integral' => $this->_getValue($profit * $product['hot_integral_rate'] / 100 / count($list)));
if($max - $item['total'] < $tmp['integral']){
$tmp['integral'] = $max - $item['total'];
$item['status'] = 1;
}
$this->userAssetsRepository->updateAssets($item['uid'], $tmp);
$item['total'] += $tmp['integral'];
$item->save();
$logList[] = array(
'uid' => $item['uid'],
'asset_type' => self::ASSET_TYPE_INTEGRAL,
'type' => self::CHANGE_TYPE_RECOMMEND_PRODUCT,
'status' => self::STATUS_GET,
'product_id' => $productItem['product_id'], 'product_id' => $productItem['product_id'],
'create_time' => date('Y-m-d H:i:s') 'order_id' => $order['order_id'],
'count' => $tmp['integral'],
); );
$hotRepository->create($hotData);
} }
$this->addLog($logList);
} }
} }
@ -173,8 +211,6 @@ class UserAssetsLogRepository extends BaseRepository
$orderRepository = app(StoreOrderRepository::class); $orderRepository = app(StoreOrderRepository::class);
$order = $orderRepository->getDetail($orderId); $order = $orderRepository->getDetail($orderId);
// Log::info('order is '.json_encode($order));
$LogList = array(); $LogList = array();
foreach ($order['orderProduct'] as $productItem) { foreach ($order['orderProduct'] as $productItem) {
$product = $this->productRepository->get($productItem['product_id']); $product = $this->productRepository->get($productItem['product_id']);
@ -241,6 +277,24 @@ class UserAssetsLogRepository extends BaseRepository
} }
public function getAllSpreadId($uid){
$key = "user:AllSpread:{$uid}";
$ret = Cache::get($key);
if($ret === false){
$uidArr = $this->userRepository->getSubIds($uid);
$childArr = array();
if($uidArr){
foreach ($uidArr as $itemUid){
$childArr = array_merge($this->getAllSpreadId($itemUid), $childArr);
}
}
$ret = array_merge($uidArr, $childArr, array($uid));
Cache::set($key, $ret, 60 * 5);
}
return $ret;
}
private function _getValue($value) private function _getValue($value)
{ {
return round($value, 2); return round($value, 2);

@ -73,8 +73,8 @@ class Auth extends BaseController
// app()->make(WechatTemplateMessageService::class)->subscribeSendTemplate($data); // app()->make(WechatTemplateMessageService::class)->subscribeSendTemplate($data);
// } // }
app(UserAssetsLogRepository::class)->shareAward(1); // app(UserAssetsLogRepository::class)->shareAward(1);
event('order.take', array('order' => array('order_id' => 1)));
return app('json')->success(); return app('json')->success();
} }

Loading…
Cancel
Save