|
@@ -11,6 +11,7 @@ use app\admin\model\store\StoreProductAttrValue;
|
|
|
use app\admin\model\system\ShippingTemplatesFree;
|
|
|
use app\admin\model\system\ShippingTemplatesRegion;
|
|
|
use app\models\system\SystemUserLevel;
|
|
|
+use app\models\tree\Tree;
|
|
|
use crmeb\basic\BaseModel;
|
|
|
use think\Exception;
|
|
|
use think\facade\Cache;
|
|
@@ -18,7 +19,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, UserLevel, WechatUser};
|
|
|
+use app\models\user\{Achievement, User, UserAddress, UserBill, UserLevel, WechatUser};
|
|
|
use crmeb\services\{SystemConfigService, UtilService, WechatTemplateService, workerman\ChannelService};
|
|
|
use crmeb\repositories\{
|
|
|
GoodsRepository, PaymentRepositories, OrderRepository, ShortLetterRepositories, UserRepository
|
|
@@ -310,8 +311,8 @@ class StoreOrder extends BaseModel
|
|
|
$cartIds = [];
|
|
|
$totalNum = 0;
|
|
|
$gainIntegral = 0;
|
|
|
- $use_max_integral=0;
|
|
|
- foreach ($cartInfo as $cart){
|
|
|
+ $use_max_integral = 0;
|
|
|
+ foreach ($cartInfo as $cart) {
|
|
|
if (!$test && !self::checkProductStock($uid, $cart['product_id'], $cart['cart_num'], $cart['product_attr_unique'], $cart['combination_id'], $cart['seckill_id'], $cart['bargain_id'])) {
|
|
|
return false;
|
|
|
}
|
|
@@ -322,9 +323,8 @@ class StoreOrder extends BaseModel
|
|
|
if (!$combinationId) $combinationId = $cart['combination_id'];
|
|
|
$cartInfoGainIntegral = isset($cart['productInfo']['give_integral']) ? bcmul($cart['cart_num'], $cart['productInfo']['give_integral'], 2) : 0;
|
|
|
$gainIntegral = bcadd($gainIntegral, $cartInfoGainIntegral, 2);
|
|
|
- if(isset($cart['productInfo']['max_integral']) && $cart['productInfo']['max_integral']>0)
|
|
|
- {
|
|
|
- $use_max_integral+=intval($cart['productInfo']['max_integral'])*intval($cart['cart_num']);
|
|
|
+ if (isset($cart['productInfo']['max_integral']) && $cart['productInfo']['max_integral'] > 0) {
|
|
|
+ $use_max_integral += intval($cart['productInfo']['max_integral']) * intval($cart['cart_num']);
|
|
|
}
|
|
|
}
|
|
|
$deduction = $seckill_id || $bargain_id || $combinationId;
|
|
@@ -380,12 +380,12 @@ class StoreOrder extends BaseModel
|
|
|
//积分抵扣
|
|
|
$res2 = true;
|
|
|
$SurplusIntegral = 0;
|
|
|
- if ($useIntegral && $userInfo['integral'] > 0 && $use_max_integral>0) {
|
|
|
+ if ($useIntegral && $userInfo['integral'] > 0 && $use_max_integral > 0) {
|
|
|
$deductionPrice = (float)bcmul($userInfo['integral'], $other['integralRatio'], 2);
|
|
|
- if($deductionPrice>$use_max_integral) $deductionPrice = $use_max_integral;
|
|
|
+ if ($deductionPrice > $use_max_integral) $deductionPrice = $use_max_integral;
|
|
|
if ($deductionPrice < $payPrice) {
|
|
|
$payPrice = bcsub($payPrice, $deductionPrice, 2);
|
|
|
- $usedIntegral = $userInfo['integral']>$use_max_integral?$use_max_integral:$userInfo['integral'];
|
|
|
+ $usedIntegral = $userInfo['integral'] > $use_max_integral ? $use_max_integral : $userInfo['integral'];
|
|
|
$SurplusIntegral = 0;
|
|
|
$res2 = false !== User::bcDec($userInfo['uid'], 'integral', $usedIntegral, 'uid');
|
|
|
}
|
|
@@ -436,9 +436,9 @@ class StoreOrder extends BaseModel
|
|
|
'add_time' => time(),
|
|
|
'unique' => $key,
|
|
|
'shipping_type' => $shipping_type,
|
|
|
- 'is_gold'=>input('is_gold',0),
|
|
|
- 'is_integral'=>input('is_integral',0),
|
|
|
- 'is_beauty'=>input('is_beauty',0),
|
|
|
+ 'is_gold' => input('is_gold', 0),
|
|
|
+ 'is_integral' => input('is_integral', 0),
|
|
|
+ 'is_beauty' => input('is_beauty', 0),
|
|
|
];
|
|
|
if ($shipping_type === 2) {
|
|
|
$orderInfo['verify_code'] = self::getStoreCode();
|
|
@@ -764,16 +764,76 @@ class StoreOrder extends BaseModel
|
|
|
|
|
|
//支付成功后
|
|
|
event('OrderPaySuccess', [$order, $formId]);
|
|
|
- $res = $res1 && $resPink && self::dividend_treatment($order);
|
|
|
- $rs = UtilService::getuserparents($order['uid']);
|
|
|
- User::where('uid',$order['uid'])->inc('consume',bcsub($order['total_price'],$order['deduction_price'],2))->update();
|
|
|
- if(sizeof($rs)>1) {
|
|
|
+ $res = $res1 && $resPink && self::dividend_treatment($order) && self::addGp($order);
|
|
|
+ $rs = UtilService::getuserparents($order['uid']);
|
|
|
+ User::where('uid', $order['uid'])->inc('consume', bcsub($order['total_price'], $order['deduction_price'], 2))->update();
|
|
|
+ if (sizeof($rs) > 1) {
|
|
|
array_shift($rs);
|
|
|
- User::where("uid", 'in', $rs)->inc("trem_consume", bcsub($order['total_price'],$order['deduction_price'],2))->update();
|
|
|
+ User::where("uid", 'in', $rs)->inc("trem_consume", bcsub($order['total_price'], $order['deduction_price'], 2))->update();
|
|
|
}
|
|
|
return false !== $res;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static function addGp($order)
|
|
|
+ {
|
|
|
+ $res = true;
|
|
|
+ $cart = StoreCart::where('id', 'in', $order['cart_id'])->select();
|
|
|
+ foreach ($cart as $v) {
|
|
|
+ if ($v['is_gift']) {
|
|
|
+ for ($i = 0; $i < $v['cart_num']; $i++) {
|
|
|
+ $product_info = StoreOrderCartInfo::where('cart_id', $v['id'])->value('cart_info');
|
|
|
+ $product_info = json_decode($product_info, true);
|
|
|
+ $achievement = $product_info['cart_num'] * ($product_info['productInfo']['attrInfo']['price']) ?? 0;
|
|
|
+ $res = $res && Tree::insertTree($order['uid']) && self::sendRecommend($order['uid'], $order['id']) && self::addAchievement($order['uid'], $achievement);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function sendRecommend($uid, $link_id)
|
|
|
+ {
|
|
|
+ $res = true;
|
|
|
+ $info = User::where('uid', $uid)->find();
|
|
|
+ $info = User::where('uid', $info['spread_uid'])->find();
|
|
|
+ if (!$info) return true;
|
|
|
+ if (Tree::where('uid', $uid)->count() > 1) {
|
|
|
+ $get = 500;
|
|
|
+ $balance = User::where('uid', $info['uid'])->value('brokerage_price');
|
|
|
+ $res = $res && UserBill::income('推荐补贴', $info['uid'], 'now_money', 'brokerage', $get, $link_id, bcadd($balance, $get, 2), '下级用户参与分红,获得推荐补贴' . $get);
|
|
|
+ $res = $res && User::where('uid', $info['uid'])->inc('brokerage_price', $get)->update();
|
|
|
+ $res = $res && $info->save();
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function addAchievement($uid, $achievement)
|
|
|
+ {
|
|
|
+ $info = User::where('uid', $uid)->find();
|
|
|
+ $spread = User::where('uid', $info['spread_uid'])->find();
|
|
|
+ $res = Achievement::create(
|
|
|
+ [
|
|
|
+ 'uid' => $uid,
|
|
|
+ 'from_uid' => $uid,
|
|
|
+ 'achievement' => $achievement,
|
|
|
+ 'add_time' => time()
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ while ($spread) {
|
|
|
+ $res = $res && Achievement::create(
|
|
|
+ [
|
|
|
+ 'uid' => $spread['uid'],
|
|
|
+ 'from_uid' => $uid,
|
|
|
+ 'achievement' => $achievement,
|
|
|
+ 'add_time' => time()
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ $spread = User::where('uid', $spread['spread_uid'])->find();
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
* 线下支付消息通知
|
|
|
* 待完善
|
|
@@ -2059,7 +2119,7 @@ class StoreOrder extends BaseModel
|
|
|
public static function sendTen()
|
|
|
{
|
|
|
$switch = sys_config('unpaid_order_switch') ? true : false;
|
|
|
- if($switch){
|
|
|
+ if ($switch) {
|
|
|
$list = self::where('paid', 0)
|
|
|
->where('is_del', 0)
|
|
|
->where('is_system_del', 0)
|
|
@@ -2198,6 +2258,7 @@ class StoreOrder extends BaseModel
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 处理分钱
|
|
|
* @param $order
|
|
@@ -2205,15 +2266,14 @@ class StoreOrder extends BaseModel
|
|
|
public static function dividend_treatment($order)
|
|
|
{
|
|
|
$userInfo = User::find($order['uid']);
|
|
|
- $userlist =User::alias('a')->join("eb_system_store b","a.uid=b.uid","left")->field('a.uid,a.spread_uid,a.nickname,a.level,a.brokerage_price,b.is_show as approve')->select()->toarray();
|
|
|
- if($order['use_integral']>0 || $order['deduction_price']>0) return true;
|
|
|
+ $userlist = User::alias('a')->join("eb_system_store b", "a.uid=b.uid", "left")->field('a.uid,a.spread_uid,a.nickname,a.level,a.brokerage_price,b.is_show as approve')->select()->toarray();
|
|
|
+ if ($order['use_integral'] > 0 || $order['deduction_price'] > 0) return true;
|
|
|
$sp_userInfo = User::find($userInfo['spread_uid']);
|
|
|
- if($sp_userInfo && $sp_userInfo['level']>0)
|
|
|
- {
|
|
|
- $sp_brokeragePrice = bcdiv(bcmul($order['total_price'],sys_config('recommend',11), 2), 100, 2);
|
|
|
- $sp_brokeragePrice1 = bcdiv(bcmul($order['total_price'],sys_config('recommend_balance',11), 2), 100, 2);
|
|
|
- $sum = bcadd($sp_brokeragePrice,$sp_brokeragePrice1,2);
|
|
|
- if(bcsub($sp_userInfo['integral'],$sum,2)>0) {
|
|
|
+ if ($sp_userInfo && $sp_userInfo['level'] > 0) {
|
|
|
+ $sp_brokeragePrice = bcdiv(bcmul($order['total_price'], sys_config('recommend', 11), 2), 100, 2);
|
|
|
+ $sp_brokeragePrice1 = bcdiv(bcmul($order['total_price'], sys_config('recommend_balance', 11), 2), 100, 2);
|
|
|
+ $sum = bcadd($sp_brokeragePrice, $sp_brokeragePrice1, 2);
|
|
|
+ if (bcsub($sp_userInfo['integral'], $sum, 2) > 0) {
|
|
|
$balance = bcadd($sp_userInfo['brokerage_price'], $sp_brokeragePrice, 2);
|
|
|
$balance1 = bcadd($sp_userInfo['now_money'], $sp_brokeragePrice1, 2);
|
|
|
$mark = $userInfo['nickname'] . '推荐奖-红利' . floatval($sp_brokeragePrice) . "元,订单号:" . $order['order_id'];
|
|
@@ -2221,8 +2281,8 @@ class StoreOrder extends BaseModel
|
|
|
$mark1 = $userInfo['nickname'] . '推荐奖-余额' . floatval($sp_brokeragePrice1) . "元,订单号:" . $order['order_id'];
|
|
|
$res1 = UserBill::income('推荐奖-余额', $sp_userInfo['uid'], 'now_money', 'brokerage', $sp_brokeragePrice1, $order['id'], $balance1, $mark1, 1);
|
|
|
$mark2 = $userInfo['nickname'] . '推荐奖-扣金券' . floatval($sum) . "元,订单号:" . $order['order_id'];
|
|
|
- $res2 = UserBill::expend('推荐奖-扣金券', $sp_userInfo['uid'], 'integral', 'recommend', $sum, $order['id'], bcsub($sp_userInfo['integral'],$sum,2), $mark2, 1);
|
|
|
- User::where('uid', $sp_userInfo['uid'])->inc('brokerage_price', $sp_brokeragePrice)->inc('now_money', floatval($sp_brokeragePrice1))->dec("integral",$sum)->update();
|
|
|
+ $res2 = UserBill::expend('推荐奖-扣金券', $sp_userInfo['uid'], 'integral', 'recommend', $sum, $order['id'], bcsub($sp_userInfo['integral'], $sum, 2), $mark2, 1);
|
|
|
+ User::where('uid', $sp_userInfo['uid'])->inc('brokerage_price', $sp_brokeragePrice)->inc('now_money', floatval($sp_brokeragePrice1))->dec("integral", $sum)->update();
|
|
|
}
|
|
|
}
|
|
|
try {
|
|
@@ -2265,9 +2325,8 @@ class StoreOrder extends BaseModel
|
|
|
}
|
|
|
unset($pids);
|
|
|
return true;
|
|
|
- }catch (Exception $e)
|
|
|
- {
|
|
|
- Log::error($e->getLine().'---'.$e->getFile().'---'.$e->getMessage());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Log::error($e->getLine() . '---' . $e->getFile() . '---' . $e->getMessage());
|
|
|
return false;
|
|
|
}
|
|
|
}
|