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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / models / WithdrawModel.php
tutor / models Last commit date
CourseModel.php 3 years ago WithdrawModel.php 3 years ago
WithdrawModel.php
188 lines
1 <?php
2 namespace Tutor\Models;
3
4 /**
5 * Class WithdrawModel
6 * @since 2.0.7
7 */
8 class WithdrawModel {
9 /**
10 * All withdraw status
11 */
12 const STATUS_PENDING = 'pending';
13 const STATUS_APPROVED = 'approved';
14 const STATUS_REJECTED = 'rejected';
15
16 /**
17 * Get withdraw summary info for an user
18 *
19 * @param int $instructor_id
20 * @return array|object|null|void
21 *
22 * @since 2.0.7
23 */
24 public static function get_withdraw_summary( $instructor_id ) {
25 global $wpdb;
26
27 $maturity_days = tutor_utils()->get_option( 'minimum_days_for_balance_to_be_available' );
28
29 $data = $wpdb->get_row(
30 $wpdb->prepare("SELECT ID, display_name,
31 total_income,total_withdraw,
32 (total_income-total_withdraw) current_balance,
33 total_matured,
34 greatest(0, total_matured - total_withdraw) available_for_withdraw
35
36 FROM (
37 SELECT ID,display_name,
38 COALESCE((select SUM(instructor_amount) from {$wpdb->prefix}tutor_earnings group by user_id having user_id=u.ID),0) total_income,
39
40 COALESCE((
41 select sum(amount) total_withdraw from {$wpdb->prefix}tutor_withdraws
42 where status='%s'
43 group by user_id
44 having user_id=u.ID
45 ),0) total_withdraw,
46
47 COALESCE((
48 SELECT SUM(instructor_amount) from(
49 SELECT user_id, instructor_amount, created_at, DATEDIFF(NOW(),created_at) AS days_old FROM {$wpdb->prefix}tutor_earnings
50 ) a
51 WHERE days_old >= %d
52 GROUP BY user_id
53 HAVING user_id = u.ID
54 ),0) total_matured
55
56 FROM {$wpdb->prefix}users u WHERE u.ID=%d
57
58 ) a",
59 self::STATUS_APPROVED,
60 $maturity_days,
61 $instructor_id
62 )
63 );
64
65 return $data;
66 }
67
68 /**
69 * Get withdrawal history
70 *
71 * @param int $user_id | optional.
72 * @param array $filter | ex:
73 * array('status' => '','date' => '', 'order' => '', 'start' => 10, 'per_page' => 10,'search' => '')
74 *
75 * @return object
76 */
77 public static function get_withdrawals_history( $user_id = 0, $filter = array(), $start=0, $limit=20 ) {
78 global $wpdb;
79
80 $filter = (array) $filter;
81 extract( $filter );
82
83 $query_by_status_sql = '';
84 $query_by_user_sql = '';
85
86 if ( ! empty( $status ) ) {
87 $status = (array) $status;
88 $status = "'" . implode( "','", $status ) . "'";
89
90 $query_by_status_sql = " AND status IN({$status}) ";
91 }
92
93 if ( $user_id ) {
94 $query_by_user_sql = " AND user_id = {$user_id} ";
95 }
96
97 // Order query @since v2.0.0
98 $order_query = '';
99 if ( isset( $order ) && '' !== $order ) {
100 $order_query = "ORDER BY created_at {$order}";
101 } else {
102 $order_query = 'ORDER BY created_at DESC';
103 }
104
105 // Date query @since v.2.0.0
106 $date_query = '';
107 if ( isset( $date ) && '' !== $date ) {
108 $date_query = "AND DATE(created_at) = CAST( '$date' AS DATE )";
109 }
110
111 // Search query @since v.2.0.0
112 $search_term_raw = empty($search) ? '' : $search;
113 $search_query = '%%';
114 if ( !empty( $search_term_raw ) ) {
115 $search_query = '%' . $wpdb->esc_like( $search_term_raw ) . '%';
116 }
117
118 $count = (int) $wpdb->get_var(
119 $wpdb->prepare(
120 "SELECT COUNT(withdraw_id)
121 FROM {$wpdb->prefix}tutor_withdraws withdraw_tbl
122 INNER JOIN {$wpdb->users} user_tbl
123 ON withdraw_tbl.user_id = user_tbl.ID
124 WHERE 1 = 1
125 {$query_by_user_sql}
126 {$query_by_status_sql}
127 {$date_query}
128 AND (user_tbl.display_name LIKE %s OR user_tbl.user_login LIKE %s OR user_tbl.user_nicename LIKE %s OR user_tbl.user_email = %s)
129 ",
130 $search_query,
131 $search_query,
132 $search_query,
133 $search_term_raw
134 )
135 );
136
137 $results = $wpdb->get_results(
138 $wpdb->prepare(
139 "SELECT withdraw_tbl.*,
140 user_tbl.display_name AS user_name,
141 user_tbl.user_email
142 FROM {$wpdb->prefix}tutor_withdraws withdraw_tbl
143 INNER JOIN {$wpdb->users} user_tbl
144 ON withdraw_tbl.user_id = user_tbl.ID
145 WHERE 1 = 1
146 {$query_by_user_sql}
147 {$query_by_status_sql}
148 {$date_query}
149
150 AND (user_tbl.display_name LIKE %s OR user_tbl.user_login LIKE %s OR user_tbl.user_nicename LIKE %s OR user_tbl.user_email = %s)
151 {$order_query}
152 LIMIT %d, %d
153 ",
154 $search_query,
155 $search_query,
156 $search_query,
157 $search_term_raw,
158 $start,
159 $limit
160 )
161 );
162
163 $withdraw_history = array(
164 'count' => $count ? $count : 0,
165 'results' => is_array($results) ? $results : array(),
166 );
167
168 return (object) $withdraw_history;
169 }
170
171 /**
172 * Get withdraw method for a specific
173 *
174 * @param int $user_id
175 *
176 * @return bool|mixed
177 */
178 public static function get_user_withdraw_method( $user_id = 0 ) {
179 $user_id = tutor_utils()->get_user_id( $user_id );
180 $account = get_user_meta( $user_id, '_tutor_withdraw_method_data', true );
181
182 if ( $account ) {
183 return maybe_unserialize( $account );
184 }
185
186 return false;
187 }
188 }