MailController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. $game_ids = [];
  108. if ($params['type'] == 2) {
  109. $game_id_string = str_replace([',', ';', ';'], ',', $params['game_id'] ?? '');
  110. $game_ids = preg_split('/\s*,\s*/', trim($game_id_string), -1, PREG_SPLIT_NO_EMPTY);
  111. $game_ids = array_values(array_unique(array_map('trim', $game_ids)));
  112. if (empty($game_ids)) {
  113. return $this->json(500, '私人邮件缺少发件人');
  114. }
  115. }
  116. $type = 0;
  117. $amount = 0;
  118. $change_score = 0;
  119. if (isset($bonus_arr[0]['id']) && !empty($bonus_arr[0]['id'])) {
  120. foreach ($bonus_arr as $key => $value) {
  121. // if (empty($value['id']) || empty($value['number'])) {
  122. // return $this->json(500, '奖品不能为空');
  123. // }
  124. if ($value['id'] == "30000" && $value['number'] > 1000000) {
  125. return $this->json(500, '金币不能超过一百万');
  126. }
  127. if ($value['id'] == 10000 && $value['number'] > 200) {
  128. return $this->json(500, '房卡不能超过二百');
  129. }
  130. if ($value['id'] == 40000 && $value['number'] > 100000) {
  131. return $this->json(500, '福卡不能超过十万');
  132. }
  133. // if (!empty($value['number']) && $value['number'] < 0.1) {
  134. // return $this->json(500, '奖品数量最小值为0.1');
  135. // }
  136. // 判断彩金管理员够不够
  137. $admin_id = session('admin')->id;
  138. $admin = DB::table('agent.dbo.admin_users')->where('id',$admin_id)->first();
  139. $lottery_amount = $admin->lottery_amount ?: 0;
  140. if ($lottery_amount < $value['number']) {
  141. return $this->json(500, '彩金额度不足');
  142. }
  143. if ($params['type'] == 2 && $value['id'] === "30000" && $lottery_amount < $value['number'] * count($game_ids)) {
  144. return $this->json(500, '彩金额度不足');
  145. }
  146. $change_score = $value['number'];
  147. $value['number'] = $value['number'] * 100;
  148. $bonus .= implode(',', $value) . ';';
  149. $type = 3;
  150. if ($value['id'] === "30000") {
  151. $amount = $value['number'];
  152. }
  153. }
  154. }
  155. $bonus = trim($bonus, ';');
  156. //个人公告
  157. if ($params['type'] == 2) {
  158. $user_info_list = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')
  159. ->whereIn('GameID', $game_ids)
  160. ->select('UserID','Channel','GameID')
  161. ->get();
  162. $user_info_map = [];
  163. foreach ($user_info_list as $item) {
  164. $user_info_map[(string)$item->GameID] = $item;
  165. }
  166. $missing_game_ids = [];
  167. foreach ($game_ids as $game_id) {
  168. if (!isset($user_info_map[(string)$game_id])) {
  169. $missing_game_ids[] = $game_id;
  170. }
  171. }
  172. if (!empty($missing_game_ids)) {
  173. return $this->json(500, '未查询到该用户:' . implode(',', $missing_game_ids));
  174. }
  175. foreach ($game_ids as $game_id){
  176. $UserInfo = $user_info_map[(string)$game_id];
  177. $user_id = $UserInfo->UserID;
  178. $Channel = $UserInfo->Channel;
  179. $data = [
  180. 'MailType' => $params['type'],
  181. 'MailStatus' => 1,
  182. 'UserID' => $user_id,
  183. 'CreateTime' => date('Y-m-d H:i:s', time()),
  184. 'TitleString' => $params['title'],
  185. 'TextString' => $params['text'],
  186. 'BonusString' => $bonus,
  187. 'FromAgentID' => $admin->id,
  188. 'type' => $type,
  189. 'amount' => $amount,
  190. // 'admin_type' => @$params['admin_type']?:0
  191. ];
  192. $result = DB::table('QPAccountsDB.dbo.PrivateMail')->insert($data);
  193. if($amount){
  194. // 添加管理员变化额度
  195. AdminScore::add_score($admin, $change_score, 1);
  196. // 添加赠送金币
  197. RecordPlatformData::addGiveGold($amount,$Channel);
  198. }
  199. }
  200. //系统公告
  201. } else {
  202. $data = [
  203. 'CreateTime' => date('Y-m-d H:i:s', time()),
  204. 'TitleString' => $params['title'],
  205. 'TextString' => $params['text'],
  206. 'BonusString' => '',
  207. 'FromAgentID' => $admin->id,
  208. ];
  209. $result = DB::table('QPAccountsDB.dbo.SystemMail')->insert($data);
  210. }
  211. if ($result) {
  212. return $this->json(200, "发布成功");
  213. } else {
  214. return $this->json(500, '发布失败,请重试');
  215. }
  216. }
  217. public function mailDelete($type, $id)
  218. {
  219. if (empty($id)) {
  220. return $this->json(500, '邮件不存在');
  221. }
  222. $table = $type == 1 ? 'QPAccountsDB.dbo.SystemMail' : 'QPAccountsDB.dbo.PrivateMail';
  223. $result = DB::table($table)
  224. ->where('MailID', $id)
  225. ->delete();
  226. if ($result !== false) {
  227. return $this->json(200, '删除成功');
  228. }
  229. return $this->json(500, '删除失败,请重试');
  230. }
  231. // 邮件充值记录
  232. public function mailRecord(Request $request)
  233. {
  234. $GameID = $request->GameID ?: '';
  235. $amount = $request->amount ?: '';
  236. $amount_search = $request->amount_search ?: '';
  237. $list = (new MailLogic())->mailRecord(1, $GameID, $amount, $amount_search);
  238. return view('admin.mail.mailRecord', compact('list', 'GameID', 'amount', 'amount_search'));
  239. }
  240. // 提现返还邮件记录
  241. public function back_mailRecord(Request $request)
  242. {
  243. $GameID = $request->GameID ?: '';
  244. $amount = $request->amount ?: '';
  245. $amount_search = $request->amount_search ?: '';
  246. $list = (new MailLogic())->mailRecord(2, $GameID, $amount, $amount_search);
  247. return view('admin.mail.back_mailRecord', compact('list', 'GameID', 'amount', 'amount_search'));
  248. }
  249. }