user_id; $store_id = $this->store_id; $saas_user = get_saas_user(); //用户信息 $userTeamGrades = TeamGrades::getUserTeamGrades($user_id); $data = [ 'user_info' => [ 'avatar' => $saas_user->avatar, 'name' => $saas_user->name, 'team_grades_level_name' => $userTeamGrades['team_grades_level_name'] ?: '' ], 'team_grades_pool' => [ 'price' => $userTeamGrades['price'] ?: '0.00',//可提现业绩分红 'no_send_price' => '0.00', //未到账业绩分红 'cash_price' => '0.00',//已提现业绩分红 'total_price' => $userTeamGrades['total_price'] ?: '0.00'//累计业绩分红 ] ]; $user = User::findOne($user_id); if ($user->price < $userTeamGrades['price']) { $data['team_grades_pool']['price'] = $user->price; } //已提现业绩分红 $cash_price = Cash::find()->where(['user_id' => $user_id, 'cash_type' => Cash::IS_CASH_TYPE_TEAM_GRADES, 'status' => [ Cash::STATUS_GIVEN, Cash::STATUS_HAND, Cash::STATUS_RECHARGE ] ])->sum('price') ?: '0.00'; $data['team_grades_pool']['cash_price'] = $cash_price; $no_send_price = 0; $teamGradesLevel = TeamGradesLevel::getLevelInfo($userTeamGrades['team_grades_level'], $store_id); if ($teamGradesLevel) { $level_reward_setting = json_decode($teamGradesLevel->level_reward_setting, true); if (!empty($level_reward_setting)) { //未到账业绩分红 $amount_list = TeamGradesPoolDetail::find()->where(['user_id' => $user_id, 'is_send' => 0]) ->select('SUM(amount) as amount, pool_id')->groupBy('pool_id')->asArray()->all(); foreach ($amount_list as $amount_item) { foreach ($level_reward_setting as $level_reward_setting_item) { if ($amount_item['amount'] >= $level_reward_setting_item['min'] && $amount_item['amount'] <= $level_reward_setting_item['max']) { $no_send_price = bcmul($amount_item['amount'], bcdiv($level_reward_setting_item['profit'], 100, 2)); } } } } } $data['team_grades_pool']['no_send_price'] = $no_send_price; //调用自动升级判断一下 TeamGradesLevel::auto_upgrade($user_id, $store_id); return [ 'code' => 0, 'msg' => '', 'data' => $data ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 分红记录 */ public function poolList() { try { $user_id = $this->user_id; $store_id = $this->store_id; $is_send = $this->is_send; $query = TeamGradesPoolDetail::find()->where(['user_id' => $user_id]); if ($is_send !== null && in_array($is_send, [TeamGradesPoolDetail::SEND_STATUS_NO, TeamGradesPoolDetail::SEND_STATUS_YES])) { $query->andWhere(['is_send' => $is_send]); } $query->orderBy('id DESC')->select('id, amount, price, is_send, level, created_at'); $pagination = pagination_make($query); $level_reward_setting = []; $userTeamGrades = TeamGrades::getUserTeamGrades($user_id); if (!empty($userTeamGrades['id'])) { $teamGradesLevel = TeamGradesLevel::getLevelInfo($userTeamGrades['team_grades_level'], $store_id); if ($teamGradesLevel) { if (!empty(json_decode($teamGradesLevel->level_reward_setting, true))) { $level_reward_setting = json_decode($teamGradesLevel->level_reward_setting, true); } } } foreach ($pagination['list'] as &$item) { $item['is_send'] = intval($item['is_send']); $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); if (!$item['is_send']) { foreach ($level_reward_setting as $setting_item) { if ($item['amount'] >= $setting_item['min'] && $item['amount'] <= $setting_item['max']) { $item['price'] = bcmul($item['amount'], bcdiv($setting_item['profit'], 100, 2)); } } } $item['level_name'] = TeamGradesLevel::getLevelInfo($item['level'], $store_id, 'level_name') ?: '-'; } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $pagination['list'], 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 业绩订单分红 */ public function orderPoolList() { try { $user_id = $this->user_id; $store_id = $this->store_id; $status = intval($this->status); $start_time = $this->start_time; $end_time = $this->end_time; $month_time = $this->month_time; $pool_detail_id = TeamGradesPoolDetail::find()->where(['user_id' => $user_id])->select('id')->column(); $query = TeamGradesPoolDetailExt::find()->alias('pde')->where(['pde.pool_detail_id' => $pool_detail_id, 'pde.is_delete' => 0]) ->andWhere(['>', 'pde.amount', 0]); $query->leftJoin(['o' => Order::tableName()], 'pde.order_id = o.id')->andWhere(['<>', 'o.trade_status', Order::ORDER_FLOW_CANCEL]); $query->leftJoin(['or' => OrderRefund::tableName()], 'o.id = or.order_id')->andWhere(['IS', 'or.id', NULL]); $total_query = clone $query; if ($start_time) { $start_time = strtotime($start_time); $query->andWhere(['>=', 'pde.created_at', $start_time]); } if ($end_time) { $end_time = strtotime($end_time); $query->andWhere(['<=', 'pde.created_at', $end_time]); } if ($month_time) {//前端传递月份如:2024-09 通过月份计算本月开始与下月初 拿到中间时间段的订单 $month_time = strtotime($month_time);// $month_start_date = strtotime(date('Y-m', $month_time)); $month_end_time = strtotime('+1 Month', $month_start_date); $query->andWhere(['AND', ['>=', 'pde.created_at', $month_start_date], ['<=', 'pde.created_at', $month_end_time]]); } if (in_array($status, [0, 1, 2])) {//-1全部 0未付款 1已付款 2已完成 if ($status === 0) { $query->andWhere(['o.is_pay' => Order::IS_PAY_FALSE]); } if ($status === 1) { $query->andWhere(['AND', ['o.is_pay' => Order::IS_PAY_TRUE], ['<>', 'o.trade_status', Order::ORDER_FLOW_CONFIRM]]); } if ($status === 2) { $query->andWhere(['o.trade_status' => Order::ORDER_FLOW_CONFIRM]); } if ($status === 3) { $query->andWhere(['o.trade_status' => Order::ORDER_FLOW_SEND]); } } $query->orderBy('pde.id DESC') ->select('pde.id, pde.created_at, pde.amount as goods_amount, o.order_no, o.is_pay, o.trade_status, o.id as order_id'); $total_goods_amount = $total_query->select('pde.goods_amount')->sum('pde.goods_amount') ?: 0; $pagination = pagination_make($query); foreach ($pagination['list'] as &$item) { $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); $item['trade_status'] = intval($item['trade_status']); $item['is_pay'] = intval($item['is_pay']); if (!$item['is_pay']) { $item['status'] = 0; $item['status_text'] = '未付款'; } if ($item['is_pay'] && $item['trade_status'] === Order::ORDER_FLOW_CONFIRM) { $item['status'] = 1; $item['status_text'] = '已付款'; } if ($item['trade_status'] === Order::ORDER_FLOW_CONFIRM) { $item['status'] = 2; $item['status_text'] = '已完成'; } } $time_type = [ [ 'date' => '近三月', 'time' => date('Y-m-d', strtotime('-3 Month')) ], [ 'date' => '近半年', 'time' => date('Y-m-d', strtotime('-6 Month')) ], [ 'date' => '近一年', 'time' => date('Y-m-d', strtotime('-1 Year')) ], ]; return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $pagination['list'], 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], 'total_goods_amount' => $total_goods_amount, 'time_type' => $time_type ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }