ExchangeController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\DB;
  6. use EXception;
  7. class ExchangeController extends Controller
  8. {
  9. //幸运兑换查询
  10. public function treasureList(Request $request)
  11. {
  12. $id = (int)$request->post('id');
  13. $gameid = (int)$request->post('gameid');
  14. $bonus_name = $request->post('bonus_name');
  15. $ratio = $request->post('ratio');
  16. $where = [];
  17. !empty($id) ? $where[] = ['ID','=',trim($id," ")] : $id = '';
  18. !empty($gameid) ? $where[] = ['GameID','=',trim($gameid," ")] : $gameid = '';
  19. !empty($bonus_name) ? $where[] = ['BonusName','like','%'.trim($bonus_name," ").'%'] : $bonus_name = '';
  20. !empty($ratio) ? $where[] = ['Currency','=',$ratio] : $ratio = '';
  21. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityIndianaConfig as a')
  22. ->leftjoin('QPAccountsDB.dbo.IndividualDatum as i','a.UserID','=','i.UserID')
  23. ->leftjoin('QPAccountsDB.dbo.AccountsInfo as ai','a.UserID','=','ai.UserID')
  24. ->select('a.ID','a.BonusName','a.NickName','a.LuckyTime','a.Mark','a.Cause','ai.GameID',
  25. 'i.UserID','i.Compellation','i.SeatPhone','i.MobilePhone','i.DwellingPlace','i.UserNote')
  26. ->where($where)
  27. ->whereNotNull('a.UserID')
  28. ->orderBy('a.ID','desc')
  29. ->paginate(10);
  30. foreach ($list as $key => &$value) {
  31. if($value->Mark == 1){
  32. $value->Cause = '已发货';
  33. }
  34. }
  35. $ratio_name = ['40000'=>'实物','30000'=>'金豆'];
  36. $select = [null,'已发货','联系方式有误','收货地址有误','发货信息缺失'];
  37. return view('admin.exchange.treasure',['list'=>$list,'select'=>$select,'id'=>$id,'gameid'=>$gameid,'bonus_name'=>$bonus_name,'ratio_name'=>$ratio_name,'ratio'=>$ratio]);
  38. }
  39. //金豆兑嗨乐分查询
  40. public function hailefen(Request $request){
  41. }
  42. //幸运兑换确认发货
  43. public function treasureUpdate(Request $request,$id)
  44. {
  45. $state = $request->post('state');
  46. $update['Cause'] = $state;
  47. if($state === '已发货'){
  48. $update['Mark'] = 1;
  49. }else{
  50. $update['Mark'] = 0;
  51. }
  52. $result = DB::table('QPAccountsDB.dbo.ActivityIndianaConfig')->where('ID', $id)->update($update);
  53. if($result){
  54. return $this->json(200, "修改成功");
  55. }else{
  56. return $this->json(500, '修改失败,请重试');
  57. }
  58. }
  59. //幸运兑换管理
  60. public function treasureGoodsList(Request $request)
  61. {
  62. $type = $request->get('type');
  63. if(isset($type)){
  64. $where = ['Currency'=>$type];
  65. $type = (int)$type;
  66. }else{
  67. $where=[];
  68. }
  69. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityIndianaConfig')
  70. ->where($where)
  71. ->orderBy('ID','desc')
  72. ->paginate(10);
  73. foreach ($list as $key => $value) {
  74. if($value->EndTime<date('Y-m-d H:i:s')){
  75. $value->overdue = '已下架';
  76. }else{
  77. $value->overdue = '夺宝中';
  78. }
  79. switch ($value->Currency) {
  80. case 30000:
  81. $value->Type = '金豆';
  82. break;
  83. case 40000:
  84. $value->Type = '实物';
  85. break;
  86. default:
  87. break;
  88. }
  89. }
  90. $goods_type = [30000=>'金豆',40000=>'实物'];
  91. return view('admin.exchange.treasure_goods',['list'=>$list,'goods_type'=>$goods_type,'type'=>$type]);
  92. }
  93. //幸运兑换新增商品页面
  94. public function treasureGoodsAddView()
  95. {
  96. $goods_type = [30000=>'金豆',40000=>'实物'];
  97. $prop_type = [2=>'金豆',0=>'实物'];
  98. return view('admin.exchange.treasure_goods_add',['goods_type'=>$goods_type,'prop_type'=>$prop_type]);
  99. }
  100. //幸运兑换新增商品
  101. public function treasureGoodsAdd(Request $request)
  102. {
  103. $params = $request->post();
  104. $treasure_goods = DB::connection('write')->table('QPAccountsDB.dbo.ActivityIndianaConfig');
  105. $LuckyNumB = rand(10001,99999);
  106. $ID = $treasure_goods->count() +1;
  107. $date = date('Y-m-d H:i:s');
  108. $insert_data=[
  109. 'ID'=>$ID,
  110. 'BonusName'=>$params['title'],
  111. 'BonusURL'=>$params['pic_url'],
  112. 'TotalAmount'=>$params['amount'],
  113. 'UsedAmount'=>0,
  114. 'StartTime'=>$date,
  115. 'EndTime'=>date('Y-m-d H:i:s',strtotime($params['time'])),
  116. 'LuckyNumB'=>$LuckyNumB,
  117. 'Currency'=>$params['goods_type'],
  118. 'Ratio'=>$params['ratio'],
  119. 'LimitCount'=>$params['limit'],
  120. 'RewardNum'=>$params['reward_num'],
  121. 'GoodsDesc'=>$params['describe'],
  122. 'PropType'=>$params['prop_type'],
  123. ];
  124. $treasure_goods->insert($insert_data);
  125. for ($i=1; $i <= $params['amount'] ; $i++) {
  126. $data[$i-1]=[
  127. 'Number'=>10000000 + $i,
  128. 'CurrentID'=>$ID,
  129. 'UserID'=>0,
  130. 'MyTime'=>$date
  131. ];
  132. }
  133. $result = DB::table('QPAccountsDB.dbo.ActivityIndianaTicket')->insert($data);
  134. if($result){
  135. return $this->json(200, "提交成功");
  136. }else{
  137. return $this->json(500, '提交失败,请重试');
  138. }
  139. }
  140. //幸运兑换商品修改页面
  141. public function treasureGoodsUpdateView(Request $request,$id)
  142. {
  143. $goods_type = [30000=>'金豆',40000=>'实物'];
  144. $prop_type = [2=>'金豆',0=>'实物'];
  145. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityIndianaConfig')
  146. ->where('ID',$id)
  147. ->first();
  148. $list->EndTime = str_replace(' ','T',$list->EndTime);
  149. return view('admin.exchange.treasure_goods_update',['list'=>$list,'goods_type'=>$goods_type,'prop_type'=>$prop_type]);
  150. }
  151. //幸运兑换商品修改
  152. public function treasureGoodsUpdate(Request $request,$id)
  153. {
  154. $post_data = $request->post();
  155. $insert_data=[
  156. 'BonusName'=>$post_data['title'],
  157. 'BonusURL'=>$post_data['pic_url'],
  158. 'EndTime'=>date('Y-m-d H:i:s',strtotime($post_data['time'])),
  159. 'LimitCount'=>$post_data['limit'],
  160. 'RewardNum'=>$post_data['reward_num'],
  161. 'GoodsDesc'=>$post_data['describe'],
  162. 'PropType'=>$post_data['prop_type'],
  163. 'Currency'=>$post_data['goods_type'],
  164. ];
  165. $result = DB::table('QPAccountsDB.dbo.ActivityIndianaConfig')->where('ID',$id)->update($insert_data);
  166. if($result){
  167. return $this->json(200, "提交成功");
  168. }else{
  169. return $this->json(500, '提交失败,请重试');
  170. }
  171. }
  172. //福利中心兑换记录
  173. public function shopList(Request $request)
  174. {
  175. $id = (int)$request->post('id');
  176. $reward = $request->post('reward');
  177. $type = $request->post('type');
  178. $status = $request->post('status');
  179. $start_time = $request->post('start_time');
  180. $end_time = $request->post('end_time');
  181. $excel = $request->get('excel');
  182. if(isset($type)){
  183. $where[] = ['asg.PropType','=',$type];
  184. $type = (int)$type;
  185. }else{
  186. $where=[];
  187. }
  188. if(isset($status)){
  189. $where[] = ['rri.Status','=',$status];
  190. $status = (int)$status;
  191. }
  192. !empty($start_time) ? $where[] = ['asr.CreateDate','>=',$start_time] : $start_time = '';
  193. !empty($end_time) ? $where[] = ['asr.CreateDate','<=',date('Y-m-d',strtotime("$end_time +1day"))] : $end_time = '';
  194. !empty($id) ? $where[] = ['ai.GameID','=',trim($id," ")] : $id = '';
  195. !empty($reward) ? $where[] = ['asg.GoodsTitle','like','%'.trim($reward," ").'%'] : '';
  196. if($excel){
  197. $cellData = DB::connection('write')->table('QPAccountsDB.dbo.ActivityShopRecord as asr')
  198. ->leftjoin('QPAccountsDB.dbo.ActivityShopGoods as asg','asr.GoodsID','=','asg.ID')
  199. ->leftjoin('QPAccountsDB.dbo.RecordRewardInKind as rri','asr.CreateDate','=','rri.CreateDate')
  200. ->leftjoin('QPAccountsDB.dbo.AccountsInfo as ai','asr.UserID','=','ai.UserID')
  201. ->select(DB::raw('CONVERT(varchar(100),asr.CreateDate,20) as CreateDate'),'asg.GoodsTitle','asg.Money','asg.PropType','ai.GameID','ai.NickName','rri.Compellation','rri.MobilePhone','rri.UserNote','rri.Status')
  202. ->where($where)
  203. ->orderBy(DB::raw('CONVERT(varchar(100),asr.CreateDate,20)'),'desc')
  204. ->get();
  205. foreach ($cellData as $key => &$value) {
  206. if($value->Status == 1){
  207. $value->Status = '已发货';
  208. }else{
  209. $value->Status = '待发货';
  210. }
  211. switch ($value->PropType) {
  212. case 0:
  213. $value->PropType = '实物';
  214. break;
  215. case 1:
  216. $value->PropType = '红包';
  217. break;
  218. case 2:
  219. $value->PropType = '金豆';
  220. $value->Status = '已发货';
  221. break;
  222. case 3:
  223. $value->PropType = '代金券';
  224. $value->Status = '已发货';
  225. break;
  226. default:
  227. # code...
  228. break;
  229. }
  230. }
  231. $title = ['兑换时间','奖品名称','奖品价格','奖品种类','玩家ID','玩家昵称','姓名','联系电话','联系地址','状态'];
  232. $cellData = json_decode(json_encode($cellData),true);
  233. downloadExcel($cellData,$title,'充值查询');
  234. }else{
  235. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityShopRecord as asr')
  236. ->leftjoin('QPAccountsDB.dbo.ActivityShopGoods as asg','asr.GoodsID','=','asg.ID')
  237. ->leftjoin('QPAccountsDB.dbo.RecordRewardInKind as rri','asr.CreateDate','=','rri.CreateDate')
  238. ->leftjoin('QPAccountsDB.dbo.AccountsInfo as ai','asr.UserID','=','ai.UserID')
  239. ->select(DB::raw('CONVERT(varchar(100),asr.CreateDate,20) as CreateDate'),'asg.GoodsTitle','asg.PropType','asg.Money','ai.GameID','ai.NickName','rri.Compellation','rri.MobilePhone','rri.UserNote','rri.Status','rri.RecordID')
  240. ->where($where)
  241. ->orderBy(DB::raw('CONVERT(varchar(100),asr.CreateDate,20)'),'desc')
  242. ->paginate(10);
  243. foreach ($list as $key => &$value) {
  244. if($value->Status == 1){
  245. $value->Cause = '已发货';
  246. }else{
  247. $value->Cause = '待发货';
  248. }
  249. switch ($value->PropType) {
  250. case 0:
  251. $value->Type = '实物';
  252. break;
  253. case 1:
  254. $value->Type = '红包';
  255. break;
  256. case 2:
  257. $value->Type = '金豆';
  258. $value->Cause = '已发货';
  259. break;
  260. case 3:
  261. $value->Type = '代金券';
  262. $value->Cause = '已发货';
  263. break;
  264. default:
  265. # code...
  266. break;
  267. }
  268. }
  269. }
  270. $select = [null,'已发货','发货信息缺失'];
  271. $order_status = [0=>'待发货',1=>'已发货'];
  272. $prop_type = [0=>'实物',1=>'红包',2=>'金豆',3=>'代金券'];
  273. return view('admin.exchange.shop',['list'=>$list,'start_time'=>$start_time,'end_time'=>$end_time,'select'=>$select,'type'=>$type,'prop_type'=>$prop_type,'order_status'=>$order_status,'status'=>$status,'id'=>$id,'reward'=>$reward]);
  274. }
  275. //兑换商城标记发货
  276. public function shopUpdate(Request $request,$id)
  277. {
  278. $state = $request->post('state');
  279. $update['Cause'] = $state;
  280. if($state === '已发货'){
  281. $update['Status'] = 1;
  282. }else{
  283. $update['Status'] = 0;
  284. }
  285. $result = DB::table('QPAccountsDB.dbo.RecordRewardInKind')->where('RecordID', $id)->update($update);
  286. if($result){
  287. return $this->json(200, "修改成功");
  288. }else{
  289. return $this->json(500, '修改失败,请重试');
  290. }
  291. }
  292. //兑换商城管理
  293. public function goodsList()
  294. {
  295. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityShopGoods')
  296. ->select('*',DB::raw('TotalAmount-UsedAmount as Surplus'))
  297. ->paginate(10);
  298. foreach ($list as $key => &$value) {
  299. switch ($value->GoodsType) {
  300. case '1':
  301. $value->GoodsType = '卡券';
  302. break;
  303. case '2':
  304. $value->GoodsType = '实物';
  305. break;
  306. default:
  307. $value->GoodsType = '热门';
  308. break;
  309. }
  310. }
  311. return view('admin.exchange.goods',['list' => $list]);
  312. }
  313. //兑换商品修改
  314. public function goodsUpdate(Request $request,$id)
  315. {
  316. $update['TotalAmount'] = $request->post('total_amount');
  317. $update['DayLimit'] = $request->post('day_limit');
  318. $result = DB::table('QPAccountsDB.dbo.ActivityShopGoods')->where('ID', $id)->update($update);
  319. if($result){
  320. return $this->json(200, "修改成功");
  321. }else{
  322. return $this->json(500, '修改失败,请重试');
  323. }
  324. }
  325. //福利中心管理
  326. public function shopGoodsList(Request $request)
  327. {
  328. $type = $request->get('type');
  329. if(isset($type)){
  330. $where = ['GoodsType'=>$type];
  331. $type = (int)$type;
  332. }else{
  333. $where=[];
  334. }
  335. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityShopGoods')
  336. ->where($where)
  337. ->orderBy('GoodsType')
  338. ->paginate(10);
  339. foreach ($list as $key => $value) {
  340. switch ($value->GoodsType) {
  341. case 0:
  342. $value->Type = '推荐';
  343. break;
  344. case 1:
  345. $value->Type = '实物';
  346. break;
  347. case 2:
  348. $value->Type = '卡劵';
  349. break;
  350. case 3:
  351. $value->Type = '道具';
  352. break;
  353. case 4:
  354. $value->Type = '菜篮子';
  355. break;
  356. default:
  357. $value->Type = '';
  358. break;
  359. }
  360. }
  361. $goods_type = [0=>'推荐',1=>'实物',2=>'卡劵',3=>'道具',4=>'菜篮子'];
  362. return view('admin.exchange.shop_goods',['list'=>$list,'goods_type'=>$goods_type,'type'=>$type]);
  363. }
  364. //福利中心新增商品页面
  365. public function shopGoodsAddView()
  366. {
  367. $goods_type = [0=>'推荐',1=>'实物',2=>'卡劵',3=>'道具',4=>'菜篮子'];
  368. $bonus = [10000=>'房卡',20000=>'实物',30000=>'金豆',40000=>'礼券',50000=>'宝珠',60000=>'红包'];
  369. $prop_type = [0=>'实物',1=>'红包',2=>'金豆',3=>'代金券'];
  370. $status = [0=>'正常',1=>'热门',2=>'限时',3=>'新品'];
  371. return view('admin.exchange.shop_goods_add',['goods_type'=>$goods_type,'prop_type'=>$prop_type,'status'=>$status,'bonus'=>$bonus]);
  372. }
  373. //福利中心新增商品
  374. public function shopGoodsAdd(Request $request)
  375. {
  376. $post_data = $request->post();
  377. try{
  378. DB::transaction(function() use($post_data){
  379. if($post_data['goods_type'] == 2){
  380. $PropID = DB::connection('write')->table('QPAccountsDB.dbo.YN_MatchProp')
  381. ->where('PropID','<','102000')
  382. ->orderBy('PropID','desc')
  383. ->first()->PropID+1;
  384. $post_data['bonus'] = $PropID;
  385. $porp_data = [
  386. 'PropID'=>$PropID,
  387. 'PropName'=>$post_data['prop_name'],
  388. 'Description'=>$post_data['prop_desc'],
  389. 'Address'=>$post_data['prop_address'],
  390. 'Phone'=>$post_data['prop_phone'],
  391. 'Business'=>$post_data['prop_business'],
  392. 'ExpiringDate'=>$post_data['expiring_date'],
  393. ];
  394. DB::table('QPAccountsDB.dbo.YN_MatchProp')->insert($porp_data);
  395. }
  396. $post_data['prop_type']==0 ? $system_message=1 : $system_message=0;
  397. $insert = [
  398. 'GoodsTitle'=>$post_data['title'],
  399. 'GoodsDesc'=>$post_data['describe'],
  400. 'GoodsURL'=>$post_data['pic_url'],
  401. 'Ratio'=>$post_data['ratio'],
  402. 'EndDate'=>date('Y-m-d H:i:s',strtotime($post_data['time'])),
  403. 'TotalAmount'=>$post_data['total_amount'],
  404. 'DayLimit'=>$post_data['day_limit'],
  405. 'ShowStatus'=>$post_data['status'],
  406. 'BonusString'=>$post_data['bonus'].','.$post_data['amount'],
  407. 'SystemMessage'=>$system_message,
  408. 'GoodsType'=>$post_data['goods_type'],
  409. 'PropType'=>$post_data['prop_type'],
  410. 'Money'=>$post_data['money'],
  411. 'GoodsShowIndex'=>$post_data['order'],
  412. ];
  413. DB::table('QPAccountsDB.dbo.ActivityShopGoods')->insert($insert);
  414. });
  415. return $this->json(200, "提交成功");
  416. }catch(\EXception $e){
  417. DB::rollBack();
  418. return $this->json(500, '提交失败,请重试');
  419. }
  420. }
  421. //福利中心商品修改页面
  422. public function shopGoodsUpdateView(Request $request,$id)
  423. {
  424. $goods_type = [0=>'推荐',1=>'实物',2=>'卡劵',3=>'道具',4=>'菜篮子'];
  425. $bonus = [10000=>'房卡',20000=>'实物',30000=>'金豆',40000=>'礼券',50000=>'宝珠',60000=>'红包'];
  426. $prop_type = [0=>'实物',1=>'红包',2=>'金豆',3=>'代金券'];
  427. $status = [0=>'正常',1=>'热门',2=>'限时',3=>'新品'];
  428. $shop_data = DB::connection('write')->table('QPAccountsDB.dbo.ActivityShopGoods')
  429. ->where('ID',$id)
  430. ->first();
  431. $shop_data->amount = substr($shop_data->BonusString,strpos($shop_data->BonusString, ',')+1);
  432. $shop_data->BonusString = substr($shop_data->BonusString,0,strpos($shop_data->BonusString, ','));
  433. $shop_data->EndDate = str_replace(' ','T',$shop_data->EndDate);
  434. return view('admin.exchange.shop_goods_update',['shop_data'=>$shop_data,'goods_type'=>$goods_type,'prop_type'=>$prop_type,'status'=>$status,'bonus'=>$bonus]);
  435. }
  436. //福利中心商品修改
  437. public function shopGoodsUpdate(Request $request,$id)
  438. {
  439. $post_data = $request->post();
  440. $update = [
  441. 'Ratio'=>$post_data['ratio'],
  442. 'EndDate'=>date('Y-m-d H:i:s',strtotime($post_data['time'])),
  443. 'TotalAmount'=>$post_data['total_amount'],
  444. 'DayLimit'=>$post_data['day_limit'],
  445. 'Money'=>$post_data['money'],
  446. 'GoodsShowIndex'=>$post_data['order'],
  447. ];
  448. $result = DB::table('QPAccountsDB.dbo.ActivityShopGoods')->where('ID',$id)->update($update);
  449. if($result){
  450. return $this->json(200, "提交成功");
  451. }else{
  452. return $this->json(500, '提交失败,请重试');
  453. }
  454. }
  455. //福卡每日发放查询
  456. public function everydayCard(Request $request)
  457. {
  458. $excel = $request->get('excel');
  459. $start_time = $request->input('start_time');
  460. $end_time = $request->input('end_time');
  461. $where = [];
  462. !empty($start_time) ? $where[] = ['mydate','>=',$start_time] : $start_time = '';
  463. !empty($end_time) ? $where[] = ['mydate','<=',$end_time] : $end_time = '';
  464. $revenue_data = DB::table('QPRecordDB.dbo.LogDayOutScores as dos')
  465. ->join('QPRecordDB.dbo.YN_RecordRevenueInfo as rri','dos.mydate','=',DB::raw('CONVERT(varchar(100), rri.UpdateTime, 23)'))
  466. ->selectRaw('mydate as date,SUM(ChangeRevenue) as ChangeRevenue,Reason')
  467. ->where($where)
  468. ->whereIn('Reason',[31,26,32,29,30])
  469. ->orderBy(DB::raw('mydate'),'desc')
  470. ->groupBy(DB::raw('mydate'),'Reason')
  471. ->get();
  472. foreach ($revenue_data as $key => &$value) {
  473. $list[$value->date]['date'] = $value->date;
  474. $list[$value->date][$value->Reason] = abs($value->ChangeRevenue);
  475. }
  476. foreach ($list as $key => &$value) {
  477. if(!array_key_exists('26',$value)){
  478. $value['26'] = 0;
  479. }
  480. if(!array_key_exists('29',$value)){
  481. $value['29'] = 0;
  482. }
  483. if(!array_key_exists('30',$value)){
  484. $value['30'] = 0;
  485. }
  486. if(!array_key_exists('31',$value)){
  487. $value['31'] = 0;
  488. }
  489. if(!array_key_exists('32',$value)){
  490. $value['32'] = 0;
  491. }
  492. $value['recovery'] = (int)$value['29']+(int)$value['30'];//回收总额
  493. $value['expenditure'] = (int)$value['31']+(int)$value['32']+(int)$value['26'];//支出总额
  494. }
  495. $arr = [];
  496. foreach ($list as $key => $value) {
  497. $arr['date'] = $value['date'];
  498. $arr['expenditure'] = $value['expenditure'];
  499. $arr['31'] = $value['31'];
  500. $arr['32'] = $value['32'];
  501. $arr['26'] = $value['26'];
  502. $arr['recovery'] = $value['recovery'];
  503. $arr['29'] = $value['29'];
  504. $arr['30'] = $value['30'];
  505. $data[]= $arr;
  506. }
  507. if($excel){
  508. $title = ['时间','福卡支出总额','福卡任务','捕鱼比赛','大抽奖','福卡回收总额','幸运兑换','福利中心'];
  509. $list = json_decode(json_encode($list),true);
  510. downloadExcel($list,$title,'福卡每日发放');
  511. }else{
  512. return view('admin.exchange.everyday_card',['list'=>$data,'start_time'=>$start_time,'end_time'=>$end_time]);
  513. }
  514. }
  515. //福卡发放详情
  516. public function revenueInfo(Request $request)
  517. {
  518. $excel = $request->get('excel');
  519. $start_time = $request->input('start_time');
  520. $end_time = $request->input('end_time');
  521. $sort = $request->input('sort');
  522. $where = [];
  523. if(empty($start_time)){
  524. $start_time = $end_time = date('Y-m-d',strtotime('-1 day'));
  525. }
  526. $where[] = ['ri.UpdateTime','>=',$start_time];
  527. $where[] = ['ri.UpdateTime','<=',date('Y-m-d',strtotime("$end_time +1day"))];
  528. $revenue_list = DB::table('QPRecordDB.dbo.YN_RecordRevenueInfo as ri')
  529. ->leftjoin('QPAccountsDB.dbo.AccountsInfo as ai','ai.UserID','=','ri.UserID')
  530. ->selectRaw('SUM(ri.ChangeRevenue) as revenue,ai.GameID,ri.Reason,ai.NickName')
  531. ->where($where)
  532. ->whereIn('ri.Reason',[31,26,32,29,30])
  533. ->groupBy('ai.GameID','ri.Reason','ai.NickName')
  534. ->get();
  535. $data = [];
  536. foreach ($revenue_list as $key => $value) {
  537. $data[$value->GameID]['gameid'] = $value->GameID;
  538. $data[$value->GameID]['nickname'] = $value->NickName;
  539. $data[$value->GameID]['expenditure'] = 0;
  540. $data[$value->GameID][$value->Reason] = abs($value->revenue);
  541. }
  542. foreach ($data as $key => &$value) {
  543. if(!array_key_exists(31,$value)){
  544. $data[$value['gameid']][31] = 0;
  545. }
  546. if(!array_key_exists(32,$value)){
  547. $data[$value['gameid']][32] = 0;
  548. }
  549. if(!array_key_exists(26,$value)){
  550. $data[$value['gameid']][26] = 0;
  551. }
  552. if(!array_key_exists(29,$value)){
  553. $data[$value['gameid']][29] = 0;
  554. }
  555. if(!array_key_exists(30,$value)){
  556. $data[$value['gameid']][30] = 0;
  557. }
  558. $value['expenditure'] = $value['31']+$value['32']+$value['26'];//福卡收入
  559. $value['recovery'] = $value['29']+$value['30'];//福卡消耗
  560. }
  561. foreach ($data as $k => $v) {
  562. $arr = [];
  563. $arr['gameid'] = $v['gameid'];
  564. $arr['nickname'] = $v['nickname'];
  565. $arr['expenditure'] = $v['expenditure'];
  566. $arr['31'] = $v['31'];
  567. $arr['32'] = $v['32'];
  568. $arr['26'] = $v['26'];
  569. $arr['recovery'] = $v['recovery'];
  570. $arr['29'] = $v['29'];
  571. $arr['30'] = $v['30'];
  572. $list[]= $arr;
  573. }
  574. if(!empty($sort)){
  575. $list = $this->arraySort($list,'recovery');
  576. }else{
  577. $list = $this->arraySort($list,'expenditure');
  578. }
  579. if($excel){
  580. $title = ['玩家游戏ID','玩家昵称','福卡收入','福卡任务','捕鱼比赛','大抽奖','福卡消耗','幸运兑换','福利中心'];
  581. $list = json_decode(json_encode($list),true);
  582. downloadExcel($list,$title,'福卡每日发放详情');
  583. }else{
  584. return view('admin.exchange.revenueinfo',['list'=>$list,'start_time'=>$start_time,'end_time'=>$end_time]);
  585. }
  586. }
  587. //添加礼包页面
  588. public function giftAddView()
  589. {
  590. return view('admin.exchange.gift_add');
  591. }
  592. //奖品内容
  593. public function giftList()
  594. {
  595. //$prize = DB::connection('write')->table('QPTreasureDB.dbo.PropCfg')->where('PropID',30000)->select('PropID','PropName')->get()->toArray();
  596. // $prop = DB::connection('write')->table('QPAccountsDB.dbo.YN_MatchProp')->select('PropID','PropName')->get()->toArray();
  597. // $data = array_merge($prize,$prop);
  598. //$data = $prize;
  599. $data = [['PropID'=>30000,'PropName'=>'金币'],['PropID'=>31000,'PropName'=>'免费币']];
  600. return response()->json($data);
  601. }
  602. //添加礼包
  603. public function giftAdd(Request $request)
  604. {
  605. $bonus = $request->get('bonus');
  606. $data['desc'] = $request->get('desc');
  607. if(!empty($bonus) && !empty($data['desc'])){
  608. $data['bonus'] = '';
  609. foreach ($bonus as $key => $value) {
  610. if(empty($value['id']) || empty($value['number'])){
  611. return $this->json(500,'请确认数据完整');
  612. }
  613. $data['bonus'] .= implode(',', $value).';';
  614. }
  615. $data['bonus'] = trim($data['bonus'],';');
  616. $result = DB::table('QPAccountsDB.dbo.ActivityShopCodesBatch')->insert($data);
  617. }else{
  618. return $this->json(500,'请确认数据完整');
  619. }
  620. if($result){
  621. return $this->json(200, "添加成功");
  622. }else{
  623. return $this->json(500, '添加失败,请重试');
  624. }
  625. }
  626. //添加兑换码页面
  627. public function codesAddView()
  628. {
  629. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityShopCodesBatch')->get();
  630. return view('admin.exchange.codes_add',['list'=>$list]);
  631. }
  632. //添加兑换码
  633. public function codesAdd(Request $request)
  634. {
  635. $admin = $request->session()->get('admin');//管理员信息
  636. $number = $request->post('number');
  637. $batch = $request->post('batch');
  638. $time = $request->post('time');
  639. $time = date('Y-m-d',strtotime("$time +1day"));
  640. $limit = $request->post('limit');
  641. empty($limit) ? $limit=0 : '';
  642. $agent = $admin->id;
  643. for ($i=1; $i <=$number ; $i++) {
  644. $code = strtolower(str_random(6));
  645. $data[] = [
  646. 'agent_id'=>$agent,
  647. 'batch'=>$batch,
  648. 'code'=>$code,
  649. 'expired_at'=>$time,
  650. 'status'=>0,
  651. 'limit'=>$limit
  652. ];
  653. }
  654. $result = DB::table('QPAccountsDB.dbo.ActivityShopCodes')->insert($data);
  655. if($result){
  656. return $this->json(200, "添加成功");
  657. }else{
  658. return $this->json(500, '添加失败,请重试');
  659. }
  660. }
  661. //兑换码列表
  662. public function exchangeCodeList(Request $request)
  663. {
  664. $start_time = $request->input('start_time');
  665. $end_time = $request->input('end_time');
  666. $status = $request->input('status');
  667. $name = $request->input('name');
  668. $excel = $request->input('excel');
  669. $where = [];
  670. !empty($start_time) ? $where[] = ['created_at','>=',$start_time] : '';
  671. !empty($end_time) ? $where[] = ['created_at','<=',date('Y-m-d',strtotime("$end_time+1day"))] : '';
  672. if(isset($status)){
  673. $where[] = ['status','=',$status];
  674. $status = (int)$status;
  675. }
  676. !empty($name) ? $where[] = ['desc','like','%'.$name.'%'] : $name = '';
  677. $prize = DB::connection('write')->table('QPTreasureDB.dbo.PropCfg')->select('PropID','PropName')->get()->toArray();
  678. $prop = DB::connection('write')->table('QPAccountsDB.dbo.YN_MatchProp')->select('PropID','PropName')->get()->toArray();
  679. $data = array_merge($prize,$prop);
  680. foreach ($data as $key => $value) {
  681. $prop_arr[$value->PropID] = $value->PropName;
  682. }
  683. if($excel){
  684. $cellData = DB::table('QPAccountsDB.dbo.ActivityShopCodes as asc')
  685. ->leftjoin('QPAccountsDB.dbo.AccountsInfo as ai','asc.toUserID','=','ai.UserID')
  686. ->leftjoin('QPAccountsDB.dbo.ActivityShopCodesBatch as scb','asc.batch','=','scb.id')
  687. ->select('asc.id','asc.code','scb.desc','scb.bonus','asc.created_at','asc.expired_at','asc.status','ai.GameID','asc.updated_at','asc.limit')
  688. ->where($where)
  689. ->orderBy('asc.id','desc')
  690. ->get();
  691. foreach ($cellData as $key => &$value) {
  692. switch ($value->status) {
  693. case '0':
  694. $value->status = '未兑换';
  695. break;
  696. case '1':
  697. $value->status = '已兑换';
  698. break;
  699. default:
  700. break;
  701. }
  702. switch ($value->limit) {
  703. case '0':
  704. $value->limit = '无限制';
  705. break;
  706. case '1':
  707. $value->limit = '仅新用户';
  708. break;
  709. default:
  710. break;
  711. }
  712. }
  713. $title = ['批次','兑换码','奖品名称','奖品明细','生成时间','过期时间','兑换限制','状态','兑换人','兑换时间'];
  714. $cellData = json_decode(json_encode($cellData),true);
  715. downloadExcel($cellData,$title,'兑换码列表');
  716. }
  717. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityShopCodes as asc')
  718. ->leftjoin('QPAccountsDB.dbo.AccountsInfo as ai','asc.toUserID','=','ai.UserID')
  719. ->leftjoin('QPAccountsDB.dbo.ActivityShopCodesBatch as scb','asc.batch','=','scb.id')
  720. ->select('asc.id','asc.code','scb.desc','scb.bonus','asc.created_at','asc.expired_at','asc.status','ai.GameID','asc.updated_at','asc.limit')
  721. ->where($where)
  722. ->orderBy('asc.id','desc')
  723. ->paginate(10);
  724. foreach ($list as $key => &$value) {
  725. $value->bonus = explode(';',$value->bonus);
  726. $value->name = '';
  727. foreach ($value->bonus as $k => &$v) {
  728. $v = explode(',', $v);
  729. $value->name .= $prop_arr[$v[0]].'x'.$v[1].',';
  730. }
  731. switch ($value->status) {
  732. case '0':
  733. $value->status = '未兑换';
  734. break;
  735. case '1':
  736. $value->status = '已兑换';
  737. break;
  738. default:
  739. break;
  740. }
  741. switch ($value->limit) {
  742. case '0':
  743. $value->limit = '无限制';
  744. break;
  745. case '1':
  746. $value->limit = '仅新用户';
  747. break;
  748. default:
  749. break;
  750. }
  751. }
  752. $status_type = ['0'=>'未兑换','1'=>'已兑换'];
  753. return view('admin.exchange.code_list',['list'=>$list,'status'=>$status,'start_time'=>$start_time,'end_time'=>$end_time,'name'=>$name,'status_type'=>$status_type]);
  754. }
  755. //话费兑换查询
  756. public function costList(Request $request)
  757. {
  758. $user_id = (int)$request->post('user_id');
  759. $prop_name = $request->post('prop_name');
  760. $ratio = $request->post('ratio');
  761. $where = [];
  762. !empty($user_id) ? $where[] = ['UseId','=',trim($user_id," ")] : $user_id = '';
  763. !empty($prop_name) ? $where[] = ['PropName','like','%'.trim($prop_name," ").'%'] : $prop_name = '';
  764. $list = DB::connection('write')->table('QPRecordDB.dbo.RecordHF')
  765. ->select('UseId','CreateTime','State','Phone','PropName','UniqueCode')
  766. ->where($where)
  767. ->orderBy('CreateTime','desc')
  768. ->paginate(10);
  769. foreach ($list as $key => &$value) {
  770. if($value->State == 1){
  771. $value->State = '已发货';
  772. }else{
  773. $value->State = '未发货';
  774. }
  775. }
  776. $select = ['已发货','未发货'];
  777. return view('admin.exchange.cost',['list'=>$list,'select'=>$select,'user_id'=>$user_id,'prop_name'=>$prop_name]);
  778. }
  779. //话费兑换确认发货
  780. public function costUpdate(Request $request,$id)
  781. {
  782. $admin = $request->session()->get('admin');//管理员信息
  783. $state = $request->post('state');
  784. $update['State'] = $state;
  785. if($state === '已发货'){
  786. $update['State'] = 1;
  787. }else{
  788. $update['State'] = 0;
  789. }
  790. $hf_detail = DB::table('QPRecordDB.dbo.RecordHF')
  791. ->where('UniqueCode', $id)
  792. ->first();
  793. $insert = [
  794. 'MailType' => 2,
  795. 'MailStatus' => 1,
  796. 'UserID' => $hf_detail->UseId,
  797. 'CreateTime' => date('Y-m-d H:i:s',time()),
  798. 'TitleString' => '充值通知',
  799. 'TextString' => '您的'.$hf_detail->PropName.'话费已经充值到'.$hf_detail->Phone.'的手机上 请注意查收',
  800. 'FromAgentID' => $admin->id,
  801. ];
  802. try{
  803. DB::transaction(function() use($id,$update,$insert){
  804. DB::table('QPRecordDB.dbo.RecordHF')->where('UniqueCode', $id)->update($update);
  805. if($update['State'] == 1){
  806. DB::table('QPAccountsDB.dbo.PrivateMail')->insert($insert);
  807. }
  808. });
  809. return $this->json(200, "提交成功");
  810. }catch(\EXception $e){
  811. DB::rollBack();
  812. return $this->json(500, '提交失败,请重试');
  813. }
  814. }
  815. }