ApiGuestController.php 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: guanxl
  5. * Date: 2018/5/16
  6. * Time: 11:22
  7. * 访客可以访问的API接口
  8. */
  9. namespace App\Http\Controllers;
  10. use App\Libs\AppClient;
  11. use App\Models\Activity;
  12. use App\Models\User;
  13. use App\Services\AccessToken;
  14. use App\Services\BrainstormingService;
  15. use App\Services\CookieService;
  16. use App\Services\DepartmentService;
  17. use App\Services\ErrorMessageService;
  18. use App\Services\OnlineLimitService;
  19. use App\Services\PkService;
  20. use App\Services\PushMessageService;
  21. use App\Services\QuestionService;
  22. use App\Services\SmsService;
  23. use App\Services\TopService;
  24. use App\Services\UserService;
  25. use Illuminate\Http\Request;
  26. use Illuminate\Support\Facades\Config;
  27. use Illuminate\Support\Facades\Cookie;
  28. use Illuminate\Support\Facades\DB;
  29. use Illuminate\Support\Facades\Log;
  30. use Illuminate\Support\Facades\Redis;
  31. use Laravel\Lumen\Routing\Controller as BaseController;
  32. class ApiGuestController extends BaseController
  33. {
  34. protected $userId;
  35. protected $activityId;
  36. protected $oauth;
  37. protected $corpId;
  38. protected $user;
  39. protected $browser;
  40. public function __construct(Request $request)
  41. {
  42. $this->oauth = CookieService::getOauth();
  43. try {
  44. $this->activityId = $request->get("activity_id");
  45. //判断是否已经登录
  46. $userData = CookieService::getBsAuthUser();
  47. if ($userData) {
  48. $user = UserService::getInstance()->getUser($userData["user_id"]);
  49. if ($user) {
  50. if ($this->activityId == $userData["activity_id"]) {
  51. if (AccessToken::getInstance()->getAccessToken($user["user_id"]) != CookieService::getBsAccessToken()) {
  52. CookieService::unsetBsAuth();
  53. }
  54. }
  55. }
  56. }
  57. $activity = BrainstormingService::getInstance()->get($this->activityId);
  58. if (empty($activity)) {
  59. Log::info("api not found activity {$this->activityId}");
  60. die(json_encode(["error" => 302, "message" => config("errormsg.not_found_activity"), "redirect" => env("NOT_FOUND_URL")]));
  61. }
  62. $openId = $request->cookie("oauth_open_id");
  63. if (empty($openId)) {
  64. Log::info(config("errormsg.not_oauth"));
  65. die(json_encode(["error" => 302, "message" => config("errormsg.not_oauth"), "redirect" => env("WEB_URL") . "/frontend?activity_id=" . $this->activityId]));
  66. }
  67. $browser = AppClient::browserType();
  68. $this->browser = $browser;
  69. switch ($activity["client_type"]) {
  70. case "wechat":
  71. if ($browser != AppClient::BROWSER_TYPE_WECHAT) {
  72. ErrorMessageService::forward("请在微信客户端打开链接!");
  73. die;
  74. }
  75. break;
  76. case "wesuit":
  77. if ($browser != AppClient::BROWSER_TYPE_WESUITAPP) {
  78. ErrorMessageService::forward("请在企业微信客户端打开链接!");
  79. die;
  80. }
  81. break;
  82. case "cmb_mobile_oa":
  83. /* if ($browser != AppClient::BROWSER_TYPE_CMB_MOBILE_OA) {
  84. ErrorMessageService::forward("请在招行移事通打开链接!");
  85. die;
  86. }*/
  87. break;
  88. case "pingan":
  89. break;
  90. case "pingan_zhiniao":
  91. if ($browser != AppClient::BROWSER_TYPE_PINGAN_ZHINIAO) {
  92. $url = "http://a.app.qq.com/o/simple.jsp?pkgname=com.pingan.xueyuan";
  93. die(json_encode(["error" => 302, "message" => "", "redirect" => $url]));
  94. }
  95. break;
  96. case "yunzhijia":
  97. if ($browser != AppClient::BROWSER_TYPE_YUNZHIJIA || !AppClient::isMobile()) {
  98. ErrorMessageService::forward("请在云之家移动端打开链接!");
  99. }
  100. break;
  101. case "dingtalk":
  102. if ($browser != AppClient::BROWSER_TYPE_DINGTALK || !AppClient::isMobile()) {
  103. ErrorMessageService::forward("请在钉钉移动端打开链接!");
  104. }
  105. break;
  106. case "kara":
  107. /* if ($browser != AppClient::BROWSER_TYPE_KARA || !AppClient::isMobile()) {
  108. ErrorMessageService::forward("请在信部落移动端打开链接!");
  109. }*/
  110. break;
  111. /* default:
  112. if (!AppClient::isWxBrowser()) {
  113. ErrorMessageService::forward("请在企业微信或微信客户端打开链接!");
  114. die;
  115. }
  116. break;*/
  117. }
  118. $userData = CookieService::getBsAuthUser();
  119. if ($userData) {
  120. Log::info($userData);
  121. $user = UserService::getInstance()->getUser($userData["user_id"]);
  122. if ($user) {
  123. if ($this->activityId == $userData["activity_id"]) {
  124. $this->userId = $userData["user_id"];
  125. $this->user = $user;
  126. $this->corpId = $user["corp_id"];
  127. } else {
  128. CookieService::unsetBsAuth();
  129. }
  130. }
  131. } else {
  132. //用openId身份去登录
  133. $openId = $this->oauth["oauth_open_id"];
  134. $avatar = $this->oauth["oauth_avatar"];
  135. $nickname = $this->oauth["oauth_nickname"];
  136. $platform = $this->oauth["oauth_platform"];
  137. $guid = $this->oauth["oauth_guid"];
  138. $department = $this->oauth["oauth_department"];
  139. $gCorpId = $this->oauth["oauth_gcorp_id"];
  140. if (!empty($this->oauth["oauth_open_id"])) {
  141. Log::info("oauth_open_id:" . $openId);
  142. //校验活动进行方式 wechat 纯微信(导入人员名单) agh_import 微信+企业微信(导人员入名单) agh 微信+企业微信(不导入人员名单) agh_corps 多企业使用
  143. //根据认证方式去处理是否需要新增人员或者单位信息。
  144. switch ($activity['auth_type']) {
  145. case "wechat_auto_add":
  146. UserService::getInstance()->addUserByOpenId($this->activityId, $openId, $avatar, $nickname, $platform);
  147. $user = UserService::getInstance()->auth2($this->activityId, $openId, $avatar, $nickname, $platform);
  148. break;
  149. case "cmb_mobile_oa_add":
  150. UserService::getInstance()->addUserByOpenId($this->activityId, $openId, $avatar, $nickname, $platform);
  151. $user = UserService::getInstance()->auth2($this->activityId, $openId, $avatar, $nickname, $platform);
  152. break;
  153. case "cmb_mobile_oa":
  154. $user = UserService::getInstance()->authByGuid($this->activityId, $openId, $avatar, $nickname, $platform, $guid);
  155. break;
  156. case "yunzhijia_add":
  157. UserService::getInstance()->addUserByOpenId($this->activityId, $openId, $avatar, $nickname, $platform);
  158. $user = UserService::getInstance()->auth2($this->activityId, $openId, $avatar, $nickname, $platform);
  159. break;
  160. case "yunzhijia":
  161. $user = UserService::getInstance()->authByGuid($this->activityId, $openId, $avatar, $nickname, $platform, $guid);
  162. break;
  163. case "dingtalk_add":
  164. UserService::getInstance()->addUserByOpenId($this->activityId, $openId, $avatar, $nickname, $platform);
  165. $user = UserService::getInstance()->auth2($this->activityId, $openId, $avatar, $nickname, $platform);
  166. break;
  167. case "dingtalk":
  168. $user = UserService::getInstance()->authByGuid($this->activityId, $openId, $avatar, $nickname, $platform, $guid);
  169. break;
  170. case "kara_sbu_add":
  171. UserService::getInstance()->addUserByOpenId($this->activityId, $openId, $avatar, $nickname, $platform,$department);
  172. $user = UserService::getInstance()->auth2($this->activityId, $openId, $avatar, $nickname, $platform);
  173. break;
  174. case "kara_add":
  175. UserService::getInstance()->addUserByOpenId($this->activityId, $openId, $avatar, $nickname, $platform);
  176. $user = UserService::getInstance()->auth2($this->activityId, $openId, $avatar, $nickname, $platform);
  177. break;
  178. case "kara":
  179. $user = UserService::getInstance()->authByGuid($this->activityId, $openId, $avatar, $nickname, $platform, $guid);
  180. break;
  181. case "pingan_zhiniao_add":
  182. UserService::getInstance()->addUserByOpenId($this->activityId, $openId, $avatar, $nickname, $platform);
  183. $user = UserService::getInstance()->auth2($this->activityId, $openId, $avatar, $nickname, $platform);
  184. break;
  185. case "pingan_zhiniao":
  186. $user = UserService::getInstance()->authByGuid($this->activityId, $openId, $avatar, $nickname, $platform, $guid);
  187. break;
  188. case "agh":
  189. $ret = UserService::getInstance()->addUserByGuid($this->activityId, $guid, $gCorpId);
  190. if($ret["error"]>0){
  191. CookieService::unsetOauth();
  192. ErrorMessageService::forward("抱歉,你不在(".$ret["corp_short_name"].")活动名单中");
  193. }
  194. $user = UserService::getInstance()->authByGuid($this->activityId, $openId, $avatar, $nickname, $platform, $guid);
  195. break;
  196. case "agh_corps":
  197. UserService::getInstance()->addUserByGuid($this->activityId, $guid, $gCorpId, true);
  198. $user = UserService::getInstance()->authByGuid($this->activityId, $openId, $avatar, $nickname, $platform, $guid);
  199. break;
  200. default:
  201. $user = UserService::getInstance()->auth2($this->activityId, $openId, $avatar, $nickname, $platform);
  202. break;
  203. }
  204. //如果认证为纯微信认证
  205. if ($activity['auth_type'] == "agh") {
  206. //若$user为空,则清除原有cookie信息,重新设置cookie
  207. if (empty($user)) {
  208. if (CookieService::getLoginTrialNum() < 3) {
  209. //清除Oauth的cookie
  210. CookieService::unsetOauth();
  211. CookieService::incrLoginTrialNum();
  212. $this->oauth["oauth_open_id"] = null;
  213. } else {
  214. CookieService::unsetLoginTrialNum();
  215. ErrorMessageService::forward("登录认证失败!");
  216. }
  217. }
  218. }
  219. if ($user) {
  220. $this->user = $user;
  221. $accessToken = AccessToken::getInstance()->create($user);
  222. //生成认证后的登录cookie
  223. CookieService::setBsAuth($user, $accessToken);
  224. Log::info($user);
  225. }
  226. }
  227. $user = UserService::getInstance()->auth2($this->activityId, $openId, $avatar, $nickname, $platform);
  228. if ($user) {
  229. $this->user = $user;
  230. $accessToken = AccessToken::getInstance()->create($user);
  231. CookieService::setBsAuth($user, $accessToken);
  232. }
  233. }
  234. } catch (\Exception $exception) {
  235. Log::info("api not found activity {$this->activityId} exception:" . $exception->getMessage());
  236. Log::info($exception->getTraceAsString());
  237. die(json_encode(["error" => 302, "message" => config("errormsg.not_found_activity"), "redirect" => env("NOT_FOUND_URL")]));
  238. }
  239. }
  240. /**
  241. * 获取活动基本信息
  242. * @param Request $request
  243. * @return \Illuminate\Http\JsonResponse
  244. */
  245. public function baseInfo(Request $request)
  246. {
  247. $data = BrainstormingService::getInstance()->get($this->activityId);
  248. if ($data) {
  249. $time = time();
  250. $data["is_activity_start"] = 0;
  251. $data["is_activity_end"] = 0;
  252. $data["is_job_time"] = 0;
  253. if ($data["start_time"] < $time || $data["start_time"] == 0) {
  254. $data["is_activity_start"] = 1;
  255. }
  256. if ($data["end_time"] < $time) {
  257. $data["is_activity_end"] = 1;
  258. }
  259. $data["limit_time"] = "";
  260. if ($data["is_jobtime_limit"] == 1) {
  261. $isWeekendLimit = true;
  262. if(isset($data["is_weekend_limit"])){
  263. $isWeekendLimit = $data["is_weekend_limit"]? true:false;
  264. }
  265. $w = date("w");
  266. if (($w > 0 && $w < 6)||$isWeekendLimit) {
  267. $jobTimes = json_decode($data["jobtimes"], true);
  268. if (is_array($jobTimes)) {
  269. foreach ($jobTimes as $jobTime) {
  270. $startTime = strtotime($jobTime["start_time"]);
  271. $endTime = strtotime($jobTime["end_time"]);
  272. if ($time >= $startTime && $time <= $endTime) {
  273. $data["is_job_time"] = 1;
  274. }
  275. $data["limit_time"] .= " " . $jobTime["start_time"] . "-" . $jobTime["end_time"];
  276. }
  277. }
  278. }
  279. }
  280. $data["level_star_config"] = json_decode($data["level_star_config"],true);
  281. $name = empty($this->user) ? "" : $this->user["name"];
  282. $data["share_home_title"] = $this->ubb($data["share_home_title"], $data, $name);
  283. $data["share_home_desc"] = $this->ubb($data["share_home_desc"], $data, $name);
  284. $data["share_pk_title"] = $this->ubb($data["share_pk_title"], $data, $name);
  285. $data["share_pk_desc"] = $this->ubb($data["share_pk_desc"], $data, $name);
  286. $data["app_name"] = env("APP_NAME");
  287. $data["app_support"] = env("APP_SUPPORT");
  288. switch ($data["client_type"]){
  289. case "yunzhijia":
  290. $authExtend = json_decode($data["auth_extend"],true);
  291. $data["yzj_app_id"] = $authExtend["yzj_app_id"];
  292. break;
  293. case "cmb_mobile_oa":
  294. $authExtend = json_decode($data["auth_extend"],true);
  295. $data["cmb_app_code"] = $authExtend["cmb_app_code"];
  296. break;
  297. }
  298. $data["activity_time"] = date("Y年m月d日 H:i", $data["start_time"]) . "至" . date("Y年m月d日 H:i", $data["end_time"]);
  299. $ws = substr(env("WEB_URL"),0,5)=="https"? "wss":"ws";
  300. $data["ws_server"] = $ws."://" . $_SERVER["HTTP_HOST"] . "/brainstorming/ws?userdata=".urlencode(Cookie::get("bs_access_user_data"))."&bs_access_token=".urlencode(Cookie::get("bs_access_token"));
  301. unset($data["is_jobtime_limit"]);
  302. unset($data["is_complete_set"]);
  303. unset($data["key"]);
  304. unset($data["app_id"]);
  305. unset($data["status"]);
  306. unset($data["auth_extend"]);
  307. $data["sponsor_corp"] = explode("/",$data["sponsor_corp"]);
  308. return response()->json([
  309. "error" => 0,
  310. "data" => $data
  311. ]);
  312. }
  313. }
  314. /**
  315. * 获得用户信息
  316. * @param Request $request
  317. * @return \Illuminate\Http\JsonResponse
  318. */
  319. public function userInfo(Request $request)
  320. {
  321. $userId = intval($request->get("user_id"));
  322. $userId = $userId > 0 ? $userId : $this->userId;
  323. if ($userId > 0) {
  324. $user = UserService::getInstance()->getUser($userId);
  325. if ($user) {
  326. //判断用户是否可用
  327. if ($user["status"] == 1) {
  328. $data = [
  329. "user_id" => $userId,
  330. "name" => $user["name"],
  331. "headpic_url" => $user["avatar"],
  332. "nickname" => $user["nickname"],
  333. "short_name" => mb_substr($user["name"], -2, 2, "utf-8"),
  334. "department_id" => $user["department_id"],
  335. "department_name" => DepartmentService::getInstance()->getDepartmentName($user["department_id"]),
  336. "knowledge_money" => $user["knowledge_money"],
  337. "is_blockade_success" => $user["is_blockade_success"],
  338. "platform" => $user["platform"],
  339. "is_white_list" => $user["is_white_list"],
  340. "is_over_online" => false,
  341. "online_limit_count" => 0
  342. ];
  343. if (OnlineLimitService::getInstance()->isOverOnline($this->activityId)) {
  344. $data["is_over_online"] = true;
  345. }
  346. $data["online_limit_count"] = OnlineLimitService::getInstance()->onlineLimitCount($this->activityId);
  347. TopService::getInstance()->updateUserTop($userId);
  348. return response()->json([
  349. "error" => 0,
  350. "data" => $data
  351. ]);
  352. }
  353. }
  354. }
  355. $data = [
  356. "user_id" => 0,
  357. "headpic_url" => $this->oauth["oauth_avatar"],
  358. "nickname" => $this->oauth["oauth_nickname"],
  359. "is_not_in_list" => 0,
  360. "platform" => $this->oauth["oauth_platform"]
  361. ];
  362. $brainstorming = BrainstormingService::getInstance()->get($this->activityId);
  363. if ($brainstorming["client_type"] != "wechat") {
  364. $data["is_not_in_list"] = 1;
  365. $data["message"] = "抱歉,你不在本次活动名单中!";
  366. }
  367. return response()->json([
  368. "error" => 0,
  369. "data" => $data
  370. ]);
  371. }
  372. public function otherActivitys()
  373. {
  374. $brainstorming = BrainstormingService::getInstance()->get($this->activityId);
  375. if ($brainstorming) {
  376. $activitys = DB::table("agh_activitys")->where("app_id", 1)
  377. ->where("corp_id", $brainstorming["corp_id"])
  378. ->where("status", 1)->get();
  379. $data = [];
  380. $time = time();
  381. foreach ($activitys as $activity) {
  382. $bs = BrainstormingService::getInstance()->get($activity->activity_id);
  383. $isActivityStart = 0;
  384. $sActivityEnd = 0;
  385. if ($bs["start_time"] < $time || $bs["start_time"] == 0) {
  386. $isActivityStart = 1;
  387. }
  388. if ($bs["end_time"] < $time) {
  389. $sActivityEnd = 1;
  390. }
  391. $topBanner = isset($bs["top_banner"]) ? $bs["top_banner"] : "";
  392. $sponsorCorp = isset($bs["sponsor_corp"]) ? $bs["sponsor_corp"] : "";
  393. $data[] = [
  394. "activity_id" => $bs["activity_id"],
  395. "title" => $bs["title"],
  396. "top_banner" => $topBanner,
  397. "sponsor_corp" => $sponsorCorp,
  398. "is_activity_start" => $isActivityStart,
  399. "is_activity_end" => $sActivityEnd,
  400. "activtiy_tims" => date("Y年m月d日 H:i", $bs["start_time"]) . "至" . date("Y年m月d日 H:i", $bs["end_time"])
  401. ];
  402. }
  403. return response()->json([
  404. "error" => 0,
  405. "data" => $data
  406. ]);
  407. } else {
  408. return response()->json([
  409. "error" => 404,
  410. "message" => "找不到活动信息"
  411. ]);
  412. }
  413. }
  414. /**
  415. * 获取题库分类
  416. */
  417. public function getClass(Request $request){
  418. $activity_id = $this -> activityId;
  419. try {
  420. $class_direct = QuestionService::getInstance() ->getClassDirect($activity_id);
  421. $class_not_direct = QuestionService::getInstance() ->getClassNotDirect($activity_id);
  422. if ($class_direct || $class_not_direct){
  423. $direct = array();
  424. $not_direct = array();
  425. $tmp_direct = array();
  426. $tmp_not_direct = array();
  427. foreach ($class_direct as $key => $c) {
  428. $tmp = json_decode($c,256);
  429. array_push($direct,$tmp);
  430. $tmp_direct[$key] = $tmp["category_id"];
  431. }
  432. array_multisort($tmp_direct,SORT_ASC ,SORT_REGULAR ,$direct);
  433. foreach ($class_not_direct as $key => $c) {
  434. $tmp = json_decode($c,256);
  435. array_push($not_direct,$tmp);
  436. $tmp_not_direct[$key] = $tmp["category_id"];
  437. }
  438. array_multisort($tmp_not_direct,SORT_ASC ,SORT_REGULAR ,$not_direct);
  439. return response()->json([
  440. "error" => 0,
  441. "direct" => $direct,
  442. "not_direct" => $not_direct
  443. ]);
  444. }return response()->json([
  445. "error" => 1000,
  446. "message" => "暂无题库!"
  447. ]);
  448. }catch (\Exception $exception) {
  449. Log::info($exception->getTraceAsString());
  450. return response()->json([
  451. "error" => 500,
  452. "message" => "服务器内部错误"
  453. ]);
  454. }
  455. }
  456. /**
  457. * 获取PK房间信息
  458. */
  459. public function room(Request $request)
  460. {
  461. $roomId = intval($request->get("room_id"));
  462. if ($roomId > 0) {
  463. try {
  464. $room = PkService::getInstance()->getRoomInfo($roomId);
  465. if ($room) {
  466. if ($this->userId > 0) {
  467. Redis::sadd("bs_pk_room_joins:" . $roomId, $this->userId);
  468. }
  469. $pkUserInfo = PkService::getInstance()->getPkUserInfo($room["sponsor_user_id"], $room["challenger_user_id"]);
  470. $data = [
  471. "room_id" => $roomId,
  472. "knowledge_money" => $room["knowledge_money"],
  473. "sponsor_score" => $room["sponsor_score"],
  474. "challenger_score" => $room["challenger_score"],
  475. "win_user_id" => $room["win_user_id"],
  476. "status" => $room["status"],
  477. "create_time" => $room["create_time"]
  478. ];
  479. $data = array_merge($data, $pkUserInfo);
  480. return response()->json([
  481. "error" => 0,
  482. "data" => $data
  483. ]);
  484. } else {
  485. return response()->json([
  486. "error" => 17000,
  487. "message" => "PK已经结束"
  488. ]);
  489. }
  490. } catch (\Exception $exception) {
  491. Log::info("get Room Info {$roomId} exception:" . $exception->getMessage());
  492. Log::info($exception->getTraceAsString());
  493. return response()->json([
  494. "error" => 500,
  495. "message" => "服务器内部错误"
  496. ]);
  497. }
  498. } else {
  499. return response()->json([
  500. "error" => 404,
  501. "message" => "PK房间不存在"
  502. ]);
  503. }
  504. }
  505. /**
  506. * @param Request $request
  507. * @return \Illuminate\Http\JsonResponse
  508. * @throws \Exception
  509. */
  510. public function sendsms(Request $request)
  511. {
  512. try {
  513. $phone = $request->json("phone");
  514. $user = User::where("activity_id", $this->activityId)->where("phone", $phone)->where("status", 1)->first();
  515. if ($user) {
  516. if (empty($user->open_id)) {
  517. \Aliyun\Core\Config::load();
  518. $verifyCode = random_int(100000, 999999);
  519. $ret = SmsService::sendSms($phone, $verifyCode);
  520. //Log::info($ret);
  521. Log::info(CookieService::getOauth());
  522. Log::info($phone);
  523. //todo send sms
  524. Redis::set("bs_sms_verify_code:" . $phone, $verifyCode);
  525. Redis::expire("bs_sms_verify_code:" . $phone, 900);
  526. return response()->json([
  527. "name" => $user['name'],
  528. "error" => 0,
  529. "message" => "OK"
  530. ]);
  531. } else {
  532. return response()->json([
  533. "error" => 1000,
  534. "message" => "工号:{$phone}已经被绑定!"
  535. ]);
  536. }
  537. } else {
  538. return response()->json([
  539. "error" => 1000,
  540. "message" => "工号:{$phone}不在此次活动名单内!"
  541. ]);
  542. }
  543. } catch (\Exception $exception) {
  544. Log::info("Send sms exception:" . $exception->getMessage());
  545. Log::info("Trace message:" . $exception->getTraceAsString());
  546. return response()->json([
  547. "error" => 500,
  548. "message" => config("errMsg.server_error")
  549. ]);
  550. }
  551. }
  552. public function userbind(Request $request)
  553. {
  554. $phone = $request->json("phone");
  555. $openId = $request->cookie("oauth_open_id");
  556. // $verifycode = $request->json("verifycode");
  557. $user = User::where("activity_id", $this->activityId)->where("phone", $phone)->where("status", 1)->first();
  558. if ($user) {
  559. if (empty($user->open_id)) {
  560. $user->open_id = $openId;
  561. $user->save();
  562. //添加到agh_wechats
  563. DB::select("replace into agh_wechats set open_id='{$openId}',phone='{$phone}'");
  564. return response()->json([
  565. "error" => 0,
  566. "message" => "OK"
  567. ]);
  568. } else {
  569. return response()->json([
  570. "error" => 1000,
  571. "message" => "工号:{$phone}已经被绑定!"
  572. ]);
  573. }
  574. } else {
  575. return response()->json([
  576. "error" => 1000,
  577. "message" => "工号:{$phone}不在此次活动名单内!"
  578. ]);
  579. }
  580. }
  581. protected function ubb($str, $brainstorming, $name)
  582. {
  583. $str = str_replace("[活动标题]", $brainstorming["title"], $str);
  584. $str = str_replace("[姓名]", $name, $str);
  585. return $str;
  586. }
  587. }