PrivateMail.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. if($order_sn){
  33. //免费币不需要邮件领取
  34. $OrderWithDraw = DB::table(TableName::QPAccountsDB() . 'OrderWithDraw')
  35. ->where('OrderID', $order_sn)
  36. ->first();
  37. if ($OrderWithDraw && $OrderWithDraw->score_type == 1) {
  38. $amount = 0;
  39. $BonusString = '';
  40. $params['amount'] = 0;
  41. $params['bonus'] = '';
  42. Log::info("private mail order_sn amount", $params);
  43. DB::table('QPTreasureDB.dbo.GameScoreInfo')->where('UserID', $UserID)->increment('InsureScore',$amount);
  44. }
  45. }
  46. $mailData = [
  47. 'MailType' => $MailType,
  48. 'MailStatus' => 1,
  49. 'UserID' => $UserID,
  50. 'CreateTime' => date('Y-m-d H:i:s', time()),
  51. 'TitleString' => $TitleString,
  52. 'TextString' => mb_strlen($TextString) > 500 ? mb_substr($TextString, 0, 500) : $TextString,
  53. 'BonusString' => $BonusString,
  54. 'type' => $type,
  55. 'order_sn' => $order_sn,
  56. 'amount' => $amount,
  57. 'DrawBase' => $flag ? $amount : 0
  58. ];
  59. $res = DB::connection('write')->table('QPAccountsDB.dbo.PrivateMail')->insertGetId($mailData);
  60. $params['res'] = $res;
  61. Log::info("private mail order_sn insert", $params);
  62. OuroGameService::notifyMail($UserID);
  63. }
  64. public static function praiseSendMail($UserID)
  65. {
  66. return;
  67. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  68. // Set the application locale based on user's language
  69. App::setLocale($language);
  70. $package = DB::connection('write')->table('QPPlatformDB.dbo.ChannelPackageName')
  71. ->where('Channel', AccountsInfo::first($UserID)->Channel)->value('PackageName');
  72. if (isset($package) && !empty($package)) {
  73. $data = [
  74. 'MailType' => 2,
  75. 'MailStatus' => 1,
  76. 'UserID' => $UserID,
  77. 'CreateTime' => date('Y-m-d H:i:s'),
  78. 'TitleString' => trans("messages.mail_type.praise"),
  79. 'TextString' => trans("messages.mail_content.praise_text", ['package' => $package]),
  80. 'BonusString' => '',
  81. 'FromAgentID' => 1,
  82. 'amount' => 0,
  83. 'type' => 3,
  84. ];
  85. DB::table('QPAccountsDB.dbo.PrivateMail')->insert($data);
  86. }
  87. }
  88. // Recharge success email
  89. public static function paySendMail($UserID, $order_sn, $favorable_price, $amount)
  90. {
  91. $amount = $amount * NumConfig::NUM_VALUE;
  92. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  93. App::setLocale($language);
  94. $TitleString = trans("messages.mail_type.pay_success");
  95. $TextString = trans("messages.mail_content.pay_success_text", [
  96. 'favorable_price' => $favorable_price,
  97. 'order_sn' => $order_sn
  98. ]);
  99. self::sendMail(2, $UserID,$TitleString,$TextString,'', $order_sn, $amount, 1);
  100. }
  101. // Withdrawal success email
  102. public static function successMail($UserID, $order_sn, $amount)
  103. {
  104. $amount = round($amount / 100, 2);
  105. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  106. App::setLocale($language);
  107. $TitleString = trans("messages.mail_type.withdraw_success");
  108. $TextString = trans("messages.mail_content.withdraw_success_text", [
  109. 'order_sn' => $order_sn,
  110. 'amount' => $amount
  111. ]);
  112. self::sendMail(2, $UserID, $TitleString, $TextString, '', $order_sn, $amount, 2);
  113. }
  114. // Withdrawal failure email
  115. public static function failMail($UserID, $order_sn, $amount, $msg, $bonus)
  116. {
  117. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  118. App::setLocale($language);
  119. $TitleString = trans("messages.mail_type.withdraw_fail");
  120. $TextString = trans("messages.mail_content.withdrawal_failure_text", [
  121. 'order_sn' => $order_sn,
  122. 'msg' => $msg
  123. ]);
  124. self::sendMail(2, $UserID, $TitleString, $TextString, $bonus, $order_sn, $amount, 2, true);
  125. }
  126. // Withdrawal refusal email
  127. public static function refuseMail($UserID, $order_sn, $amount, $flag = false)
  128. {
  129. $bonus = '30000,' . $amount;
  130. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  131. App::setLocale($language);
  132. $TitleString = trans("messages.mail_type.withdraw_refuse");
  133. $TextString = trans("messages.mail_content.withdraw_refuse_text", [
  134. 'order_sn' => $order_sn
  135. ]);
  136. self::sendMail(2, $UserID, $TitleString, $TextString, $bonus, $order_sn, $amount, 2, $flag);
  137. }
  138. // Withdrawal clearance email
  139. public static function ClearDrawMail($UserID, $order_sn, $amount, $flag = false)
  140. {
  141. $bonus = '30000,' . $amount;
  142. $language = GlobalUserInfo::getLocaleByUserID( $UserID,'en');
  143. App::setLocale($language);
  144. $TitleString = trans("messages.mail_type.withdraw_clear");
  145. $TextString = trans("messages.mail_content.withdraw_clear_text", [
  146. 'order_sn' => $order_sn
  147. ]);
  148. self::sendMail(2, $UserID, $TitleString, $TextString, $bonus, $order_sn, $amount, 2, $flag);
  149. }
  150. public static function RecoveryMail($UserId, $order_sn)
  151. {
  152. // 获取用户语言
  153. App::setLocale(GlobalUserInfo::getLocaleByUserID( $UserId,'en'));
  154. // 使用语言包获取标题和文本内容
  155. $TitleString = trans('messages.mail_content.withdrawal_failure_text');
  156. $TextString = trans('messages.mail_content.recovery_text', ['order_sn' => $order_sn]);
  157. self::sendMail(2, $UserId, $TitleString, $TextString, '', $order_sn, 0, 2);
  158. }
  159. public static function ReplyMessage($userId, $message)
  160. {
  161. // 获取用户语言
  162. App::setLocale(GlobalUserInfo::getLocaleByUserID( $userId,'en'));
  163. // 使用语言包获取标题
  164. $TitleString = trans('messages.mail_content.customer_service_reply');
  165. self::sendMail(8, $userId, $TitleString, $message, '', 'ser' . time() . rand(100, 999), 0, 9);
  166. }
  167. public static function PaySuccess($user_id, $payAmt, $favorable_price, $order_sn)
  168. {
  169. // 获取用户语言
  170. App::setLocale(GlobalUserInfo::getLocaleByUserID( $user_id,'en'));
  171. // 使用语言包获取标题和文本内容
  172. $TitleString = trans('messages.mail_content.transaction_completed');
  173. $TextString = trans('messages.mail_content.purchase_text', [
  174. 'favorable_price' => $favorable_price,
  175. 'order_sn' => $order_sn,
  176. ]);
  177. self::sendMail(2, $user_id, $TitleString, $TextString, '', $order_sn, $payAmt);
  178. }
  179. }