ExchangeController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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'=>'金币']];
  600. $data = [['PropID'=>31000,'PropName'=>'免费币']];
  601. return response()->json($data);
  602. }
  603. //添加礼包
  604. public function giftAdd(Request $request)
  605. {
  606. $bonus = $request->get('bonus');
  607. $data['desc'] = $request->get('desc');
  608. if(!empty($bonus) && !empty($data['desc'])){
  609. $data['bonus'] = '';
  610. foreach ($bonus as $key => $value) {
  611. if(empty($value['id']) || empty($value['number'])){
  612. return $this->json(500,'请确认数据完整');
  613. }
  614. $data['bonus'] .= implode(',', $value).';';
  615. }
  616. $data['bonus'] = trim($data['bonus'],';');
  617. $result = DB::table('QPAccountsDB.dbo.ActivityShopCodesBatch')->insert($data);
  618. }else{
  619. return $this->json(500,'请确认数据完整');
  620. }
  621. if($result){
  622. return $this->json(200, "添加成功");
  623. }else{
  624. return $this->json(500, '添加失败,请重试');
  625. }
  626. }
  627. //添加兑换码页面
  628. public function codesAddView()
  629. {
  630. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityShopCodesBatch')->get();
  631. return view('admin.exchange.codes_add',['list'=>$list]);
  632. }
  633. //添加兑换码
  634. public function codesAdd(Request $request)
  635. {
  636. $admin = $request->session()->get('admin');//管理员信息
  637. $number = $request->post('number');
  638. $batch = $request->post('batch');
  639. $time = $request->post('time');
  640. $time = date('Y-m-d',strtotime("$time +1day"));
  641. $limit = $request->post('limit');
  642. empty($limit) ? $limit=0 : '';
  643. $agent = $admin->id;
  644. for ($i=1; $i <=$number ; $i++) {
  645. $code = strtolower(str_random(6));
  646. $data[] = [
  647. 'agent_id'=>$agent,
  648. 'batch'=>$batch,
  649. 'code'=>$code,
  650. 'expired_at'=>$time,
  651. 'status'=>0,
  652. 'limit'=>$limit
  653. ];
  654. }
  655. $result = DB::table('QPAccountsDB.dbo.ActivityShopCodes')->insert($data);
  656. if($result){
  657. return $this->json(200, "添加成功");
  658. }else{
  659. return $this->json(500, '添加失败,请重试');
  660. }
  661. }
  662. //兑换码列表
  663. public function exchangeCodeList(Request $request)
  664. {
  665. $start_time = $request->input('start_time');
  666. $end_time = $request->input('end_time');
  667. $status = $request->input('status');
  668. $name = $request->input('name');
  669. $excel = $request->input('excel');
  670. $where = [];
  671. !empty($start_time) ? $where[] = ['created_at','>=',$start_time] : '';
  672. !empty($end_time) ? $where[] = ['created_at','<=',date('Y-m-d',strtotime("$end_time+1day"))] : '';
  673. if(isset($status)){
  674. $where[] = ['status','=',$status];
  675. $status = (int)$status;
  676. }
  677. !empty($name) ? $where[] = ['desc','like','%'.$name.'%'] : $name = '';
  678. $prize = DB::connection('write')->table('QPTreasureDB.dbo.PropCfg')->select('PropID','PropName')->get()->toArray();
  679. $prop = DB::connection('write')->table('QPAccountsDB.dbo.YN_MatchProp')->select('PropID','PropName')->get()->toArray();
  680. $data = array_merge($prize,$prop);
  681. foreach ($data as $key => $value) {
  682. $prop_arr[$value->PropID] = $value->PropName;
  683. }
  684. if($excel){
  685. $cellData = DB::table('QPAccountsDB.dbo.ActivityShopCodes as asc')
  686. ->leftjoin('QPAccountsDB.dbo.AccountsInfo as ai','asc.toUserID','=','ai.UserID')
  687. ->leftjoin('QPAccountsDB.dbo.ActivityShopCodesBatch as scb','asc.batch','=','scb.id')
  688. ->select('asc.id','asc.code','scb.desc','scb.bonus','asc.created_at','asc.expired_at','asc.status','ai.GameID','asc.updated_at','asc.limit')
  689. ->where($where)
  690. ->orderBy('asc.id','desc')
  691. ->get();
  692. foreach ($cellData as $key => &$value) {
  693. switch ($value->status) {
  694. case '0':
  695. $value->status = '未兑换';
  696. break;
  697. case '1':
  698. $value->status = '已兑换';
  699. break;
  700. default:
  701. break;
  702. }
  703. switch ($value->limit) {
  704. case '0':
  705. $value->limit = '无限制';
  706. break;
  707. case '1':
  708. $value->limit = '仅新用户';
  709. break;
  710. default:
  711. break;
  712. }
  713. }
  714. $title = ['批次','兑换码','奖品名称','奖品明细','生成时间','过期时间','兑换限制','状态','兑换人','兑换时间'];
  715. $cellData = json_decode(json_encode($cellData),true);
  716. downloadExcel($cellData,$title,'兑换码列表');
  717. }
  718. $list = DB::connection('write')->table('QPAccountsDB.dbo.ActivityShopCodes as asc')
  719. ->leftjoin('QPAccountsDB.dbo.AccountsInfo as ai','asc.toUserID','=','ai.UserID')
  720. ->leftjoin('QPAccountsDB.dbo.ActivityShopCodesBatch as scb','asc.batch','=','scb.id')
  721. ->select('asc.id','asc.code','scb.desc','scb.bonus','asc.created_at','asc.expired_at','asc.status','ai.GameID','asc.updated_at','asc.limit')
  722. ->where($where)
  723. ->orderBy('asc.id','desc')
  724. ->paginate(10);
  725. foreach ($list as $key => &$value) {
  726. $value->bonus = explode(';',$value->bonus);
  727. $value->name = '';
  728. foreach ($value->bonus as $k => &$v) {
  729. $v = explode(',', $v);
  730. $value->name .= $prop_arr[$v[0]].'x'.$v[1].',';
  731. }
  732. switch ($value->status) {
  733. case '0':
  734. $value->status = '未兑换';
  735. break;
  736. case '1':
  737. $value->status = '已兑换';
  738. break;
  739. default:
  740. break;
  741. }
  742. switch ($value->limit) {
  743. case '0':
  744. $value->limit = '无限制';
  745. break;
  746. case '1':
  747. $value->limit = '仅新用户';
  748. break;
  749. default:
  750. break;
  751. }
  752. }
  753. $status_type = ['0'=>'未兑换','1'=>'已兑换'];
  754. return view('admin.exchange.code_list',['list'=>$list,'status'=>$status,'start_time'=>$start_time,'end_time'=>$end_time,'name'=>$name,'status_type'=>$status_type]);
  755. }
  756. //话费兑换查询
  757. public function costList(Request $request)
  758. {
  759. $user_id = (int)$request->post('user_id');
  760. $prop_name = $request->post('prop_name');
  761. $ratio = $request->post('ratio');
  762. $where = [];
  763. !empty($user_id) ? $where[] = ['UseId','=',trim($user_id," ")] : $user_id = '';
  764. !empty($prop_name) ? $where[] = ['PropName','like','%'.trim($prop_name," ").'%'] : $prop_name = '';
  765. $list = DB::connection('write')->table('QPRecordDB.dbo.RecordHF')
  766. ->select('UseId','CreateTime','State','Phone','PropName','UniqueCode')
  767. ->where($where)
  768. ->orderBy('CreateTime','desc')
  769. ->paginate(10);
  770. foreach ($list as $key => &$value) {
  771. if($value->State == 1){
  772. $value->State = '已发货';
  773. }else{
  774. $value->State = '未发货';
  775. }
  776. }
  777. $select = ['已发货','未发货'];
  778. return view('admin.exchange.cost',['list'=>$list,'select'=>$select,'user_id'=>$user_id,'prop_name'=>$prop_name]);
  779. }
  780. //话费兑换确认发货
  781. public function costUpdate(Request $request,$id)
  782. {
  783. $admin = $request->session()->get('admin');//管理员信息
  784. $state = $request->post('state');
  785. $update['State'] = $state;
  786. if($state === '已发货'){
  787. $update['State'] = 1;
  788. }else{
  789. $update['State'] = 0;
  790. }
  791. $hf_detail = DB::table('QPRecordDB.dbo.RecordHF')
  792. ->where('UniqueCode', $id)
  793. ->first();
  794. $insert = [
  795. 'MailType' => 2,
  796. 'MailStatus' => 1,
  797. 'UserID' => $hf_detail->UseId,
  798. 'CreateTime' => date('Y-m-d H:i:s',time()),
  799. 'TitleString' => '充值通知',
  800. 'TextString' => '您的'.$hf_detail->PropName.'话费已经充值到'.$hf_detail->Phone.'的手机上 请注意查收',
  801. 'FromAgentID' => $admin->id,
  802. ];
  803. try{
  804. DB::transaction(function() use($id,$update,$insert){
  805. DB::table('QPRecordDB.dbo.RecordHF')->where('UniqueCode', $id)->update($update);
  806. if($update['State'] == 1){
  807. DB::table('QPAccountsDB.dbo.PrivateMail')->insert($insert);
  808. }
  809. });
  810. return $this->json(200, "提交成功");
  811. }catch(\EXception $e){
  812. DB::rollBack();
  813. return $this->json(500, '提交失败,请重试');
  814. }
  815. }
  816. }