ChannelQuestionNaireController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Http\Controllers\Channel\Channel;
  3. use App\Http\Controllers\Channel\BaseController;
  4. use App\Modules\Channel\Models\ChannelQuestionNaire;
  5. use App\Modules\Channel\Services\ChannelQuestionNaireService;
  6. use App\Modules\Channel\Services\ChannelUserService;
  7. use Illuminate\Http\Request;
  8. //结算比例
  9. /**
  10. * 渠道问卷调查
  11. * Class ChannelSwitchController
  12. * @package App\Http\Controllers\Channel\Channel
  13. */
  14. class ChannelQuestionNaireController extends BaseController
  15. {
  16. /**
  17. * 添加问卷调查
  18. * @param Request $request
  19. * @return mixed
  20. */
  21. public function add_question_naire(Request $request)
  22. {
  23. $id = $request->input('id', '');
  24. $reply_grade = $request->input('reply_grade', '');
  25. $business_name = ChannelQuestionNaireService::getNickName($this->getChannelUserId());
  26. if (!$id || !$reply_grade) {
  27. return response()->error("PARAM_EMPTY");
  28. }
  29. $result = ChannelQuestionNaireService::updateInfo($id, $reply_grade, $business_name);
  30. if ($result) {
  31. return response()->success();
  32. } else {
  33. return response()->error("HANDLE_FAILED");
  34. }
  35. }
  36. /**
  37. * 获取渠道的问卷调查是否显示或者提交过
  38. * @param Request $request
  39. */
  40. function checkQuestionNaireShow(Request $request)
  41. {
  42. $isShow = 0;
  43. $isReply = 0;
  44. $channel_user_id = $this->getChannelUserId();
  45. $channel_user = ChannelUserService::getById($channel_user_id);
  46. if ($channel_user) {
  47. $isShow = ChannelQuestionNaire::checkQuestionNaire($channel_user->company_id, false);
  48. $isReply = ChannelQuestionNaire::checkQuestionNaire($channel_user->company_id, true);
  49. }
  50. $isShow = ($isShow > 0) ? true : false;
  51. $isReply = ($isReply > 0) ? true : false;
  52. $business_name = ChannelQuestionNaireService::getNickName($channel_user_id);
  53. return response()->success(['isShow' => $isShow, 'nickName' => $business_name, 'isReply' => $isReply]);
  54. }
  55. /**
  56. * 设置问卷调查的显示状态
  57. * @param Request $request
  58. * @return mixed
  59. */
  60. function setQuestionNaireShowed(Request $request)
  61. {
  62. $channel_user_id = $this->getChannelUserId();
  63. $business_name = ChannelQuestionNaireService::getNickName($channel_user_id);
  64. //查询这个channel_user_id本月是否已经显示过
  65. $channel_user = ChannelUserService::getById($channel_user_id);
  66. $company_id = $channel_user->company_id;
  67. $distribution_manages_id = $channel_user->distribution_manages_id;
  68. $result = ChannelQuestionNaire::geFirstQuestionNaire($company_id);
  69. if (!$result) {
  70. $result = ChannelQuestionNaireService::addQuestionNaire(compact('channel_user_id', 'business_name', 'distribution_manages_id', 'company_id'));
  71. }
  72. if ($result) {
  73. return response()->success(['id' => $result->id]);
  74. } else {
  75. return response()->error("HANDLE_FAILED");
  76. }
  77. }
  78. }