|
@@ -332,8 +332,14 @@ class TradeService extends BaseService
|
|
|
*/
|
|
*/
|
|
|
public function getUserTradeTotal($userId, $status = 0, $time = 0)
|
|
public function getUserTradeTotal($userId, $status = 0, $time = 0)
|
|
|
{
|
|
{
|
|
|
- $where = ['a.user_id' => $userId, 'a.mark' => 1,'b.status'=>1];
|
|
|
|
|
- return $this->model->from('trade as a')
|
|
|
|
|
|
|
+ $cacheKey = "caches:trade:userTotal:{$userId}_".(is_array($status)? implode('-', $status):$status)."_{$time}";
|
|
|
|
|
+ $data = RedisService::get($cacheKey);
|
|
|
|
|
+ if($data){
|
|
|
|
|
+ return $data;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $where = ['a.user_id' => $userId, 'a.mark' => 1,'b.status'=>1,'b.mark'=>1];
|
|
|
|
|
+ $data = $this->model->from('trade as a')
|
|
|
->leftJoin('member as b','b.id','=','a.user_id')
|
|
->leftJoin('member as b','b.id','=','a.user_id')
|
|
|
->where($where)
|
|
->where($where)
|
|
|
->where(function ($query) use ($status, $time) {
|
|
->where(function ($query) use ($status, $time) {
|
|
@@ -348,6 +354,9 @@ class TradeService extends BaseService
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
->sum('a.real_price');
|
|
->sum('a.real_price');
|
|
|
|
|
+
|
|
|
|
|
+ RedisService::set($cacheKey, $data, rand(3,5));
|
|
|
|
|
+ return $data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -359,8 +368,14 @@ class TradeService extends BaseService
|
|
|
*/
|
|
*/
|
|
|
public function getTeamTradeTotal($userId, $status = 0, $time = 0)
|
|
public function getTeamTradeTotal($userId, $status = 0, $time = 0)
|
|
|
{
|
|
{
|
|
|
|
|
+ $cacheKey = "caches:trade:teamTotal:{$userId}_".(is_array($status)? implode('-', $status):$status)."_{$time}";
|
|
|
|
|
+ $data = RedisService::get($cacheKey);
|
|
|
|
|
+ if($data){
|
|
|
|
|
+ return $data;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$where = ['b.parent_id' => $userId, 'a.mark' => 1,'b.status'=>1];
|
|
$where = ['b.parent_id' => $userId, 'a.mark' => 1,'b.status'=>1];
|
|
|
- return $this->model->from('trade as a')
|
|
|
|
|
|
|
+ $data = $this->model->from('trade as a')
|
|
|
->leftJoin('member as b', 'b.id', '=', 'a.user_id')
|
|
->leftJoin('member as b', 'b.id', '=', 'a.user_id')
|
|
|
->where($where)
|
|
->where($where)
|
|
|
->where(function ($query) use ($status, $time) {
|
|
->where(function ($query) use ($status, $time) {
|
|
@@ -375,6 +390,103 @@ class TradeService extends BaseService
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
->sum('a.real_price');
|
|
->sum('a.real_price');
|
|
|
|
|
+
|
|
|
|
|
+ RedisService::set($cacheKey, $data, rand(3,5));
|
|
|
|
|
+ return $data;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取用户佣金统计
|
|
|
|
|
+ * @param $userId
|
|
|
|
|
+ * @param int $status
|
|
|
|
|
+ * @param int $time
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getTradeBonusTotal($userId, $status = 0, $time = 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ $cacheKey = "caches:trade:bonus:{$userId}_".(is_array($status)? implode('-', $status):$status)."_".(is_array($time)? implode('-', $time):$time);
|
|
|
|
|
+ $data = RedisService::get($cacheKey);
|
|
|
|
|
+ if($data){
|
|
|
|
|
+ return round($data, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $where = ['a.user_id' => $userId, 'a.mark' => 1,'b.status'=>1];
|
|
|
|
|
+ $data = $this->model->from('trade as a')
|
|
|
|
|
+ ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
|
|
|
|
|
+ ->where($where)
|
|
|
|
|
+ ->where(function ($query) use ($status, $time) {
|
|
|
|
|
+ $query->whereIn('a.status', is_array($status) ? $status : [$status]);
|
|
|
|
|
+
|
|
|
|
|
+ // 本月
|
|
|
|
|
+ if ($time == 1) {
|
|
|
|
|
+ $query->where('a.pay_time', '>=', strtotime(date('Y-m-01')));
|
|
|
|
|
+ } // 今日
|
|
|
|
|
+ else if ($time == 2) {
|
|
|
|
|
+ $query->where('a.pay_time', '>=', strtotime(date('Y-m-d')));
|
|
|
|
|
+ }else if (is_array($time)){
|
|
|
|
|
+ $start = isset($time[0])? $time[0] : '';
|
|
|
|
|
+ $end = isset($time[1])? $time[1] : '';
|
|
|
|
|
+ if($end && $end>$start){
|
|
|
|
|
+ $query->where('a.pay_time', '<=', strtotime($end));
|
|
|
|
|
+ if($start){
|
|
|
|
|
+ $query->where('a.pay_time', '>=', strtotime($start));
|
|
|
|
|
+ }
|
|
|
|
|
+ }else if ($start){
|
|
|
|
|
+ $query->where('a.pay_time', '=', strtotime($start));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ ->sum('a.bonus');
|
|
|
|
|
+ RedisService::set($cacheKey, $data, rand(3,5));
|
|
|
|
|
+ return round($data, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取用户收益统计
|
|
|
|
|
+ * @param $userId
|
|
|
|
|
+ * @param int $status
|
|
|
|
|
+ * @param int $time
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getTradeProfitTotal($userId, $status = 0, $time = 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ $cacheKey = "caches:trade:profit:{$userId}_".(is_array($status)? implode('-', $status):$status)."_".(is_array($time)? implode('-', $time):$time);
|
|
|
|
|
+ $data = RedisService::get($cacheKey);
|
|
|
|
|
+ if($data){
|
|
|
|
|
+ return round($data, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $where = ['a.user_id' => $userId, 'a.mark' => 1,'b.status'=>1];
|
|
|
|
|
+ $data = $this->model->from('trade as a')
|
|
|
|
|
+ ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
|
|
|
|
|
+ ->where($where)
|
|
|
|
|
+ ->where(function ($query) use ($status, $time) {
|
|
|
|
|
+ $query->whereIn('a.status', is_array($status) ? $status : [$status]);
|
|
|
|
|
+
|
|
|
|
|
+ // 本月
|
|
|
|
|
+ if ($time == 1) {
|
|
|
|
|
+ $query->where('a.pay_time', '>=', strtotime(date('Y-m-01')));
|
|
|
|
|
+ } // 今日
|
|
|
|
|
+ else if ($time == 2) {
|
|
|
|
|
+ $query->where('a.pay_time', '>=', strtotime(date('Y-m-d')));
|
|
|
|
|
+ }else if (is_array($time)){
|
|
|
|
|
+ $start = isset($time[0])? $time[0] : '';
|
|
|
|
|
+ $end = isset($time[1])? $time[1] : '';
|
|
|
|
|
+ if($end && $end>$start){
|
|
|
|
|
+ $query->where('a.pay_time', '<=', strtotime($end));
|
|
|
|
|
+ if($start){
|
|
|
|
|
+ $query->where('a.pay_time', '>=', strtotime($start));
|
|
|
|
|
+ }
|
|
|
|
|
+ }else if ($start){
|
|
|
|
|
+ $query->where('a.pay_time', '=', strtotime($start));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ ->sum('a.profit');
|
|
|
|
|
+ RedisService::set($cacheKey, $data, rand(3,5));
|
|
|
|
|
+ return round($data, 2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|