|
|
|
@ -18,6 +18,7 @@ use app\common\repositories\BaseRepository; |
|
|
|
|
use app\common\repositories\store\product\ProductAssistRepository; |
|
|
|
|
use app\common\repositories\store\product\ProductRepository; |
|
|
|
|
use app\common\repositories\system\groupData\GroupDataRepository; |
|
|
|
|
use app\common\repositories\system\merchant\MerchantCategoryRepository; |
|
|
|
|
use app\common\repositories\system\merchant\MerchantRepository; |
|
|
|
|
use think\db\exception\DataNotFoundException; |
|
|
|
|
use think\db\exception\DbException; |
|
|
|
@ -35,14 +36,16 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
const ASSET_TYPE_HUITONG = 4; // 惠通宝 |
|
|
|
|
const ASSET_TYPE_CONTRIBUTION = 5; // 贡献值 |
|
|
|
|
|
|
|
|
|
const CHANGE_TYPE_ORDER_GET = 1; // 订单获取 |
|
|
|
|
const CHANGE_TYPE_ORDER = 1; // 个人下单 |
|
|
|
|
const CHANGE_TYPE_SIGN = 2; // 签到 |
|
|
|
|
const CHANGE_TYPE_SHARE = 3; // 分红 |
|
|
|
|
const CHANGE_TYPE_ORDER_PAY = 4; // 订单消费 |
|
|
|
|
const CHANGE_TYPE_SPREAD = 5; // 推广 |
|
|
|
|
const CHANGE_TYPE_CULTIVATE = 6; // 培育 |
|
|
|
|
const CHANGE_TYPE_TRANSFER = 7; // 赠与 |
|
|
|
|
const CHANGE_TYPE_EXCHANGE = 8; // 兑换 |
|
|
|
|
const CHANGE_TYPE_SHARE = 3; // 消费积分兑换分红点 |
|
|
|
|
const CHANGE_TYPE_SHARE_GET = 4; // 分红点返佣 |
|
|
|
|
const CHANGE_TYPE_SPREAD_GET = 5; // 推广返佣 |
|
|
|
|
const CHANGE_TYPE_CULTIVATE = 6; // 培育奖 |
|
|
|
|
const CHANGE_TYPE_AGENT = 7; // 区域代理奖 |
|
|
|
|
const CHANGE_TYPE_HUITONG = 8; // 惠通宝兑换消费积分 |
|
|
|
|
const CHANGE_TYPE_HUITONG_TO = 9; // 转让他人 |
|
|
|
|
const CHANGE_TYPE_HUITONG_GET = 10; // 他人转让 |
|
|
|
|
|
|
|
|
|
const STATUS_FROZEN = 0; // 冻结 |
|
|
|
|
const STATUS_SUCCESS = 1; // 成功 |
|
|
|
@ -67,14 +70,16 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
public function getChangeType() |
|
|
|
|
{ |
|
|
|
|
return array( |
|
|
|
|
self::CHANGE_TYPE_ORDER_GET => "订单获取", |
|
|
|
|
self::CHANGE_TYPE_SIGN => "签到", |
|
|
|
|
self::CHANGE_TYPE_SHARE => "分红", |
|
|
|
|
self::CHANGE_TYPE_ORDER_PAY => "订单消费", |
|
|
|
|
self::CHANGE_TYPE_SPREAD => "推广", |
|
|
|
|
self::CHANGE_TYPE_CULTIVATE => "培育", |
|
|
|
|
self::CHANGE_TYPE_TRANSFER => "赠与", |
|
|
|
|
self::CHANGE_TYPE_EXCHANGE => "兑换", |
|
|
|
|
self::CHANGE_TYPE_ORDER => '个人下单', |
|
|
|
|
self::CHANGE_TYPE_SIGN => '签到', |
|
|
|
|
self::CHANGE_TYPE_SHARE => '消费积分兑换分红点', |
|
|
|
|
self::CHANGE_TYPE_SHARE_GET => '分红点返佣', |
|
|
|
|
self::CHANGE_TYPE_SPREAD_GET => '推广返佣', |
|
|
|
|
self::CHANGE_TYPE_CULTIVATE => '培育奖', |
|
|
|
|
self::CHANGE_TYPE_AGENT => '区域代理奖', |
|
|
|
|
self::CHANGE_TYPE_HUITONG => '惠通宝兑换消费积分', |
|
|
|
|
self::CHANGE_TYPE_HUITONG_TO => '转让他人', |
|
|
|
|
self::CHANGE_TYPE_HUITONG_GET => '他人转让', |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -155,38 +160,64 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 6. 商户和平台资产 |
|
|
|
|
// $this->merchantAndPlatformAssets($orderItem); |
|
|
|
|
$this->merchantAndPlatformAssets($orderItem); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function merchantAndPlatformAssets($orderItem){ |
|
|
|
|
/** |
|
|
|
|
* @var MerchantRepository $merchantRepository |
|
|
|
|
*/ |
|
|
|
|
$merchantRepository = app(MerchantRepository::class); |
|
|
|
|
$merchant = $merchantRepository->get($orderItem['mer_id']); |
|
|
|
|
if(empty($merchant)){ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
public function merchantAndPlatformAssets($orderItem) |
|
|
|
|
{ |
|
|
|
|
/** |
|
|
|
|
* @var UserRepository $userRepository |
|
|
|
|
*/ |
|
|
|
|
$userRepository = app(UserRepository::class); |
|
|
|
|
$user = $userRepository->searchOne(['phone' => $merchant['mer_phone']]); |
|
|
|
|
$user = $userRepository->searchOne(['mer_id' => $orderItem['mer_id']]); |
|
|
|
|
if ($user) { |
|
|
|
|
$logList = array(); |
|
|
|
|
$welfare = $huitong = $contribution = 0; |
|
|
|
|
if($user){ |
|
|
|
|
$welfare = $consume = $huitong = $contribution = 0; |
|
|
|
|
$consume = round($orderItem['total_price'] * $orderItem['commission_rate'] / 100, 2); |
|
|
|
|
$consume = $this->_getValue($consume); |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $user['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_CONSUME, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderItem['order_id'], |
|
|
|
|
'count' => $consume, |
|
|
|
|
'mer_id' => $orderItem['mer_id'], |
|
|
|
|
); |
|
|
|
|
if($orderItem['integral']){ |
|
|
|
|
$welfare = round($orderItem['integral'] * (100 - $orderItem['commission_rate']) / 100, 2); |
|
|
|
|
$welfare = $this->_getValue($welfare); |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $user['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_WELFARE, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderItem['order_id'], |
|
|
|
|
'count' => $welfare, |
|
|
|
|
'mer_id' => $merchant['id'], |
|
|
|
|
'mer_id' => $orderItem['mer_id'], |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
$this->addLog($logList); |
|
|
|
|
$this->userAssetsRepository->orderEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution')); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if($orderItem['integral']){ |
|
|
|
|
$welfare = round($orderItem['integral'] * $orderItem['commission_rate'] / 100, 2); |
|
|
|
|
$welfare = $this->_getValue($welfare); |
|
|
|
|
$log = array( |
|
|
|
|
'uid' => 0, |
|
|
|
|
'asset_type' => self::ASSET_TYPE_WELFARE, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderItem['order_id'], |
|
|
|
|
'count' => $welfare, |
|
|
|
|
'mer_id' => 0, |
|
|
|
|
); |
|
|
|
|
$this->addLog([$log]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -203,7 +234,8 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function recommendAssets($merId, $orderId, $config, $base){ |
|
|
|
|
public function recommendAssets($merId, $orderId, $config, $base) |
|
|
|
|
{ |
|
|
|
|
$consume = $welfare = $huitong = $contribution = 0; |
|
|
|
|
/** |
|
|
|
|
* @var MerchantRepository $merRepository |
|
|
|
@ -213,7 +245,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
if (empty($merchant)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if($merchant['spread_uid'] == 0){ |
|
|
|
|
if ($merchant['spread_uid'] == 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -227,31 +259,31 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$log= array( |
|
|
|
|
$log = array( |
|
|
|
|
'uid' => $user['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_WELFARE, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_SPREAD_GET, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if($user['agent_district_id']){ |
|
|
|
|
if ($user['agent_district_id']) { |
|
|
|
|
// 区域代理 |
|
|
|
|
$orderWelfare = round($base * $config['welfare_agent_recommend'] / 100, 2); |
|
|
|
|
$welfare = $this->_getValue($orderWelfare); |
|
|
|
|
$ext = array('district_id' => $user['agent_district_id'], 'name' => "区域代理推荐商家"); |
|
|
|
|
}elseif ($user['group_id']){ |
|
|
|
|
} elseif ($user['group_id']) { |
|
|
|
|
// 项目经理 |
|
|
|
|
$orderWelfare = round($base * $config['welfare_project_recommend'] / 100, 2); |
|
|
|
|
$welfare = $this->_getValue($orderWelfare); |
|
|
|
|
$ext = array('group_id' => $user['group_id'], 'name' => "项目经理推荐商家"); |
|
|
|
|
}elseif ($user['mer_id']){ |
|
|
|
|
} elseif ($user['mer_id']) { |
|
|
|
|
// 商家 |
|
|
|
|
$orderWelfare = round($base * $config['welfare_merchant_recommend'] / 100, 2); |
|
|
|
|
$welfare = $this->_getValue($orderWelfare); |
|
|
|
|
$ext = array('mer_id' => $user['mer_id'], 'name' => "商家推荐商家"); |
|
|
|
|
} else{ |
|
|
|
|
return ; |
|
|
|
|
} else { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
$log['count'] = $welfare; |
|
|
|
|
$log['ext'] = $ext; |
|
|
|
@ -274,7 +306,8 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function agentAssets($districtId, $orderId, $config, $base){ |
|
|
|
|
public function agentAssets($districtId, $orderId, $config, $base) |
|
|
|
|
{ |
|
|
|
|
$consume = $welfare = $huitong = $contribution = 0; |
|
|
|
|
/** |
|
|
|
|
* @var UserRepository $userRepository |
|
|
|
@ -291,7 +324,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $user['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_WELFARE, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_AGENT, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'count' => $welfare, |
|
|
|
@ -337,7 +370,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $userProject['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_WELFARE, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_CULTIVATE, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'count' => $welfare, |
|
|
|
@ -349,7 +382,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $userProject['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_HUITONG, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_CULTIVATE, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'count' => $huitong, |
|
|
|
@ -361,7 +394,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $userProject['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_CONTRIBUTION, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_CULTIVATE, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'count' => $contribution, |
|
|
|
@ -417,7 +450,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $userProject['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_WELFARE, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_SPREAD_GET, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'count' => $welfare, |
|
|
|
@ -429,7 +462,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $userProject['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_HUITONG, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_SPREAD_GET, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'count' => $huitong, |
|
|
|
@ -441,7 +474,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $userProject['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_CONTRIBUTION, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_SPREAD_GET, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderId, |
|
|
|
|
'count' => $contribution, |
|
|
|
@ -474,7 +507,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $orderItem['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_CONSUME, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderItem['order_id'], |
|
|
|
|
'count' => $orderItem['pay_price'], |
|
|
|
@ -489,7 +522,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $orderItem['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_WELFARE, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderItem['order_id'], |
|
|
|
|
'count' => $welfare, |
|
|
|
@ -501,7 +534,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $orderItem['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_HUITONG, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderItem['order_id'], |
|
|
|
|
'count' => $huitong, |
|
|
|
@ -513,7 +546,7 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
$logList[] = array( |
|
|
|
|
'uid' => $orderItem['uid'], |
|
|
|
|
'asset_type' => self::ASSET_TYPE_CONTRIBUTION, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER_GET, |
|
|
|
|
'type' => self::CHANGE_TYPE_ORDER, |
|
|
|
|
'status' => self::STATUS_FROZEN, |
|
|
|
|
'order_id' => $orderItem['order_id'], |
|
|
|
|
'count' => $contribution, |
|
|
|
@ -524,8 +557,9 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function _getValue($value){ |
|
|
|
|
if($value < 0.01){ |
|
|
|
|
private function _getValue($value) |
|
|
|
|
{ |
|
|
|
|
if ($value < 0.01) { |
|
|
|
|
return 0.01; |
|
|
|
|
} |
|
|
|
|
return $value; |
|
|
|
@ -564,13 +598,14 @@ class UserAssetsLogRepository extends BaseRepository |
|
|
|
|
* @author zhangkxiang |
|
|
|
|
* @editor |
|
|
|
|
*/ |
|
|
|
|
public function list($uid, $where, $page, $limit){ |
|
|
|
|
public function list($uid, $where, $page, $limit) |
|
|
|
|
{ |
|
|
|
|
$query = $this->dao->search($uid, $where); |
|
|
|
|
$count = $query->count(); |
|
|
|
|
$data = $query->page($page, $limit)->select(); |
|
|
|
|
$list = array(); |
|
|
|
|
$changeType = $this->getChangeType(); |
|
|
|
|
foreach ($data as $item){ |
|
|
|
|
foreach ($data as $item) { |
|
|
|
|
$item['type'] = $changeType[$item['type']]; |
|
|
|
|
$list[] = $item; |
|
|
|
|
} |
|
|
|
|