MailController.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. $value['number'] = $value['number'] * 100;
  135. $bonus .= implode(',', $value) . ';';
  136. $type = 3;
  137. if ($value['id'] === "30000") {
  138. $amount = $value['number'];
  139. }
  140. }
  141. }
  142. $bonus = trim($bonus, ';');
  143. //个人公告
  144. if ($params['type'] == 2) {
  145. $uids = [];
  146. if(strstr($params['game_id'],';')){
  147. $uids = explode(';',$params['game_id']);
  148. }else{
  149. $uids = [trim($params['game_id'])];
  150. }
  151. foreach ($uids as $game_id){
  152. $UserInfo = DB::connection('write')->table('QPAccountsDB.dbo.AccountsInfo')->where('GameID', $game_id)
  153. ->select('UserID','Channel')
  154. ->first();
  155. if (!$UserInfo) {
  156. return $this->json(500, '未查询到该用户');
  157. }
  158. $user_id = $UserInfo->UserID;
  159. $Channel = $UserInfo->Channel;
  160. $data = [
  161. 'MailType' => $params['type'],
  162. 'MailStatus' => 1,
  163. 'UserID' => $user_id,
  164. 'CreateTime' => date('Y-m-d H:i:s', time()),
  165. 'TitleString' => $params['title'],
  166. 'TextString' => $params['text'],
  167. 'BonusString' => $bonus,
  168. 'FromAgentID' => $admin->id,
  169. 'type' => $type,
  170. 'amount' => $amount,
  171. // 'admin_type' => @$params['admin_type']?:0
  172. ];
  173. $result = DB::table('QPAccountsDB.dbo.PrivateMail')->insert($data);
  174. if($amount){
  175. // 添加管理员变化额度
  176. AdminScore::add_score($admin, $change_score, 1);
  177. // 添加赠送金币
  178. RecordPlatformData::addGiveGold($amount,$Channel);
  179. }
  180. }
  181. //系统公告
  182. } else {
  183. $data = [
  184. 'CreateTime' => date('Y-m-d H:i:s', time()),
  185. 'TitleString' => $params['title'],
  186. 'TextString' => $params['text'],
  187. 'BonusString' => '',
  188. 'FromAgentID' => $admin->id,
  189. ];
  190. $result = DB::table('QPAccountsDB.dbo.SystemMail')->insert($data);
  191. }
  192. if ($result) {
  193. return $this->json(200, "发布成功");
  194. } else {
  195. return $this->json(500, '发布失败,请重试');
  196. }
  197. }
  198. // 邮件充值记录
  199. public function mailRecord(Request $request)
  200. {
  201. $GameID = $request->GameID ?: '';
  202. $amount = $request->amount ?: '';
  203. $amount_search = $request->amount_search ?: '';
  204. $list = (new MailLogic())->mailRecord(1, $GameID, $amount, $amount_search);
  205. return view('admin.mail.mailRecord', compact('list', 'GameID', 'amount', 'amount_search'));
  206. }
  207. // 提现返还邮件记录
  208. public function back_mailRecord(Request $request)
  209. {
  210. $GameID = $request->GameID ?: '';
  211. $amount = $request->amount ?: '';
  212. $amount_search = $request->amount_search ?: '';
  213. $list = (new MailLogic())->mailRecord(2, $GameID, $amount, $amount_search);
  214. return view('admin.mail.back_mailRecord', compact('list', 'GameID', 'amount', 'amount_search'));
  215. }
  216. }