Index.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. <?php
  2. namespace app\index\controller;
  3. use think\facade\Db;
  4. use app\middleware\Log;
  5. use think\facade\Cache;
  6. use ReflectionException;
  7. use app\middleware\Safe;
  8. use think\file\UploadedFile;
  9. use \think\response\Json;
  10. use think\facade\Request;
  11. use think\admin\Controller;
  12. use InvalidArgumentException;
  13. use app\service\WeiboService;
  14. use app\admin\model\SystemNotice;
  15. use think\facade\Log as FacadeLog;
  16. use think\db\exception\DbException;
  17. use think\admin\service\SystemService;
  18. use think\exception\FuncNotFoundException;
  19. use think\exception\ClassNotFoundException;
  20. use think\db\exception\DataNotFoundException;
  21. use think\db\exception\ModelNotFoundException;
  22. /**
  23. * Class Index
  24. * @package app\index\controller
  25. */
  26. class Index extends Controller
  27. {
  28. /**
  29. * 获取品牌任务相关配置
  30. *
  31. * @throws FuncNotFoundException
  32. * @throws ClassNotFoundException
  33. * @throws ReflectionException
  34. * @throws DbException
  35. * @throws ModelNotFoundException
  36. * @throws DataNotFoundException
  37. * @return mixed
  38. */
  39. public function brand()
  40. {
  41. $conf = $this->getBrandConfigAndState();
  42. if ($conf instanceof Json) {
  43. return $conf;
  44. }
  45. return $this->successResponse($conf);
  46. }
  47. /**
  48. * 检测登录 通过cookie中的SUB字段的内容,调用用户接口检测登录状态
  49. * @throws ClassNotFoundException
  50. * @throws ReflectionException
  51. * @return mixed
  52. */
  53. public function checkLogin()
  54. {
  55. FacadeLog::info("checkLogin cookies:" . json_encode(Request::post()));
  56. $sub = Request::post('cookie');
  57. $uid = 0;
  58. $userInfoRes = (new WeiboService($uid))->userinfo($sub);
  59. if (empty($userInfoRes) || $userInfoRes['ok'] != 1) {
  60. return $this->response(403, $userInfoRes['msg'] ?? '没有登录');
  61. }
  62. // 使用客户端信息生成token
  63. $token = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_ACCEPT_ENCODING'] . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . get_client_ip(0) . $userInfoRes['data']['uid']);
  64. $user = $userInfoRes['data'];
  65. $userInfo = Db::table('awards_user_info')->where('uid', $user['uid'])->find();
  66. $count = 0;
  67. $isShare = 0;
  68. if (empty($userInfo)) {
  69. $userAttr = [
  70. 'uid' => $user['uid'],
  71. 'portrait' => $user['profile_image_url'],
  72. 'nickname' => $user['name'],
  73. 'is_share' => 0,
  74. 'count' => 1,
  75. 'create_at' => time()
  76. ];
  77. if (0 == Db::table('awards_user_info')->insert($userAttr)) {
  78. return $this->response(5001, '系统错误,请稍后再试~');
  79. }
  80. } else {
  81. $count = Db::table('awards_user_task_log')->where('uid', $user['uid'])->count('id');
  82. $isShare = $userInfo['is_share'];
  83. }
  84. // 生成加密用的密钥和向量
  85. $cipher = "aes-256-gcm";
  86. $ivlen = openssl_cipher_iv_length($cipher);
  87. $iv = bin2hex(openssl_random_pseudo_bytes($ivlen));
  88. $aesKey = bin2hex(openssl_random_pseudo_bytes(32));
  89. // $user = array_merge($user, [
  90. // 'aes_key' => $aesKey,
  91. // 'ase_iv' => $iv,
  92. // ]);
  93. $cacheUser = [
  94. 'aes_key' => $aesKey,
  95. 'ase_iv' => $iv,
  96. 'uid' => $user['uid'],
  97. ];
  98. $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
  99. ->where('end_at', '>=', time())->find();
  100. $isBeginActivity = 1;
  101. if (empty($activity)) {
  102. $isBeginActivity = 0;
  103. }
  104. $userInfo = [];
  105. if ($count > 0) {
  106. $userInfo = Db::table('awards_user_task_log')->alias('l')
  107. ->leftJoin('awards_user_info u', 'l.uid = u.uid')
  108. ->field(['u.nickname', 'u.portrait', 'u.uid', 'l.duration', 'l.number'])
  109. ->order('l.number', 'desc')
  110. ->order('l.duration', 'asc')
  111. ->find();
  112. }
  113. // 缓存用户信息1天
  114. Cache::set('u:' . $token, json_encode($cacheUser), 86400);
  115. return $this->successResponse([
  116. 'user' => $user,
  117. 'token' => $token,
  118. 'isShare' => $isShare,
  119. 'count' => $count,
  120. 'isBeginActivity' => $isBeginActivity,
  121. 'task' => $userInfo
  122. ]);
  123. }
  124. /**
  125. * 是否可以参与游戏
  126. * @throws ClassNotFoundException
  127. * @throws ReflectionException
  128. * @return mixed
  129. */
  130. public function checkRole()
  131. {
  132. $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
  133. ->where('end_at', '>=', time())->find();
  134. if (empty($activity)) {
  135. return $this->response(5002, '活动末开始');
  136. }
  137. $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
  138. $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
  139. return $this->successResponse([
  140. 'isShare' => $userInfo['is_share'],
  141. 'count' => $count
  142. ]);
  143. }
  144. /**
  145. * 提交任务接口
  146. * @throws FuncNotFoundException
  147. * @throws ClassNotFoundException
  148. * @throws DbException
  149. * @throws ModelNotFoundException
  150. * @throws DataNotFoundException
  151. * @return mixed
  152. */
  153. public function submitTask()
  154. {
  155. $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
  156. ->where('end_at', '>=', time())->find();
  157. if (empty($activity)) {
  158. return $this->response(5002, '活动末开始');
  159. }
  160. // if (empty(Safe::$body)) {
  161. // return $this->response(5003, '参数有误');
  162. // }
  163. //
  164. // if (!isset(Safe::$body['duration']) || Safe::$body['duration'] < 1 || Safe::$body['duration'] > 1000) {
  165. // return $this->response(5003, '时长参数有误');
  166. // }
  167. //
  168. // if (!isset(Safe::$body['number']) || Safe::$body['number'] < 0 || Safe::$body['number'] > 1000) {
  169. // return $this->response(5003, '时长参数有误');
  170. // }
  171. //
  172. // $duration = Safe::$body['duration'];
  173. // $number = Safe::$body['number'];
  174. $duration = Request::post("duration");
  175. $number = Request::post("number");
  176. $date = date('Y-m-d');
  177. $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
  178. if (empty($userInfo)) {
  179. return $this->response(403, '没有登录');
  180. }
  181. $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
  182. if ($count >= $userInfo['count']) {
  183. return $this->response(5002, '没有参与次数');
  184. }
  185. $log = [
  186. 'uid' => Safe::$user['uid'],
  187. 'date' => $date,
  188. 'duration' => $duration,
  189. 'number' => $number,
  190. 'create_at' => time()
  191. ];
  192. if (0 == Db::table('awards_user_task_log')->insert($log)) {
  193. return $this->response(5001, '系统错误,请稍后再试~');
  194. }
  195. return $this->successResponse(null, '提交成功');
  196. }
  197. /**
  198. * 提交发布微博接口
  199. * @throws FuncNotFoundException
  200. * @throws ClassNotFoundException
  201. * @throws DbException
  202. * @throws ModelNotFoundException
  203. * @throws DataNotFoundException
  204. * @return mixed
  205. */
  206. public function submitShare()
  207. {
  208. $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
  209. ->where('end_at', '>=', time())->find();
  210. if (empty($activity)) {
  211. return $this->response(5002, '活动末开始');
  212. }
  213. $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
  214. if (empty($userInfo)) {
  215. return $this->response(403, '没有登录');
  216. }
  217. if ($userInfo['is_share'] > 0) {
  218. return $this->response(601, '已发布');
  219. }
  220. // 更新任务状态
  221. $nums = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->update([
  222. 'is_share' => 1,
  223. 'count' => 4,
  224. 'share_at' => time()
  225. ]);
  226. if ($nums) {
  227. return $this->successResponse(null, '提交成功');
  228. } else {
  229. return $this->response(601, '发布失败');
  230. }
  231. }
  232. /**
  233. * 开始游戏
  234. * @return mixed|Json
  235. * @throws DataNotFoundException
  236. * @throws DbException
  237. * @throws ModelNotFoundException
  238. */
  239. public function startGame()
  240. {
  241. $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
  242. ->where('end_at', '>=', time())->find();
  243. if (empty($activity)) {
  244. return $this->response(5002, '活动末开始');
  245. }
  246. $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
  247. if (empty($userInfo)) {
  248. return $this->response(403, '没有登录');
  249. }
  250. $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
  251. if ($count >= $userInfo['count']) {
  252. return $this->response(5002, '没有参与次数');
  253. }
  254. $game = Db::table('awards_user_game')
  255. ->where('uid', '=', Safe::$user['uid'])
  256. ->where('state', '=', 1)
  257. ->find();
  258. if (!empty($game)) {
  259. Db::table('awards_user_game')->where('id', '=', $game['id'])->delete(true);
  260. Db::table('awards_user_game_log')->where('game_id', '=', $game['id'])->delete(true);
  261. }
  262. $gameId = $this->uuid();
  263. $attr = [
  264. 'game_id' => $gameId,
  265. 'uid' => Safe::$user['uid'],
  266. 'begin_at' => time(),
  267. 'end_at' => 0,
  268. 'state' => 1,
  269. 'create_at' => time()
  270. ];
  271. Db::table('awards_user_game')->insert($attr);
  272. return $this->successResponse(['gameId' => $gameId], '开始游戏成功');
  273. }
  274. /**
  275. * 结束游戏
  276. * @return mixed|Json
  277. * @throws DataNotFoundException
  278. * @throws DbException
  279. * @throws ModelNotFoundException
  280. */
  281. public function endGame()
  282. {
  283. $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
  284. ->where('end_at', '>=', time())->find();
  285. if (empty($activity)) {
  286. return $this->response(5002, '活动末开始');
  287. }
  288. $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
  289. if (empty($userInfo)) {
  290. return $this->response(403, '没有登录');
  291. }
  292. $gameId = Request::post("gameId");
  293. $game = Db::table('awards_user_game')
  294. ->where('uid', '=', Safe::$user['uid'])
  295. ->where('game_id', '=', $gameId)
  296. ->where('state', '=', 1)
  297. ->find();
  298. if (empty($game)) {
  299. return $this->response(6001, '游戏不存在');
  300. }
  301. $endAt = time();
  302. Db::table('awards_user_game')->where('game_id', '=', $gameId)->update([
  303. 'end_at' => $endAt,
  304. 'state' => 2,
  305. 'update_at' => time()
  306. ]);
  307. $count = Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->count('id');
  308. if ($count >= $userInfo['count']) {
  309. return $this->response(5002, '没有参与次数');
  310. }
  311. return $this->successResponse(null, '提交成功');
  312. }
  313. /**
  314. * 提交彩蛋
  315. * @return mixed|Json
  316. * @throws DataNotFoundException
  317. * @throws DbException
  318. * @throws ModelNotFoundException
  319. */
  320. public function submitEasterEgg()
  321. {
  322. $easterEgg = Request::post("easterEgg");
  323. if (!in_array($easterEgg, [1, 2, 3,4 ,5 ,6,7, 8, 9, 10, 11, 12, 13, 14, 15])) {
  324. return $this->response(6003, '游戏参数有误');
  325. }
  326. $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
  327. ->where('end_at', '>=', time())->find();
  328. if (empty($activity)) {
  329. return $this->response(5002, '活动末开始');
  330. }
  331. $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
  332. if (empty($userInfo)) {
  333. return $this->response(403, '没有登录');
  334. }
  335. $gameId = Request::post("gameId");
  336. $game = Db::table('awards_user_game')
  337. ->where('uid', '=', Safe::$user['uid'])
  338. ->where('game_id', '=', $gameId)
  339. ->where('state', '=', 1)
  340. ->find();
  341. if (empty($game)) {
  342. return $this->response(6001, '游戏不存在');
  343. }
  344. $log = Db::table('awards_user_game_log')
  345. ->where('uid', '=', Safe::$user['uid'])
  346. ->where('game_id', '=', $gameId)
  347. ->where('draw', '=', $easterEgg)
  348. ->find();
  349. if (!empty($log)) {
  350. return $this->successResponse(null, '提交成功');
  351. }
  352. $log = Db::table('awards_user_game_log')
  353. ->where('uid', '=', Safe::$user['uid'])
  354. ->where('game_id', '=', $gameId)
  355. ->order('create_at', 'desc')
  356. ->find();
  357. if (empty($log)) {
  358. $startTime = $game['begin_at'];
  359. } else {
  360. $startTime = $log['create_at'];
  361. }
  362. $duration = time() - $startTime;
  363. if ($duration < 0) {
  364. return $this->response(6002, '游戏参数有误');
  365. }
  366. $attr = [
  367. 'uid' => Safe::$user['uid'],
  368. 'game_id' => $gameId,
  369. 'draw' => $easterEgg,
  370. 'duration' => $duration,
  371. 'create_at' => time()
  372. ];
  373. Db::table('awards_user_game_log')->insert($attr);
  374. return $this->successResponse(null, '提交成功');
  375. }
  376. function uuid()
  377. {
  378. $chars = md5(uniqid(mt_rand(), true));
  379. $uuid = substr ( $chars, 0, 8 )
  380. . substr ( $chars, 8, 4 )
  381. . substr ( $chars, 12, 4 )
  382. . substr ( $chars, 16, 4 )
  383. . substr ( $chars, 20, 12 );
  384. return $uuid ;
  385. }
  386. /**
  387. * 彩蛋中奖列表
  388. * @return mixed|Json
  389. * @throws DataNotFoundException
  390. * @throws DbException
  391. * @throws ModelNotFoundException
  392. */
  393. public function easterEggDrawList()
  394. {
  395. $orders = Db::table('awards_order')->alias('o')
  396. ->leftJoin('awards_user_info u', 'o.uid = u.uid')
  397. ->leftJoin('awards_gift g', 'o.gift_id = g.id')
  398. ->field(['u.nickname', 'g.name as giftName'])
  399. ->where('o.type', 1)
  400. ->select();
  401. return $this->successResponse($orders);
  402. }
  403. public function rankingDrawList()
  404. {
  405. // $activity = Db::table('awards_activity')->where('end_at', '>', time())->find();
  406. // $isBeginActivity = 1;
  407. // if ($activity) {
  408. $isBeginActivity = 0;
  409. // }
  410. // $orders = [];
  411. // if ($isBeginActivity == 0) {
  412. // $orders = Db::query("select u.nickname, u.portrait, l.uid, l.duration, l.number from awards_user_task_log as l left join awards_user_info as u on l.uid = u.uid
  413. //where u.portrait != '' and u.portrait is not null and l.number >= 15 group by l.uid order by l.id desc limit 50");
  414. // }
  415. $orders = Db::query("select u.nickname, u.portrait, g.name as giftName from awards_order as o
  416. left join awards_user_info as u on o.uid = u.uid
  417. left join awards_gift as g on o.gift_id = g.id where o.type = 2 and o.rank > 0 order by o.rank asc");
  418. return $this->successResponse([
  419. 'isBeginActivity' => $isBeginActivity,
  420. 'list' => $orders
  421. ]);
  422. }
  423. /**
  424. * 头号排行接口
  425. * @throws FuncNotFoundException
  426. * @throws ClassNotFoundException
  427. * @throws DbException
  428. * @throws ModelNotFoundException
  429. * @throws DataNotFoundException
  430. * @return mixed
  431. */
  432. public function topRanking()
  433. {
  434. $ranking = Db::query("select u.nickname, u.portrait, l.uid, l.duration, l.number from awards_user_task_log as l left join awards_user_info as u on l.uid = u.uid
  435. where u.portrait != '' and u.portrait is not null and l.number >= 15 group by l.uid order by l.id desc limit 100");
  436. $userInfo = Db::table('awards_user_task_log')->alias('l')
  437. ->leftJoin('awards_user_info u', 'l.uid = u.uid')
  438. ->field(['u.nickname', 'u.portrait', 'l.uid', 'l.duration', 'l.number'])
  439. ->where('l.uid', '=', Safe::$user['uid'])
  440. ->order('l.number', 'desc')
  441. ->order('l.duration', 'asc')
  442. ->find();
  443. $res = [
  444. 'self' => $userInfo,
  445. 'ranking' => $ranking
  446. ];
  447. return $this->successResponse($res);
  448. }
  449. /**
  450. * 最新排行接口
  451. * @throws FuncNotFoundException
  452. * @throws ClassNotFoundException
  453. * @throws DbException
  454. * @throws ModelNotFoundException
  455. * @throws DataNotFoundException
  456. * @return mixed
  457. */
  458. public function newRanking()
  459. {
  460. $ranking = Db::query("select u.nickname, u.portrait, l.uid, l.duration, l.number from awards_user_task_log as l left join awards_user_info as u on l.uid = u.uid
  461. where u.portrait != '' and u.portrait is not null and l.duration > 15 group by l.uid order by l.create_at desc, l.number desc, l.duration asc limit 50");
  462. $userInfo = Db::table('awards_user_task_log')->alias('l')
  463. ->leftJoin('awards_user_info u', 'l.uid = u.uid')
  464. ->field(['u.nickname', 'u.portrait', 'l.uid', 'l.duration', 'l.number'])
  465. ->where('l.uid', '=', Safe::$user['uid'])
  466. ->order('l.number', 'desc')
  467. ->order('l.duration', 'asc')
  468. ->find();
  469. $res = [
  470. 'self' => $userInfo,
  471. 'ranking' => $ranking
  472. ];
  473. return $this->successResponse($res);
  474. }
  475. /**
  476. * 提交领取信息接口
  477. * @throws FuncNotFoundException
  478. * @throws ClassNotFoundException
  479. * @throws DbException
  480. * @throws ModelNotFoundException
  481. * @throws DataNotFoundException
  482. * @return mixed
  483. */
  484. public function submitReceive()
  485. {
  486. $name = trim(Request::post("name"));
  487. $mobile = trim(Request::post("mobile"));
  488. $address = trim(Request::post("address"));
  489. $giftId = trim(Request::post("giftId"));
  490. $type = trim(Request::post("type"));
  491. $orders = Db::table('awards_order')->where('uid', Safe::$user['uid'])->where('type', $type)->find();
  492. if (empty($orders)) {
  493. return $this->response(5001, '参数有误');
  494. }
  495. $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
  496. if (empty($userInfo)) {
  497. return $this->response(403, '没有登录');
  498. }
  499. if (strlen($name) < 1 || strlen($name) > 50) {
  500. return $this->response(5001, '姓名有误');
  501. }
  502. if (strlen($mobile) != 11) {
  503. return $this->response(5001, '手机号有误');
  504. }
  505. if (strlen($address) < 1 || strlen($address) > 1000) {
  506. return $this->response(5001, '地址有误');
  507. }
  508. // 更新任务状态
  509. $nums = Db::table('awards_order')->where('uid', Safe::$user['uid'])->where('type', $type)->update([
  510. 'name' => $name,
  511. 'mobile' => $mobile,
  512. 'address' => $address,
  513. ]);
  514. if ($nums < 1) {
  515. return $this->response(5001, '系统错误,请稍后再试~');
  516. }
  517. return $this->successResponse(null, '提交成功');
  518. }
  519. /**
  520. * 获取轮播中奖接口
  521. * @throws FuncNotFoundException
  522. * @throws ClassNotFoundException
  523. * @throws DbException
  524. * @throws ModelNotFoundException
  525. * @throws DataNotFoundException
  526. * @return mixed
  527. */
  528. public function getRotationAward() {
  529. $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
  530. ->where('end_at', '>=', time())->find();
  531. if (empty($activity)) {
  532. return $this->response(5002, '活动末开始');
  533. }
  534. $orders = Db::table('awards_order')->alias('o')
  535. ->leftJoin('awards_user_info u', 'o.uid = u.uid')
  536. ->leftJoin('awards_gift g', 'o.gift_id = g.id')
  537. ->field(['u.nickname', 'u.portrait', 'u.uid', 'g.name as giftName'])
  538. ->order('o.id', 'desc')
  539. ->select();
  540. return $this->successResponse($orders);
  541. }
  542. /**
  543. * 排行中奖接口
  544. * @throws FuncNotFoundException
  545. * @throws ClassNotFoundException
  546. * @throws DbException
  547. * @throws ModelNotFoundException
  548. * @throws DataNotFoundException
  549. * @return mixed
  550. */
  551. public function getRankingWinAward() {
  552. $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
  553. ->where('end_at', '>=', time())->find();
  554. if (!empty($activity)) {
  555. return $this->response(5002, '活动末结束');
  556. }
  557. $orders = Db::query("select u.nickname, u.portrait,o.gift_id, g.name as giftName from awards_order as o
  558. left join awards_user_info as u on o.uid = u.uid
  559. left join awards_gift as g on o.gift_id = g.id where o.type = 2 and o.rank > 0 order by o.rank asc");
  560. $isWinAward = 0;
  561. $giftId = 0;
  562. foreach ($orders as $val) {
  563. if ($val['uid'] == Safe::$user['uid'] && !empty($val['rank'])) {
  564. $isWinAward = 1;
  565. $giftId = $val['gift_id'];
  566. break;
  567. }
  568. }
  569. return $this->successResponse([
  570. 'isWinAward' => $isWinAward,
  571. 'giftId' => $giftId
  572. ]);
  573. }
  574. /**
  575. * 抽奖接口
  576. * @throws FuncNotFoundException
  577. * @throws ClassNotFoundException
  578. * @throws DbException
  579. * @throws ModelNotFoundException
  580. * @throws DataNotFoundException
  581. * @return mixed
  582. */
  583. public function getLuckDraw()
  584. {
  585. $userInfo = Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->find();
  586. if ($userInfo['draw_count'] >= 30) {
  587. return $this->response(5002, '抽奖次数已达上线~');
  588. }
  589. Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->update([
  590. 'draw_count' => $userInfo['draw_count'] + 1
  591. ]);
  592. $orders = Db::table('awards_order')->where('uid', Safe::$user['uid'])->where('type', 1)->find();
  593. $isWinAward = 0;
  594. if ($orders) {
  595. return $this->successResponse([
  596. 'isWinAward' => $isWinAward,
  597. 'giftId' => 0
  598. ]);
  599. }
  600. $gifts = Db::table('awards_gift')->where('type', 1)->select();
  601. // $logCount = Db::table('awards_user_task_log')->distinct('uid')->count('id');
  602. /**
  603. * 活动专属周边礼包 id 4:中奖概率30%,每天中出去1个
  604. * 电影票代金券 id 5:中奖概率40%,每天中出去2个
  605. */
  606. $rate = [4 => 30, 5 => 40];
  607. /**
  608. * 活动专属周边礼包 id 4:每天中出去1个
  609. * 电影票代金券 id 5:每天中出去2个
  610. */
  611. $giftDayCount = [4 => 1, 5 => 2];
  612. $limit = 100;
  613. $userRate = rand(1, $limit);
  614. $giftId = 0;
  615. $beginAt = strtotime(date('Y-m-d',time()));
  616. $endAt = time();
  617. foreach ($gifts as $gift) {
  618. // 判断奖品库存
  619. $orderCount = Db::table('awards_order')
  620. ->where('type', 1)
  621. ->where('gift_id', $gift['id'])
  622. ->count('id');
  623. if ($orderCount >= $gift['count']) {
  624. continue;
  625. }
  626. // 判断奖品当天是否有中奖记录
  627. $orderCount = Db::table('awards_order')
  628. ->where('type', 1)
  629. ->where('gift_id', $gift['id'])
  630. ->where('create_at', '>=', $beginAt)
  631. ->where('create_at', '<', $endAt)
  632. ->count('id');
  633. if ($orderCount >= $giftDayCount[$gift['id']]) {
  634. continue;
  635. }
  636. // 判断是否中奖
  637. if ($userRate <= $rate[$gift['id']]) {
  638. $isWinAward = 1;
  639. $giftId = $gift['id'];
  640. }
  641. // 如果参与活动人数 5000人内 有人中奖过,那么不在计算。
  642. // $total = $logCount + 1;
  643. // if ($orderCount == floor($total/$limit)) {
  644. // $isWinAward = 0;
  645. // $giftId = 0;
  646. // break;
  647. // }
  648. //
  649. // for ($i=0;$i<$gift['count'];$i++) {
  650. // $giftRage = rand(0, $limit);
  651. // if ($userRate == $giftRage) {
  652. // $isWinAward = 1;
  653. // $giftId = $gift['id'];
  654. // break;
  655. // }
  656. // }
  657. //
  658. // // 如果参与活动人数 5000人内 还没有人中奖那最后一人必中。
  659. // if ($orderCount < floor($total/$limit) && $isWinAward ==0 && ($total%$limit) == 0) {
  660. // $isWinAward = 1;
  661. // $giftId = $gift['id'];
  662. // break;
  663. // }
  664. }
  665. // 如果中奖 插入用户中奖信息
  666. if ($isWinAward == 1) {
  667. $order = [
  668. 'uid' => Safe::$user['uid'],
  669. 'gift_id' => $giftId,
  670. 'type' => 1,
  671. 'create_at' => time(),
  672. ];
  673. if (0 == Db::table('awards_order')->insert($order)) {
  674. return $this->response(5001, '系统错误,请稍后再试~');
  675. }
  676. }
  677. return $this->successResponse([
  678. 'isWinAward' => $isWinAward,
  679. 'giftId' => $giftId
  680. ]);
  681. }
  682. /**
  683. * 奖品记录接口
  684. * @throws FuncNotFoundException
  685. * @throws ClassNotFoundException
  686. * @throws DbException
  687. * @throws ModelNotFoundException
  688. * @throws DataNotFoundException
  689. * @return mixed
  690. */
  691. public function getAwardLog()
  692. {
  693. $awards = Db::table('awards_order')->alias('o')
  694. ->leftJoin('awards_gift g', 'o.gift_id = g.id')
  695. ->field(['g.name as giftName', 'o.*'])
  696. ->where('o.uid', Safe::$user['uid'])
  697. ->select();
  698. $res = [];
  699. foreach ($awards as $val) {
  700. $type = '抽奖';
  701. if ($val['type'] == 2) {
  702. $type = '排名奖';
  703. }
  704. $isReceive = 1;
  705. if (empty($val['name']) && empty($val['address']) && empty($val['mobile'])) {
  706. $isReceive = 0;
  707. }
  708. $res[] = [
  709. 'giftId' => $val['gift_id'],
  710. 'giftName' => $val['giftName'],
  711. 'typeLabel' => $type,
  712. 'type' => $val['type'],
  713. 'createAt' => date('y-m-d h:i:s', $val['create_at']),
  714. 'address' => $val['address'],
  715. 'name' => $val['name'],
  716. 'mobile' => $val['mobile'],
  717. 'isReceive' => $isReceive
  718. ];
  719. }
  720. return $this->successResponse($res);
  721. }
  722. public function clearGameData()
  723. {
  724. // 更新用户参与状态
  725. Db::table('awards_user_info')->where('uid', Safe::$user['uid'])->update([
  726. 'is_share' => 0,
  727. 'share_at' => 0,
  728. 'count' => 1,
  729. ]);
  730. Db::table('awards_user_task_log')->where('uid', Safe::$user['uid'])->delete();
  731. Db::table('awards_order')->where('uid', Safe::$user['uid'])->delete();
  732. return $this->successResponse(null, '清除成功');
  733. }
  734. /**
  735. * 品牌任务关注接口
  736. * @throws FuncNotFoundException
  737. * @throws ClassNotFoundException
  738. * @throws ReflectionException
  739. * @throws DbException
  740. * @throws ModelNotFoundException
  741. * @throws DataNotFoundException
  742. * @return mixed
  743. */
  744. public function follow()
  745. {
  746. // 先获取品牌任务配置及状态
  747. $conf = $this->getBrandConfigAndState();
  748. if ($conf instanceof Json) {
  749. return $conf;
  750. }
  751. // 已经关注过了
  752. if ($conf['state']['follow_state'] == 1) {
  753. return $this->successResponse([
  754. 'result' => 2,
  755. 'brand' => $conf,
  756. ], '您已经关注过了');
  757. }
  758. // 调用接口关注
  759. $weiboRes = (new WeiboService(Safe::$user['uid']))->add($conf['config']['follow']['id']);
  760. if (empty($weiboRes) || $weiboRes['code'] != 10000) {
  761. return $this->response(600, $weiboRes['msg'] ?? '关注失败~');
  762. }
  763. $date = date('Y-m-d');
  764. $redisKey = $this->getTaskStateRedisKey(intval(Safe::$user['uid']));
  765. // 如果已经完成了另外两项,则标记品牌任务已经完成
  766. $finishState = $conf['state']['finish_state'];
  767. if ($conf['state']['view_state'] == 1 && $conf['state']['forward_state'] == 1) {
  768. $finishState = 1;
  769. }
  770. // 更新任务状态
  771. $nums = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update([
  772. 'follow_state' => 1,
  773. 'finish_state' => $finishState,
  774. ]);
  775. if ($nums) {
  776. $conf['state']['follow_state'] = 1;
  777. $conf['state']['finish_state'] = $finishState;
  778. Cache::set($redisKey, json_encode($conf['state']), 86400);
  779. return $this->successResponse([
  780. 'result' => 1,
  781. 'brand' => $conf,
  782. ], '关注成功');
  783. } else {
  784. return $this->response(601, '更新任务状态失败');
  785. }
  786. }
  787. /**
  788. * 品牌任务转发博文接口
  789. * @throws FuncNotFoundException
  790. * @throws ClassNotFoundException
  791. * @throws ReflectionException
  792. * @throws DbException
  793. * @throws ModelNotFoundException
  794. * @throws DataNotFoundException
  795. * @return mixed
  796. */
  797. public function forward()
  798. {
  799. // 先获取品牌任务配置及状态
  800. $conf = $this->getBrandConfigAndState();
  801. if ($conf instanceof Json) {
  802. return $conf;
  803. }
  804. // 已经转发过了
  805. if ($conf['state']['forward_state'] == 1) {
  806. return $this->successResponse([
  807. 'result' => 2,
  808. 'brand' => $conf,
  809. ], '您已经转发过了');
  810. }
  811. // 调用微博接口转发
  812. $weiboRes = (new WeiboService(Safe::$user['uid']))->repost($conf['config']['forward']['id'], $conf['config']['forward']['content'] ?? '');
  813. if (empty($weiboRes) || $weiboRes['code'] != 10000) {
  814. return $this->response(600, $weiboRes['msg'] ?? '转发失败~');
  815. }
  816. $date = date('Y-m-d');
  817. $redisKey = $this->getTaskStateRedisKey(intval(Safe::$user['uid']));
  818. // 如果已经完成了另外两项,则标记品牌任务已经完成
  819. $finishState = $conf['state']['finish_state'];
  820. if ($conf['state']['view_state'] == 1 && $conf['state']['follow_state'] == 1) {
  821. $finishState = 1;
  822. }
  823. // 更新任务状态
  824. $nums = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update([
  825. 'forward_state' => 1,
  826. 'finish_state' => $finishState,
  827. ]);
  828. if ($nums) {
  829. $conf['state']['forward_state'] = 1;
  830. $conf['state']['finish_state'] = $finishState;
  831. Cache::set($redisKey, json_encode($conf['state']), 86400);
  832. return $this->successResponse([
  833. 'result' => 1,
  834. 'brand' => $conf,
  835. ], '转发成功');
  836. } else {
  837. return $this->response(601, '更新任务状态失败');
  838. }
  839. }
  840. /**
  841. * 获取活动规则
  842. * @throws FuncNotFoundException
  843. * @throws ReflectionException
  844. * @throws InvalidArgumentException
  845. * @throws ClassNotFoundException
  846. * @return mixed
  847. */
  848. public function getRule()
  849. {
  850. $config = SystemService::instance()->getData('activity:rule');
  851. return $this->successResponse($config);
  852. }
  853. /**
  854. * 聚合页配置信息
  855. * @throws FuncNotFoundException
  856. * @throws ReflectionException
  857. * @throws InvalidArgumentException
  858. * @throws ClassNotFoundException
  859. * @return mixed
  860. */
  861. public function groupPageConfig()
  862. {
  863. return $this->successResponse(['config' => SystemService::instance()->getData('group:page:config')]);
  864. }
  865. // public function index()
  866. // {
  867. // $this->redirect('video');
  868. // }
  869. /**
  870. * 聚合页通知获取
  871. * 查询最近20条通知
  872. * @throws DbException
  873. * @throws ModelNotFoundException
  874. * @throws DataNotFoundException
  875. * @return mixed
  876. */
  877. public function notices()
  878. {
  879. $rows = SystemNotice::limit(20)->order('id', 'desc')->select();
  880. return $this->successResponse([
  881. "lists" => $rows,
  882. ]);
  883. }
  884. /**
  885. * 首次弹窗
  886. * 发放邀请函微博
  887. * @return Json
  888. */
  889. public function sendInviteWeibo()
  890. {
  891. $config = SystemService::instance()->getData('group:page:config');
  892. $sendRes = (new WeiboService(Safe::$user['uid']))->status($config['firstDialog']['content']);
  893. if (empty($sendRes) || $sendRes['code'] != 10000) {
  894. return $this->response(403, $sendRes['msg'] ?? '发布失败');
  895. }
  896. Cache::set('u:f:' . Safe::$user['uid'], 1, 15552000);
  897. return $this->successResponse(null, '发布成功!');
  898. }
  899. /**
  900. * 首次弹窗用户未选择发送邀请函
  901. * 标记已经首次弹窗过了
  902. * @return mixed
  903. */
  904. public function setFirst()
  905. {
  906. Cache::set('u:f:' . Safe::$user['uid'], 1, 15552000);
  907. return $this->successResponse(null, '操作成功!');
  908. }
  909. /**
  910. * 标记用户已经浏览过主页了,用户点了去浏览时调用
  911. * @throws FuncNotFoundException
  912. * @throws ClassNotFoundException
  913. * @throws ReflectionException
  914. * @throws DbException
  915. * @throws ModelNotFoundException
  916. * @throws DataNotFoundException
  917. * @return mixed
  918. */
  919. public function setViewed()
  920. {
  921. // 先获取品牌任务配置及状态
  922. $conf = $this->getBrandConfigAndState();
  923. if ($conf instanceof Json) {
  924. return $conf;
  925. }
  926. if ($conf['state']['view_state'] == 1) {
  927. return $this->successResponse([
  928. 'result' => 2,
  929. 'brand' => $conf,
  930. ], '您已经浏览过了');
  931. }
  932. $date = date('Y-m-d');
  933. $redisKey = $this->getTaskStateRedisKey(intval(Safe::$user['uid']));
  934. // 如果已经完成了另外两项,则标记品牌任务已经完成
  935. $finishState = $conf['state']['finish_state'];
  936. if ($conf['state']['forward_state'] == 1 && $conf['state']['follow_state'] == 1) {
  937. $finishState = 1;
  938. }
  939. $nums = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update([
  940. 'view_state' => 1,
  941. 'finish_state' => $finishState,
  942. ]);
  943. if ($nums) {
  944. $conf['state']['view_state'] = 1;
  945. $conf['state']['finish_state'] = $finishState;
  946. Cache::set($redisKey, json_encode($conf['state']), 86400);
  947. return $this->successResponse([
  948. 'result' => 1,
  949. 'brand' => $conf,
  950. ], '浏览成功');
  951. } else {
  952. return $this->response(601, '更新任务状态失败');
  953. }
  954. }
  955. /**
  956. * 用户完成端外分享时调用接口加票
  957. * @throws FuncNotFoundException
  958. * @throws ClassNotFoundException
  959. * @throws ReflectionException
  960. * @throws DbException
  961. * @throws ModelNotFoundException
  962. * @throws DataNotFoundException
  963. * @return mixed
  964. */
  965. public function shareFinishAddVotes()
  966. {
  967. // 先获取品牌任务配置及状态
  968. $conf = $this->getBrandConfigAndState();
  969. if ($conf instanceof Json) {
  970. return $conf;
  971. }
  972. if ($conf['state']['share_add_votes'] == 1) {
  973. return $this->successResponse([
  974. 'result' => 2,
  975. 'brand' => $conf,
  976. ], '您今日已经领取过投票机会了~');
  977. }
  978. // 调用接口给用户发券(加票)
  979. $weiboRes = (new WeiboService(Safe::$user['uid']))->setcoupons($conf['config']['share']['votes']);
  980. if (empty($weiboRes) || $weiboRes['code'] != 10000) {
  981. return $this->response(600, $weiboRes['msg'] ?? '加票失败~');
  982. }
  983. // 标记状态
  984. $date = date('Y-m-d');
  985. $redisKey = $this->getTaskStateRedisKey(intval(Safe::$user['uid']));
  986. $nums = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update([
  987. 'share_add_votes' => 1,
  988. ]);
  989. if ($nums) {
  990. $conf['state']['share_add_votes'] = 1;
  991. Cache::set($redisKey, json_encode($conf['state']), 86400);
  992. return $this->successResponse([
  993. 'result' => 1,
  994. 'brand' => $conf,
  995. ], '加票成功');
  996. } else {
  997. return $this->response(601, '更新任务状态失败');
  998. }
  999. }
  1000. /**
  1001. * 完成品牌任务后领取加票机会接口
  1002. * @throws FuncNotFoundException
  1003. * @throws ClassNotFoundException
  1004. * @throws ReflectionException
  1005. * @throws DbException
  1006. * @throws ModelNotFoundException
  1007. * @throws DataNotFoundException
  1008. * @return mixed
  1009. */
  1010. public function taskFinishAddVotes()
  1011. {
  1012. // 先获取品牌任务配置及状态
  1013. $conf = $this->getBrandConfigAndState();
  1014. if ($conf instanceof Json) {
  1015. return $conf;
  1016. }
  1017. if ($conf['state']['finish_add_votes'] == 1) {
  1018. return $this->successResponse([
  1019. 'result' => 2,
  1020. 'brand' => $conf,
  1021. ], '您今日已经领取过投票机会了~');
  1022. }
  1023. // 未完成品牌任务 领取失败
  1024. if ($conf['state']['finish_state'] == 0) {
  1025. return $this->response(603, '请先完成品牌任务,再来领取加票', [
  1026. 'result' => 0,
  1027. 'brand' => $conf,
  1028. ]);
  1029. }
  1030. // 调用微博接口 给用户发券(加票)
  1031. $weiboRes = (new WeiboService(Safe::$user['uid']))->setcoupons($conf['config']['task']['votes']);
  1032. if (empty($weiboRes) || $weiboRes['code'] != 10000) {
  1033. return $this->response(600, $weiboRes['msg'] ?? '加票失败~');
  1034. }
  1035. // 标记加票成功
  1036. $date = date('Y-m-d');
  1037. $redisKey = $this->getTaskStateRedisKey(intval(Safe::$user['uid']));
  1038. $nums = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update([
  1039. 'finish_add_votes' => 1,
  1040. ]);
  1041. if ($nums) {
  1042. $conf['state']['finish_add_votes'] = 1;
  1043. Cache::set($redisKey, json_encode($conf['state']), 86400);
  1044. return $this->successResponse([
  1045. 'result' => 1,
  1046. 'brand' => $conf,
  1047. ], '加票成功');
  1048. } else {
  1049. return $this->response(601, '更新任务状态失败');
  1050. }
  1051. }
  1052. /**
  1053. * 获取品牌任务配置及状态
  1054. * @throws FuncNotFoundException
  1055. * @throws ReflectionException
  1056. * @throws InvalidArgumentException
  1057. * @throws ClassNotFoundException
  1058. * @throws DbException
  1059. * @throws ModelNotFoundException
  1060. * @throws DataNotFoundException
  1061. * @return \think\response\Json|array
  1062. */
  1063. protected function getBrandConfigAndState()
  1064. {
  1065. $config = SystemService::instance()->getData('brand:task:config');
  1066. $date = date('Y-m-d');
  1067. $dateForRedis = date('Ymd');
  1068. if (empty(Safe::$user['uid'])) {
  1069. $state = [
  1070. // 品牌任务完成状态
  1071. 'finish_state' => 0,
  1072. // 关注子任务状态
  1073. 'follow_state' => 0,
  1074. // 转发子任务状态
  1075. 'forward_state' => 0,
  1076. // 查看浏览主页任务状态
  1077. 'view_state' => 0,
  1078. // 品牌任务完成后是否加票
  1079. 'finish_add_votes' => 0,
  1080. // 分享完成后是否加票
  1081. 'share_add_votes' => 0,
  1082. 'uid' => 0,
  1083. 'date' => $date,
  1084. ];
  1085. } else {
  1086. $redisKey = "t:{$dateForRedis}:" . Safe::$user['uid'];
  1087. $state = Cache::get($redisKey);
  1088. if (empty($state)) {
  1089. // 缓存失败 查数据库
  1090. $state = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->find();
  1091. if (empty($state)) {
  1092. // 当天第一次,初始化数据
  1093. $state = [
  1094. // 品牌任务完成状态
  1095. 'finish_state' => 0,
  1096. // 关注子任务状态
  1097. 'follow_state' => 0,
  1098. // 转发子任务状态
  1099. 'forward_state' => 0,
  1100. // 查看浏览主页任务状态
  1101. 'view_state' => 0,
  1102. // 品牌任务完成后是否加票
  1103. 'finish_add_votes' => 0,
  1104. // 分享完成后是否加票
  1105. 'share_add_votes' => 0,
  1106. 'uid' => Safe::$user['uid'],
  1107. 'date' => $date,
  1108. ];
  1109. if (0 == Db::table('awards_user_task')->insert($state)) {
  1110. return $this->response(5001, '系统错误,请稍后再试~');
  1111. }
  1112. }
  1113. Cache::set($redisKey, json_encode($state), 86400);
  1114. } else {
  1115. $state = json_decode($state, true);
  1116. }
  1117. // 如果未关注状态,查询下已经实际已经关注了
  1118. if ($state['follow_state'] == 0) {
  1119. $weiboRes = (new WeiboService(Safe::$user['uid']))->friends($config['follow']['id']);
  1120. if (isset($weiboRes['data'][$config['follow']['id']]) && $weiboRes['data'][$config['follow']['id']] == 1) {
  1121. $nums = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update(['follow_state' => 1]);
  1122. if ($nums) {
  1123. $state['follow_state'] = 1;
  1124. Cache::set($redisKey, json_encode($state), 86400);
  1125. }
  1126. }
  1127. }
  1128. }
  1129. // 校准状态,可能存在异常情况关注,转发,浏览都完成了,但是总的品牌任务状态没标记成已完成
  1130. if ($state['follow_state'] == 1 && $state['forward_state'] == 1 && $state['view_state'] == 1 && $state['finish_state'] != 1) {
  1131. $nums = Db::table('awards_user_task')->where('uid', Safe::$user['uid'])->where('date', $date)->update(['finish_state' => 1]);
  1132. if ($nums) {
  1133. $state['finish_state'] = 1;
  1134. Cache::set($redisKey, json_encode($state), 86400);
  1135. }
  1136. }
  1137. return [
  1138. 'config' => $config,
  1139. 'state' => $state,
  1140. ];
  1141. }
  1142. /**
  1143. * 获取品牌任务redis 缓存键
  1144. * @param int $uid
  1145. * @return string
  1146. */
  1147. protected function getTaskStateRedisKey(int $uid): string
  1148. {
  1149. $dateForRedis = date('Ymd');
  1150. return "t:{$dateForRedis}:" . $uid;
  1151. }
  1152. /**
  1153. * @param $code
  1154. * @param $msg
  1155. * @param $data
  1156. * @return Json
  1157. */
  1158. protected function response($code, $msg, $data = null)
  1159. {
  1160. return json(
  1161. [
  1162. 'code' => $code,
  1163. 'message' => $msg,
  1164. 'data' => $data,
  1165. 'trackID' => Log::$logID,
  1166. ],
  1167. 200
  1168. );
  1169. }
  1170. /**
  1171. * @param $data
  1172. * @param $msg
  1173. * @return mixed
  1174. */
  1175. protected function successResponse($data, $msg = '操作成功')
  1176. {
  1177. return $this->response(0, $msg, $data);
  1178. }
  1179. }