MailController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\logic\admin\MailLogic;
  5. use App\Models\AdminScore;
  6. use App\Models\RecordPlatformData;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Cache;
  10. use Storage;
  11. use Excel;
  12. class MailController extends Controller
  13. {
  14. //邮件列表
  15. public function mailList(Request $request)
  16. {
  17. $type = $request->get('type');
  18. $GameID = $request->get('GameID');
  19. $amount = $request->get('amount');
  20. $amount_search = $request->get('amount_search');
  21. $admin_type = $request->get('admin_type',-1);
  22. !isset($type) ? $type = 0 : '';
  23. $startTime = str_replace('T', ' ', $request->start_time ?? "");
  24. $endTime = str_replace('T', ' ', $request->end_time ?? "");
  25. $prize = DB::connection('read')->table('QPTreasureDB.dbo.PropCfg')->select('PropID', 'PropName')->get()->toArray();
  26. //$prop = DB::connection('read')->table('QPAccountsDB.dbo.YN_MatchProp')->select('PropID', 'PropName')->get()->toArray();
  27. //$data = array_merge($prize, $prop);
  28. // foreach ($data as $key => $value) {
  29. // $prop_arr[$value->PropID] = $value->PropName;
  30. // }
  31. if ($type == 1) {
  32. $list = DB::connection('read')->table('QPAccountsDB.dbo.SystemMail')->orderBy('MailID', 'desc')->paginate(10);
  33. } else {
  34. $where[] = ['MailType', '=', 2];
  35. if (!empty($amount)) {
  36. $where[] = ['pm.amount', '=', $amount * 100];
  37. }
  38. if (!empty($startTime)) {
  39. $where[] = ['pm.createTime', '>=', $startTime];
  40. }
  41. if ($admin_type!=-1) {
  42. // $where[] = ['pm.admin_type', '=', $admin_type];
  43. }
  44. if (!empty($endTime)) {
  45. $where[] = ['pm.createTime', '<=', $endTime];
  46. }
  47. !empty($GameID) && $where[] = ['ai.GameID', '=', $GameID];
  48. switch ($amount_search) {
  49. case 100:
  50. $where[] = ['pm.amount', '<', 10000];
  51. break;
  52. case 500:
  53. $where[] = ['pm.amount', '>=', 10000];
  54. $where[] = ['pm.amount', '<=', 50000];
  55. break;
  56. case 1000:
  57. $where[] = ['pm.amount', '>=', 50000];
  58. $where[] = ['pm.amount', '<=', 100000];
  59. break;
  60. case 1001:
  61. $where[] = ['pm.amount', '>', 100000];
  62. break;
  63. }
  64. !empty($GameID) && $where[] = ['ai.GameID', '=', $GameID];
  65. $list = DB::connection('read')->table('QPAccountsDB.dbo.PrivateMail as pm')
  66. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai', 'pm.UserID', '=', 'ai.UserID')
  67. ->select('pm.*', 'ai.GameID')
  68. ->where($where)
  69. // ->whereNotNull('FromAgentID')
  70. // ->where('type', 3)
  71. ->orderBy('MailID', 'desc')
  72. ->paginate(10);
  73. }
  74. $gift = [30000 => '金币',31000 => '免费币'];
  75. foreach ($list as $key => &$value) {
  76. if (!empty($value->BonusString)) {
  77. $bonus = $value->BonusString;
  78. $bonus = explode(';', $bonus);
  79. $value->BonusString = '';
  80. foreach ($bonus as $k => &$v) {
  81. $v = explode(',', $v);
  82. $value->BonusString .= $gift[$v[0]] . ($v[1] / 100) . ',';
  83. }
  84. }
  85. }
  86. return view('admin.mail.list', ['list' => $list,'type_list' => ['-1' => '全部', 1 => '召回', 2=>'测试', 3=>'好评',4 => '活动奖励',5 => '补偿', 6 => '其他',0 => '默认' ], 'type' => $type, 'GameID' => $GameID, 'amount' => $amount,'amount_search' => $amount_search,'startTime' => $startTime, 'endTime' => $endTime,'admin_type' => $admin_type]);
  87. }
  88. //邮件发布页面
  89. public function mailAddView(Request $request)
  90. {
  91. return view('admin.mail.mail_add');
  92. }
  93. //邮件发布
  94. public function mailAdd(Request $request)
  95. {
  96. $admin = $request->session()->get('admin');//管理员信息
  97. $params = $request->all();
  98. $bonus_arr = $params['bonus'];
  99. if (count($bonus_arr) > 5) {
  100. return $this->json(500, '奖品最多不超过五件');
  101. }
  102. $bonus = '';
  103. if (empty($params['title']) || empty($params['text'])) {
  104. return $this->json(500, '请确认数据完整');
  105. }
  106. $params['type'] = 2;
  107. $type = 0;
  108. $amount = 0;
  109. $change_score = 0;
  110. if (isset($bonus_arr[0]['id']) && !empty($bonus_arr[0]['id'])) {
  111. foreach ($bonus_arr as $key => $value) {
  112. // if (empty($value['id']) || empty($value['number'])) {
  113. // return $this->json(500, '奖品不能为空');
  114. // }
  115. if ($value['id'] == "30000" && $value['number'] > 1000000) {
  116. return $this->json(500, '金币不能超过一百万');
  117. }
  118. if ($value['id'] == 10000 && $value['number'] > 200) {
  119. return $this->json(500, '房卡不能超过二百');
  120. }
  121. if ($value['id'] == 40000 && $value['number'] > 100000) {
  122. return $this->json(500, '福卡不能超过十万');
  123. }
  124. // if (!empty($value['number']) && $value['number'] < 0.1) {
  125. // return $this->json(500, '奖品数量最小值为0.1');
  126. // }
  127. // 判断彩金管理员够不够
  128. $admin_id = session('admin')->id;
  129. $admin = DB::table('agent.dbo.admin_users')->where('id',$admin_id)->first();
  130. $lottery_amount = $admin->lottery_amount ?: 0;
  131. if ($lottery_amount < $value['number']) {
  132. return $this->json(500, '彩金额度不足');
  133. }
  134. $change_score = $value['number'];
  135. $value['number'] = $value['number'] * 100;
  136. $bonus .= implode(',', $value) . ';';
  137. $type = 3;
  138. if ($value['id'] === "30000") {
  139. $amount = $value['number'];
  140. }
  141. }
  142. }
  143. $bonus = trim($bonus, ';');
  144. //个人公告
  145. if ($params['type'] == 2) {
  146. $uids = [];
  147. if(strstr($params['game_id'],';')){
  148. $uids = explode(';',$params['game_id']);
  149. }else{
  150. $uids = [trim($params['game_id'])];
  151. }
  152. foreach ($uids as $game_id){
  153. $UserInfo = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')->where('GameID', $game_id)
  154. ->select('UserID','Channel')
  155. ->first();
  156. if (!$UserInfo) {
  157. return $this->json(500, '未查询到该用户');
  158. }
  159. $user_id = $UserInfo->UserID;
  160. $Channel = $UserInfo->Channel;
  161. $data = [
  162. 'MailType' => $params['type'],
  163. 'MailStatus' => 1,
  164. 'UserID' => $user_id,
  165. 'CreateTime' => date('Y-m-d H:i:s', time()),
  166. 'TitleString' => $params['title'],
  167. 'TextString' => $params['text'],
  168. 'BonusString' => $bonus,
  169. 'FromAgentID' => $admin->id,
  170. 'type' => $type,
  171. 'amount' => $amount,
  172. // 'admin_type' => @$params['admin_type']?:0
  173. ];
  174. $result = DB::table('QPAccountsDB.dbo.PrivateMail')->insert($data);
  175. if($amount){
  176. // 添加管理员变化额度
  177. AdminScore::add_score($admin, $change_score, 1);
  178. // 添加赠送金币
  179. RecordPlatformData::addGiveGold($amount,$Channel);
  180. }
  181. }
  182. //系统公告
  183. } else {
  184. $data = [
  185. 'CreateTime' => date('Y-m-d H:i:s', time()),
  186. 'TitleString' => $params['title'],
  187. 'TextString' => $params['text'],
  188. 'BonusString' => '',
  189. 'FromAgentID' => $admin->id,
  190. ];
  191. $result = DB::table('QPAccountsDB.dbo.SystemMail')->insert($data);
  192. }
  193. if ($result) {
  194. return $this->json(200, "发布成功");
  195. } else {
  196. return $this->json(500, '发布失败,请重试');
  197. }
  198. }
  199. // 邮件充值记录
  200. public function mailRecord(Request $request)
  201. {
  202. $GameID = $request->GameID ?: '';
  203. $amount = $request->amount ?: '';
  204. $amount_search = $request->amount_search ?: '';
  205. $list = (new MailLogic())->mailRecord(1, $GameID, $amount, $amount_search);
  206. return view('admin.mail.mailRecord', compact('list', 'GameID', 'amount', 'amount_search'));
  207. }
  208. // 提现返还邮件记录
  209. public function back_mailRecord(Request $request)
  210. {
  211. $GameID = $request->GameID ?: '';
  212. $amount = $request->amount ?: '';
  213. $amount_search = $request->amount_search ?: '';
  214. $list = (new MailLogic())->mailRecord(2, $GameID, $amount, $amount_search);
  215. return view('admin.mail.back_mailRecord', compact('list', 'GameID', 'amount', 'amount_search'));
  216. }
  217. }