MailController.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. foreach ($list as $key => &$value) {
  75. if (!empty($value->BonusString)) {
  76. $bonus = $value->BonusString;
  77. $bonus = explode(';', $bonus);
  78. $value->BonusString = '';
  79. foreach ($bonus as $k => &$v) {
  80. $v = explode(',', $v);
  81. $value->BonusString .= '金币x' . ($v[1] / 100) . ',';
  82. }
  83. }
  84. }
  85. 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]);
  86. }
  87. //邮件发布页面
  88. public function mailAddView(Request $request)
  89. {
  90. return view('admin.mail.mail_add');
  91. }
  92. //邮件发布
  93. public function mailAdd(Request $request)
  94. {
  95. $admin = $request->session()->get('admin');//管理员信息
  96. $params = $request->all();
  97. $bonus_arr = $params['bonus'];
  98. if (count($bonus_arr) > 5) {
  99. return $this->json(500, '奖品最多不超过五件');
  100. }
  101. $bonus = '';
  102. if (empty($params['title']) || empty($params['text'])) {
  103. return $this->json(500, '请确认数据完整');
  104. }
  105. $params['type'] = 2;
  106. $type = 0;
  107. $amount = 0;
  108. $change_score = 0;
  109. if (isset($bonus_arr[0]['id']) && !empty($bonus_arr[0]['id'])) {
  110. foreach ($bonus_arr as $key => $value) {
  111. // if (empty($value['id']) || empty($value['number'])) {
  112. // return $this->json(500, '奖品不能为空');
  113. // }
  114. if ($value['id'] == "30000" && $value['number'] > 1000000) {
  115. return $this->json(500, '金币不能超过一百万');
  116. }
  117. if ($value['id'] == 10000 && $value['number'] > 200) {
  118. return $this->json(500, '房卡不能超过二百');
  119. }
  120. if ($value['id'] == 40000 && $value['number'] > 100000) {
  121. return $this->json(500, '福卡不能超过十万');
  122. }
  123. // if (!empty($value['number']) && $value['number'] < 0.1) {
  124. // return $this->json(500, '奖品数量最小值为0.1');
  125. // }
  126. // 判断彩金管理员够不够
  127. $admin_id = session('admin')->id;
  128. $admin = DB::table('agent.dbo.admin_users')->where('id',$admin_id)->first();
  129. $lottery_amount = $admin->lottery_amount ?: 0;
  130. if ($lottery_amount < $value['number']) {
  131. return $this->json(500, '彩金额度不足');
  132. }
  133. $change_score = $value['number'];
  134. if (!preg_match('/^\d+$/', $change_score)) {
  135. return $this->json(500, '金额必须是整数');
  136. }
  137. $value['number'] = $value['number'] * 100;
  138. $bonus .= implode(',', $value) . ';';
  139. $type = 3;
  140. if ($value['id'] === "30000") {
  141. $amount = $value['number'];
  142. }
  143. }
  144. }
  145. $bonus = trim($bonus, ';');
  146. //个人公告
  147. if ($params['type'] == 2) {
  148. $uids = [];
  149. if(strstr($params['game_id'],';')){
  150. $uids = explode(';',$params['game_id']);
  151. }else{
  152. $uids = [trim($params['game_id'])];
  153. }
  154. foreach ($uids as $game_id){
  155. $UserInfo = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')->where('GameID', $game_id)
  156. ->select('UserID','Channel')
  157. ->first();
  158. if (!$UserInfo) {
  159. return $this->json(500, '未查询到该用户');
  160. }
  161. $user_id = $UserInfo->UserID;
  162. $Channel = $UserInfo->Channel;
  163. $data = [
  164. 'MailType' => $params['type'],
  165. 'MailStatus' => 1,
  166. 'UserID' => $user_id,
  167. 'CreateTime' => date('Y-m-d H:i:s', time()),
  168. 'TitleString' => $params['title'],
  169. 'TextString' => $params['text'],
  170. 'BonusString' => $bonus,
  171. 'FromAgentID' => $admin->id,
  172. 'type' => $type,
  173. 'amount' => $amount,
  174. // 'admin_type' => @$params['admin_type']?:0
  175. ];
  176. $result = DB::table('QPAccountsDB.dbo.PrivateMail')->insert($data);
  177. if($amount){
  178. // 添加管理员变化额度
  179. AdminScore::add_score($admin, $change_score, 1);
  180. // 添加赠送金币
  181. RecordPlatformData::addGiveGold($amount,$Channel);
  182. }
  183. }
  184. //系统公告
  185. } else {
  186. $data = [
  187. 'CreateTime' => date('Y-m-d H:i:s', time()),
  188. 'TitleString' => $params['title'],
  189. 'TextString' => $params['text'],
  190. 'BonusString' => '',
  191. 'FromAgentID' => $admin->id,
  192. ];
  193. $result = DB::table('QPAccountsDB.dbo.SystemMail')->insert($data);
  194. }
  195. if ($result) {
  196. return $this->json(200, "发布成功");
  197. } else {
  198. return $this->json(500, '发布失败,请重试');
  199. }
  200. }
  201. // 邮件充值记录
  202. public function mailRecord(Request $request)
  203. {
  204. $GameID = $request->GameID ?: '';
  205. $amount = $request->amount ?: '';
  206. $amount_search = $request->amount_search ?: '';
  207. $list = (new MailLogic())->mailRecord(1, $GameID, $amount, $amount_search);
  208. return view('admin.mail.mailRecord', compact('list', 'GameID', 'amount', 'amount_search'));
  209. }
  210. // 提现返还邮件记录
  211. public function back_mailRecord(Request $request)
  212. {
  213. $GameID = $request->GameID ?: '';
  214. $amount = $request->amount ?: '';
  215. $amount_search = $request->amount_search ?: '';
  216. $list = (new MailLogic())->mailRecord(2, $GameID, $amount, $amount_search);
  217. return view('admin.mail.back_mailRecord', compact('list', 'GameID', 'amount', 'amount_search'));
  218. }
  219. }