|
@@ -21,7 +21,7 @@ use crmeb\traits\ModelTrait;
|
|
|
use think\facade\Log;
|
|
|
use app\models\system\SystemStore;
|
|
|
use app\models\routine\RoutineTemplate;
|
|
|
-use app\models\user\{User, UserAddress, UserBill, UserSpread, WechatUser};
|
|
|
+use app\models\user\{Achievement, User, UserAddress, UserBill, UserLevel, UserSpread, WechatUser};
|
|
|
use crmeb\services\{MiniProgramService,
|
|
|
SystemConfigService,
|
|
|
WechatService,
|
|
@@ -829,14 +829,79 @@ class StoreOrder extends BaseModel
|
|
|
UserBill::expend('购买商品', $order['uid'], 'now_money', 'pay_money', $order['pay_price'], $order['id'], $now_money, '支付' . floatval($order['pay_price']) . '元购买商品');
|
|
|
|
|
|
event('OrderPaySuccess', [$order, $formId]);
|
|
|
+ $res_Gift = true;
|
|
|
if ($order['is_gift']) {
|
|
|
- TreeRecommend::insertTree($order['uid'], User::where('uid', $order['uid'])->value('spread_uid'));
|
|
|
- StorePink::pinkRecommend($order['id']);
|
|
|
+ $res_Gift = TreeRecommend::insertTree($order['uid'], User::where('uid', $order['uid'])->value('spread_uid'))
|
|
|
+ && StorePink::pinkRecommend($order['id'])
|
|
|
+ && self::addAchievement($order);
|
|
|
}
|
|
|
- $res = $res1 && $resPink && User::backOrderBrokerage($order) && self::areaAward($order);
|
|
|
+ $res = $res_Gift && $res1 && $resPink && User::backOrderBrokerage($order) && self::areaAward($order) && self::gainUserIntegral($order);
|
|
|
return false !== $res;
|
|
|
}
|
|
|
|
|
|
+ private static function addAchievement($order)
|
|
|
+ {
|
|
|
+ $res = Achievement::create(
|
|
|
+ [
|
|
|
+ 'uid' => $order['uid'],
|
|
|
+ 'from_uid' => $order['uid'],
|
|
|
+ 'achievement' => $order['total_price'],
|
|
|
+ 'order_id' => $order['id'],
|
|
|
+ 'add_time' => time()
|
|
|
+ ]
|
|
|
+ ) && User::where('uid', $order['uid'])->inc('achievement', $order['total_price'])->inc('self_achievement', $order['total_price'])->update();
|
|
|
+ $spread = User::where('uid', $order['uid'])->value('spread_uid');
|
|
|
+ while ($spread) {
|
|
|
+ $res = $res && Achievement::create(
|
|
|
+ [
|
|
|
+ 'uid' => $spread,
|
|
|
+ 'from_uid' => $order['uid'],
|
|
|
+ 'achievement' => $order['total_price'],
|
|
|
+ 'order_id' => $order['id'],
|
|
|
+ 'add_time' => time()
|
|
|
+ ]
|
|
|
+ ) && User::where('uid', $spread)->inc('achievement', $order['total_price'])->update();
|
|
|
+ UserLevel::setLevelComplete($spread);
|
|
|
+ $spread = User::where('uid', $spread)->value('spread_uid');
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 购买商品赠送积分
|
|
|
+ * @param $order
|
|
|
+ * @return bool
|
|
|
+ * @throws DataNotFoundException
|
|
|
+ * @throws ModelNotFoundException|DbException
|
|
|
+ */
|
|
|
+ public static function gainUserIntegral($order)
|
|
|
+ {
|
|
|
+ if ($order['gain_integral'] > 0) {
|
|
|
+ $userInfo = User::getUserInfo($order['uid']);
|
|
|
+
|
|
|
+ $res2 = false != UserBill::income('购买商品赠送积分', $order['uid'], 'integral', 'gain', $order['gain_integral'], $order['id'], $userInfo['integral'], '购买商品赠送' . floatval($order['gain_integral']) . '积分', 0);
|
|
|
+ $res = $res2 && self::spreadIntegral($order);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function spreadIntegral($order)
|
|
|
+ {
|
|
|
+ $recommend_integral = sys_config('recommend_integral_ratio', 0, true);
|
|
|
+ $integral = bcmul($order['gain_integral'], bcdiv($recommend_integral, 100, 4), 2);
|
|
|
+ if ($integral > 0) {
|
|
|
+ $userInfo = User::getUserInfo($order['uid']);
|
|
|
+ $spreadInfo = User::getUserInfo($userInfo['spread_uid']);
|
|
|
+ if (!$spreadInfo) return true;
|
|
|
+
|
|
|
+ $res = false != UserBill::income('推荐用户购买商品赠送积分', $spreadInfo['uid'], 'integral', 'spread_gain', $integral, $order['id'], $spreadInfo['integral'], '推荐用户购买商品赠送' . floatval($integral) . '积分', 0);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
public static function areaAward($order)
|
|
|
{
|
|
|
if (isset($order['combination_id']) && $order['combination_id']) return true;
|
|
@@ -1391,28 +1456,6 @@ class StoreOrder extends BaseModel
|
|
|
return compact('noBuy', 'noPostage', 'noTake', 'noReply', 'noPink', 'noRefund');
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * 购买商品赠送积分
|
|
|
- * @param $order
|
|
|
- * @return bool
|
|
|
- * @throws \think\Exception
|
|
|
- * @throws DataNotFoundException
|
|
|
- * @throws ModelNotFoundException
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public static function gainUserIntegral($order)
|
|
|
- {
|
|
|
- if ($order['gain_integral'] > 0) {
|
|
|
- $userInfo = User::getUserInfo($order['uid']);
|
|
|
- BaseModel::beginTrans();
|
|
|
- $res1 = false != User::where('uid', $userInfo['uid'])->update(['integral' => bcadd($userInfo['integral'], $order['gain_integral'], 2)]);
|
|
|
- $res2 = false != UserBill::income('购买商品赠送积分', $order['uid'], 'integral', 'gain', $order['gain_integral'], $order['id'], $userInfo['integral'], '购买商品赠送' . floatval($order['gain_integral']) . '积分');
|
|
|
- $res = $res1 && $res2;
|
|
|
- BaseModel::checkTrans($res);
|
|
|
- return $res;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
|
|
|
|
|
|
* 获取当前订单中有没有拼团存在
|