|
@@ -795,54 +795,81 @@ class StoreOrder extends BaseModel
|
|
|
$user2 = User::where('uid', $user1['spread_uid'])->find();
|
|
|
if ($type == 1){
|
|
|
$str = '购买';
|
|
|
- }elseif ($type == 2){
|
|
|
- $str = '进货';
|
|
|
- }elseif ($type ==3){
|
|
|
- $str = '店家购买';
|
|
|
- }
|
|
|
- foreach ($list as $item){
|
|
|
- $product = StoreProduct::where('id', $item['product_id'])->find();
|
|
|
- $num = $item['cart_info']['cart_num'];
|
|
|
- $price1 = $product['push'] * $num;// 直推奖励
|
|
|
- $price2 = $product['push_sale'] * $num;// 直推销售奖励
|
|
|
- $price3 = $product['Interposition'] * $num;// 间推奖励
|
|
|
- $price4 = $product['Interposition_sale'] * $num;// 间推销售奖励
|
|
|
- if ($user1){
|
|
|
- User::where('uid', $user['spread_uid'])->inc('brokerage_price', $price1+$price2)->update();
|
|
|
- $user1['brokerage_price'] += $price1;
|
|
|
- UserBill::income('直推奖励', $user1['uid'], 'now_money', 'push', $price1, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
- $user1['brokerage_price'] += $price2;
|
|
|
- UserBill::income('直推销售提成', $user1['uid'], 'now_money', 'sale', $price2, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
+ foreach ($list as $item){
|
|
|
+ $product = StoreProduct::where('id', $item['product_id'])->find();
|
|
|
+ $num = $item['cart_info']['cart_num'];
|
|
|
+ $price1 = $product['push'] * $num;// 直推奖励
|
|
|
+ $price3 = $product['Interposition'] * $num;// 间推奖励
|
|
|
+ if ($user1){
|
|
|
+ User::where('uid', $user['spread_uid'])->inc('brokerage_price', $price1)->update();
|
|
|
+ $user1['brokerage_price'] += $price1;
|
|
|
+ UserBill::income('直推奖励', $user1['uid'], 'now_money', 'push', $price1, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
+ }
|
|
|
+ if ($user2){
|
|
|
+ User::where('uid', $user1['spread_uid'])->inc('brokerage_price', $price3)->update();
|
|
|
+ $user2['brokerage_price'] += $price3;
|
|
|
+ UserBill::income('间推奖励', $user2['uid'], 'now_money', 'jt_push', $price3, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].','.$str.'编号'.$item['product_id'].'数量'.$num);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if ($user2){
|
|
|
- User::where('uid', $user1['spread_uid'])->inc('brokerage_price', $price3+$price4)->update();
|
|
|
- $user2['brokerage_price'] += $price3;
|
|
|
- UserBill::income('间推奖励', $user2['uid'], 'now_money', 'jt_push', $price3, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].','.$str.'编号'.$item['product_id'].'数量'.$num);
|
|
|
- $user2['brokerage_price'] += $price4;
|
|
|
- UserBill::income('间推销售提成', $user2['uid'], 'now_money', 'zt_sale', $price4, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
+
|
|
|
+ }elseif ($type == 2){
|
|
|
+ $str = '进货';
|
|
|
+ foreach ($list as $item){
|
|
|
+ $product = StoreProduct::where('id', $item['product_id'])->find();
|
|
|
+ $num = $item['cart_info']['cart_num'];
|
|
|
+ $price1 = $product['push'] * $num;// 直推奖励
|
|
|
+ $price3 = $product['Interposition'] * $num;// 间推奖励
|
|
|
+ if ($user1){
|
|
|
+ User::where('uid', $user['spread_uid'])->inc('brokerage_price', $price1)->update();
|
|
|
+ $user1['brokerage_price'] += $price1;
|
|
|
+ UserBill::income('直推奖励', $user1['uid'], 'now_money', 'push', $price1, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
+ }
|
|
|
+ if ($user2){
|
|
|
+ User::where('uid', $user1['spread_uid'])->inc('brokerage_price', $price3)->update();
|
|
|
+ $user2['brokerage_price'] += $price3;
|
|
|
+ UserBill::income('间推奖励', $user2['uid'], 'now_money', 'jt_push', $price3, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].','.$str.'编号'.$item['product_id'].'数量'.$num);
|
|
|
+ }
|
|
|
}
|
|
|
- if ($type == 2){
|
|
|
- $user_product = UserProduct::where('uid', $order['uid'])->where('product_id', $item['product_id'])->find();
|
|
|
- if (!$user_product){
|
|
|
- UserProduct::create([
|
|
|
- 'uid' => $order['uid'],
|
|
|
- 'product_id' => $item['product_id'],
|
|
|
- 'number' => $num
|
|
|
- ]);
|
|
|
- }else{
|
|
|
- $user_product['number'] += $num;
|
|
|
- $user_product->save();
|
|
|
+ }elseif ($type ==3){
|
|
|
+ $str = '老师购买';
|
|
|
+ foreach ($list as $item){
|
|
|
+ $product = StoreProduct::where('id', $item['product_id'])->find();
|
|
|
+ $num = $item['cart_info']['cart_num'];
|
|
|
+ $price2 = $product['push_sale'] * $num;// 直推销售奖励
|
|
|
+ $price4 = $product['Interposition_sale'] * $num;// 间推销售奖励
|
|
|
+ if ($user1){
|
|
|
+ User::where('uid', $user['spread_uid'])->inc('brokerage_price', $price2)->update();
|
|
|
+ $user1['brokerage_price'] += $price2;
|
|
|
+ UserBill::income('直推销售提成', $user1['uid'], 'now_money', 'sale', $price2, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
+ }
|
|
|
+ if ($user2){
|
|
|
+ User::where('uid', $user1['spread_uid'])->inc('brokerage_price', $price4)->update();
|
|
|
+ $user2['brokerage_price'] += $price4;
|
|
|
+ UserBill::income('间推销售提成', $user2['uid'], 'now_money', 'zt_sale', $price4, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if ($type == 3){
|
|
|
- $user_product = UserProduct::where('uid', $order['consignor'])->where('product_id', $item['product_id'])->find();
|
|
|
- $user_product['number'] -= $num;
|
|
|
+ }
|
|
|
+ if ($type == 2){
|
|
|
+ $user_product = UserProduct::where('uid', $order['uid'])->where('product_id', $item['product_id'])->find();
|
|
|
+ if (!$user_product){
|
|
|
+ UserProduct::create([
|
|
|
+ 'uid' => $order['uid'],
|
|
|
+ 'product_id' => $item['product_id'],
|
|
|
+ 'number' => $num
|
|
|
+ ]);
|
|
|
+ }else{
|
|
|
+ $user_product['number'] += $num;
|
|
|
$user_product->save();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if ($type == 3){
|
|
|
+ $user_product = UserProduct::where('uid', $order['consignor'])->where('product_id', $item['product_id'])->find();
|
|
|
+ $user_product['number'] -= $num;
|
|
|
+ $user_product->save();
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -2225,19 +2252,28 @@ class StoreOrder extends BaseModel
|
|
|
*/
|
|
|
public static function bonus()
|
|
|
{
|
|
|
- $user_address = User::where('provinces', 1)->column('address');
|
|
|
+ $user_address = User::where('provinces', 1)->where('address', '<>', ' ')->column('address');
|
|
|
$time = strtotime('-1 month');
|
|
|
$date1 = mktime(0,0,0,date('m',$time),01,date('Y',$time));
|
|
|
$date2 = mktime(23,59,59,date('m',$time),date('t',$time),date('Y',$time));
|
|
|
if (count($user_address) > 0){
|
|
|
$eve = [];
|
|
|
foreach ($user_address as $item){
|
|
|
- $order = StoreOrder::where('user_address', 'like', '%'.$item.'%')->whereBetweenTime('add_time', $date1, $date2)->where('paid', 1)->count();
|
|
|
- if ($order > 0){
|
|
|
+ $order = StoreOrder::where('user_address', 'like', '%'.$item.'%')->whereBetweenTime('add_time', $date1, $date2)->where('paid', 1)->select();
|
|
|
+ $price = 0;
|
|
|
+ foreach ($order as $value){
|
|
|
+ $attr = StoreOrderCartInfo::where('oid', $value['id'])->select();
|
|
|
+ foreach ($attr as $v){
|
|
|
+ $bonus = StoreProduct::where('id', $v['cart_info']['product_id'])->value('bonus');
|
|
|
+ $price += $bonus * $v['cart_info']['cart_num'];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if ($price > 0){
|
|
|
$eve[] = [
|
|
|
'province' => $item,
|
|
|
'number' => User::where('provinces', 1)->where('address', 'like', '%'.$item.'%')->count(),
|
|
|
- 'price' => $order * sys_config('bonus'),
|
|
|
+ 'price' => $price,
|
|
|
];
|
|
|
|
|
|
}
|
|
@@ -2274,15 +2310,21 @@ class StoreOrder extends BaseModel
|
|
|
$date2 = mktime(23,59,59,date('m',$time),date('t',$time),date('Y',$time));
|
|
|
foreach ($user as $item)
|
|
|
{
|
|
|
- $order = StoreOrder::where('uid', $item['uid'])->whereBetweenTime('add_time', $date1, $date2)->where('paid', 1)->count();
|
|
|
- if ($order > 1){
|
|
|
+ $order = StoreOrder::where('uid', $item['uid'])->whereBetweenTime('add_time', $date1, $date2)->where('paid', 1)->select();
|
|
|
+ if (count($order) > 0){
|
|
|
+ $price = 0;
|
|
|
+ foreach ($order as $value){
|
|
|
+ $attr = StoreOrderCartInfo::where('oid', $value['id'])->select();
|
|
|
+ foreach ($attr as $v){
|
|
|
+ $team = StoreProduct::where('id', $v['cart_info']['product_id'])->value('team');
|
|
|
+ $price += $team * $v['cart_info']['cart_num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
$uid = getParent($item['spread_uid'], $user->toArray());
|
|
|
if ($uid){
|
|
|
$details = User::where('uid', $uid[0])->find();
|
|
|
- $jl = $order * sys_config('team');
|
|
|
- User::where('uid', $details['uid'])->inc('brokerage_price', $jl)->update();
|
|
|
- UserBill::income('业绩分红',$details['uid'], 'now_money', 'team', $jl, 0, $details['brokerage_price']+$jl, '团队奖励');
|
|
|
-
|
|
|
+ User::where('uid', $details['uid'])->inc('brokerage_price', $price)->update();
|
|
|
+ UserBill::income('团队缉拿管理',$details['uid'], 'now_money', 'team', $price, 0, $details['brokerage_price']+$price, '团队奖励');
|
|
|
}
|
|
|
}
|
|
|
}
|