|
|
|
@ -141,14 +141,124 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
*/ |
|
|
|
|
$orderRepository = app(StoreOrderRepository::class); |
|
|
|
|
|
|
|
|
|
$order = $orderRepository->getDetail($orderItem['order_id']); |
|
|
|
|
|
|
|
|
|
// 爆单奖励 |
|
|
|
|
// $this->hotAward($order); |
|
|
|
|
// |
|
|
|
|
// // 分享奖励 |
|
|
|
|
// $this->shareAward($order); |
|
|
|
|
|
|
|
|
|
$this->serveAward($order); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function serveAward($order){ |
|
|
|
|
$this->_updateUserGroup($order['uid']); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @var StoreOrderHotRepository $hotRepository |
|
|
|
|
* @var UserGroupRepository $groupRepository |
|
|
|
|
*/ |
|
|
|
|
$hotRepository = app(StoreOrderHotRepository::class); |
|
|
|
|
$groupRepository = app(UserGroupRepository::class); |
|
|
|
|
|
|
|
|
|
$groupData = $groupRepository->getList([], 1, 10); |
|
|
|
|
$groupList = $groupData['list']->toArray(); |
|
|
|
|
|
|
|
|
|
foreach ($order['orderProduct'] as $productItem) { |
|
|
|
|
$product = $this->productRepository->get($productItem['product_id']); |
|
|
|
|
$profit = $productItem['total_price'] - $productItem['cost']; |
|
|
|
|
if ($product['is_hot']) { |
|
|
|
|
$shareRate = $product['hot_integral_one'] + $product['hot_integral_two']; |
|
|
|
|
} else { |
|
|
|
|
$shareRate = $product['normal_integral_one'] + $product['normal_integral_two']; |
|
|
|
|
} |
|
|
|
|
$total = $this->_getValue($profit * (100 - $shareRate) /100); |
|
|
|
|
|
|
|
|
|
$currentRate = 0; |
|
|
|
|
foreach ($groupList as $group){ |
|
|
|
|
$where = array('group_id' => $group['group_id']); |
|
|
|
|
$userList = $this->userRepository->selectWhere($where); |
|
|
|
|
if($userList->isEmpty()){ |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$integral = $this->_getValue($total*($group['rate'] - $currentRate)/100/count($userList)); |
|
|
|
|
var_dump(array($profit, $total, $integral)); |
|
|
|
|
|
|
|
|
|
$logList = array(); |
|
|
|
|
foreach ($userList as $user){ |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $user['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_INTEGRAL, |
|
|
|
|
'type' => self::CHANGE_TYPE_SERVER, |
|
|
|
|
'status' => self::STATUS_GET, |
|
|
|
|
'product_id' => $productItem['product_id'], |
|
|
|
|
'order_id' => $order['order_id'], |
|
|
|
|
'count' => $integral, |
|
|
|
|
); |
|
|
|
|
$this->userAssetsRepository->updateAssets($user['uid'], array('integral' => $integral)); |
|
|
|
|
} |
|
|
|
|
$this->addLog($logList); |
|
|
|
|
$currentRate = $group['rate']; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$order = $orderRepository->getDetail($orderItem['order_id']); |
|
|
|
|
|
|
|
|
|
private function _updateUserGroup($orderUid){ |
|
|
|
|
/** |
|
|
|
|
* @var UserGroupRepository $groupRepository |
|
|
|
|
*/ |
|
|
|
|
$groupRepository = app(UserGroupRepository::class); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @var StoreOrderRepository $orderRepository |
|
|
|
|
*/ |
|
|
|
|
$orderRepository = app(StoreOrderRepository::class); |
|
|
|
|
|
|
|
|
|
$groupData = $groupRepository->getList([], 1, 10); |
|
|
|
|
$groupList = array_reverse($groupData['list']->toArray()); |
|
|
|
|
|
|
|
|
|
$user= $this->userRepository->get($orderUid); |
|
|
|
|
$count = 0; |
|
|
|
|
while ($user){ |
|
|
|
|
$uidArr = $this->getAllSpreadId($user['uid']); |
|
|
|
|
$uidArr = array_merge($uidArr, [$user['uid']]); |
|
|
|
|
$orderData = $orderRepository->orderStatisticsByUidArr($uidArr); |
|
|
|
|
foreach ($groupList as $group){ |
|
|
|
|
if($orderData['count'] >= $group['order_count'] or $orderData['sum'] >= $group['order_sum']){ |
|
|
|
|
$user['group_id'] = $group['group_id']; |
|
|
|
|
$user->save(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if($user['spread_uid']){ |
|
|
|
|
$user = $this->userRepository->get($user['spread_uid']); |
|
|
|
|
}else{ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
$count++; |
|
|
|
|
if($count>=20){ |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 爆单奖励 |
|
|
|
|
* @param $order |
|
|
|
|
* @return void |
|
|
|
|
* @throws DataNotFoundException |
|
|
|
|
* @throws DbException |
|
|
|
|
* @throws ModelNotFoundException |
|
|
|
|
*/ |
|
|
|
|
public function hotAward($order){ |
|
|
|
|
/** |
|
|
|
|
* @var StoreOrderHotRepository $hotRepository |
|
|
|
|
*/ |
|
|
|
|
$hotRepository = app(StoreOrderHotRepository::class); |
|
|
|
|
foreach ($order['orderProduct'] as $productItem){ |
|
|
|
|
$product = $this->productRepository->get($productItem['product_id']); |
|
|
|
|
Log::info("product is". json_encode($product)); |
|
|
|
@ -203,14 +313,8 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function shareAward($orderId) |
|
|
|
|
public function shareAward($order) |
|
|
|
|
{ |
|
|
|
|
/** |
|
|
|
|
* @var StoreOrderRepository $orderRepository |
|
|
|
|
*/ |
|
|
|
|
$orderRepository = app(StoreOrderRepository::class); |
|
|
|
|
$order = $orderRepository->getDetail($orderId); |
|
|
|
|
|
|
|
|
|
$LogList = array(); |
|
|
|
|
foreach ($order['orderProduct'] as $productItem) { |
|
|
|
|
$product = $this->productRepository->get($productItem['product_id']); |
|
|
|
@ -236,7 +340,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
'type' => self::CHANGE_TYPE_SHARE, |
|
|
|
|
'status' => self::STATUS_GET, |
|
|
|
|
'product_id' => $productItem['product_id'], |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'order_id' => $order['order_id'], |
|
|
|
|
'count' => $tmp['integral'], |
|
|
|
|
); |
|
|
|
|
$LogList[] = array( |
|
|
|
@ -245,7 +349,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
'type' => self::CHANGE_TYPE_SHARE, |
|
|
|
|
'status' => self::STATUS_GET, |
|
|
|
|
'product_id' => $productItem['product_id'], |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'order_id' => $order['order_id'], |
|
|
|
|
'count' => $diamondOne, |
|
|
|
|
); |
|
|
|
|
$this->userAssetsRepository->updateAssets($order['spread_uid'], $tmp); |
|
|
|
@ -258,7 +362,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
'type' => self::CHANGE_TYPE_SHARE, |
|
|
|
|
'status' => self::STATUS_GET, |
|
|
|
|
'product_id' => $productItem['product_id'], |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'order_id' => $order['order_id'], |
|
|
|
|
'count' => $tmp['integral'], |
|
|
|
|
); |
|
|
|
|
$LogList[] = array( |
|
|
|
@ -267,7 +371,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
'type' => self::CHANGE_TYPE_SHARE, |
|
|
|
|
'status' => self::STATUS_GET, |
|
|
|
|
'product_id' => $productItem['product_id'], |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'order_id' => $order['order_id'], |
|
|
|
|
'count' => $diamondTwo, |
|
|
|
|
); |
|
|
|
|
$this->userAssetsRepository->updateAssets($order['top_uid'], $tmp); |
|
|
|
@ -277,19 +381,23 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getAllSpreadId($uid){ |
|
|
|
|
$key = "user:AllSpread:{$uid}"; |
|
|
|
|
public function getAllSpreadId($uid, $count= 0){ |
|
|
|
|
if($count>=30){ |
|
|
|
|
return array(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$key = "user:AllSpread1:{$uid}"; |
|
|
|
|
$ret = Cache::get($key); |
|
|
|
|
if($ret === false){ |
|
|
|
|
if($ret === null){ |
|
|
|
|
$uidArr = $this->userRepository->getSubIds($uid); |
|
|
|
|
$childArr = array(); |
|
|
|
|
if($uidArr){ |
|
|
|
|
foreach ($uidArr as $itemUid){ |
|
|
|
|
$childArr = array_merge($this->getAllSpreadId($itemUid), $childArr); |
|
|
|
|
$childArr = array_merge($this->getAllSpreadId($itemUid, ++$count), $childArr); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$ret = array_merge($uidArr, $childArr, array($uid)); |
|
|
|
|
Cache::set($key, $ret, 60 * 5); |
|
|
|
|
$ret = array_merge($uidArr, $childArr); |
|
|
|
|
Cache::set($key, $ret, 10); |
|
|
|
|
} |
|
|
|
|
return $ret; |
|
|
|
|
} |
|
|
|
|