diff --git a/addons/shopro/controller/Category.php b/addons/shopro/controller/Category.php
index e8bb909..f22fd66 100755
--- a/addons/shopro/controller/Category.php
+++ b/addons/shopro/controller/Category.php
@@ -3,11 +3,20 @@
namespace addons\shopro\controller;
use app\admin\model\shopro\Category as CategoryModel;
+use app\admin\model\shopro\commission\Agent;
use app\admin\model\shopro\goods\Goods;
class Category extends Common
{
+ const LEVEL_1 = 1;
+ const LEVEL_2 = 2;//会员
+ const LEVEL_3 = 3;//初级代理
+ const LEVEL_4 = 4;//中级代理
+ const LEVEL_5 = 5;//高级代理
+
+ const LEVEL_6 = 6;//公司账户
+
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
@@ -35,6 +44,7 @@ class Category extends Common
* @return
*/
public function goodsList() {
+ $user = auth_user();
$category = CategoryModel::where('parent_id', 0)->normal()->order('weigh', 'desc')->order('id', 'desc')->select();
// $category_ids = [];
// foreach ($category as $item) {
@@ -51,12 +61,44 @@ class Category extends Common
foreach ($row['goods_list'] as $v) {
$v->image = formatImage($v->image);
$v->images = array_map('formatImage', $v->images);
- $v->back_score = 40;
+ $v->back_score = $this->getBackScore($user, $v->id);
}
}
$this->success('商城分类', $category);
}
+ /**
+ * 计算用户等级返现金额
+ */
+ public function getBackScore($user, $goods_id) {
+ if (empty($user)) {
+ return 0;
+ }
+ $level = Agent::where('user_id', $user->id)->value('level');
+// dd($level);
+ $goods_info = Goods::get($goods_id);
+ $level_price = 0;
+ if ($level == self::LEVEL_1) {
+ $level_price = $goods_info['price'][0];
+ }
+ if ($level == self::LEVEL_2) {
+ $level_price = $goods_info['user_price'];
+ }
+ if ($level == self::LEVEL_3) {
+ $level_price = $goods_info['level1_price'];
+ }
+ if ($level == self::LEVEL_4) {
+ $level_price = $goods_info['level2_price'];
+ }
+ if ($level == self::LEVEL_5) {
+ $level_price = $goods_info['level3_price'];
+ }
+ if ($level == self::LEVEL_6) {
+ $level_price = $goods_info['company_price'];
+ }
+ return bcsub($goods_info['price'][0], $level_price, 2);
+ }
+
}
diff --git a/addons/shopro/controller/Coupon.php b/addons/shopro/controller/Coupon.php
index a35f342..388f6d9 100755
--- a/addons/shopro/controller/Coupon.php
+++ b/addons/shopro/controller/Coupon.php
@@ -114,13 +114,19 @@ class Coupon extends Common
$data = Level::get(['level' => $userInfo['level']])->toArray();
//添加优惠券领取标识
- $is_get = 1;//未领取
+ $is_get = 0;//未领取
$coupon_ids = [];
$user_id = $user->id;
+ $result = [
+ 'programme_1' => [],
+ 'programme_2' => [],
+ ];
if($data['coupon_rules']['programme_1']) {
+ $result['programme_1'] = $data['coupon_rules']['programme_1'];
$coupon_ids = array_merge($coupon_ids, array_column($data['coupon_rules']['programme_1'], 'id'));
}
if ($data['coupon_rules']['programme_2']) {
+ $result['programme_2'] = $data['coupon_rules']['programme_2'];
$coupon_ids = array_merge($coupon_ids, array_column($data['coupon_rules']['programme_2'], 'id'));
}
$coupon_ids = array_values(array_unique($coupon_ids));
@@ -130,9 +136,10 @@ class Coupon extends Common
->whereIn('coupon_id', $coupon_ids)
->select();
if ($coupon_list) {
- $is_get = 0;
+ $is_get = 1;
}
- $data['coupon_rules']['is_get'] = $is_get;
- $this->success('success',$data['coupon_rules']);
+ $result['is_get'] = $is_get;
+ $result['level_name'] = $data['name'];
+ $this->success('success',$result);
}
}
diff --git a/addons/shopro/controller/Index.php b/addons/shopro/controller/Index.php
index 1872f42..07ff79a 100755
--- a/addons/shopro/controller/Index.php
+++ b/addons/shopro/controller/Index.php
@@ -176,7 +176,7 @@ class Index extends Common
//未注册 注册手机号
$userAuth = new UserAuth();
$auth = $userAuth->register(['mobile' => $mobile]);
- set_token_in_header($auth->getToken());
+// set_token_in_header($auth->getToken());
// set_token_in_header($auth->getToken());
// $this->error(__('手机号未注册'))
}
diff --git a/addons/shopro/controller/goods/Goods.php b/addons/shopro/controller/goods/Goods.php
index 1f2a894..3c112e6 100755
--- a/addons/shopro/controller/goods/Goods.php
+++ b/addons/shopro/controller/goods/Goods.php
@@ -4,15 +4,26 @@ namespace addons\shopro\controller\goods;
use addons\shopro\controller\Common;
use addons\shopro\service\goods\GoodsService;
+use app\admin\model\shopro\commission\Agent;
+use app\admin\model\shopro\order\Order;
use app\admin\model\shopro\user\GoodsLog;
use app\admin\model\shopro\activity\Activity;
+use app\admin\model\shopro\user\User;
class Goods extends Common
{
- protected $noNeedLogin = ['*'];
+ protected $noNeedLogin = ['index', 'ids', 'detail', 'activity', 'activityList'];
protected $noNeedRight = ['*'];
+ const LEVEL_1 = 1;
+ const LEVEL_2 = 2;//会员
+ const LEVEL_3 = 3;//初级代理
+ const LEVEL_4 = 4;//中级代理
+ const LEVEL_5 = 5;//高级代理
+
+ const LEVEL_6 = 6;//公司账户
+
public function index()
{
$params = $this->request->param();
@@ -124,11 +135,43 @@ class Goods extends Common
$goods['sku_prices'] = $skuPrices;
$goods['content'] = $content;
unset($goods['new_sku_prices']);
- $goods['back_score'] = 0;
+ $goods['back_score'] = $this->getBackScore($user, $id);
$this->success('获取成功', $goods);
}
+ /**
+ * 计算用户等级返现金额
+ */
+ public function getBackScore($user, $goods_id) {
+ if (empty($user)) {
+ return 0;
+ }
+ $level = Agent::where('user_id', $user->id)->value('level');
+// dd($level);
+ $goods_info = \app\admin\model\shopro\goods\Goods::get($goods_id);
+ $level_price = 0;
+ if ($level == self::LEVEL_1) {
+ $level_price = $goods_info['price'][0];
+ }
+ if ($level == self::LEVEL_2) {
+ $level_price = $goods_info['user_price'];
+ }
+ if ($level == self::LEVEL_3) {
+ $level_price = $goods_info['level1_price'];
+ }
+ if ($level == self::LEVEL_4) {
+ $level_price = $goods_info['level2_price'];
+ }
+ if ($level == self::LEVEL_5) {
+ $level_price = $goods_info['level3_price'];
+ }
+ if ($level == self::LEVEL_6) {
+ $level_price = $goods_info['company_price'];
+ }
+ return bcsub($goods_info['price'][0], $level_price, 2);
+ }
+
/**
@@ -194,4 +237,34 @@ class Goods extends Common
$goods = $service->activity($activity_id)->whereIds($goodsIds)->show()->order('weigh', 'desc')->paginate();
$this->success('获取成功', $goods);
}
+
+
+ /**
+ * 新人商品用户是否可以购买
+ */
+ public function isNewUser() {
+ $user = auth_user();
+ $user_id = $user->id;
+ $goods_id = $this->request->param('goods_id');
+ if ($goods_id) {
+ $user_level = Agent::where('user_id', $user_id)->value('level');
+ $goods_info = \app\admin\model\shopro\goods\Goods::get($goods_id);
+ if (!empty($goods_info)) {
+ if ($goods_info['is_new_user'] == 1) {
+ if ($user_level != 1 ) {
+ $this->error('你无发购买新人大礼包', [], 100);
+ }
+
+ $new_order = Order::with(['items' => function($query) use($goods_id) {
+ $query->where('goods_id', $goods_id);
+ }])->where('user_id', $user_id)
+ ->find();
+ if ($new_order) {
+ $this->error('您已经购买过新人大礼包了', [], 200);
+ }
+ }
+ $this->success('当前商品不是新人大礼包', []);
+ }
+ }
+ }
}
diff --git a/addons/shopro/controller/user/User.php b/addons/shopro/controller/user/User.php
index b289c65..b3e6699 100755
--- a/addons/shopro/controller/user/User.php
+++ b/addons/shopro/controller/user/User.php
@@ -149,7 +149,7 @@ class User extends Common
//登录注册根据注册码绑定上级
if (!empty($params['user_code'])) {
$parent_user_id = UserModel::where('user_code', $params['user_code'])->value('id');
- if (empty($parent_user_id)) {
+ if (!empty($parent_user_id) && empty($user->parent_user_id)) {
$user->parent_user_id = $parent_user_id;
$user->save();
}
diff --git a/addons/shopro/job/Commission.php b/addons/shopro/job/Commission.php
index 6f72cc8..4204a44 100755
--- a/addons/shopro/job/Commission.php
+++ b/addons/shopro/job/Commission.php
@@ -45,8 +45,10 @@ class Commission extends BaseJob
try {
$userId = $payload['user_id'];
$order = $payload['order'];
+ \think\Log::info('当前分销商ID=' . json_encode($userId));
+// dd(11);
$agentScore = new CommissionScoreLog($userId);
-
+ \think\Log::info('当前分销商数据=' . json_encode($agentScore));
if ($agentScore->user) {
Db::transaction(function () use ($agentScore, $order) {
$agentScore->runAgentUpgradePlan($order);
@@ -69,10 +71,12 @@ class Commission extends BaseJob
try {
$userId = $payload['user_id'];
$order = $payload['order'];
+ \think\Log::info('当前分销商ID=' . json_encode($userId));
$agentScore = new CommissionScoreLog($userId);
-
+ \think\Log::info('当前分销商数据=' . json_encode($agentScore->user));
if ($agentScore->user) {
Db::transaction(function () use ($agentScore, $order) {
+ \think\Log::info('当前分销商订单数据=' . json_encode($order));
$agentScore->agentScoreSettlePlan($order);
});
}
diff --git a/addons/shopro/listener/Commission.php b/addons/shopro/listener/Commission.php
index 8daa323..dc48c5a 100755
--- a/addons/shopro/listener/Commission.php
+++ b/addons/shopro/listener/Commission.php
@@ -66,6 +66,7 @@ class Commission
$user = $params['user'];
$agent = new AgentService($user);
+ $CommissionScoreLog = new CommissionScoreLog($user);
// 绑定用户关系
$agent->bindUserRelation('pay');
@@ -75,7 +76,7 @@ class Commission
foreach ($items as $item) {
// 异步执行积分结算计划
- (new CommissionScoreLog($user))->createAsyncAgentScoreSettlePlan($item);
+ $CommissionScoreLog->agentScoreSettlePlan($item);
if (isset($item['ext']['is_commission']) && !$item['ext']['is_commission']) continue;
@@ -100,7 +101,7 @@ class Commission
// 分销商数据统计&升级(异步执行)
$agent->createAsyncAgentUpgrade();
// 分销商升级(新)
- (new CommissionScoreLog($user))->createAsyncAgentUpgradeNew($order);
+// $CommissionScoreLog->runAgentUpgradePlan($order);
}
// 线下付款后
diff --git a/addons/shopro/service/CommissionScoreLog.php b/addons/shopro/service/CommissionScoreLog.php
index acc171e..0f702f5 100644
--- a/addons/shopro/service/CommissionScoreLog.php
+++ b/addons/shopro/service/CommissionScoreLog.php
@@ -35,6 +35,8 @@ class CommissionScoreLog
const LEVEL_4 = 4;//中级代理
const LEVEL_5 = 5;//高级代理
+ const LEVEL_6 = 6;//公司账户
+
public function __construct($user = null)
{
if (is_numeric($user)) {
@@ -53,221 +55,137 @@ class CommissionScoreLog
* @param object $currentAgent 当前待分佣的分销商 默认自购开始算
* @param int $currentCommissionLevel 当前分佣层级 一级(自购)开始算
*/
- public function agentScoreSettlePlan($order, $currentAgent = null, $currentCommissionLevel = 1) {
-// if ($currentCommissionLevel >= self::CALC_LEVEL) {
-// return true;
-// }
- // 当前层级为1且分销订单是自购订单 则当前分销商为购买人自己
- if ($currentCommissionLevel === 1) {
- $currentAgent = new Agent($order->user_id);
- }
-
- if ($currentAgent && !empty($currentAgent->user)) {
+ public function agentScoreSettlePlan($order, $currentCommissionLevel = 1)
+ {
+ \think\Log::info('当前分销商订单数据=' . json_encode($order));
+ $currentAgent = new Agent($this->user);
+ \think\Log::info('当前分销商数据222=' . json_encode($currentAgent));
+ if (!empty($currentAgent)) {
// 获取用户分销等级
- $agentLevel = $this->getAgentLevel($currentAgent);
+ $agentLevel = $currentAgent->getAgentLevel();
+ \think\Log::info('当前用户分销等级=' . json_encode($agentLevel));
if ($agentLevel) {
- //普通用户
-// if ($agentLevel == self::LEVEL_1) {
- $this->userBackScorePlan($order, $currentAgent, $currentCommissionLevel, $agentLevel);
-// }
-// //会员
-// if ($agentLevel == self::LEVEL_2) {
-// $this->memberBackPlan($order, $currentAgent, $currentCommissionLevel, $agentLevel);
-// }
-//
-// //初级代理
-// if ($agentLevel == self::LEVEL_3 ) {
-// $this->level1BackPlan($order, $currentAgent, $currentCommissionLevel, $agentLevel);
-// }
-//
-// //中级代理
-// if ($agentLevel == self::LEVEL_4) {
-// $this->level2BackPlan($order, $currentAgent, $currentCommissionLevel, $agentLevel);
-// }
-//
-// //高级代理
-// if ($agentLevel == self::LEVEL_5) {
-// return $this->level3BackPlan($order, $currentAgent, $currentCommissionLevel, $agentLevel);
-// }
+ $this->userBackScorePlan($order, $currentAgent, $currentCommissionLevel, $agentLevel, $level5 = 0);
}
}
return true;
- // 递归执行下一次
-// $currentCommissionLevel++;
-// // 超出分销层级
-// if (self::CALC_LEVEL < $currentCommissionLevel) {
-// return true;
-// }
-// $parentUserId = $currentAgent->getParentUserId();
-// // 执行下一级分销任务
-// if ($parentUserId) {
-// $parentAgent = new Agent($parentUserId);
-// $this->agentScoreSettlePlan($order, $parentAgent, $currentCommissionLevel);
-// } else {
-// return true;
-// }
-
-
-
}
/**
* 用户返积分计划
*/
- public function userBackScorePlan($order, $currentAgent, $currentCommissionLevel, $initLevel) {
- // 递归执行下一次
- $currentCommissionLevel++;
+ public function userBackScorePlan($order, $currentAgent, $currentCommissionLevel, $initLevel, $level5) {
+ \think\Log::info('当前分销商等级=' . $initLevel . '] ---start'.'---高级分销商---'.$level5);
+
+ \think\Log::info('当前分销商订单信息=' . json_encode($order) . '] ---start'.'---高级分销商---'.$level5.'---循环次数---'.$currentCommissionLevel);
+
// 超出分销层级
if (self::CALC_LEVEL < $currentCommissionLevel) {
return true;
}
$parentUserId = $currentAgent->getParentUserId();
- // 执行下一级分销任务
+ $currentLevel = $this->getAgentLevel($currentAgent);
+ $current_level_price = $this->getGoodPriceByLevel($order['goods_id'], $currentLevel)[0];
+ $company_level_price = $this->getGoodPriceByLevel($order['goods_id'], self::LEVEL_6)[0];
+
+ \think\Log::info('上级分销商ID=' . $parentUserId . '] ---start'.'---高级分销商---'.$level5.'---循环次数---'.$currentCommissionLevel);
+ //非用户角色下单立即反积分
+ if ($initLevel > self::LEVEL_1 && $currentCommissionLevel == 1) {
+ $amount = bcsub($order['goods_price'], $current_level_price, 2);
+ //算积分
+ Wallet::change($currentAgent->user->id, 'score', $amount, 'back_score', [], '下单返现');
+ $this->calcCompany($current_level_price, $company_level_price);
+ }
+ // 执行下一级返现任务
if ($parentUserId) {
$parentAgent = new Agent($parentUserId);
$parentLevel = $this->getAgentLevel($parentAgent);
- $parent_level_price = $this->getGoodPriceByLevel($order->goods_id, $parentLevel);
- $current_level_price = $this->getGoodPriceByLevel($order->goods_id, $currentAgent);
- $crrentLevel = $this->getAgentLevel($currentAgent);
- //只有上级分销等级 比自己高才算佣金
+
+ \think\Log::info('父用户等级'.$parentLevel);
+ \think\Log::info('当前用户等级'.$currentLevel);
+ $parent_level_price = $this->getGoodPriceByLevel($order['goods_id'], $parentLevel)[0];
+ $is_new_user = $this->getGoodPriceByLevel($order['goods_id'], $parentLevel)[1];
+
+ //新人大礼包商品不用计算返积分 给用户升级
+ if ($is_new_user == 1 && $initLevel == self::LEVEL_1) {
+// $currentAgent->level = self::LEVEL_2;
+// $currentAgent->save();
+ return true;
+ }
+
+
+ //只有上级分销等级 比初始高才算佣金
if ($parentLevel > $initLevel) {
//1.会员不参与反佣
if ($parentLevel == self::LEVEL_2) {
return true;
}
- //2.向上反佣金
- if ($parentLevel > $crrentLevel) {
+
+ //3.向上反佣金
+ if ($parentLevel > $currentLevel) {
$amount = bcsub($current_level_price, $parent_level_price, 2);
+ \think\Log::info('上级商品价格'.$parent_level_price);
+ \think\Log::info('当前商品价格'.$current_level_price);
+ if (!empty($amount) && $amount> 0) {
+ $this->calcCompany($parent_level_price, $company_level_price);
+ //算积分
+ Wallet::change($parentAgent->user->id, 'score', $amount, 'team_order', [], '团队下单');
+ }
}
- //3.用户的上上级是高级 算团队2%
- if ($parentLevel == self::LEVEL_5 && $crrentLevel == self::LEVEL_5) {
- $amount = bcmul($order->pay_fee, '0.02', 2);
- }
+ }
+
+ //4.用户的上上级是高级 算团队2%
+ if ($parentLevel == self::LEVEL_5 && $currentLevel == self::LEVEL_5 && $level5<2) {
- if (!empty($amount) && $amount> 0) {
+ if ($level5 == 0) {
+ $amount = bcmul($order['goods_price'], '0.02', 2);
+ $this->calcCompany($parent_level_price, $company_level_price, $amount);
//算积分
Wallet::change($parentAgent->user->id, 'score', $amount, 'team_order', [], '团队下单');
}
+ $level5++;
}
- $this->userBackScorePlan($order, $parentAgent, $currentCommissionLevel, $initLevel);
- } else {
- return true;
- }
- return true;
- }
-
- /**
- * 会员返佣计划
- */
- public function memberBackPlan($order, $currentAgent = null, $currentCommissionLevel = 1) {
- // 递归执行下一次
- $currentCommissionLevel++;
- // 超出分销层级
- if (self::CALC_LEVEL < $currentCommissionLevel) {
- return true;
- }
- $parentUserId = $currentAgent->getParentUserId();
- // 执行下一级分销任务
- if ($parentUserId) {
- $parentAgent = new Agent($parentUserId);
- $parentLevel = $this->getAgentLevel($parentAgent);
- $level_price = $this->getGoodPriceByLevel($order->goods_id, $parentLevel);
- $amount = bcsub($level_price, $order->pay_fee, 2);
- //算积分
- Wallet::change($parentAgent->user->id, 'score', $amount, 'team_order', [], '团队下单');
-
- $this->memberBackPlan($order, $parentAgent, $currentCommissionLevel);
- } else {
- return true;
- }
-
-
- return true;
- }
-
- /**
- * 初级代理返佣金
- * @param $order
- * @param $currentAgent
- * @param $currentCommissionLevel
- */
- public function level1BackPlan($order, $currentAgent = null, $currentCommissionLevel = 1) {
- // 递归执行下一次
- $currentCommissionLevel++;
- // 超出分销层级
- if (self::CALC_LEVEL < $currentCommissionLevel) {
- return true;
- }
- $parentUserId = $currentAgent->getParentUserId();
- // 执行下一级分销任务
- if ($parentUserId) {
- $parentAgent = new Agent($parentUserId);
- $parentLevel = $this->getAgentLevel($parentAgent);
- $level_price = $this->getGoodPriceByLevel($order->goods_id, $parentLevel);
- $amount = bcsub($level_price, $order->goods_amount, 2);
- //算积分
- Wallet::change($parentAgent->user->id, 'score', $amount, 'team_order', [], '团队下单');
+ // 递归执行下一次
+ $currentCommissionLevel++;
+ if ($parentAgent) {
+ $this->userBackScorePlan($order, $parentAgent, $currentCommissionLevel, $initLevel, $level5);
+ } else {
+ return true;
+ }
- $this->level1BackPlan($order, $parentAgent, $currentCommissionLevel);
} else {
return true;
}
-
return true;
-
}
/**
- * 中级代理返佣金
* @param $order
- * @param $currentAgent
- * @param $currentCommissionLevel
+ * 公司账户算佣金
*/
- public function level2BackPlan($order, $currentAgent = null, $currentCommissionLevel = 1) {
- // 递归执行下一次
- $currentCommissionLevel++;
- // 超出分销层级
- if (self::CALC_LEVEL < $currentCommissionLevel) {
- return true;
+ public function calcCompany($currentPrice, $companyPrice, $amountRate = 0) {
+ $amount = bcsub($currentPrice, $companyPrice, 2);
+ //同级奖励佣金 算差额
+ if ($amountRate > 0) {
+ $amount = bcsub($amount, $amountRate, 2);
}
- $parentUserId = $currentAgent->getParentUserId();
- // 执行下一级分销任务
- if ($parentUserId) {
- $parentAgent = new Agent($parentUserId);
- $parentLevel = $this->getAgentLevel($parentAgent);
- $level_price = $this->getGoodPriceByLevel($order->goods_id, $parentLevel);
- $amount = bcsub($level_price, $order->goods_amount, 2);
- //算积分
- Wallet::change($parentAgent->user->id, 'score', $amount, 'team_order', [], '团队下单');
-
- $this->level2BackPlan($order, $parentAgent, $currentCommissionLevel);
- } else {
- return true;
- }
-
- return true;
+ Wallet::change(2, 'score', $amount, 'team_order', [], '用户下单');
}
- public function level3BackPlan($order, $currentAgent = null, $currentCommissionLevel = 1) {
- //高级不参与反佣金
- return true;
- }
-
-
-
- /**
+ /*
* 执行分销用户升级计划
*/
public function runAgentUpgradePlan($order, $currentCommissionLevel = 1) {
//默认只算到10级
if ($currentCommissionLevel >= self::CALC_LEVEL) {
- return true;
+ return false;
}
$canUpgradeLevel = $this->checkAgentUpgradeLevel($this->agent, $order);
+ \think\Log::info('当前分销商升级信息=' . $canUpgradeLevel . '] ---start'.'---循环次数---'.$currentCommissionLevel);
if ($canUpgradeLevel) {
// if ($this->config->isUpgradeCheck()) {
// $this->agent->level_status = $canUpgradeLevel;
@@ -278,10 +196,11 @@ class CommissionScoreLog
$this->agent->save();
}
$parentUserId = $this->getParentUserId();
+ \think\Log::info('上级分销商ID=' . $parentUserId . '] ---start'.'---分销商订单---'.json_encode($order).'---循环次数---'.$currentCommissionLevel);
if ($parentUserId) {
$this->createAsyncAgentUpgradeNew($parentUserId, $order);
}
- return true;
+ return false;
}
@@ -290,7 +209,7 @@ class CommissionScoreLog
* 创建[分销商升级&统计业绩]异步队列任务
* 为了防止计算量大而引起阻塞,使用异步递归
*/
- public function createAsyncAgentUpgradeNew($order,$user_id = 0)
+ public function createAsyncAgentUpgradeNew($user_id, $order)
{
if ($user_id === 0) {
$user_id = $this->user->id;
@@ -349,7 +268,8 @@ class CommissionScoreLog
* 查询用户消费和下级团队消费总额
*/
public function getNextTeamTotal($user_id) {
- $nextUserIds = $this->getNextTeamUserIds($this->getParent($user_id));
+ $nextUserIds = [];
+ $this->getNextTeamUserIds($this->getParent($user_id), $nextUserIds);
return Order::whereIn('user_id', $nextUserIds)
->where('status', Order::STATUS_PAID)
->sum('order_amount');
@@ -359,13 +279,12 @@ class CommissionScoreLog
* 获取所有下级团队人数
* @return
*/
- public function getNextTeamUserIds($user) {
- static $nextUserIds = [];
+ public function getNextTeamUserIds($user, &$nextUserIds) {
foreach ($user as $item) {
$nextUserIds[] = $item['id'];
$nexUserData = $this->getParent($item['id']);
if (is_array($nexUserData)) {
- $this->getNextTeamUserIds($nexUserData);
+ $this->getNextTeamUserIds($nexUserData, $nextUserIds);
}
}
return $nextUserIds;
@@ -393,8 +312,28 @@ class CommissionScoreLog
*/
public function getGoodPriceByLevel($goods_id, $level) {
$goods_info = Goods::get($goods_id);
- $name = 'leve'.$level.'_price';
- return $goods_info[$name] ?? 00;
+ $level_price = 0;
+ if ($level == self::LEVEL_1) {
+ $level_price = $goods_info['price'][0];
+ }
+ if ($level == self::LEVEL_2) {
+ $level_price = $goods_info['user_price'];
+ }
+ if ($level == self::LEVEL_3) {
+ $level_price = $goods_info['level1_price'];
+ }
+ if ($level == self::LEVEL_4) {
+ $level_price = $goods_info['level2_price'];
+ }
+ if ($level == self::LEVEL_5) {
+ $level_price = $goods_info['level3_price'];
+ }
+ if ($level == self::LEVEL_6) {
+ $level_price = $goods_info['company_price'];
+ }
+ \think\Log::info('当前商品价格=' .json_encode($goods_info));
+
+ return [$level_price, $goods_info['is_new_user']];
}
diff --git a/addons/shopro/service/order/OrderCreate.php b/addons/shopro/service/order/OrderCreate.php
index cafec7c..31472e5 100755
--- a/addons/shopro/service/order/OrderCreate.php
+++ b/addons/shopro/service/order/OrderCreate.php
@@ -38,8 +38,23 @@ class OrderCreate
*/
protected $address_id = 0;
+ /**
+ * 自提相关信息
+ */
protected $warehouse_id = 0;
+ /**
+ * 自提时间
+ * @var string
+ */
+ protected $selffetch_time = '';
+
+ /**
+ * 自提手机号
+ */
+ protected $self_phone = '';
+
+
protected $dispatch_type;
/**
@@ -158,6 +173,8 @@ class OrderCreate
$this->remark = $params['remark'] ?? '';
$this->warehouse_id = $params['warehouse_id'] ?? 0;
+ $this->selffetch_time = $params['selffetch_time'] ?? 0;
+ $this->self_phone = $params['phone'] ?? 0;
$this->dispatch_type = $params['dispatch_type'] ?? 'express';
@@ -1119,6 +1136,8 @@ class OrderCreate
$orderData['status'] = Order::STATUS_UNPAID;
$orderData['platform'] = request()->header('platform');
$orderData['warehouse_id'] = $this->warehouse_id;//添加自提地址
+ $orderData['selffetch_time'] = $this->selffetch_time;//添加自提地址
+ $orderData['self_phone'] = $this->self_phone;//添加自提联系人
diff --git a/application/admin/controller/shopro/Coupon.php b/application/admin/controller/shopro/Coupon.php
index 1d58bef..51a3798 100755
--- a/application/admin/controller/shopro/Coupon.php
+++ b/application/admin/controller/shopro/Coupon.php
@@ -190,8 +190,9 @@ class Coupon extends Common
'limit_num' => 1,
'items'=> $params['items'],
'stock' => 10000,
- 'use_time_type' => 'range',
- 'days' => 365,
+ 'use_time_type' => 'days',
+ 'days' => $params['days'],
+ 'start_days' => $params['start_days'],
'type' => 'reduce',
'amount' => $amount,//优惠券面值金额
'enough' => 0,//消费门槛
diff --git a/application/admin/controller/shopro/user/User.php b/application/admin/controller/shopro/user/User.php
index 7d01ffa..1451114 100755
--- a/application/admin/controller/shopro/user/User.php
+++ b/application/admin/controller/shopro/user/User.php
@@ -34,7 +34,7 @@ class User extends Common
$data = $this->model->sheepFilter()->paginate($this->request->param('list_rows', 10));
foreach ($data as $key=>$row) {
- $user_info = UserModel::with(['agent.level_info'])->find()->toArray();
+// $user_info = UserModel::with(['agent.level_info'])->find()->toArray();
// dd($user_info);
$agent = Agent::with('level_info')->where('user_id', $row['id'])->find();
if (!empty($agent)) {
diff --git a/application/admin/model/content/Article.php b/application/admin/model/content/Article.php
index 3383571..e0f5441 100755
--- a/application/admin/model/content/Article.php
+++ b/application/admin/model/content/Article.php
@@ -18,6 +18,8 @@ class Article extends Model
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
+ protected $dateFormat = 'Y-m-d H:i:s';
+
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
diff --git a/application/admin/model/content/Company.php b/application/admin/model/content/Company.php
index 4dbfef7..270a91c 100755
--- a/application/admin/model/content/Company.php
+++ b/application/admin/model/content/Company.php
@@ -18,6 +18,8 @@ class Company extends Model
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
+ protected $dateFormat = 'Y-m-d H:i:s';
+
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
diff --git a/application/admin/model/content/Notice.php b/application/admin/model/content/Notice.php
index e89cc97..352258b 100755
--- a/application/admin/model/content/Notice.php
+++ b/application/admin/model/content/Notice.php
@@ -19,6 +19,8 @@ class Notice extends Model
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
+ protected $dateFormat = 'Y-m-d H:i:s';
+
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
diff --git a/application/admin/model/shopro/user/WalletLog.php b/application/admin/model/shopro/user/WalletLog.php
index 85ba3a1..8572805 100755
--- a/application/admin/model/shopro/user/WalletLog.php
+++ b/application/admin/model/shopro/user/WalletLog.php
@@ -39,6 +39,7 @@ class WalletLog extends Common
'user_exchange' => '积分转让',
'team_order' => '团队下单',
'order_recharge' => '积分充值',
+ 'back_score' => '下单返现'
],
'money' => [
'order_pay' => '商城订单-余额支付',
diff --git a/application/admin/view/shopro/coupon/add.html b/application/admin/view/shopro/coupon/add.html
index 5a91261..5817a87 100755
--- a/application/admin/view/shopro/coupon/add.html
+++ b/application/admin/view/shopro/coupon/add.html
@@ -90,32 +90,32 @@