Gift.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. <?php
  2. /**
  3. * 礼包管理
  4. * Created by PhpStorm.
  5. * User: Administrator
  6. * Date: 2018/1/23
  7. * Time: 15:27
  8. */
  9. namespace app\admin\controller;
  10. // use app\common\controller\Base;
  11. use think\Db;
  12. class Gift extends Admin
  13. {
  14. private $_type = [
  15. '0' => '普通礼包',
  16. '1' => '充值礼包'
  17. ];
  18. private $_condis = [
  19. 'TOPLEVEL' => '最高档位可领',
  20. 'MULLEVEL' => '多档位可领',
  21. 'REPEATABLE' => '可重复领取',
  22. 'UNREPEATABLE' => '不可重复领取',
  23. ];
  24. private $_condisType = [
  25. 'TOPLEVEL' => '累计充值',
  26. 'MULLEVEL' => '累计充值',
  27. 'REPEATABLE' => '单笔充值',
  28. 'UNREPEATABLE' => '单笔充值',
  29. ];
  30. private $status_list = [
  31. 0 => '待审核',
  32. 1 => '通过',
  33. 2 => '未通过'
  34. ];
  35. protected function _initialize()
  36. {
  37. parent::_initialize();
  38. }
  39. /**
  40. * 礼包列表
  41. * @return mixed
  42. */
  43. public function index()
  44. {
  45. $condition['cy_libaoinfo.isdelete'] = 0;
  46. $title = $this->request->get('title', '', 'trim');
  47. $gameid = $this->request->get('gameid', '', 'trim');
  48. !empty($title) && $condition['title'] = $title;
  49. $condition['gameid'] = $gameid;
  50. $start_time = input('request.cr_start');
  51. //开始时间和结束时间不为空时
  52. if ($start_time != '' && input('request.cr_end') != '') {
  53. $condition['cy_libaoinfo.create_time'] = [
  54. ['>=', strtotime($start_time)],
  55. ['<=', strtotime(input('request.cr_end').' 23:59:59')],
  56. ];
  57. } //开始时间不为空时
  58. elseif ($start_time!= '') {
  59. $condition['cy_libaoinfo.create_time'] = ['>=', strtotime($start_time)];
  60. } //结束时间不为空时
  61. elseif (input('request.cr_end') != '') {
  62. $condition['cy_libaoinfo.create_time'] = ['<=', strtotime(input('request.cr_end').' 23:59:59')];
  63. }
  64. $tmpGameList = model('Common/Game')->getAllByCondition('id,name');
  65. $GiftModel = model('Common/Gift');
  66. $giftList = $GiftModel->getList($condition);
  67. $this->assign('game_list', $tmpGameList);
  68. $this->assign('list', $giftList);
  69. $this->assign('title', $title);
  70. $this->assign('page', $giftList->render());
  71. return $this->fetch();
  72. }
  73. /**
  74. * 新增礼包
  75. * @return mixed
  76. */
  77. public function add()
  78. {
  79. if ($this->request->isPost()) {
  80. $data = $this->getParam();
  81. $data['gameid'] = $data['select'];
  82. unset($data['select']);
  83. if (true !== ($res = $this->validate($data, 'Gift'))) {
  84. $this->error($res);
  85. }
  86. $GiftModel = model('Common/Gift');
  87. if ($GiftModel->add($data)) {
  88. $this->success('添加成功',url('index'));
  89. }
  90. $this->error($GiftModel->getError() ?: '添加失败');
  91. }
  92. $tmpGameList = model('Common/Game')->getAllByCondition('id,name',['cooperation_status'=>['in',[0,1,2]]]);
  93. $this->assign('game_list', $tmpGameList);
  94. return $this->fetch('add');
  95. }
  96. /**
  97. * 编辑礼包
  98. */
  99. public function edit()
  100. {
  101. $data = $this->checkData();
  102. if ($this->request->isPost()) {
  103. $data = $this->getParam();
  104. if (true !== ($res = $this->validate($data, 'Gift.edit'))) {
  105. $this->error($res);
  106. }
  107. $GiftModel = model('Common/Gift');
  108. model('Common/Gift')->startTrans();
  109. if ($GiftModel->allowField(true)->save($data, ['id' => $data['id']]) !== false ) {
  110. model('Common/Giftcode')->where('infoid',$data['id'])->where('status',0)->delete();
  111. foreach ($data['code'] as $v) {
  112. $codes[] = ['code' => $v,'infoid'=>$data['id']];
  113. }
  114. model('Common/Giftcode')->insertAll($codes);
  115. model('Common/Gift')->commit();
  116. $this->success('编辑成功',url('index'));
  117. }
  118. model('Common/Gift')->rollback();
  119. $this->error($GiftModel->getError() ?: '编辑失败');
  120. }
  121. $code = model('Common/Giftcode')->where('infoid',$data['id'])->where('status',0)->column('code', 'id');
  122. // $code = $data->giftCode()->column('code', 'id');
  123. $this->assign('code', implode("\r\n", $code));
  124. $this->assign('data', $data);
  125. $tmpGameList = model('Common/Game')->getAllByCondition();
  126. foreach ($tmpGameList as $game) {
  127. $gameList[ $game['id']] = $game;
  128. }
  129. $game = explode(',', $data['gameid']);
  130. $tmpGameList = model('Common/Game')->getAllByCondition('name', ['id' => ['in', $game]]);
  131. $this->assign('game_name', implode(',', array_column($tmpGameList, 'name')));
  132. return $this->fetch();
  133. }
  134. /**
  135. * 设置是否最新
  136. */
  137. public function setNew()
  138. {
  139. $id = input('id',0,'intval');
  140. $is_new = input('is_new',0,'intval');
  141. if(empty($id)){
  142. $this->error('礼包ID不能为空');
  143. }
  144. $GiftModel = model('Common/Gift');
  145. if($is_new)
  146. $data['is_new'] = 1; //设为最新
  147. else
  148. $data['is_new'] = 0; //取消最新
  149. $data['update_time'] = NOW_TIMESTAMP;
  150. if ($GiftModel->allowField(true)->save($data, ['id' => $id]) !== false ) {
  151. if($is_new)
  152. $this->success('设为最新成功',url('index'));
  153. else
  154. $this->success('取消成功');
  155. }
  156. $this->error($GiftModel->getError() ?: '设为最新失败');
  157. }
  158. /**
  159. * 删除礼包
  160. */
  161. public function delete()
  162. {
  163. $data = $this->checkData();
  164. if ($data->save(['isdelete'=>1],['id'=>$this->request->param('id', 0, 'intval')])) {
  165. $this->success('删除成功!');
  166. }
  167. $this->error('删除失败');
  168. }
  169. /**
  170. * 最新礼包列表
  171. * @return mixed
  172. */
  173. public function newList()
  174. {
  175. $condition['cy_libaoinfo.isdelete'] = 0;
  176. $condition['cy_libaoinfo.is_new'] = 1;
  177. $title = $this->request->get('title', '', 'trim');
  178. $gameName = $this->request->get('game_name', '', 'trim');
  179. !empty($title) && $condition['title'] = $title;
  180. !empty($gameName) && $condition['gameName'] = $gameName;
  181. $GiftModel = model('Common/Gift');
  182. $giftList = $GiftModel->getList($condition,'cy_libaoinfo.update_time desc');
  183. $this->assign('list', $giftList);
  184. $this->assign('title', $title);
  185. $this->assign('game_name', $gameName);
  186. $this->assign('page', $giftList->render());
  187. return $this->fetch('new_list');
  188. }
  189. /**
  190. * 获取参数新增(复用)
  191. * @return mixed
  192. */
  193. protected function getParam()
  194. {
  195. $data = $this->request->param();
  196. $data['starttime'] = $this->request->param('starttime', 0, 'strtotime');
  197. $data['endtime'] = $this->request->param('endtime', 0, 'strtotime');
  198. // if ($data['is_top']) {
  199. // $data['t_starttime'] = $this->request->param('t_starttime', 0, 'strtotime');
  200. // $data['t_endtime'] = $this->request->param('t_endtime', 0, 'strtotime');
  201. // }
  202. if (isset($data['code'])) {
  203. $code = $data['code'];
  204. $codeArray = explode("\r\n", $code);
  205. $codeArray = array_map('filterAndTrimInput', $codeArray);
  206. $codeArray = array_filter($codeArray);
  207. $data['code'] = $codeArray;
  208. $data['total'] = count($codeArray);
  209. }
  210. return $data;
  211. }
  212. /**
  213. * 检查礼包信息
  214. * @return array|false|\PDOStatement|string|\think\Model
  215. * @throws \think\db\exception\DataNotFoundException
  216. * @throws \think\db\exception\ModelNotFoundException
  217. * @throws \think\exception\DbException
  218. */
  219. protected function checkData()
  220. {
  221. $id = $this->request->param('id', 0, 'intval');
  222. $GiftModel = model('Common/Gift');
  223. $data = [];
  224. if (empty($id) || !($data = $GiftModel->find($id))) {
  225. $this->error('参数错误,不存该礼包');
  226. }
  227. return $data;
  228. }
  229. /**
  230. * 公会礼包管理页面
  231. */
  232. public function guildGift(){
  233. $keyword = input('keyword' , '' , 'filterAndTrimInput');
  234. $gameId = input('gameid' , '' , 'filterAndTrimInput');
  235. $lanmu = input('lanmu' , '' , 'filterAndTrimInput');
  236. $limitFirst = input('limitFirst' , '' , 'filterAndTrimInput'); // 当 lanmu 为 2 是 1 累计充值 2 单笔充值
  237. $condisFirst = input('condisFirst' , '' , 'filterAndTrimInput'); // 当 limitFirst 为 1 是累计充值 TOPLEVEL 最高档位可领 MULLEVEL 多档位可领
  238. $condisSecend = input('condisSecend' , '' , 'filterAndTrimInput');// 当 limitFirst 为 2 是单笔充值 REPEATABLE 可重复领取 UNREPEATABLE 不可重复领取
  239. $limit_channel= input('limit_channel', '' , 'filterAndTrimInput'); // 条件筛选,是否开启渠道限制
  240. $condition = [];
  241. if ( ! empty($keyword) ) {
  242. $condition['l.title'] = array('LIKE', '%'.$keyword.'%');
  243. }
  244. if ( ! empty($lanmu) ) {
  245. $condition['l.type'] = $lanmu - 1;
  246. }
  247. // 礼包类型为充值礼包
  248. if ( ! empty($lanmu) && $lanmu == 2) {
  249. if ( ! empty($limitFirst) ) {
  250. // 累计充值
  251. if ($limitFirst == 1) {
  252. if (empty($condisSecend) && ! empty($condisFirst) && in_array($condisFirst, ['TOPLEVEL', 'MULLEVEL'])) {
  253. $condition['l.get_condis'] = $condisFirst;
  254. }
  255. if (empty($condisFirst)) {
  256. $condition['l.get_condis'] = array(['eq','TOPLEVEL'],['eq','MULLEVEL'],'or');
  257. }
  258. }
  259. // 单笔充值
  260. if ($limitFirst == 2) {
  261. if (empty($condisFirst) && ! empty($condisSecend) && in_array($condisSecend, ['UNREPEATABLE', 'REPEATABLE'])) {
  262. $condition['l.get_condis'] = $condisSecend;
  263. }
  264. if (empty($condisFirst)) {
  265. $condition['l.get_condis'] = array(['eq','UNREPEATABLE'],['eq','REPEATABLE'],'or');
  266. }
  267. }
  268. }
  269. }else{ // 普通礼包
  270. if ($limit_channel == '0'){
  271. $condition['b.status'] = "0";
  272. }elseif ($limit_channel == 1){
  273. $condition['b.status'] = [['eq',1],['exp',Db::raw('is null')],'or'];
  274. }
  275. }
  276. if ( ! empty($gameId) ) {
  277. $condition['g.id'] = $gameId;
  278. }
  279. $condition['l.isdelete'] = 0;
  280. // 判断:因为字段的特殊性, 普通礼包是没有领取限制,故要做条件过滤
  281. // 没选礼包类型,有选领取限制,则默认礼包类型为充值礼包
  282. if (!array_key_exists('l.type', $condition) && array_key_exists('l.get_condis', $condition)){
  283. $condition['l.type'] = 1;
  284. }
  285. // 既有选礼包类型,又选领取限制
  286. if(array_key_exists('l.type', $condition) && array_key_exists('l.get_condis', $condition)){
  287. if ($condition['l.type'] != 1){
  288. $condition['l.get_condis'] = rand(1234,5678);
  289. }
  290. }
  291. $guildGiftInfoM = model('GuildGiftinfo');
  292. $list = $guildGiftInfoM
  293. ->alias('l')
  294. ->field('l.id, l.title, l.gameid, l.type, l.starttime, l.limit_pens, l.limit_amount,l.endtime, l.is_top, l.t_starttime, l.t_endtime, l.update_time, l.create_time, g.name as gamename,l.get_condis, b.status as is_channel_limit')
  295. ->join('cy_game g',' l.gameid = g.id')
  296. ->join('cy_guild_limit b','l.id = b.infoid','left')
  297. ->where($condition)
  298. ->order('l.create_time desc')
  299. ->paginate(10, false, ['query' => input('get.')])
  300. ->each(function($item, $key){
  301. $type = $this->_type;
  302. $libaoCondis = $this->_condis;
  303. $libaoCondisType = $this->_condisType;
  304. $item['type_1'] = $item['type'];
  305. // 累计充值
  306. if (in_array($item['get_condis'], ['TOPLEVEL', 'MULLEVEL'])) {
  307. $item['libaoCondis'] = $libaoCondis[$item['get_condis']];
  308. $item['libaoCondisType']= $libaoCondisType[$item['get_condis']];
  309. }
  310. // 单笔充值
  311. if (in_array($item['get_condis'], ['UNREPEATABLE', 'REPEATABLE'])) {
  312. $item['libaoCondis'] = $libaoCondis[$item['get_condis']];
  313. $item['libaoCondisType'] = $libaoCondisType[$item['get_condis']].'('.$item['limit_pens'].')笔';
  314. }
  315. $item['type'] = $type[$item['type']];
  316. });
  317. /*$sql = $guildGiftInfoM->getLastSql();
  318. dump($sql);*/
  319. $this->assign('list', $list);
  320. $this->assign('page', $list->render());
  321. $game_list = model('Game')->field('id,name')->order('name asc')->select();
  322. $this->assign('game_list', $game_list);
  323. $this->assign('lanmu_list', $this->_type);
  324. return $this->fetch('guildlist');
  325. }
  326. /**
  327. * 删除公会礼包
  328. */
  329. public function delGuildGift() {
  330. $id = $this->request->param('id', 0, 'intval');
  331. if ( ! $id ) {
  332. $this->error('数据不存在');
  333. }
  334. $delete = model('GuildGiftinfo')->save(['isdelete' => 1],['id' => $id]);
  335. if ( $delete !== false ) {
  336. $this->success('删除成功');
  337. } else {
  338. $this->error('删除失败');
  339. }
  340. }
  341. /**
  342. * 添加公会礼包
  343. */
  344. public function addGuildGift()
  345. {
  346. if ($this->request->isGet()) {
  347. $game_list = model('Game')->field('id,name')->order('name asc')->select();
  348. $this->assign('game_list', $game_list);
  349. return $this->fetch('guildadd');
  350. }
  351. if($this->request->isPost()){
  352. $libao_data['gameid'] = input('post.gameid', 0, 'intval');
  353. $libao_data['title'] = input('post.title', '', 'filterAndTrimInput');
  354. $libao_data['content'] = input('post.content', '', 'filterAndTrimInput');
  355. $libao_data['is_top'] = input('post.is_top', 0, 'intval');
  356. $libao_data['limit_amount'] = input('post.limit_amount');
  357. $libao_data['type'] = input('post.type', 0, 'intval'); // 0 普通礼包 1 充值礼包
  358. $libao_data['starttime'] = input('post.starttime', 0, 'strtotime');
  359. $libao_data['endtime'] = input('post.endtime', 0, 'strtotime');
  360. $get_condis1 = input('post.get_condis1', 0, 'intval'); // 领取限制1 当type 为1 充值礼包时才用到 1 累计充值 2 单笔充值
  361. $get_condis2 = input('post.get_condis2', '', 'filterAndTrimInput'); //领取限制2 根据 get_condis1 不同的值 变换
  362. $limit_num = input('post.limit_num', 0, 'intval'); // 充值笔数 当type 为1 get_condis1 为 2 单笔充值 才用到
  363. if ( $libao_data['is_top'] ) {
  364. $libao_data['t_starttime'] = input('post.t_starttime', 0, 'strtotime');
  365. $libao_data['t_endtime'] = input('post.t_endtime', 0, 'strtotime');
  366. }
  367. if ($libao_data['type'] == 1) {
  368. if ( empty($libao_data['limit_amount'])) {
  369. $this->error('充值礼包,领取条件不能为空' );
  370. }
  371. if(!preg_match("/^[1-9][0-9]*$/",$libao_data['limit_amount'])) {
  372. $this->error('充值礼包,领取条件只能输入大于0的正整数' );
  373. }
  374. // 累计充值
  375. if (isset($get_condis1) && $get_condis1 == 1) {
  376. if (!in_array($get_condis2, ['TOPLEVEL', 'MULLEVEL'])) {
  377. $this->error('抱歉,领取限制2参数有误!' );
  378. }
  379. $libao_data['get_condis'] = $get_condis2;
  380. }
  381. // 单笔充值
  382. if (isset($get_condis1) && $get_condis1 == 2) {
  383. if (!in_array($get_condis2, ['REPEATABLE', 'UNREPEATABLE'])) {
  384. $this->error('抱歉,领取限制2参数有误!' );
  385. }
  386. $libao_data['get_condis'] = $get_condis2;
  387. if(!preg_match("/^[1-9][0-9]*$/", $limit_num)) {
  388. $this->error('充值礼包,充值笔数只能输入大于0的正整数' );
  389. }
  390. $libao_data['limit_pens'] = $limit_num;
  391. }
  392. }
  393. $libao_data['create_time'] = NOW_TIMESTAMP;
  394. $libao_data['update_time'] = NOW_TIMESTAMP;
  395. if ( empty($libao_data['gameid']) || empty($libao_data['title']) || empty($libao_data['content'])
  396. || empty($libao_data['starttime']) || empty($libao_data['endtime']) ) {
  397. $this->error('参数不完整', url('Gift/addGuildGift') );
  398. }
  399. $code = input('post.code');
  400. $codeToArray = explode("\r\n", $code);
  401. $codeToArray = array_map('filterAndTrimInput', $codeToArray);
  402. $codeToArray = array_filter($codeToArray);
  403. $total = count($codeToArray);
  404. $libao_data['total'] = $total;
  405. $GuildGiftinfoM = model('GuildGiftinfo');
  406. $GuildGiftinfoM->data($libao_data);
  407. $GuildGiftinfoM->save();
  408. $lastInsId = $GuildGiftinfoM->id;
  409. if ( $lastInsId ) {
  410. $mLibao = model('GuildGift');
  411. $list = [];
  412. foreach ( $codeToArray as $eachCode ) {
  413. $libaoInfo = array(
  414. 'infoid' => $lastInsId,
  415. 'code' => $eachCode,
  416. 'update_time' => NOW_TIMESTAMP,
  417. );
  418. $list[] = $libaoInfo;
  419. }
  420. $mLibao->saveAll($list);
  421. $this->success('添加成功', url('Gift/guildGift') );
  422. } else {
  423. $this->error('添加失败', url('Gift/addGuildGift') );
  424. }
  425. }
  426. }
  427. /**
  428. * 编辑公会礼包
  429. */
  430. public function editGuildGift(){
  431. if ( $this->request->isGet() ) {
  432. $id = input('id', 0, 'intval');
  433. if ( $id > 0 ) {
  434. $data = model('GuildGiftinfo')->where( array('id'=>$id) )->find();
  435. $code = model('GuildGift')->where( array('infoid'=>$id) )->column('code');
  436. if ( ! empty($code) ) {
  437. $code_str = '';
  438. foreach ( $code as $key => $value ) {
  439. $code_str .= $value."\r\n";
  440. }
  441. }
  442. $gameInfo = model('Game')->where(['id' => $data['gameid']])->find();
  443. $data['gameName'] = $gameInfo['name'];
  444. $data['code'] = $code_str;
  445. $this->assign('vo', $data);
  446. }
  447. $game_list = model('Game')->field('id,name')->order('name asc')->select();
  448. $this->assign('game_list', $game_list);
  449. $this->assign('noedit', 1);
  450. return $this->fetch('guildedit');
  451. }
  452. if ( $this->request->isPost() ) {
  453. $id = input('post.id', 0, 'intval');
  454. if ( ! $id ) {
  455. $this->error('数据不存在', url('Gift/index') );
  456. }
  457. $libao_data['title'] = input('post.title' , '' , 'filterAndTrimInput');
  458. $libao_data['content'] = input('post.content' , '' , 'filterAndTrimInput');
  459. $libao_data['is_top'] = input('post.is_top' , 0 , 'intval');
  460. $libao_data['limit_amount'] = input('post.limit_amount' , 0 , 'intval');
  461. $libao_data['type'] = input('post.type' , 0 , 'intval');
  462. $libao_data['starttime'] = input('post.starttime' , 0 , 'strtotime');
  463. $libao_data['endtime'] = input('post.endtime' , 0 , 'strtotime');
  464. if ( $libao_data['is_top'] ) {
  465. $libao_data['t_starttime'] = input('post.t_starttime', 0, 'strtotime');
  466. $libao_data['t_endtime'] = input('post.t_endtime', 0, 'strtotime');
  467. }
  468. if ($libao_data['type'] == 1) {
  469. if ( empty($libao_data['limit_amount'])) {
  470. $this->error('充值礼包,领取条件不能为空' );
  471. }
  472. if(!preg_match("/^[1-9][0-9]*$/",$libao_data['limit_amount'])) {
  473. $this->error('充值礼包,领取条件只能输入大于0的正整数' );
  474. }
  475. }
  476. $update = model('GuildGiftinfo')->save($libao_data,array('id'=>$id));
  477. if ( $update !== false ) {
  478. $this->success('修改成功', url('Gift/guildGift') );
  479. } else {
  480. $this->error('修改失败', url('Gift/editGuildGift', array('id'=>$id) ) );
  481. }
  482. }
  483. }
  484. /**
  485. * 公会礼包渠道限制
  486. */
  487. public function giftChannelLimit(){
  488. if ($this->request->isGet()){
  489. $id = input('id', 0, 'intval');
  490. if (empty($id)){
  491. $this->error('参数错误' );
  492. }
  493. $data = model('GuildLimit')->where(['infoid'=>$id])->find();
  494. $this->assign('info',$data);
  495. $this->assign('infoid',$id);
  496. $this->assign('limitArr',$data['part_channel']);
  497. $this->assign('channel_list',model('Channel')->where(['status'=>1])->field('id,name')->select());
  498. return $this->fetch('giftChannelLimit');
  499. }
  500. if ($this->request->isPost()){
  501. $Data = $this->request->param();
  502. $formData = [];
  503. parse_str($Data['formData'] , $formData);
  504. $infoid = isset($formData['infoid']) ? $formData['infoid'] : null;
  505. $all_limit = isset($formData['all_limit']) ? $formData['all_num'] : null;
  506. $all_num = isset($formData['all_num']) ? $formData['all_num'] : null;
  507. $all_day = isset($formData['all_day']) ? $formData['all_day'] : null;
  508. $all_day_num = isset($formData['all_day_num']) ? $formData['all_day_num'] : null;
  509. $part_limit = isset($formData['part_limit']) ? $formData['part_limit'] : null;
  510. $part_num = isset($formData['part_num']) ? $formData['part_num'] : null;
  511. $part_day = isset($formData['part_day']) ? $formData['part_day'] : null;
  512. $part_day_num = isset($formData['part_day_num']) ? $formData['part_day_num'] : null;
  513. if (isset($Data['limitArr'])) {
  514. $denied_channel_1 = implode(',' , $Data['limitArr']) . ',';
  515. } else {
  516. $denied_channel_1 = '';
  517. }
  518. $status = isset($formData['status']) ? $formData['status'] : null;
  519. $remark = isset($formData['remark']) ? $formData['remark'] : null;
  520. $condition = [];
  521. /*---------------所有渠道配置---------------*/
  522. if (!empty($all_limit)){
  523. $condition['all_limit'] = $all_limit-1;
  524. }else{
  525. $all_limit = 2;
  526. $condition['all_limit'] = 1;
  527. }
  528. // 开启,则必须配置数量;不开启,但是填写了数量,则必须判断
  529. if (($all_limit == 1) || ($all_limit == 2 && $all_num != '')){
  530. if (preg_match("/^\d+$/",$all_num) ){
  531. $condition['all_num'] = $all_num;
  532. }else{
  533. $this->result('',0,'所有渠道配置:限制总额数量必须为>=0的整数!数量不能为空');
  534. }
  535. }
  536. if (!empty($all_day)){
  537. $condition['all_day'] = $all_day-1;
  538. }else{
  539. $all_day = 2;
  540. $condition['all_day'] = 1;
  541. }
  542. // 开启,则必须配置数量;不开启,但是填写了数量,则必须判断
  543. if ( ($all_day == 1) || ($all_day == 2 && $all_day_num != '' )){
  544. if (preg_match("/^\d+$/",$all_day_num) ){
  545. $condition['all_day_num'] = $all_day_num;
  546. }else{
  547. $this->result('',0,'所有渠道配置:每日限额数量必须为>=0的整数!数量不能为空');
  548. }
  549. }
  550. // 限制总额 和 每日限额都开启
  551. if($all_limit == 1 && $all_day == 1){
  552. if ($all_day_num > $all_num){
  553. $this->result('',0,'所有渠道配置:每日限额不能大于限制总额');
  554. }
  555. }
  556. /*---------------部分渠道配置---------------*/
  557. if (!empty($part_limit)){
  558. $condition['part_limit'] = $part_limit-1;
  559. }else{
  560. $part_limit = 2;
  561. $condition['part_limit'] = 1;
  562. }
  563. // 开启,则必须配置数量;不开启,但是填写了数量,则必须判断
  564. if ( ($part_limit == 1) || ($part_limit == 2 && $part_num != '')){
  565. if (preg_match("/^\d+$/",$part_num)){
  566. $condition['part_num'] = $part_num;
  567. }else{
  568. $this->result('',0,'部分渠道配置:限制总额数量必须为>=0的整数!数量不能为空');
  569. }
  570. }
  571. if (!empty($part_day)){
  572. $condition['part_day'] = $part_day-1;
  573. }else{
  574. $part_day = 2;
  575. $condition['part_day'] = 1;
  576. }
  577. // 开启,则必须配置数量;不开启,但是填写了数量,则必须判断
  578. if ( ($part_day == 1) || ($part_day == 2 && $part_day_num != '')){
  579. if (preg_match("/^\d+$/",$part_day_num)){
  580. $condition['part_day_num'] = $part_day_num;
  581. }else{
  582. $this->result('',0,'部分渠道配置:每日限额数量必须为>=0的整数!数量不能为空');
  583. }
  584. }
  585. // 限制总额 和 每日限额都开启
  586. if($part_limit == 1 && $part_day == 1){
  587. if ($part_day_num > $part_num){
  588. $this->result('',0,'部分渠道配置:每日限额不能大于限制总额');
  589. }
  590. }
  591. // 若部分渠道:开启限制总额 或 每日限额,渠道不能为空
  592. if (($part_limit == 1 || $part_day == 1) && ($denied_channel_1 == ',' || $denied_channel_1=='')){
  593. $this->result('',0,'部分渠道配置:开启限制总额或每日限额后,渠道不能为空');
  594. }
  595. if ($denied_channel_1 != ','){
  596. $condition['part_channel'] = $denied_channel_1;
  597. }
  598. /*---------------总开关---------------*/
  599. if (empty($status)){
  600. $this->result('',0,'请选择是否开启领取限制');
  601. }
  602. $condition['status'] = $status-1;
  603. // 若总开关打开,则4个开关必须至少有一个是打开的
  604. if($status == 1 && !($all_limit==1 || $all_day==1 || $part_limit==1|| $part_day==1 )){
  605. $this->result('',0,'领取限制开启,则所有渠道或部分渠道至少有一个限制开启');
  606. }
  607. if (!empty($remark)){
  608. $condition['remark'] = $remark;
  609. }
  610. $res = model('GuildLimit')->setGiftLimit($infoid,$condition);
  611. if ($res !== false){
  612. $this->result(url('Gift/guildGift'),1,'设置成功' );
  613. }
  614. $this->result('',0,'设置失败');
  615. }
  616. }
  617. /**
  618. * ajax获取所有渠道列表
  619. */
  620. public function getChannelAll()
  621. {
  622. $channel_list = model('Common/Channel')->getChannleList();
  623. // 去除超级管理员渠道
  624. /*unset($channel_list[11]);*/
  625. echo json_encode($channel_list);
  626. }
  627. /**
  628. * 公会礼包领取记录
  629. */
  630. public function guildGiftReceive(){
  631. $giftId = input('giftId' , '' , 'filterAndTrimInput');
  632. $type = input('type' , '' , 'filterAndTrimInput'); // 1 普通礼包 2充值礼包 入库 需要减1
  633. $limitFirst = input('limitFirst' , '' , 'filterAndTrimInput'); // 当 lanmu 为 2 是 1 累计充值 2 单笔充值
  634. $condisFirst = input('condisFirst' , '' , 'filterAndTrimInput'); // 当 limitFirst 为 1 是累计充值 TOPLEVEL 最高档位可领 MULLEVEL 多档位可领
  635. $condisSecend = input('condisSecend' , '' , 'filterAndTrimInput');// 当 limitFirst 为 2 是单笔充值 REPEATABLE 可重复领取 UNREPEATABLE 不可重复领取
  636. $channel_id = input('channel_id' , '' , 'filterAndTrimInput');
  637. $channel_top = input('.channel_top' , '' , 'filterAndTrimInput');
  638. $condition = [];
  639. if ( ! empty($giftId) ) {
  640. $condition['i.id'] = $giftId;
  641. }
  642. if ( ! empty($type) ) {
  643. $condition['i.type'] = $type - 1;
  644. }
  645. // 礼包类型为充值礼包
  646. if ( ! empty($type) && $type == 2) {
  647. if ( ! empty($limitFirst) ) {
  648. // 累计充值
  649. if ($limitFirst == 1) {
  650. if (empty($condisSecend) && ! empty($condisFirst) && in_array($condisFirst, ['TOPLEVEL', 'MULLEVEL'])) {
  651. $condition['i.get_condis'] = $condisFirst;
  652. }
  653. if (empty($condisFirst)) {
  654. $condition['i.get_condis'] = array(['eq','TOPLEVEL'],['eq','MULLEVEL'],'or');
  655. }
  656. }
  657. // 单笔充值
  658. if ($limitFirst == 2) {
  659. if (empty($condisFirst) && ! empty($condisSecend) && in_array($condisSecend, ['UNREPEATABLE', 'REPEATABLE'])) {
  660. $condition['i.get_condis'] = $condisSecend;
  661. }
  662. if (empty($condisFirst)) {
  663. $condition['i.get_condis'] = array(['eq','UNREPEATABLE'],['eq','REPEATABLE'],'or');
  664. }
  665. }
  666. }
  667. }
  668. if ( ! empty($channel_id) ) {
  669. $condition['l.channel_id'] = $channel_id;
  670. }
  671. // 判断:因为字段的特殊性, 普通礼包是没有领取限制,故要做条件过滤
  672. // 没选礼包类型,有选领取限制,则默认礼包类型为充值礼包
  673. if (!array_key_exists('i.type', $condition) && array_key_exists('i.get_condis', $condition)){
  674. $condition['i.type'] = 1;
  675. }
  676. // 既有选礼包类型,又选领取限制
  677. if(array_key_exists('i.type', $condition) && array_key_exists('i.get_condis', $condition)){
  678. if ($condition['i.type'] != 1){
  679. $condition['i.get_condis'] = rand(1234,5678);
  680. }
  681. }
  682. $giftLog = model('GuildGiftlog');
  683. $list = $giftLog ->alias('l')
  684. ->join('cy_guild_giftinfo i ',' i.id = l.infoid','left')
  685. ->join('cy_game g',' l.game_id = g.id')
  686. ->field('i.id,l.channel_id,i.title,i.type,i.limit_pens,l.game_id,i.limit_amount,l.create_time,count(l.id) as total,i.get_condis, g.name as game_name')
  687. ->where($condition)
  688. ->order('l.id DESC')
  689. ->group('l.infoid, l.channel_id')
  690. ->paginate(10, false, ['query' => input('get.')])
  691. ->each(function($game, $key){
  692. $type = $this->_type;
  693. $libaoCondis = $this->_condis;
  694. $libaoCondisType = $this->_condisType;
  695. // 累计充值
  696. if (in_array($game['get_condis'], ['TOPLEVEL', 'MULLEVEL'])) {
  697. $game['type2'] = $libaoCondis[$game['get_condis']];
  698. $game['type1']= $libaoCondisType[$game['get_condis']];
  699. }
  700. // 单笔充值
  701. if (in_array($game['get_condis'], ['UNREPEATABLE', 'REPEATABLE'])) {
  702. $game['type2'] = $libaoCondis[$game['get_condis']];
  703. $game['type1'] = $libaoCondisType[$game['get_condis']].'('.$game['limit_pens'].')笔';
  704. }
  705. $game['type_1'] = $game['type'];
  706. $game['channel_name'] = get_current_channel_name($game['channel_id']);
  707. $game['top_channel'] = setDefault(get_top_second_channel_name($game['channel_id']));
  708. // $game['top_channel'] = 111111;
  709. $giftLog_1 = model('GuildGiftlog');
  710. $game['used'] = $giftLog_1->where(['create_time' => $game['create_time']])->count();
  711. $game['first_time'] = $giftLog_1->where(['infoid' => $game['id']])->field('create_time')->order('create_time ASC')->find();
  712. $game['type'] = $type[$game['type']];
  713. $game['get_condis'] = $this->_condis[$game['get_condis']];
  714. });
  715. /*dump(model('Channel')->where(['status'=>1])->field('id,name')->select());
  716. exit;*/
  717. $this->assign('list', $list);
  718. $this->assign('page', $list->render());
  719. $gameList = model('Common/Game')->getAllByCondition('id,name');
  720. $this->assign('game_list',$gameList);
  721. $this->assign('channel_list',model('Channel')->where(['status'=>1])->field('id,name')->select());
  722. $this->assign('giftList', $this->_getGiftNameList());
  723. $this->assign('channelTopList', getChannelByTop());
  724. $this->assign('lanmu_list', $this->_type);
  725. return $this->fetch('guildReceivelist');
  726. }
  727. /**
  728. * 获取礼包名称列表
  729. */
  730. private function _getGiftNameList() {
  731. $gift_list = [];
  732. //$giftInfo = model('GuildGiftinfo');
  733. // $gift_list = $giftInfo->field('id, title as name')->where(['isdelete' => 0])->order('id desc')->select();
  734. $gift_list = Db::table('cy_guild_giftinfo')->field('id, title as name')->where(['isdelete' => 0])->order('id desc')->select();
  735. return $gift_list;
  736. }
  737. /**
  738. * 礼包详情
  739. *
  740. * @param int giftId
  741. * @return string
  742. */
  743. public function detaileGuildGift() {
  744. $giftId = input('giftId', '', 'filterAndTrimInput');
  745. $channelId = input('channelId', '', 'filterAndTrimInput');
  746. $giftModel = model('GuildGiftinfo');
  747. $giftInfo = $giftModel->where(['id' => $giftId])->find();
  748. if (!$giftInfo) {
  749. $this->error('无此礼包!', url('guildGiftReceive') );
  750. }
  751. $giftLog = model('GuildGiftlog');
  752. $result = $giftLog->where(['infoid' => $giftId, 'channel_id' => $channelId])->select();
  753. if ( $result ) {
  754. $group = array();
  755. $list = array();
  756. foreach ($result as $k => $v) {
  757. $group[$v['create_time']][] = $v;
  758. }
  759. foreach ($group as $time => $item) {
  760. foreach ($item as $key => $val) {
  761. $list[$time]['id'] = $val['user_id'];
  762. $list[$time]['startTime'] = $time;
  763. $list[$time]['giftNum'] = count($item);
  764. $list[$time]['giftCode'][$key] = $val['code']."\r\n";
  765. $list[$time]['giftType'] = $val['type'];
  766. if ($val['type'] == 1) {
  767. $member = model('Members')->where(['id'=>$val['user_id']])->field('username')->find()['username'];
  768. $list[$time]['username'] = isset($member) ? $member : '0';
  769. } else {
  770. $list[$time]['username'] = 0;
  771. }
  772. }
  773. }
  774. $list = array_values($list);
  775. }
  776. $this->assign('list', $list);
  777. /*dump(model('Members')->where(['id'=>27550904])->field('username')->find()['username']);
  778. dump($list);*/
  779. return $this->fetch('detaileGuildGift');
  780. }
  781. /**
  782. * 公会领取礼包审核页
  783. */
  784. public function getGiftCheckList(){
  785. $gift_name = input('get.gift_name', '', 'filterAndTrimInput');
  786. $condis = input('get.condis', '', 'filterAndTrimInput');
  787. $channel_id = input('get.channel_id', 0, 'intval');
  788. $start_time = input('get.start_time', '', 'filterAndTrimInput');
  789. $end_time = input('get.end_time', '', 'filterAndTrimInput');
  790. $condition = [];
  791. if ( ! empty($gift_name) ) {
  792. $condition['a.infoid'] = $gift_name;
  793. }
  794. if ( ! empty($condis) ) {
  795. $condition['b.get_condis'] = $condis;
  796. }
  797. if ( ! empty($channel_id) ) {
  798. $condition['a.channel_id'] = $channel_id;
  799. }
  800. /*$time_condition = makeTimeCondition($start_time, $end_time);
  801. if(is_array($time_condition) && count($time_condition)>0) {
  802. $condition['a.create_time'] = $time_condition;
  803. }
  804. // 未设置任何条件时,默认显示当天数据
  805. if(empty($condition) || count($condition) == 0) {
  806. $start = $_GET['start_time'] = date('Y-m-d');
  807. $condition['a.create_time'] = makeTimeCondition($start);
  808. }*/
  809. //开始时间和结束时间不为空时
  810. if ($start_time != '' && $end_time != '') {
  811. $condition['a.create_time'] = [
  812. ['>=', strtotime($start_time)],
  813. ['<=', strtotime($end_time . ' 23:59:59')],
  814. ];
  815. } //开始时间不为空时
  816. elseif ($start_time != '') {
  817. $condition['a.create_time'] = ['>=', strtotime($start_time)];
  818. } //结束时间不为空时
  819. elseif ($end_time != '') {
  820. $condition['a.create_time'] = ['<=', strtotime($end_time . ' 23:59:59')];
  821. } else {
  822. $start_time = date('Y-m-d', time());
  823. $end_time = date('Y-m-d', time());
  824. $condition['a.create_time'] = [
  825. ['>=', strtotime($start_time)],
  826. ['<=', strtotime($end_time . ' 23:59:59')],
  827. ];
  828. }
  829. $list = model('GuildGiftapply')
  830. ->alias('a')
  831. ->join("cy_guild_giftinfo b "," a.infoid = b.id ")
  832. ->join("cy_game c "," c.id = a.game_id")
  833. ->join("cy_department d "," d.id = a.channel_id")
  834. ->field("a.*,b.title,b.get_condis,b.type as gift_type, c.name as game_name ,d.name as channel_name,d.id_path ")
  835. ->where($condition)
  836. ->order('a.audit_status asc, a.create_time desc')
  837. ->paginate(10, false, ['query' => input('get.')])
  838. ->each(function($item, $key){
  839. $item['id_path'] = mb_substr($item['id_path'],1,2);
  840. $departArr = model('Channel')->where("id = '{$item['id_path']}'")->field('name')->find();
  841. $item['dj_departName'] = $departArr['name'];
  842. return $item;
  843. });
  844. // 获取 礼包 数组
  845. $this->assign('page', $list->render());
  846. $this->assign('list',$list);
  847. $this->assign('gift_List', $this->_getGiftNameList());
  848. $this->assign('channel_list',model('Channel')->where(['status'=>1])->field('id,name')->select());
  849. $this->assign('status_list', $this->status_list);
  850. $this->assign('condis_list', $this->_condis);
  851. $this->assign('giftType_list', $this->_type);
  852. $this->assign('start_time', $start_time);
  853. $this->assign('end_time', $end_time);
  854. return $this->fetch('getGiftCheckList');
  855. }
  856. /**
  857. * 公会礼包审核
  858. */
  859. function getGiftCheck(){
  860. $id = input('post.id', 0, 'intval');
  861. $channel_id = input('post.channel_id', 0, 'intval');
  862. $audit_status = input('post.audit_status', 0, 'intval');
  863. $apply_num = input('post.apply_num', 0, 'intval');
  864. $audit_num = input('post.audit_num', 0, 'filterAndTrimInput');
  865. $audit_cmmt = input('post.audit_cmmt', '', 'filterAndTrimInput');
  866. if (empty($id)){
  867. $this->result('',0,'参数错误');
  868. }
  869. if (empty($audit_status)){
  870. $this->result('',0,'请选择是否审核通过');
  871. }
  872. if ($audit_status ==1 && (empty($audit_num) || !preg_match("/^[1-9][0-9]*$/",$audit_num))){
  873. $this->result('',0,'发放数量必须为正整数');
  874. }
  875. // 如果审核通过,确定要发放礼包,对礼包数目进行核查
  876. if ($audit_status == 1){
  877. $giftApplyArr = model("GuildGiftapply")->where("id = '{$id}'")->find();
  878. if ($giftApplyArr['apply_num'] != $apply_num){
  879. $this->result('',0,'领取数量和记录的不一致');
  880. }
  881. }
  882. if ($audit_status ==1 && ((int)$audit_num > (int)$apply_num)){
  883. $this->result('',0,'发放数量不能超过领取数量');
  884. }
  885. // 获取礼包剩余数量,验证发放数量是否会超过 实际 剩余数量
  886. if ($audit_status ==1){
  887. $giftInfoArr = model("GuildGiftinfo")->where("id = '{$giftApplyArr['infoid']}'")->find();
  888. $giftHasNum = (int)$giftInfoArr['total'] - (int)$giftInfoArr['used'];
  889. if($giftHasNum < $audit_num){
  890. $this->result('',0,'发放数量不能超过礼包剩余数量');
  891. }
  892. }
  893. // 不同意时 发放数量为0
  894. if ($audit_status ==2){
  895. $audit_num = 0;
  896. }
  897. // 开启事物
  898. Db::startTrans();
  899. // 更新公会礼包申请表
  900. $data = [
  901. 'audit_status' => $audit_status,
  902. 'audit_num' => $audit_num,
  903. 'audit_cmmt' => $audit_cmmt,
  904. 'audit_time' => time(),
  905. 'read_yn' => 0,
  906. ];
  907. if ($audit_status == 2){
  908. $guildStatus = '不通过';
  909. }else {
  910. $guildStatus = '通过';
  911. }
  912. $res1 = model('GuildGiftapply')->save($data,['id'=>$id]);
  913. // 消息通知表 数据
  914. $noticeArr = [
  915. 'title'=> '“'.$giftInfoArr['title'].'”领取申请'.$guildStatus,
  916. 'content'=> '“'.$giftInfoArr['title'].'礼包领取”审核不通过,原因为:'.$audit_cmmt.'。',
  917. 'create_time'=> time(),
  918. 'channel_id'=> $channel_id,
  919. ];
  920. $res2 = true;
  921. $res4 = true;
  922. $res5 = true;
  923. if ($audit_status == 1){
  924. $data2 = ['used'=> (int)$giftInfoArr['used'] + $audit_num ,'update_time'=>time()];
  925. $res2 = model("GuildGiftinfo")->save($data2,['id'=>$giftApplyArr['infoid']]);
  926. $noticeArr['content'] = '“'.$giftInfoArr['title'].'礼包领取”审核通过,请及时查收。';
  927. // 如果备注不为空,则要加上备注
  928. if(!empty($audit_cmmt)){
  929. $noticeArr['content'] = '“'.$giftInfoArr['title'].'礼包领取”审核通过,请及时查收,注意事项:'.$audit_cmmt;
  930. }
  931. }
  932. $resApplyInfo = model('GuildGiftapply')->alias('a')
  933. ->field('a.channel_id,a.id as appli_id,a.game_id,b.title,b.type,b.id as lbinfo_id')
  934. ->join('cy_guild_giftinfo b ',' a.infoid = b.id')
  935. ->where(['a.id'=>$id, 'b.isdelete'=>0])
  936. ->find();
  937. if($audit_status == 1 && $resApplyInfo['type'] == 0){
  938. $resApplyCode = model('GuildGiftapply')->alias('a')
  939. ->field('b.code,b.id')
  940. ->join("cy_guild_gift b "," a.infoid = b.infoid",'left')
  941. ->where(['a.id'=>$id, 'b.status'=>0])
  942. ->limit($audit_num)
  943. ->select();
  944. if (empty($resApplyCode) || count($resApplyCode) < $audit_num){
  945. $msg = "礼包剩余数量不足";
  946. $res4 = false;
  947. }
  948. if ($res4){
  949. // 普通礼包写入cy_guild_giftlog 礼包领取记录表
  950. $insertLogArr = [];
  951. $GuildGift_idArr = [];
  952. foreach ($resApplyCode as $v){
  953. $insertLogArr[] = [
  954. 'user_id' => 0,
  955. 'channel_id' => $resApplyInfo['channel_id'],
  956. 'game_id' => $resApplyInfo['game_id'],
  957. 'title' => $resApplyInfo['title'],
  958. 'type' => $resApplyInfo['type'],
  959. 'infoid' => $resApplyInfo['lbinfo_id'],
  960. 'giftid' => $v['id'],
  961. 'code' => $v['code'],
  962. 'create_time' => time(),
  963. ];
  964. $GuildGift_idArr[] = ['id'=>$v['id'],'status'=>1,'update_time'=>time()];
  965. }
  966. $GuildGiftlogModel = model('GuildGiftlog');
  967. $res4 = $GuildGiftlogModel->saveAll($insertLogArr);
  968. $res5 = model('GuildGift')->saveAll($GuildGift_idArr);
  969. if (!$res4 || !$res5){
  970. $res4 = false;
  971. }
  972. }
  973. }
  974. $GuildMessageModel = model('GuildMessage');
  975. $GuildMessageModel->data($noticeArr);
  976. $res3 = $GuildMessageModel->save();
  977. // 提交事务
  978. if($res1 && $res2 && $res3 && $res4 && $res5){
  979. Db::commit();
  980. $this->result('',1,'更新成功');
  981. }else{
  982. Db::rollback();
  983. $this->result('',0,'更新失败:'.$msg);
  984. }
  985. }
  986. /**
  987. * 礼包领取记录 列表
  988. */
  989. public function giftReceiveList(){
  990. $condition = [];
  991. $username = input('username' , '' , 'filterAndTrimInput');
  992. $gameid = input('gameid' , '' , 'filterAndTrimInput');
  993. $title = input('title' , '' , 'filterAndTrimInput');
  994. if (!empty($username)){
  995. $condition['a.username'] = $username;
  996. }
  997. if (!empty($title)){
  998. $condition['l.title'] = $title;
  999. }
  1000. $start_time = input('request.cr_start');
  1001. //开始时间和结束时间不为空时
  1002. if ($start_time != '' && input('request.cr_end') != '') {
  1003. $condition['a.create_time'] = [
  1004. ['>=', strtotime($start_time)],
  1005. ['<=', strtotime(input('request.cr_end').' 23:59:59')],
  1006. ];
  1007. } //开始时间不为空时
  1008. elseif ($start_time!= '') {
  1009. $condition['a.create_time'] = ['>=', strtotime($start_time)];
  1010. } //结束时间不为空时
  1011. elseif (input('request.cr_end') != '') {
  1012. $condition['a.create_time'] = ['<=', strtotime(input('request.cr_end').' 23:59:59')];
  1013. }else {
  1014. $start_time = $end_time = date('Y-m-d', time());
  1015. $condition['a.create_time'] = ['>=', strtotime($start_time)];
  1016. }
  1017. $list = model('Libaolog')->alias('a')
  1018. ->join('cy_libaoinfo l','l.id=a.libaoid')
  1019. ->join('cy_game g','g.id=l.gameid','left')
  1020. ->field('a.id,l.title,a.username,a.create_time,g.name,a.code')
  1021. ->where($condition);
  1022. if (!empty($gameid)){
  1023. // gameid 字段为逗号分隔的多游戏ID,需用 FIND_IN_SET 匹配
  1024. $list->whereRaw(sprintf('FIND_IN_SET(%d,l.gameid)', (int)$gameid));
  1025. }
  1026. $list = $list->order('a.create_time desc')
  1027. ->paginate(10, false, ['query' => input('get.')])
  1028. ->each(function($item, $key){
  1029. $item['username'] = stringObfuscation($item['username'],3);
  1030. return $item;
  1031. });
  1032. $this->assign('list', $list);
  1033. $this->assign('page', $list->render());
  1034. $tmpGameList = model('Common/Game')->getAllByCondition('id,name');
  1035. $gameList = array();
  1036. foreach ($tmpGameList as $game) {
  1037. $gameList[ $game['id']] = $game;
  1038. }
  1039. $this->assign('game_list',$gameList);
  1040. return $this->fetch('giftReceiveList');
  1041. }
  1042. /**
  1043. * 获取用户名(礼包领取记录)
  1044. */
  1045. public function checkReceiveUser(){
  1046. $id = input('id' , '' , 'filterAndTrimInput');
  1047. if (empty($id)) $this->error('参数错误!');
  1048. $info = model('Libaolog')->alias('a')
  1049. ->join('cy_libaoinfo l','l.id=a.libaoid')
  1050. ->field('a.username,l.title')
  1051. ->where('a.id',$id)
  1052. ->find();
  1053. $this->insertLog($this->current_node,"查看账号:".$info['username'].",关联礼包名:".$info['title'],151);
  1054. $this->success($info['username']);
  1055. }
  1056. }