FinanceMail.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace App\Command;
  3. use App\Models\User;
  4. use App\Services\Config;
  5. use App\Services\Mail;
  6. use App\Services\Analytics;
  7. use App\Utils\Telegram;
  8. use Exception;
  9. use Ozdemir\Datatables\Datatables;
  10. use App\Utils\DatatablesHelper;
  11. class FinanceMail
  12. {
  13. public static function sendFinanceMail_day()
  14. {
  15. $datatables = new Datatables(new DatatablesHelper());
  16. $datatables->query(
  17. 'select code.number, code.userid, code.usedatetime from code
  18. where TO_DAYS(NOW()) - TO_DAYS(code.usedatetime) = 1 and code.type = -1 and code.isused= 1'
  19. );
  20. $text_json = $datatables->generate();
  21. $text_array = json_decode($text_json, true);
  22. $codes = $text_array['data'];
  23. $text_html = '<table border=1><tr><td>金额</td><td>用户ID</td><td>用户名</td><td>充值时间</td>';
  24. $income_count = 0;
  25. $income_total = 0.00;
  26. foreach ($codes as $code) {
  27. $text_html .= '<tr>';
  28. $text_html .= '<td>' . $code['number'] . '</td>';
  29. $text_html .= '<td>' . $code['userid'] . '</td>';
  30. $user = User::find($code['userid']);
  31. $text_html .= '<td>' . $user->user_name . '</td>';
  32. $text_html .= '<td>' . $code['usedatetime'] . '</td>';
  33. $text_html .= '</tr>';
  34. ++$income_count;
  35. $income_total += $code['number'];
  36. }
  37. //易付通的单独表
  38. $datatables2 = new Datatables(new DatatablesHelper());
  39. $datatables2->query('select COUNT(*) as "count_yft" from INFORMATION_SCHEMA.TABLES where TABLE_NAME = "yft_order_info"');
  40. $count_yft = $datatables2->generate();
  41. if (strpos($count_yft, '"count_yft":1')) {
  42. $datatables2->query(
  43. 'select yft_order_info.price, yft_order_info.user_id, yft_order_info.create_time from yft_order_info
  44. where TO_DAYS(NOW()) - TO_DAYS(yft_order_info.create_time) = 1 and yft_order_info.state= 1'
  45. );
  46. $text_json2 = $datatables2->generate();
  47. $text_array2 = json_decode($text_json2, true);
  48. $codes2 = $text_array2['data'];
  49. foreach ($codes2 as $code2) {
  50. $text_html .= '<tr>';
  51. $text_html .= '<td>' . $code2['price'] . '</td>';
  52. $text_html .= '<td>' . $code2['user_id'] . '</td>';
  53. $user = User::find($code2['user_id']);
  54. $text_html .= '<td>' . $user->user_name . '</td>';
  55. $text_html .= '<td>' . $code2['create_time'] . '</td>';
  56. $text_html .= '</tr>';
  57. ++$income_count;
  58. $income_total += $code['price'];
  59. }
  60. }
  61. $text_html .= '</table>';
  62. $text_html .= '<br>昨日总收入笔数:' . $income_count . '<br>昨日总收入金额:' . $income_total;
  63. $adminUser = User::where('is_admin', '=', '1')->get();
  64. foreach ($adminUser as $user) {
  65. echo 'Send offline mail to user: ' . $user->id;
  66. $subject = Config::get('appName') . '-财务日报';
  67. $to = $user->email;
  68. $title = '财务日报';
  69. $text = $text_html;
  70. try {
  71. Mail::send($to, $subject, 'news/finance.tpl', [
  72. 'user' => $user, 'title' => $title, 'text' => $text
  73. ], [
  74. ]);
  75. } catch (Exception $e) {
  76. echo $e->getMessage();
  77. }
  78. }
  79. if (Config::get('finance_public') == true) {
  80. $sts = new Analytics();
  81. Telegram::Send(
  82. '新鲜出炉的财务日报~' . PHP_EOL .
  83. '昨日总收入笔数:' . $income_count . PHP_EOL .
  84. '昨日总收入金额:' . $income_total . PHP_EOL .
  85. '凌晨也在努力工作~'
  86. );
  87. }
  88. }
  89. public static function sendFinanceMail_week()
  90. {
  91. $datatables = new Datatables(new DatatablesHelper());
  92. $datatables->query(
  93. 'SELECT code.number FROM code
  94. WHERE DATEDIFF(NOW(),code.usedatetime) <=7 AND DATEDIFF(NOW(),code.usedatetime) >=1 AND code.isused = 1'
  95. );
  96. //每周的第一天是周日,因此统计周日~周六的七天
  97. $text_json = $datatables->generate();
  98. $text_array = json_decode($text_json, true);
  99. $codes = $text_array['data'];
  100. $text_html = '';
  101. $income_count = 0;
  102. $income_total = 0.00;
  103. foreach ($codes as $code) {
  104. ++$income_count;
  105. $income_total += $code['number'];
  106. }
  107. //易付通的单独表
  108. $datatables2 = new Datatables(new DatatablesHelper());
  109. $datatables2->query('select COUNT(*) as "count_yft" from INFORMATION_SCHEMA.TABLES where TABLE_NAME = "yft_order_info"');
  110. $count_yft = $datatables2->generate();
  111. if (strpos($count_yft, '"count_yft":1')) {
  112. $datatables2->query(
  113. 'select yft_order_info.price from yft_order_info
  114. where yearweek(date_format(yft_order_info.create_time,\'%Y-%m-%d\')) = yearweek(now())-1 and yft_order_info.state= 1'
  115. );
  116. //每周的第一天是周日,因此统计周日~周六的七天
  117. $text_json2 = $datatables2->generate();
  118. $text_array2 = json_decode($text_json2, true);
  119. $codes2 = $text_array2['data'];
  120. foreach ($codes2 as $code2) {
  121. ++$income_count;
  122. $income_total += $code2['price'];
  123. }
  124. }
  125. $text_html .= '<br>上周总收入笔数:' . $income_count . '<br>上周总收入金额:' . $income_total;
  126. $adminUser = User::where('is_admin', '=', '1')->get();
  127. foreach ($adminUser as $user) {
  128. echo 'Send offline mail to user: ' . $user->id;
  129. $subject = Config::get('appName') . '-财务周报';
  130. $to = $user->email;
  131. $title = '财务周报';
  132. $text = $text_html;
  133. try {
  134. Mail::send($to, $subject, 'news/finance.tpl', [
  135. 'user' => $user, 'title' => $title, 'text' => $text
  136. ], [
  137. ]);
  138. } catch (Exception $e) {
  139. echo $e->getMessage();
  140. }
  141. }
  142. if (Config::get('finance_public') == true) {
  143. $sts = new Analytics();
  144. Telegram::Send(
  145. '新鲜出炉的财务周报~' . PHP_EOL .
  146. '上周总收入笔数:' . $income_count . PHP_EOL .
  147. '上周总收入金额:' . $income_total . PHP_EOL .
  148. '周末也在努力工作~'
  149. );
  150. }
  151. }
  152. public static function sendFinanceMail_month()
  153. {
  154. $datatables = new Datatables(new DatatablesHelper());
  155. $datatables->query(
  156. 'select code.number from code
  157. where date_format(code.usedatetime,\'%Y-%m\')=date_format(date_sub(curdate(), interval 1 month),\'%Y-%m\') and code.type = -1 and code.isused= 1'
  158. );
  159. $text_json = $datatables->generate();
  160. $text_array = json_decode($text_json, true);
  161. $codes = $text_array['data'];
  162. $text_html = '';
  163. $income_count = 0;
  164. $income_total = 0.00;
  165. foreach ($codes as $code) {
  166. ++$income_count;
  167. $income_total += $code['number'];
  168. }
  169. $text_html .= '<br>上月总收入笔数:' . $income_count . '<br>上月总收入金额:' . $income_total;
  170. $adminUser = User::where('is_admin', '=', '1')->get();
  171. foreach ($adminUser as $user) {
  172. echo 'Send offline mail to user: ' . $user->id;
  173. $subject = Config::get('appName') . '-财务月报';
  174. $to = $user->email;
  175. $title = '财务月报';
  176. $text = $text_html;
  177. try {
  178. Mail::send($to, $subject, 'news/finance.tpl', [
  179. 'user' => $user, 'title' => $title, 'text' => $text
  180. ], [
  181. ]);
  182. } catch (Exception $e) {
  183. echo $e->getMessage();
  184. }
  185. }
  186. if (Config::get('finance_public') == true) {
  187. $sts = new Analytics();
  188. Telegram::Send(
  189. '新鲜出炉的财务月报~' . PHP_EOL .
  190. '上月总收入笔数:' . $income_count . PHP_EOL .
  191. '上月总收入金额:' . $income_total . PHP_EOL .
  192. '月初也在努力工作~'
  193. );
  194. }
  195. }
  196. }