ChannelQuestionNaireController.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Http\Controllers\Manage\Channel;
  3. use App\Http\Controllers\Manage\BaseController;
  4. use App\Http\Controllers\Manage\Channel\Transformers\ChannelQuestionNaireTransformer;
  5. use App\Modules\Channel\Models\ChannelQuestionNaire;
  6. use App\Modules\Channel\Services\ChannelQuestionNaireService;
  7. use App\Modules\Channel\Services\CompanyService;
  8. use Illuminate\Http\Request;
  9. //结算比例
  10. /**
  11. * 渠道问卷调查
  12. * Class ChannelSwitchController
  13. * @package App\Http\Controllers\Channel\Channel
  14. */
  15. class ChannelQuestionNaireController extends BaseController
  16. {
  17. /**
  18. * 获取问卷调查信息
  19. * @param Request $request
  20. * @return mixed
  21. */
  22. public function get_question_naires(Request $request)
  23. {
  24. $business_name = $request->input('business_name', '');
  25. $params = [];
  26. if ($business_name) {
  27. $params['business_name'] = $business_name;
  28. }
  29. $data = ChannelQuestionNaireService::getQuestionNaires($params, false);
  30. foreach ($data as $item) {
  31. $channel_user_id = $item->channel_user_id;
  32. $distribution_manages_id = $item->distribution_manages_id;
  33. $total_grade = $this->getTotalGradePreMonth($distribution_manages_id, false);
  34. $total_naire_company_count = $this->getNaireCompanyCountPreMonth($distribution_manages_id, false);
  35. $total_grade_pre_month = $this->getTotalGradePreMonth($distribution_manages_id, true);
  36. $naire_company_count_pre_month = $this->getNaireCompanyCountPreMonth($distribution_manages_id, true);
  37. $item->company_count = CompanyService::getCompanyCountByManageId($distribution_manages_id);;
  38. $item->un_naire_company_count = $item->company_count - $naire_company_count_pre_month;
  39. if ($naire_company_count_pre_month == 0) {
  40. $item->average_grade_pre_month = 0;
  41. } else {
  42. $item->average_grade_pre_month = round(($total_grade_pre_month / $naire_company_count_pre_month), 2);
  43. }
  44. if ($total_naire_company_count == 0) {
  45. $item->total_average_grade = 0;
  46. } else {
  47. $item->total_average_grade = round(($total_grade / $total_naire_company_count), 2);
  48. }
  49. }
  50. return response()->pagination(new ChannelQuestionNaireTransformer(), $data);
  51. }
  52. /**
  53. * 获取上个月调查的公司的数量
  54. * @param $channel_user_id
  55. * @return mixed
  56. */
  57. public static function getNaireCompanyCountPreMonth($distribution_manages_id, $isPreMonth = true)
  58. {
  59. return ChannelQuestionNaire::getNaireCompanyCount($distribution_manages_id, $isPreMonth);
  60. }
  61. /**
  62. * 获取商务上个月的总分数
  63. * @param $channel_user_id
  64. */
  65. public static function getTotalGradePreMonth($distribution_manages_id, $isPreMonth = true)
  66. {
  67. return ChannelQuestionNaire::getTotalGrade($distribution_manages_id, $isPreMonth);
  68. }
  69. }