|
|
@@ -11,6 +11,7 @@
|
|
|
|
|
|
namespace App\Services\Api;
|
|
|
|
|
|
+use App\Models\AgentModel;
|
|
|
use App\Models\CartModel;
|
|
|
use App\Models\GoodsModel;
|
|
|
use App\Models\GoodsSkuModel;
|
|
|
@@ -246,6 +247,7 @@ class OrderService extends BaseService
|
|
|
->select(['id', 'openid','wechat_openid', 'mobile', 'nickname', 'realname', 'balance', 'status'])
|
|
|
->first();
|
|
|
$status = isset($userInfo['status']) ? $userInfo['status'] : 0;
|
|
|
+ $parentId = isset($userInfo['parent_id']) ? $userInfo['parent_id'] : 0;
|
|
|
$openid = isset($userInfo['openid']) ? $userInfo['openid'] : '';
|
|
|
$wechatOpenid = isset($userInfo['wechat_openid']) &&$userInfo['wechat_openid'] ? $userInfo['wechat_openid'] : $openid;
|
|
|
$openid = $platform=='wechat'?$wechatOpenid:$openid;
|
|
|
@@ -286,6 +288,10 @@ class OrderService extends BaseService
|
|
|
$orderTotal = 0.1;
|
|
|
}
|
|
|
|
|
|
+ // 推荐消费者的佣金
|
|
|
+ $agentDirectBonusRate = ConfigService::make()->getConfigByCode('agent_direct_bonus_rate', 0);
|
|
|
+ $agentDirectBonusRate = $agentDirectBonusRate>0 && $agentDirectBonusRate<100? $agentDirectBonusRate : 0;
|
|
|
+ $recBonus = moneyFormat($agentDirectBonusRate * $total/100, 2);
|
|
|
|
|
|
// 订单数据
|
|
|
$order = [
|
|
|
@@ -300,6 +306,10 @@ class OrderService extends BaseService
|
|
|
'receiver_area' => $area,
|
|
|
'receiver_address' => $address,
|
|
|
'bonus' => $bonus,
|
|
|
+ 'rec_bonus_id' => $parentId,
|
|
|
+ 'rec_bonus_rate' => $agentDirectBonusRate,
|
|
|
+ 'rec_bonus' => $recBonus,
|
|
|
+ 'rec_bonus_settle' => 2,
|
|
|
'create_time' => time(),
|
|
|
'update_time' => time(),
|
|
|
'status' => 1,
|
|
|
@@ -600,7 +610,6 @@ class OrderService extends BaseService
|
|
|
->select(['id', 'openid', 'mobile', 'parent_id', 'nickname', 'realname', 'balance', 'status'])
|
|
|
->first();
|
|
|
$status = isset($userInfo['status']) ? $userInfo['status'] : 0;
|
|
|
- $parentId = isset($userInfo['parent_id']) ? $userInfo['parent_id'] : 0;
|
|
|
if ($check && (empty($userInfo) || $status != 1)) {
|
|
|
$this->error = 1045;
|
|
|
RedisService::clear($cacheLockKey);
|
|
|
@@ -609,7 +618,7 @@ class OrderService extends BaseService
|
|
|
|
|
|
// 订单信息
|
|
|
$info = $this->model->with(['orderGoods'])->where(['id' => $id, 'mark' => 1])
|
|
|
- ->select(['id', 'order_no', 'store_id', 'pay_total', 'bonus', 'delivery_no', 'delivery_company', 'delivery_code', 'status'])
|
|
|
+ ->select(['id', 'order_no', 'store_id', 'pay_total', 'bonus','rec_bonus_id','rec_bonus','rec_bonus_settle', 'delivery_no', 'delivery_company', 'delivery_code', 'status'])
|
|
|
->first();
|
|
|
$orderNo = isset($info['order_no']) ? $info['order_no'] : '';
|
|
|
$deliveryNo = isset($info['delivery_no']) ? $info['delivery_no'] : '';
|
|
|
@@ -617,7 +626,9 @@ class OrderService extends BaseService
|
|
|
$storeId = isset($info['store_id']) ? $info['store_id'] : 0;
|
|
|
$orderTotal = isset($info['pay_total']) ? $info['pay_total'] : 0;
|
|
|
$bonus = isset($info['bonus']) ? $info['bonus'] : 0;
|
|
|
+ $recBonus = isset($info['rec_bonus']) ? $info['rec_bonus'] : 0;
|
|
|
$status = isset($info['status']) ? $info['status'] : 0;
|
|
|
+ $recBonusId = isset($info['rec_bonus_id']) ? $info['status'] : 0;
|
|
|
$orderGoods = isset($info['order_goods']) ? $info['order_goods'] : [];
|
|
|
if (empty($info) || empty($orderNo)) {
|
|
|
$this->error = '订单信息不存在';
|
|
|
@@ -678,7 +689,7 @@ class OrderService extends BaseService
|
|
|
|
|
|
|
|
|
// 代理佣金结算
|
|
|
- if (SettleService::make()->agentBonus($userId, $orderTotal, $info, $parentId) < 0) {
|
|
|
+ if (SettleService::make()->agentBonus($userId, $recBonus, $info, $recBonusId) < 0) {
|
|
|
DB::rollBack();
|
|
|
$this->error = SettleService::make()->getError();
|
|
|
RedisService::clear($cacheLockKey);
|