PrivateMail.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. namespace App\Models;
  3. use App;
  4. use App\Facade\RedisConnect;
  5. use App\Facade\TableName;
  6. use App\Game\GlobalUserInfo;
  7. use App\Game\Services\OuroGameService;
  8. use App\Http\helper\NumConfig;
  9. use App\Util;
  10. use Illuminate\Database\Eloquent\Model;
  11. use Illuminate\Support\Facades\DB;
  12. use Illuminate\Support\Facades\Log;
  13. class PrivateMail extends Model
  14. {
  15. const TABLE = 'QPAccountsDB.dbo.PrivateMail';
  16. protected $table = self::TABLE;
  17. public $timestamps = false;
  18. public static function sendMail($MailType, $UserID, $TitleString, $TextString, $BonusString, $order_sn, $amount = 0, $type = 1, $flag = false)
  19. {
  20. $params = compact('MailType', 'UserID', 'TitleString', 'TextString', 'BonusString', 'order_sn',
  21. 'amount', 'type', 'flag');
  22. if (!empty($order_sn) && $type == 2) {
  23. $redis = new RedisConnect();
  24. if ($redis->redis()->exists($order_sn)) {
  25. Log::info("private mail order_sn already exists", $params);
  26. return true;
  27. } else {
  28. Log::info("private mail order_sn set", $params);
  29. $redis->redis()->setnx($order_sn, 1);
  30. }
  31. }
  32. $mailData = [
  33. 'MailType' => $MailType,
  34. 'MailStatus' => 1,
  35. 'UserID' => $UserID,
  36. 'CreateTime' => date('Y-m-d H:i:s', time()),
  37. 'TitleString' => $TitleString,
  38. 'TextString' => mb_strlen($TextString) > 500 ? mb_substr($TextString, 0, 500) : $TextString,
  39. 'BonusString' => $BonusString,
  40. 'type' => $type,
  41. 'order_sn' => $order_sn,
  42. 'amount' => $amount,
  43. 'DrawBase' => $flag ? $amount : 0
  44. ];
  45. $res = DB::connection('write')->table('QPAccountsDB.dbo.PrivateMail')->insertGetId($mailData);
  46. $params['res'] = $res;
  47. Log::info("private mail order_sn insert", $params);
  48. OuroGameService::notifyMail($UserID);
  49. }
  50. public static function praiseSendMail($UserID)
  51. {
  52. return;
  53. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  54. // Set the application locale based on user's language
  55. App::setLocale($language);
  56. $package = DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  57. ->where('Channel', AccountsInfo::first($UserID)->Channel)->value('PackageName');
  58. if (isset($package) && !empty($package)) {
  59. $data = [
  60. 'MailType' => 2,
  61. 'MailStatus' => 1,
  62. 'UserID' => $UserID,
  63. 'CreateTime' => date('Y-m-d H:i:s'),
  64. 'TitleString' => trans("messages.mail_type.praise"),
  65. 'TextString' => trans("messages.mail_content.praise_text", ['package' => $package]),
  66. 'BonusString' => '',
  67. 'FromAgentID' => 1,
  68. 'amount' => 0,
  69. 'type' => 3,
  70. ];
  71. DB::table('QPAccountsDB.dbo.PrivateMail')->insert($data);
  72. }
  73. }
  74. // Recharge success email
  75. public static function paySendMail($UserID, $order_sn, $favorable_price, $amount)
  76. {
  77. $amount = $amount * NumConfig::NUM_VALUE;
  78. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  79. App::setLocale($language);
  80. $TitleString = trans("messages.mail_type.pay_success");
  81. $TextString = trans("messages.mail_content.pay_success_text", [
  82. 'favorable_price' => $favorable_price,
  83. 'order_sn' => $order_sn
  84. ]);
  85. self::sendMail(2, $UserID,$TitleString,$TextString,'', $order_sn, $amount, 1);
  86. }
  87. // Withdrawal success email
  88. public static function successMail($UserID, $order_sn, $amount)
  89. {
  90. $amount = round($amount / 100, 2);
  91. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  92. App::setLocale($language);
  93. $TitleString = trans("messages.mail_type.withdraw_success");
  94. $TextString = trans("messages.mail_content.withdraw_success_text", [
  95. 'order_sn' => $order_sn,
  96. 'amount' => $amount
  97. ]);
  98. self::sendMail(2, $UserID, $TitleString, $TextString, '', $order_sn, $amount, 2);
  99. }
  100. // Withdrawal failure email
  101. public static function failMail($UserID, $order_sn, $amount, $msg, $bonus)
  102. {
  103. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  104. App::setLocale($language);
  105. $TitleString = trans("messages.mail_type.withdraw_fail");
  106. $TextString = trans("messages.mail_content.withdrawal_failure_text", [
  107. 'order_sn' => $order_sn,
  108. 'msg' => $msg
  109. ]);
  110. self::sendMail(2, $UserID, $TitleString, $TextString, $bonus, $order_sn, $amount, 2, true);
  111. }
  112. // Withdrawal refusal email
  113. public static function refuseMail($UserID, $order_sn, $amount, $flag = false)
  114. {
  115. $bonus = '30000,' . $amount;
  116. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  117. App::setLocale($language);
  118. $TitleString = trans("messages.mail_type.withdraw_refuse");
  119. $TextString = trans("messages.mail_content.withdraw_refuse_text", [
  120. 'order_sn' => $order_sn
  121. ]);
  122. self::sendMail(2, $UserID, $TitleString, $TextString, $bonus, $order_sn, $amount, 2, $flag);
  123. }
  124. // Withdrawal clearance email
  125. public static function ClearDrawMail($UserID, $order_sn, $amount, $flag = false)
  126. {
  127. $bonus = '30000,' . $amount;
  128. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  129. App::setLocale($language);
  130. $TitleString = trans("messages.mail_type.withdraw_clear");
  131. $TextString = trans("messages.mail_content.withdraw_clear_text", [
  132. 'order_sn' => $order_sn
  133. ]);
  134. self::sendMail(2, $UserID, $TitleString, $TextString, $bonus, $order_sn, $amount, 2, $flag);
  135. }
  136. public static function RecoveryMail($UserId, $order_sn)
  137. {
  138. // 获取用户语言
  139. App::setLocale(GlobalUserInfo::getLocaleByUserID( $UserId,'en'));
  140. // 使用语言包获取标题和文本内容
  141. $TitleString = trans('messages.mail_content.withdrawal_failure_text');
  142. $TextString = trans('messages.mail_content.recovery_text', ['order_sn' => $order_sn]);
  143. self::sendMail(2, $UserId, $TitleString, $TextString, '', $order_sn, 0, 2);
  144. }
  145. public static function ReplyMessage($userId, $message)
  146. {
  147. // 获取用户语言
  148. App::setLocale(GlobalUserInfo::getLocaleByUserID( $userId,'en'));
  149. // 使用语言包获取标题
  150. $TitleString = trans('messages.mail_content.customer_service_reply');
  151. self::sendMail(8, $userId, $TitleString, $message, '', 'ser' . time() . rand(100, 999), 0, 9);
  152. }
  153. public static function PaySuccess($user_id, $payAmt, $favorable_price, $order_sn)
  154. {
  155. // 获取用户语言
  156. App::setLocale(GlobalUserInfo::getLocaleByUserID( $user_id,'en'));
  157. // 使用语言包获取标题和文本内容
  158. $TitleString = trans('messages.mail_content.transaction_completed');
  159. $TextString = trans('messages.mail_content.purchase_text', [
  160. 'favorable_price' => $favorable_price,
  161. 'order_sn' => $order_sn,
  162. ]);
  163. self::sendMail(2, $user_id, $TitleString, $TextString, '', $order_sn, $payAmt);
  164. }
  165. }