Task.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace App\Http\Controllers\Fpdx;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\Controllers\Wechat\Media;
  6. use App\Http\Controllers\Wechat\Kfaccount;
  7. use App\Http\Controllers\Core\User;
  8. use App\Http\Controllers\Core\Ding;
  9. use App\Models\Fpdx\TaskModel;
  10. use App\Models\User\UserModel;
  11. use App\Models\Fpdx\RoomModel;
  12. use App\Models\Fpdx\ActivityModel;
  13. class Task extends Controller
  14. {
  15. /**
  16. * 完成任务通知
  17. * @param Request $request
  18. * @return array|mixed
  19. * @throws \ApiException
  20. */
  21. public function complate(Request $request)
  22. {
  23. if (
  24. empty($request->room_id)
  25. || empty($request->day)
  26. || empty($request->uid)
  27. ) {
  28. return [
  29. 'code' => 10005,
  30. 'msg' => '参数错误'
  31. ];
  32. }
  33. // uid -> 绑定openid
  34. $openData = User::getOpenidByUid($request->uid);
  35. // 期数,房间号,匹配对象uid
  36. $roomModel = new RoomModel();
  37. $room = $roomModel->getRoom($request->room_id, $request->uid);
  38. // 匹配对象照片;
  39. $pairUser = UserModel::find($room->member[0]);
  40. // 任务及信息推送
  41. switch ($request->day) {
  42. case '1':
  43. // 任务完成推送
  44. $content = "你已经完成第一天的恋爱任务!解锁对方交友卡片,<a href='http://www.pocketuniversity.cn/ChargePartner/Http/index?media_id=gh_b598cb7474d8&room_id={$request->room_id}&base_route=couple&page=ucard&ucard_id={$pairUser->uid}&from=fpdx'>点此查看</a>";
  45. $array = [
  46. 'touser' => $openData['openid'],
  47. 'content' => $content,
  48. 'kf_account' => 'notice@admin'
  49. ];
  50. Kfaccount::text($array);
  51. break;
  52. case '2':
  53. if (!$pairUser->check_photo) {
  54. break;
  55. }
  56. // 任务完成推送
  57. $content = "你已经完成第二天的恋爱任务!解锁对方照片,<a href='http://www.pocketuniversity.cn/ChargePartner/Http/index?media_id=gh_b598cb7474d8&room_id={$request->room_id}&base_route=couple&page=ucard&ucard_id={$pairUser->uid}&from=fpdx'>点此查看</a>";
  58. $array = [
  59. 'touser' => $openData['openid'],
  60. 'content' => $content,
  61. 'kf_account' => 'notice@admin'
  62. ];
  63. Kfaccount::text($array);
  64. // 交友照片推送
  65. $img = "http://oss.pocketuniversity.cn{$pairUser->photo_src}";
  66. $response = Media::uploadImg($img);
  67. if ($response['code'] == 0) {
  68. Kfaccount::image($openData['openid'], ['media_id' => $response['data']['media_id']]);
  69. } else {
  70. return $response;
  71. }
  72. break;
  73. case '3':
  74. if (!$pairUser->check_contact) {
  75. break;
  76. }
  77. // 任务完成推送
  78. $content = "你已经完成第三天的恋爱任务!解锁对方联系方式,<a href='http://www.pocketuniversity.cn/ChargePartner/Http/index?media_id=gh_b598cb7474d8&room_id={$request->room_id}&base_route=couple&page=ucard&ucard_id={$pairUser->uid}&from=fpdx'>点此查看</a>";
  79. $array = [
  80. 'touser' => $openData['openid'],
  81. 'content' => $content,
  82. 'kf_account' => 'notice@admin'
  83. ];
  84. Kfaccount::text($array);
  85. // 联系方式推送
  86. $content_1 = "TA的联系方式是:";
  87. $content = "";
  88. if ($pairUser->qq) {
  89. $content .= "{$pairUser->qq}(QQ)|";
  90. }
  91. if ($pairUser->weixin) {
  92. $content .= "{$pairUser->weixin}(微信)";
  93. }
  94. if (!empty($content)) {
  95. $content = $content_1 . $content;
  96. $array = [
  97. 'touser' => $openData['openid'],
  98. 'content' => $content,
  99. 'kf_account' => 'notice@admin'
  100. ];
  101. Kfaccount::text($array);
  102. break;
  103. }
  104. }
  105. return [
  106. 'code' => 0,
  107. 'msg' => '成功'
  108. ];
  109. }
  110. /**
  111. * 自动创建分配对象当前期cp任务
  112. */
  113. public static function autoCreateCpTask()
  114. {
  115. $taskModel = new TaskModel();
  116. $activitys = ActivityModel::getActivitys();
  117. $stage_id = $activitys['next'];
  118. $task = $taskModel->where('term', $stage_id)->first();
  119. if (collect($task)->isEmpty()) {
  120. $lastTask = $taskModel->where('term', $activitys['last'])->get();
  121. if (collect($lastTask)->isEmpty()) {
  122. Ding::robot([
  123. 'title' => '[分配对象]CP任务创建提醒',
  124. 'text' => "尝试创建分配对象第「{$stage_id}」期CP任务...\n没有找到上期任务...\n放弃创建\n"
  125. ]);
  126. } else {
  127. foreach ($lastTask as $value) {
  128. $taskModel->create([
  129. 'data' => $value->data,
  130. 'term' => $stage_id,
  131. 'day' => $value->day
  132. ]);
  133. }
  134. Ding::robot([
  135. 'title' => '[分配对象]CP任务创建提醒',
  136. 'text' => "尝试创建分配对象第「{$stage_id}」期CP任务...\n创建成功\n"
  137. ]);
  138. }
  139. } else {
  140. Ding::robot([
  141. 'title' => '[分配对象]CP任务创建提醒',
  142. 'text' => "尝试创建分配对象第「{$stage_id}」期CP任务...\n该任务易存在...\n放弃创建\n"
  143. ]);
  144. }
  145. }
  146. }