|
@@ -6,6 +6,7 @@ namespace app\models\user;
|
|
|
use app\admin\model\store\StoreProductCate;
|
|
|
use app\models\store\StoreCart;
|
|
|
use app\models\store\StoreOrder;
|
|
|
+use app\models\store\StoreOrderCartInfo;
|
|
|
use app\models\store\StoreProduct;
|
|
|
use app\models\system\Message;
|
|
|
use crmeb\services\SystemConfigService;
|
|
@@ -332,6 +333,59 @@ class User extends BaseModel
|
|
|
return $res;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ * TODO 一级返佣
|
|
|
+ * @param $orderInfo
|
|
|
+ * @return bool
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws ModelNotFoundException
|
|
|
+ * @throws DbException
|
|
|
+ */
|
|
|
+ public static function backOrderBrokerageSP($orderInfo, bool $open = true)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (isset($orderInfo['combination_id']) && $orderInfo['combination_id']) return true;
|
|
|
+ if (isset($orderInfo['seckill_id']) && $orderInfo['seckill_id']) return true;
|
|
|
+ if (isset($orderInfo['bargain_id']) && $orderInfo['bargain_id']) return true;
|
|
|
+ if (isset($orderInfo['exchange_id']) && $orderInfo['exchange_id']) return true;
|
|
|
+
|
|
|
+ $userInfo = User::getUserInfo($orderInfo['uid']);
|
|
|
+
|
|
|
+ if (!$userInfo || !$userInfo['spread_uid'] || $userInfo['spread_uid'] == $orderInfo['uid']) return true;
|
|
|
+ $spread_user = User::where('uid', $userInfo['spread_uid'])->find();
|
|
|
+ if (!$spread_user) return true;
|
|
|
+ $level = UserLevel::getUserLevelInfo(UserLevel::getUserLevel($spread_user['uid']));
|
|
|
+ if (UserLevel::getUserLevelInfo(UserLevel::getUserLevel($userInfo['uid']), 'level_id') != $level['level_id']) return true;
|
|
|
+ $res = true;
|
|
|
+ $cartId = is_string($orderInfo['cart_id']) ? json_decode($orderInfo['cart_id'], true) : $orderInfo['cart_id'];
|
|
|
+ $cartInfo = StoreOrderCartInfo::whereIn('cart_id', $cartId)->column('cart_info');
|
|
|
+ $sum_sp = ['real' => 0, 'virtual' => 0];
|
|
|
+ foreach ($cartInfo as $value) {
|
|
|
+ $product = json_decode($value, true);
|
|
|
+ if (isset($product['productInfo'])) {
|
|
|
+ $productInfo = $product['productInfo'];
|
|
|
+ $cates = StoreProductCate::where('product_id', $product['product_id'])->column('cate_id');
|
|
|
+ if (in_array(49, $cates)) {
|
|
|
+ $sum_sp[(isset($productInfo['store_type']) && $productInfo['store_type'] == 1 ? 'real' : 'virtual')] += ($product['cart_num'] ?? 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $brokeragePrice = bcmul($sum_sp['real'], $level['same_level_award_ratio'], 2);
|
|
|
+ if ($brokeragePrice > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $orderInfo['uid'] . ')' . '购买实体升级商品,获得平级奖励' . $brokeragePrice;
|
|
|
+ $res = $res && UserBill::income('获得商品平级奖', $spread_user['uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id'], $spread_user['brokerage_price'], $mark, 0);
|
|
|
+ }
|
|
|
+ $brokeragePrice = bcmul($sum_sp['virtual'], $level['same_level_award_ratio'], 2);
|
|
|
+ if ($brokeragePrice > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $orderInfo['uid'] . ')' . '购买虚拟升级商品,获得平级奖励' . $brokeragePrice;
|
|
|
+ $res = $res && UserBill::income('获得商品平级奖', $spread_user['uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id'], bcadd($spread_user['brokerage_price'], $brokeragePrice, 2), $mark);
|
|
|
+ Message::addMessage($orderInfo['uid'], $mark, 200);
|
|
|
+ $res = $res && User::where('uid', $spread_user['uid'])->inc('brokerage_price', $brokeragePrice)->update();
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* TODO 二级推广
|
|
|
* @param $orderInfo
|