GoldController.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. <?php
  2. /*金币场管理*/
  3. namespace App\Http\Controllers\Admin;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\helper\HttpCurl;
  6. use App\Http\helper\NumConfig;
  7. use App\Http\logic\admin\GoldLogic;
  8. use App\Models\GroupControlRecord;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Facades\DB;
  11. use App\Models\Order;
  12. use Excel;
  13. use Illuminate\Support\Facades\Log;
  14. class GoldController extends Controller
  15. {
  16. //充值数据
  17. public function rechargeList(Request $request)
  18. {
  19. $excel = $request->get('excel');
  20. $end_time = $request->input('end_time');
  21. $start_time = $request->input('start_time');
  22. $start_time = str_replace('T', ' ', $start_time);
  23. $end_time = str_replace('T', ' ', $end_time);
  24. $where = [];
  25. if (empty($start_time)) {
  26. $where[] = ['RecordDate', '>=', date('Y-m-d', strtotime('-1 week'))];
  27. $start_time = date('Y-m-d', strtotime('-1 week'));
  28. } else {
  29. $where[] = ['RecordDate', '>=', $start_time];
  30. }
  31. if (empty($end_time)) {
  32. $where[] = ['RecordDate', '<=', date('Y-m-d')];
  33. $end_time = date('Y-m-d');
  34. } else {
  35. $where[] = ['RecordDate', '<=', $end_time];
  36. }
  37. if ($excel) {
  38. $cellData = DB::connection('write')->table('QPRecordDB.dbo.LogDayRecharge as ldr')
  39. ->leftJoin('QPRecordDB.dbo.RecordCardCost as rcc', 'ldr.RecordDate', '=', 'rcc.mydate')
  40. ->select('ldr.RecordDate', 'ldr.RecordDate as week', 'ldr.TotalRechargeMoney', 'ldr.TodayUsers', 'ldr.TodayNewUsers', 'rcc.LoginCount')
  41. ->where($where)
  42. ->orderBy('RecordDate', 'Desc')
  43. ->get();
  44. foreach ($cellData as $key => &$value) {
  45. $week = array("日", "一", "二", "三", "四", "五", "六");
  46. $value->week = $week[date('w', strtotime($value->week))];
  47. $value->LoginCount == 0 ? $value->recharge_rate = 0 : $value->recharge_rate = ((round(($value->TodayUsers / $value->LoginCount), 4)) * 100) . '%';
  48. $value->LoginCount == 0 ? $value->arpu = 0 : $value->arpu = round(($value->TotalRechargeMoney / $value->LoginCount), 4);
  49. $value->TodayUsers == 0 ? $value->arppu = 0 : $value->arppu = round(($value->TotalRechargeMoney / $value->TodayUsers), 4);
  50. unset($value->LoginCount);
  51. }
  52. $title = ['时间', '星期', '充值收入', '今日充值用户', '新增充值用户', '充值率', 'ARPU', 'ARPPU'];
  53. $cellData = json_decode(json_encode($cellData), true);
  54. downloadExcel($cellData, $title, '金币场充值数据');
  55. exit;
  56. array_unshift($cellData, $title);
  57. Excel::create('金币场充值数据', function ($excel) use ($cellData) {
  58. $excel->sheet('score', function ($sheet) use ($cellData) {
  59. $sheet->rows($cellData);
  60. $sheet->setWidth(array('A' => 15, 'B' => 15, 'C' => 15, 'D' => 15, 'E' => 15, 'F' => 15, 'G' => 15, 'H' => 15));
  61. });
  62. })->export('xls');
  63. } else {
  64. $list = DB::connection('write')->table('QPRecordDB.dbo.LogDayRecharge as ldr')
  65. ->leftJoin('QPRecordDB.dbo.RecordCardCost as rcc', 'ldr.RecordDate', '=', 'rcc.mydate')
  66. ->select('ldr.RecordDate', 'ldr.TotalRechargeMoney', 'ldr.TodayUsers', 'ldr.TodayNewUsers', 'rcc.LoginCount')
  67. ->where($where)
  68. ->orderBy('RecordDate', 'Desc')
  69. ->paginate(10);
  70. foreach ($list as $key => &$value) {
  71. $week = array("日", "一", "二", "三", "四", "五", "六");
  72. $value->week = $week[date('w', strtotime($value->RecordDate))];
  73. $value->LoginCount == 0 ? $value->recharge_rate = 0 : $value->recharge_rate = ((round(($value->TodayUsers / $value->LoginCount), 4)) * 100);
  74. $value->LoginCount == 0 ? $value->arpu = 0 : $value->arpu = round(($value->TotalRechargeMoney / $value->LoginCount), 4);
  75. $value->TodayUsers == 0 ? $value->arppu = 0 : $value->arppu = round(($value->TotalRechargeMoney / $value->TodayUsers), 4);
  76. $value->TotalRechargeMoney = number_float($value->TotalRechargeMoney / 100);
  77. $value->arpu = number_float($value->arpu / 100);
  78. $value->arppu = number_float($value->arppu / 100);
  79. }
  80. return view('admin.gold.recharge_list', ['list' => $list, 'end_time' => $end_time, 'start_time' => $start_time]);
  81. }
  82. }
  83. //金币数据
  84. public function goldList(Request $request)
  85. {
  86. $excel = $request->get('excel');
  87. $end_time = $request->input('end_time');
  88. $start_time = $request->input('start_time');
  89. $start_time = str_replace('T', ' ', $start_time);
  90. $end_time = str_replace('T', ' ', $end_time);
  91. $where = [];
  92. if (empty($start_time)) {
  93. $where[] = ['mydate', '>=', date('Y-m-d', strtotime('-1 week'))];
  94. $start_time = date('Y-m-d', strtotime('-1 week'));
  95. } else {
  96. $where[] = ['mydate', '>=', $start_time];
  97. }
  98. if (empty($end_time)) {
  99. $where[] = ['mydate', '<=', date('Y-m-d')];
  100. $end_time = date('Y-m-d');
  101. } else {
  102. $where[] = ['mydate', '<=', $end_time];
  103. }
  104. if ($excel) {
  105. $cellData = DB::connection('read')->table('QPRecordDB.dbo.RecordCardCost')
  106. ->select('mydate', DB::raw('mydate as week'), 'AllScore', DB::raw('IsNull(Waste+Revenue-AllOutScore,0)'), 'AllOutScore', 'AllActiveUserScore', 'AllWorkingScore', 'Waste', 'Revenue', 'PlayCount')
  107. ->where($where)
  108. ->orderBy('mydate', 'desc')
  109. ->get();
  110. foreach ($cellData as $key => &$value) {
  111. $week = array("日", "一", "二", "三", "四", "五", "六");
  112. $value->week = $week[date('w', strtotime($value->week))];
  113. }
  114. $title = ['时间', '星期', '总金币池', '金币收入', '日发放总额', '日活跃资金量', '日流通量总额', '机器人输赢', '税收', '金币场次'];
  115. $cellData = json_decode(json_encode($cellData), true);
  116. downloadExcel($cellData, $title, '金币场金币数据');
  117. } else {
  118. $list = DB::connection('read')->table('QPRecordDB.dbo.RecordCardCost')
  119. ->select('mydate', 'AllScore', DB::raw('IsNull(Waste+Revenue-AllOutScore,0) as gold'), 'AllOutScore', 'AllActiveUserScore', 'AllWorkingScore', 'Waste', 'Revenue', 'PlayCount')
  120. ->where($where)
  121. ->orderBy('mydate', 'desc')
  122. ->paginate(10);
  123. foreach ($list as $key => &$value) {
  124. $week = array("日", "一", "二", "三", "四", "五", "六");
  125. $value->week = $week[date('w', strtotime($value->mydate))];
  126. $value->AllScore = number_format($value->AllScore);
  127. $value->gold = number_format($value->gold);
  128. $value->AllOutScore = number_format($value->AllOutScore);
  129. $value->AllActiveUserScore = number_format($value->AllActiveUserScore);
  130. $value->AllWorkingScore = number_format($value->AllWorkingScore);
  131. $value->Waste = number_format($value->Waste);
  132. $value->Revenue = number_format($value->Revenue);
  133. $value->PlayCount = number_format($value->PlayCount);
  134. // $value->gold = $value->Waste + $value->Revenue - $value->AllOutScore;
  135. }
  136. return view('admin.gold.gold_list', ['list' => $list, 'end_time' => $end_time, 'start_time' => $start_time]);
  137. }
  138. }
  139. //用户数据
  140. public function userList(Request $request)
  141. {
  142. $excel = $request->get('excel');
  143. $end_time = $request->input('end_time');
  144. $start_time = $request->input('start_time');
  145. $start_time = str_replace('T', ' ', $start_time);
  146. $end_time = str_replace('T', ' ', $end_time);
  147. $where = [];
  148. if (empty($start_time)) {
  149. $where[] = ['mydate', '>=', date('Y-m-d', strtotime('-1 week'))];
  150. $start_time = date('Y-m-d', strtotime('-1 week'));
  151. } else {
  152. $where[] = ['mydate', '>=', $start_time];
  153. }
  154. if (empty($end_time)) {
  155. $where[] = ['mydate', '<=', date('Y-m-d')];
  156. $end_time = date('Y-m-d');
  157. } else {
  158. $where[] = ['mydate', '<=', $end_time];
  159. }
  160. if ($excel) {
  161. set_time_limit(0);
  162. $where_raw = "DATEDIFF(DD,'$start_time',ocs.InsertDateTime)>=0 AND DATEDIFF(DD,'$end_time',ocs.InsertDateTime)<=0";
  163. $cellData = DB::connection('read')->table('QPRecordDB.dbo.LogOnLineCountSum as ocs')
  164. ->leftJoin('QPRecordDB.dbo.RecordCardCost as rcc', 'rcc.mydate', '=', DB::raw('CONVERT(varchar(100), ocs.InsertDateTime, 23)'))
  165. ->select(DB::raw("CONVERT(varchar(100), ocs.InsertDateTime, 23) as InsertDate"), 'mydate', 'LoginCount', 'RegisterCount', DB::raw("Max(ocs.OnlineCountSum) as maxOnline"), 'SleepUserCount', DB::raw('null as lostUser'), 'WakeupUserCount', 'Retention1', 'Retention3', 'Retention7', 'Retention30', 'ARetention1', 'ARetention3', 'ARetention7', 'ARetention30')
  166. ->whereRaw($where_raw)
  167. ->groupBy('mydate', DB::raw('CONVERT(varchar(100), ocs.InsertDateTime, 23)'), 'LoginCount', 'RegisterCount', 'SleepUserCount', 'WakeupUserCount', 'Retention1', 'Retention3', 'Retention7', 'Retention30', 'ARetention1', 'ARetention3', 'ARetention7', 'ARetention30')
  168. ->orderBy('InsertDate', 'desc')
  169. ->get();
  170. foreach ($cellData as $key => &$value) {
  171. $week = array("日", "一", "二", "三", "四", "五", "六");
  172. $value->mydate = $week[date('w', strtotime($value->mydate))];
  173. }
  174. $title = ['时间', '星期', '活跃用户', '新增用户', '最高在线', '流失用户', '休眠用户', '回归用户', '新增次日留存', '新增3日留存', '新增7日留存', '新增30日留存', '活跃次日留存', '活跃3日留存', '活跃7日留存', '活跃30日留存'];
  175. $cellData = json_decode(json_encode($cellData), true);
  176. downloadExcel($cellData, $title, '金币场用户数据');
  177. } else {
  178. $where_raw = "DATEDIFF(DD,'$start_time',ocs.InsertDateTime)>=0 AND DATEDIFF(DD,'$end_time',ocs.InsertDateTime)<=0";
  179. $list = DB::connection('read')->table('QPRecordDB.dbo.LogOnLineCountSum as ocs')
  180. ->leftJoin('QPRecordDB.dbo.RecordCardCost as rcc', 'rcc.mydate', '=', DB::raw('CONVERT(varchar(100), ocs.InsertDateTime, 23)'))
  181. ->select(DB::raw("CONVERT(varchar(100), ocs.InsertDateTime, 23) as InsertDate,Max(ocs.OnlineCountSum) as maxOnline"), 'LoginCount', 'RegisterCount', 'SleepUserCount', DB::raw('null as lostUser'), 'WakeupUserCount', 'Retention1', 'Retention3', 'Retention7', 'Retention30', 'ARetention1', 'ARetention3', 'ARetention7', 'ARetention30')
  182. ->whereRaw($where_raw)
  183. ->groupBy(DB::raw('CONVERT(varchar(100), ocs.InsertDateTime, 23)'), 'LoginCount', 'RegisterCount', 'SleepUserCount', 'WakeupUserCount', 'Retention1', 'Retention3', 'Retention7', 'Retention30', 'ARetention1', 'ARetention3', 'ARetention7', 'ARetention30')
  184. ->orderBy(DB::raw('CONVERT(varchar(100), ocs.InsertDateTime, 23)'), 'desc')
  185. ->paginate(10);
  186. foreach ($list as $key => &$value) {
  187. $week = array("日", "一", "二", "三", "四", "五", "六");
  188. $value->week = $week[date('w', strtotime($value->InsertDate))];
  189. }
  190. return view('admin.gold.user_list', ['list' => $list, 'end_time' => $end_time, 'start_time' => $start_time]);
  191. }
  192. }
  193. //游戏日志
  194. public function gameLogList(Request $request)
  195. {
  196. $excel = $request->get('excel');
  197. $end_time = $request->input('end_time');
  198. $start_time = $request->input('start_time');
  199. $kind_id = $request->input('kind_id');
  200. $room_type = $request->input('room_type');
  201. $game_level = $request->post('game_level');
  202. $start_time = str_replace('T', ' ', $start_time);
  203. $end_time = str_replace('T', ' ', $end_time);
  204. $room_list = [];
  205. if (!empty($kind_id)) {
  206. $room_list = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  207. ->where('GameID', $kind_id)
  208. ->select('ServerID', 'ServerName')
  209. ->get();
  210. }
  211. $where = [];
  212. if (empty($start_time)) {
  213. $start_time = date('Y-m-d', strtotime("$end_time -10day"));
  214. }
  215. $where[] = ['RecordDate', '>=', $start_time];
  216. if (empty($end_time)) {
  217. $end_time = date('Y-m-d');
  218. }
  219. $where[] = ['RecordDate', '<=', $end_time];
  220. $count_where[] = ['RecordDate', '=', date('Y-m-d', strtotime('-1 day'))];
  221. !empty($kind_id) ? $where[] = $count_where[] = ['KindID', '=', $kind_id] : '';
  222. !empty($room_type) ? $where[] = $count_where[] = ['RoomType', '=', $room_type] : '';
  223. //只选取斗地主 捕鱼 捞腌菜 百人斗牛 百人龙虎斗 动动三张(game_id 依次)
  224. $game_id = ['622', '1002', '2003', '2010', '2011', '1005'];
  225. //$game_name = DB::table('QPPlatformDB.dbo.GameGameItem')->whereIn('GameId',$game_id)->pluck('GameName','GameID');//单选框数据
  226. $game_name = DB::connection('write')->table('QPPlatformDB.dbo.GameKindItem')->whereIn('GameID', [1005, 2030, 2050])->pluck('KindName as GameName', 'GameID');//单选框数据
  227. $room = ['1' => '初级场', '2' => '普通场', '4' => '中级场', '8' => '高级场', '64' => '包厢',];
  228. $count = DB::connection('read')->table('QPRecordDB.dbo.LogDayDataByRoom')
  229. ->where($count_where)
  230. ->count();
  231. $count == 0 ? $count = 1 : '';
  232. $start = strtotime($start_time);
  233. $end = strtotime($end_time);
  234. while ($start <= $end) {
  235. $date[] = date('Y-m-d', $start);
  236. $start = strtotime('+1 day', $start);
  237. }
  238. if ($excel) {
  239. $cellData = DB::connection('read')->table('QPRecordDB.dbo.LogDayDataByRoom')
  240. ->selectRaw("RecordDate,RecordDate as date,SUM(PlayCount) as PlayCount,SUM(PlayersCount) as PlayersCount,SUM(CONVERT(bigint,AverageCount)) as AverageCount,SUM(BankruptcyPlayersCount) as BankruptcyPlayersCount,SUM(BankruptcyRate) as BankruptcyRate,SUM(PayPlayCount) as PayPlayCount,SUM(CONVERT(bigint,PayAverageCount)) as PayAverageCount,SUM(AllLoginScore) as AllLoginScore,SUM(PayUserScore) as PayUserScore,SUM(AllWorkingScore) as AllWorkingScore,SUM(AllRevenue) as AllRevenue,SUM(CONVERT(bigint,AverageUserScore)) as AverageUserScore,SUM(CONVERT(bigint,AveragePlayScore)) as AveragePlayScore,SUM(AndroidScore) as AndroidScore")
  241. ->whereIn('RecordDate', $date)
  242. ->where($where)
  243. ->groupBy('RecordDate')
  244. ->orderBy('RecordDate', 'DESC')
  245. ->get();
  246. $title = ['时间', '星期', '游戏总局数', '登陆用户数', '人均局数', '破产用户数', '破产率', '充值用户总局数', '充值用户人均局数', '登录用户携带金币量', '付费用户携带金币量', '总流水', '总税收', '人均流水', '均局流水', '机器人输赢', '税收流水比'];
  247. foreach ($cellData as $key => &$value) {
  248. $week = array("日", "一", "二", "三", "四", "五", "六");
  249. $value->date = $week[date('w', strtotime($value->date))];
  250. $count == 0 ? $value->BankruptcyRate = 0 : $value->BankruptcyRate = round(($value->BankruptcyRate) / $count, 2);
  251. $value->AllWorkingScore == 0 ? $value->Percentage = 0 : $value->Percentage = round($value->AllRevenue / $value->AllWorkingScore * 100, 2) . '%';
  252. }
  253. $cellData = json_decode(json_encode($cellData), true);
  254. downloadExcel($cellData, $title, '金币场游戏日志');
  255. } else {
  256. DB::connection()->enableQueryLog();
  257. $list = DB::connection('read')->table('QPRecordDB.dbo.LogDayDataByRoom')
  258. ->selectRaw('RecordDate,SUM(PlayCount) as PlayCount,SUM(PlayersCount) as PlayersCount,SUM(CONVERT(bigint,AverageCount)) as AverageCount,SUM(BankruptcyPlayersCount) as BankruptcyPlayersCount,SUM(BankruptcyRate) as BankruptcyRate,SUM(PayPlayCount) as PayPlayCount,SUM(CONVERT(bigint,PayAverageCount)) as PayAverageCount,SUM(AllLoginScore) as AllLoginScore,SUM(PayUserScore) as PayUserScore,SUM(AllWorkingScore) as AllWorkingScore,SUM(AllRevenue) as AllRevenue,SUM(CONVERT(bigint,AverageUserScore)) as AverageUserScore,SUM(CONVERT(bigint,AveragePlayScore)) as AveragePlayScore,SUM(AndroidWorkingScore) as AndroidWorkingScore,SUM(AndroidScore) as AndroidScore')
  259. ->whereIn('RecordDate', $date)
  260. ->where($where)
  261. ->groupBy('RecordDate')
  262. ->orderBy('RecordDate', 'DESC')
  263. ->paginate(10);
  264. foreach ($list as $key => &$value) {
  265. $week = array("日", "一", "二", "三", "四", "五", "六");
  266. $value->week = $week[date('w', strtotime($value->RecordDate))];
  267. $count == 0 ? $value->BankruptcyRate = 0 : $value->BankruptcyRate = round(($value->BankruptcyRate) / $count, 2);
  268. $value->AllLoginScore = number_format($value->AllLoginScore / 100, 2, '.', '');
  269. $value->PayUserScore = number_format($value->PayUserScore / 100, 2, '.', '');
  270. $value->AllWorkingScore == 0 ? $value->Percentage = 0 : $value->Percentage = round($value->AllRevenue / $value->AllWorkingScore * 100, 2) . '%';
  271. $value->AllWorkingScore = number_format($value->AllWorkingScore / 100, 2, '.', '');
  272. $value->AllRevenue = number_format($value->AllRevenue / 100, 2, '.', '');
  273. $value->AverageUserScore = number_format($value->AverageUserScore / 100, 2, '.', '');
  274. $value->AveragePlayScore = number_format($value->AveragePlayScore / 100, 2, '.', '');
  275. $value->AndroidScore = number_format($value->AndroidScore / 100, 2, '.', '');
  276. }
  277. return view('admin.gold.game_list', ['list' => $list, 'end_time' => $end_time, 'start_time' => $start_time, 'room_type' => $room_type, 'game_name' => $game_name, 'kind_id' => $kind_id, 'room' => $room, 'room_list' => $room_list, 'game_level' => $game_level]);
  278. }
  279. }
  280. //游戏配置 -- 正式场
  281. public function gameConfigList(Request $request)
  282. {
  283. $kind_id = $request->post('kind_id');
  284. $game_level = $request->post('game_level');
  285. $gameType = $request->gameType ?: '';
  286. $room_list = [];
  287. $kindID_arr = config('games.openKGame');
  288. $ServerIDs = [32, 33, 39]; // 过滤试玩场
  289. if (!empty($kind_id)) {
  290. $where[] = ['ki.KindID', '=', $kind_id];
  291. $room_list = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  292. ->where('GameID', $kind_id)
  293. ->whereNotIn('ServerID', $ServerIDs)
  294. ->select('ServerID', 'ServerName')
  295. ->get();
  296. }
  297. $where = [];
  298. !empty($game_level) ? $where[] = ['gi.ServerID', '=', $game_level] : '';
  299. if (!empty($gameType)) {
  300. $gameType = explode(',', $gameType);
  301. $where[] = [function ($query) use ($gameType) {
  302. $query->whereIn('gi.GameID', $gameType);
  303. }];
  304. }
  305. $game_name = DB::connection('read')->table('QPPlatformDB.dbo.GameKindItem')
  306. ->whereIn('GameID', $kindID_arr)
  307. ->pluck('KindName as GameName', 'GameID');//单选框数据
  308. $list = (new GoldLogic())->gameConfigList($where, $kindID_arr);
  309. return view('admin.gold.game_config_list', [
  310. 'list' => $list,
  311. 'kind_id' => $kind_id,
  312. 'game_level' => $game_level,
  313. 'game_name' => $game_name,
  314. 'room_list' => $room_list,
  315. 'gameType' => $gameType
  316. ]);
  317. }
  318. //游戏配置 -- 试玩场
  319. public function demo_gameconfig(Request $request)
  320. {
  321. $kind_id = $request->post('kind_id');
  322. $game_level = $request->post('game_level');
  323. $room_list = [];
  324. $kindID_arr = [1005, 2030, 2050, 2060, 2061];
  325. $ServerIDs = [32, 33, 39]; // 过滤试玩场
  326. if (!empty($kind_id)) {
  327. $where[] = ['ki.KindID', '=', $kind_id];
  328. $room_list = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  329. ->where('GameID', $kind_id)
  330. ->whereIn('ServerID', $ServerIDs)
  331. ->select('ServerID', 'ServerName')
  332. ->get();
  333. }
  334. $where = [];
  335. !empty($game_level) ? $where[] = ['gi.ServerID', '=', $game_level] : '';
  336. $game_name = DB::connection('read')->table('QPPlatformDB.dbo.GameKindItem')
  337. ->whereIn('GameID', $kindID_arr)
  338. ->pluck('KindName as GameName', 'GameID');//单选框数据
  339. $list = (new GoldLogic())->gameConfigList($where, $ServerIDs, true);
  340. return view('admin.gold.demo_gameconfig', ['list' => $list, 'kind_id' => $kind_id, 'game_level' => $game_level, 'game_name' => $game_name, 'room_list' => $room_list, 'demo' => 1]);
  341. }
  342. //游戏配置修改页面
  343. public function gameConfigUpdateView(Request $request, $id)
  344. {
  345. $filed = ['gi.GameID', 'gi.ServerName', 'gi.ServerID as gi_ServerID', 'RoomStock', 'ki.KindName', 'ki.KindID', 'si.*'];
  346. $config = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo as gi')
  347. ->leftJoin('QPPlatformDB.dbo.GameKindItem as ki', 'ki.GameID', '=', 'gi.GameID')
  348. ->leftJoin('QPTreasureDB.dbo.StockConfigInfo as si', 'gi.ServerID', 'si.ServerID')
  349. ->where('gi.ServerID', $id)
  350. ->select($filed)
  351. ->first();
  352. $showConfig = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  353. ->where('ServerID', $id)
  354. ->select('CellScore', 'MinEnterScore', 'MaxEnterScore', 'ServerName', 'CellScore')
  355. ->first();
  356. $showConfig->CellScore = $showConfig->CellScore / 100;
  357. $showConfig->MinEnterScore = number_float($showConfig->MinEnterScore / 100);
  358. $showConfig->MaxEnterScore = number_float($showConfig->MaxEnterScore / 100);
  359. $config->BaseScore = $config->BaseScore / 100;
  360. return view('admin.gold.game_config_update', ['config' => $config, 'showConfig' => $showConfig]);
  361. }
  362. //游戏配置修改
  363. public function gameConfigUpdate(Request $request, $id)
  364. {
  365. $params = $request->post();
  366. $BaseScore = (float)$params['BaseScore'] * 100;
  367. unset($params['BaseScore']);
  368. foreach ($params as $key => $val) {
  369. $params[$key] = (int)$val;
  370. }
  371. $params['InitScore'] = 0;
  372. $params['BaseScore'] = $BaseScore;
  373. $query = DB::connection('read')->table('QPTreasureDB.dbo.StockConfigInfo')->where('ServerID', $id)->first();
  374. if ($query) {
  375. $result = DB::table('QPTreasureDB.dbo.StockConfigInfo')->where('ServerID', $id)->update($params);
  376. } else {
  377. $params['ServerID'] = $id;
  378. $result = DB::table('QPTreasureDB.dbo.StockConfigInfo')->insert($params);
  379. }
  380. // 获取实时库存
  381. $logic = new GoldLogic();
  382. $res = $logic->sync_stock($id);
  383. $stock = $res['data']['stock'] ?? '';
  384. $admin_id = session('admin')->id;
  385. // 添加群控记录
  386. GroupControlRecord::add_record($id, (int)$stock, $admin_id);
  387. if ($result) {
  388. return $this->json(200, "处理成功");
  389. } else {
  390. return $this->json(500, '处理失败,请重试');
  391. }
  392. }
  393. //捕魚库存查询
  394. public function fishStock(Request $request)
  395. {
  396. $list = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  397. ->select('GameID', 'SortID', 'RoomStock')
  398. ->where('GameID', 2003)
  399. ->paginate(20);
  400. foreach ($list as $key => &$value) {
  401. $value->RoomStock = explode(';', chop($value->RoomStock, ';'));
  402. switch ($value->SortID) {
  403. case '1':
  404. $value->SortName = '初级';
  405. break;
  406. case '2':
  407. $value->SortName = '普通';
  408. break;
  409. case '4':
  410. $value->SortName = '中级';
  411. break;
  412. case '8':
  413. $value->SortName = '高级';
  414. break;
  415. default:
  416. $value->SortName = '';
  417. break;
  418. }
  419. }
  420. return view('admin.gold.fish_stock_list', ['list' => $list]);
  421. }
  422. //金币每日发放查询
  423. public function goldEverydayList(Request $request)
  424. {
  425. $excel = $request->get('excel');
  426. $end_time = $request->input('end_time');
  427. $start_time = $request->input('start_time');
  428. $where = [];
  429. if (empty($start_time)) {
  430. $start_time = date('Y-m-d', strtotime("$end_time -9day"));
  431. }
  432. $where[] = ['mydate', '>=', $start_time];
  433. if (empty($end_time)) {
  434. $end_time = date('Y-m-d');
  435. }
  436. $where[] = ['mydate', '<=', $end_time];
  437. if ($excel) {
  438. $cellData = DB::connection('read')->table('QPRecordDB.dbo.LogDayOutScores')
  439. ->select('mydate', DB::raw('0 as AllScore'), 'RegisterScore', 'SignScore', 'ExchangeScore', 'SpreaderScore', 'RechargeScore', 'BankruptcyScore', 'TaskScore', 'ShareScore', 'MemberScore', 'BindPhone', 'ActivityScore')
  440. ->where($where)
  441. ->orderBy('mydate', 'desc')
  442. ->get();
  443. foreach ($cellData as $key => &$value) {
  444. foreach ($value as $k => $v) {
  445. if ($k !== 'mydate') {
  446. $value->AllScore += $v;
  447. }
  448. }
  449. }
  450. $title = ['时间', '发放总额', '注册增送', '签到赠送', '福卡兑换', '全民推广提取', '充值发放', '破产补助', '任务获得', '每日分享', '周卡月卡发放', '比赛发放', '手机绑定发放', '活动发放'];
  451. $cellData = json_decode(json_encode($cellData), true);
  452. downloadExcel($cellData, $title, '金币场金币每日发放查询');
  453. } else {
  454. $list = DB::connection('read')->table('QPRecordDB.dbo.LogDayOutScores')
  455. ->select('mydate', DB::raw('0 as AllScore'), 'RegisterScore', 'SignScore', 'ExchangeScore', 'SpreaderScore', 'RechargeScore', 'BankruptcyScore', 'TaskScore', 'ShareScore', 'MemberScore', 'BindPhone', 'ActivityScore')
  456. ->where($where)
  457. ->orderBy('mydate', 'desc')
  458. ->paginate(10);
  459. foreach ($list as $key => &$value) {
  460. foreach ($value as $k => &$v) {
  461. if ($k !== 'mydate') {
  462. $value->AllScore += $v;
  463. }
  464. is_numeric($v) ? $v = number_format($v) : '';
  465. }
  466. $value->AllScore = number_format($value->AllScore);
  467. }
  468. return view('admin.gold.day_list', ['list' => $list, 'end_time' => $end_time, 'start_time' => $start_time]);
  469. }
  470. }
  471. //捕鱼数据统计
  472. public function fishList(Request $request)
  473. {
  474. $excel = $request->get('excel');
  475. $sort = $request->get('sort');
  476. $type = $request->get('type');
  477. $end_time = $request->input('end_time');
  478. $start_time = $request->input('start_time');
  479. $where = [];
  480. if (empty($start_time)) {
  481. $where[] = ['RecordDate', '>=', date('Y-m-d', strtotime('-1 day'))];
  482. $start_time = date('Y-m-d', strtotime('-1 day'));
  483. } else {
  484. $where[] = ['RecordDate', '>=', $start_time];
  485. }
  486. if (empty($end_time)) {
  487. $where[] = ['RecordDate', '<=', date('Y-m-d', strtotime('+1 day'))];
  488. $end_time = date('Y-m-d', strtotime('+1 day'));
  489. } else {
  490. $where[] = ['RecordDate', '<=', date('Y-m-d', strtotime('+1 day', strtotime($end_time)))];
  491. }
  492. !empty($sort) ? $where[] = ['SortId', '=', $sort] : '';
  493. isset($type) ? $where[] = ['FishType', '=', $type] : '';
  494. if ($excel) {
  495. $cellData = DB::connection('write')->table('QPRecordDB.dbo.FishDotRecord')
  496. ->selectRaw('CONVERT(varchar(10),RecordDate,23) as RecordDate,SUM(GoldStock) as GoldStock,SUM(Revenue) as Revenue,SUM(GoldTurnover) as GoldTurnover,SUM(GoldOut) as GoldOut')
  497. ->where($where)
  498. ->orderBy('RecordDate', 'desc')
  499. ->groupBy(DB::raw('CONVERT(varchar(10),RecordDate,23)'))
  500. ->get();
  501. $title = ['时间', '金豆库存', '金豆税收', '金豆流水', '金豆放出'];
  502. $cellData = json_decode(json_encode($cellData), true);
  503. downloadExcel($cellData, $title, '捕鱼数据统计');
  504. } else {
  505. $list = DB::connection('write')->table('QPRecordDB.dbo.FishDotRecord')
  506. ->selectRaw('CONVERT(varchar(10),RecordDate,23) as RecordDate,SUM(GoldStock) as GoldStock,SUM(Revenue) as Revenue,SUM(GoldTurnover) as GoldTurnover,SUM(GoldOut) as GoldOut')
  507. ->where($where)
  508. ->orderBy(DB::raw('CONVERT(varchar(10),RecordDate,23)'), 'desc')
  509. ->groupBy(DB::raw('CONVERT(varchar(10),RecordDate,23)'))
  510. ->paginate(10);
  511. $sort_name = ['1' => '初级', '2' => '普通', '4' => '中级', '8' => '高级'];
  512. $type_name = ['0', '1', '2', '3', '4', '5', '6', '7'];
  513. foreach ($list as $key => &$value) {
  514. foreach ($value as $k => &$v) {
  515. is_numeric($v) ? $v = number_format($v) : '';
  516. }
  517. }
  518. return view('admin.gold.fish_list', ['list' => $list, 'end_time' => $end_time, 'start_time' => $start_time, 'sort' => $sort, 'type' => $type, 'sort_name' => $sort_name, 'type_name' => $type_name]);
  519. }
  520. }
  521. //打点查看
  522. public function operateList(Request $request)
  523. {
  524. $end_time = $request->input('end_time');
  525. $start_time = $request->input('start_time');
  526. $excel = $request->get('excel');
  527. if (empty($start_time)) {
  528. $start_time = date('Y-m-d');
  529. $where[] = ['og.OperateTime', '>=', $start_time];
  530. } else {
  531. $where[] = ['og.OperateTime', '>=', $start_time];
  532. }
  533. if (empty($end_time)) {
  534. $where[] = ['og.OperateTime', '<=', date('Y-m-d', strtotime('+1 day'))];
  535. $end_time = date('Y-m-d', strtotime('+1 day'));
  536. } else {
  537. $where[] = ['og.OperateTime', '<=', date('Y-m-d', strtotime('+1 day', strtotime($end_time)))];
  538. }
  539. //只查询 商城金豆 where_group
  540. $where_group = ['23'];
  541. $data = DB::table('QPRecordDB.dbo.YN_RecordOperateGroupConfig as ogc')
  542. ->leftJoin('QPRecordDB.dbo.YN_RecordOperateLog as og', 'ogc.GroupID', '=', 'og.GroupID')
  543. ->selectRaw('IsNULL(COUNT(*),0) as count,ogc.GroupID,ogc.GroupName,og.OperateType')
  544. // ->where($where)
  545. ->whereIn('ogc.GroupID', $where_group)
  546. ->whereIn('OperateType', [1, 2, 3])
  547. ->groupBy('ogc.GroupID', 'og.OperateType', 'ogc.GroupName')
  548. ->orderBy('ogc.GroupID')
  549. ->orderBy('og.OperateType')
  550. ->get();
  551. foreach ($data as $key => $value) {
  552. $arr[$value->GroupID][] = json_decode(json_encode($value), true);
  553. }
  554. foreach ($arr as $k => &$v) {
  555. $order_arr = [];
  556. $operate_type = array_map('end', $v);
  557. if (!in_array(1, $operate_type)) {
  558. $v[1] = [
  559. 'count' => 0,
  560. 'GroupID' => $v[0]['GroupID'],
  561. 'GroupName' => $v[0]['GroupName'],
  562. 'OperateType' => 1,
  563. ];
  564. }
  565. if (!in_array(2, $operate_type)) {
  566. $v[2] = [
  567. 'count' => 0,
  568. 'GroupID' => $v[0]['GroupID'],
  569. 'GroupName' => $v[0]['GroupName'],
  570. 'OperateType' => 2,
  571. ];
  572. }
  573. if (!in_array(3, $operate_type)) {
  574. $v[3] = [
  575. 'count' => 0,
  576. 'GroupID' => $v[0]['GroupID'],
  577. 'GroupName' => $v[0]['GroupName'],
  578. 'OperateType' => 3,
  579. ];
  580. }
  581. foreach ($v as $val) {
  582. $order_arr[] = $val['OperateType'];
  583. }
  584. array_multisort($order_arr, SORT_ASC, SORT_NUMERIC, $v);
  585. $new = $excel_data = [];
  586. for ($i = 0; $i < count($v); $i++) {
  587. $new['group_id'] = $v[$i]['GroupID'];
  588. $new['name'] = $v[$i]['GroupName'];
  589. $new['count' . $i] = $v[$i]['count'];
  590. }
  591. if ($new['count0'] !== 0) {
  592. $new['rate1'] = number_format($new['count1'] / $new['count0'], 2, '.', '');
  593. } else {
  594. $new['rate1'] = 0;
  595. }
  596. if ($new['count1'] !== 0) {
  597. $new['rate2'] = number_format($new['count2'] / $new['count1'], 2, '.', '');
  598. } else {
  599. $new['rate2'] = 0;
  600. }
  601. $excel_data = [
  602. 'name' => $new['name'],
  603. 'count0' => $new['count0'],
  604. 'rate1' => $new['rate1'],
  605. 'count1' => $new['count1'],
  606. 'rate2' => $new['rate2'],
  607. 'count2' => $new['count2'],
  608. ];
  609. $list[] = $new;
  610. $cellData[] = $excel_data;
  611. }
  612. if ($excel) {
  613. $title = ['名称', '展现次数', '转化率', '点击次数', '转化率', '完成次数'];
  614. $cellData = json_decode(json_encode($cellData), true);
  615. downloadExcel($cellData, $title, '打点数据统计');
  616. }
  617. return view('admin.gold.operate_list', ['list' => $list, 'end_time' => $end_time, 'start_time' => $start_time]);
  618. }
  619. //打点详情
  620. public function operateDetail(Request $request, $id)
  621. {
  622. $end_time = $request->input('end_time');
  623. $start_time = $request->input('start_time');
  624. $excel = $request->get('excel');
  625. if (empty($start_time)) {
  626. $start_time = date('Y-m-d');
  627. $where[] = ['og.OperateTime', '>=', $start_time];
  628. } else {
  629. $where[] = ['og.OperateTime', '>=', $start_time];
  630. }
  631. if (empty($end_time)) {
  632. $where[] = ['og.OperateTime', '<=', date('Y-m-d', strtotime('+1 day'))];
  633. $end_time = date('Y-m-d', strtotime('+1 day'));
  634. } else {
  635. $where[] = ['og.OperateTime', '<=', date('Y-m-d', strtotime('+1 day', strtotime($end_time)))];
  636. }
  637. $operate = config('operate');
  638. $operate_config = $operate[$id]['goods_id'];
  639. $data = DB::table('QPRecordDB.dbo.YN_RecordOperateLog as rol')
  640. ->leftJoin('agent.dbo.goods as g', 'rol.Param', '=', 'g.id')
  641. ->selectRaw('g.title,count(*) as num,rol.Param,rol.OperateType')
  642. ->whereIn('OperateType', [1, 2, 3])
  643. ->whereIn('rol.Param', $operate_config)
  644. ->orderBy('num', 'asc')
  645. ->groupBy('rol.Param', 'rol.OperateType', 'g.title')
  646. ->get();
  647. foreach ($data as $key => $value) {
  648. $arr[$value->Param][] = json_decode(json_encode($value), true);
  649. }
  650. foreach ($arr as $k => &$v) {
  651. $order_arr = [];
  652. $operate_type = array_map('end', $v);
  653. if (!in_array(1, $operate_type)) {
  654. $v[1] = [
  655. 'title' => $v[0]['title'],
  656. 'num' => 0,
  657. 'Param' => $v[0]['Param'],
  658. 'OperateType' => 1,
  659. ];
  660. }
  661. if (!in_array(2, $operate_type)) {
  662. $v[2] = [
  663. 'title' => $v[0]['title'],
  664. 'num' => 0,
  665. 'Param' => $v[0]['Param'],
  666. 'OperateType' => 2,
  667. ];
  668. }
  669. if (!in_array(3, $operate_type)) {
  670. $v[3] = [
  671. 'title' => $v[0]['title'],
  672. 'num' => 0,
  673. 'Param' => $v[0]['Param'],
  674. 'OperateType' => 3,
  675. ];
  676. }
  677. foreach ($v as $val) {
  678. $order_arr[] = $val['OperateType'];
  679. }
  680. array_multisort($order_arr, SORT_ASC, SORT_NUMERIC, $v);
  681. $new = $excel_data = [];
  682. for ($i = 0; $i < count($v); $i++) {
  683. $new['name'] = $v[$i]['title'];
  684. $new['count' . $i] = $v[$i]['num'];
  685. }
  686. if ($new['count0'] !== 0) {
  687. $new['rate1'] = number_format($new['count1'] / $new['count0'], 2, '.', '');
  688. } else {
  689. $new['rate1'] = 0;
  690. }
  691. if ($new['count1'] !== 0) {
  692. $new['rate2'] = number_format($new['count2'] / $new['count1'], 2, '.', '');
  693. } else {
  694. $new['rate2'] = 0;
  695. }
  696. $excel_data = [
  697. 'name' => $new['name'],
  698. 'count0' => $new['count0'],
  699. 'rate1' => $new['rate1'],
  700. 'count1' => $new['count1'],
  701. 'rate2' => $new['rate2'],
  702. 'count2' => $new['count2'],
  703. ];
  704. $list[] = $new;
  705. $cellData[] = $excel_data;
  706. }
  707. if ($excel) {
  708. $title = ['名称', '展现次数', '转化率', '点击次数', '转化率', '完成次数'];
  709. $cellData = json_decode(json_encode($cellData), true);
  710. downloadExcel($cellData, $title, '打点数据统计');
  711. }
  712. return view('admin.gold.operate_detail', ['list' => $list, 'id' => $id]);
  713. }
  714. public function room_list(Request $request)
  715. {
  716. $ServerIDs = [32, 33, 39, 56, 57, 58]; // 过滤试玩场
  717. $GameID = (int)$request->post('GameID');
  718. $demo = $request->demo ?: 0;
  719. $sql = $list = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  720. ->where('GameID', $GameID);
  721. $demo == 1 ? $sql->whereIn('ServerID', $ServerIDs) : $sql->whereNotIn('ServerID', $ServerIDs);
  722. $list = $sql->select('ServerID', 'ServerName')->get();
  723. return apiReturnSuc($list);
  724. }
  725. // 更新库存
  726. public function sync_stock(Request $request, $id)
  727. {
  728. $logic = new GoldLogic();
  729. $res = $logic->sync_stock($id);
  730. if ($res === false) {
  731. return apiReturnFail($logic->getError());
  732. }
  733. return apiReturnSuc($res);
  734. }
  735. // 群控库存操作记录列表
  736. public function update_stock_log(Request $request)
  737. {
  738. $start_time = $request->start_time ?: '';
  739. $end_time = $request->end_time ?: '';
  740. $ServerID = $request->ServerID ?: '';
  741. $kind_id = $request->kind_id ?: '';
  742. $where = [];
  743. !empty($start_time) && $where[] = ['log.create_time', '>=', $start_time];
  744. !empty($end_time) && $where[] = ['log.create_time', '>=', $end_time];
  745. !empty($ServerID) && $where[] = ['log.ServerID', $ServerID];
  746. $kindID_arr = [1005, 2030, 2050, 2060, 2061];
  747. $game_name = DB::connection('read')->table('QPPlatformDB.dbo.GameKindItem')
  748. ->whereIn('GameID', $kindID_arr)
  749. ->pluck('KindName as GameName', 'GameID');//单选框数据
  750. $room_list = [];
  751. if (!empty($kind_id)) {
  752. $where[] = ['ki.KindID', '=', $kind_id];
  753. $room_list = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  754. ->where('GameID', $kind_id)
  755. ->where('ServerType', 1)
  756. ->select('ServerID', 'ServerName')
  757. ->get();
  758. }
  759. $list = DB::connection('read')->table('agent.dbo.update_stock_log as log')
  760. ->leftJoin('QPPlatformDB.dbo.GameRoomInfo as gi', 'log.ServerID', 'gi.ServerID')
  761. ->join('agent.dbo.admin_users as au', 'log.admin_id', 'au.id')
  762. ->leftJoin('QPPlatformDB.dbo.GameKindItem as ki', 'ki.GameID', '=', 'gi.GameID')
  763. ->where($where)
  764. ->select('log.*', 'gi.ServerName', 'au.account')
  765. ->orderByDesc('log.create_time')
  766. ->paginate(10);
  767. return view('admin.gold.update_stock_log', [
  768. 'list' => $list,
  769. 'start_time' => $start_time,
  770. 'end_time' => $end_time,
  771. 'ServerID' => $ServerID,
  772. 'game_name' => $game_name,
  773. 'kind_id' => $kind_id,
  774. 'room_list' => $room_list
  775. ]);
  776. }
  777. // 修改库存
  778. // public function update_stock(Request $request, $id)
  779. // {
  780. // // 展示配置
  781. // $showConfig = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  782. // ->where('ServerID', $id)
  783. // ->select('CellScore', 'MinEnterScore', 'MaxEnterScore', 'ServerName', 'CellScore')
  784. // ->first();
  785. // $showConfig->CellScore = $showConfig->CellScore / 100;
  786. // $showConfig->MinEnterScore = number_float($showConfig->MinEnterScore / 100);
  787. // $showConfig->MaxEnterScore = number_float($showConfig->MaxEnterScore / 100);
  788. //
  789. // if ($request->isMethod('post')) {
  790. //
  791. // $stock = (int)$request->stock ?: 0;
  792. //// if (abs($stock) > $showConfig->CellScore * 1000) {
  793. //// return apiReturnFail('不能超过房间底分1000倍');
  794. //// }
  795. // $logic = new GoldLogic();
  796. //
  797. // $res = (new GoldLogic())->update_stock($id, $stock * NumConfig::NUM_VALUE);
  798. //
  799. // Log::info('返回结果修改库存' . json_encode($res));
  800. // if ($res === false) {
  801. // return apiReturnFail($logic->getError());
  802. // }
  803. // $data = [
  804. // 'ServerID' => $res['server_id'],
  805. // 'BeforeStock' => $res['old_stock'],
  806. // 'AfterStock' => $res['new_stock'],
  807. // 'content' => $stock < 0 ? '减少 ' . abs($stock) : '增加 ' . $stock,
  808. // 'admin_id' => session('admin')->id,
  809. // ];
  810. //
  811. // DB::connection('write')->table('agent.dbo.update_stock_log')
  812. // ->insert($data);
  813. // return apiReturnSuc();
  814. // } else {
  815. // $filed = ['gi.GameID', 'gi.ServerName', 'gi.ServerID as gi_ServerID'];
  816. // $config = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo as gi')
  817. // ->where('gi.ServerID', $id)
  818. // ->select($filed)
  819. // ->first();
  820. // return view('admin.gold.update_stock', [
  821. // 'showConfig' => $showConfig,
  822. // 'config' => $config
  823. // ]);
  824. // }
  825. // }
  826. public function update_stock(Request $request, $id)
  827. {
  828. $SortID = $request->SortID;
  829. if ($request->isMethod('post')) {
  830. $Stock = $request->stock ?: 0;
  831. $first = DB::connection('write')->table('QPPlatformDB.dbo.RoomStockStatic')
  832. ->where('GameID', $id)
  833. ->where('SortID', $SortID)
  834. ->first();
  835. $Stock = $Stock * NumConfig::NUM_VALUE;
  836. if (!$first) { // 房间不存在
  837. DB::connection('write')->table('QPPlatformDB.dbo.RoomStockStatic')
  838. ->insert(['GameID'=>$id,'SortID'=>$SortID,'Stock'=>$Stock,'Revenue'=>0]);
  839. }else{
  840. $Stock = $first->Stock + $Stock;
  841. DB::connection('write')->table('QPPlatformDB.dbo.RoomStockStatic')
  842. ->where('GameID', $id)
  843. ->where('SortID', $SortID)
  844. ->update(['Stock' => $Stock]);
  845. }
  846. return apiReturnSuc();
  847. }
  848. // 展示配置
  849. $showConfig = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  850. ->where('GameID', $id)
  851. ->where('SortID', $SortID)
  852. ->select('CellScore', 'MinEnterScore', 'MaxEnterScore', 'ServerName', 'CellScore')
  853. ->first();
  854. $ServerName = DB::connection('read')->table('QPPlatformDB.dbo.GameRoomInfo')
  855. ->where('GameID', $id)
  856. ->where('SortID', $SortID)
  857. ->select('ServerName')
  858. ->first();
  859. $config = DB::connection('write')->table('QPPlatformDB.dbo.RoomStockStatic')
  860. ->where('GameID', $id)
  861. ->where('SortID', $SortID)
  862. ->first();
  863. // if (!$config) {
  864. // return '暂无法配置';
  865. // }
  866. return view('admin.gold.update_stock', [
  867. 'showConfig' => $showConfig,
  868. 'config' => $config,
  869. 'ServerName' => $ServerName,
  870. 'GameID' => $id,
  871. 'SortID' => $SortID
  872. ]);
  873. }
  874. }