Index.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\api\controller;
  3. use app\model\Activity;
  4. use app\model\Customer;
  5. use app\model\CustomerClue;
  6. use app\model\CustomerVisitLog;
  7. use app\model\MaterialCase;
  8. use app\model\Decostyle;
  9. use app\model\Org;
  10. use app\model\Employee;
  11. use app\model\Construction;
  12. use app\model\Community;
  13. use app\model\MaterialEvidence;
  14. use app\model\Building;
  15. use app\model\BuildingSpecialEmp;
  16. use app\model\CompanyVrshow;
  17. class Index extends Base
  18. {
  19. /*
  20. * 首页顶部汇总数据
  21. */
  22. public function datacount()
  23. {
  24. $first = date('Y-m-d 00:00:00', strtotime('first day of this month'));
  25. $last = date('Y-m-d 23:59:59', strtotime('last day of this month'));
  26. // 本月建档
  27. $customer = Customer::where([['addtime', 'between', [$first, $last]], ['employee_id', '=', $this->request->token['employee_id']]])->count();
  28. // 本月定金
  29. $ding = CustomerVisitLog::where([['addtime', 'between', [$first, $last]], ['employee_id', '=', $this->request->token['employee_id']], ['state', 'in', CustomerVisitLog::changeState('交定', 'chaos')]])->count();
  30. // 本月签单
  31. $sign = CustomerVisitLog::where([['addtime', 'between', [$first, $last]], ['employee_id', '=', $this->request->token['employee_id']], ['state', 'in', CustomerVisitLog::changeState('签单', 'chaos')]])->count();
  32. // 本月线索
  33. $clue = CustomerClue::where([['addtime', 'between', [$first, $last]], ['employee_id', '=', $this->request->token['employee_id']]])->count();
  34. // 现有客户总量
  35. $total = Customer::where([['employee_id', '=', $this->request->token['employee_id']]])->count();
  36. // 数据整理
  37. $data = [
  38. 'ding' => $ding,
  39. 'sign' => $sign,
  40. 'customer' => $customer,
  41. 'clue' => $clue
  42. ];
  43. return json(['code' => self::success, 'month' => $data, 'total' => $total]);
  44. }
  45. //批量审核回答
  46. public function all_approve_comment()
  47. {
  48. $data['id'] = input('id');
  49. $data['status'] = input('status', 0);
  50. $data['sum'] = mt_rand(1000, 333444);
  51. return json(['code' => 0, 'data' => $data, 'count' => 0, 'msg' => '获取成功']);
  52. exit;
  53. }
  54. //案例,风格,设计师,在施工地,小区楼盘,业主好评等数量统计
  55. public function afszxy_count()
  56. {
  57. $token = $this->request->token;
  58. $where[] = ['type', '=', 0];
  59. $where[] = ['root_id', '=', $token['root_org']];
  60. $communityArr = Community::where($where)->field('id,name,pinyin,case_num')->select()->toArray();
  61. $comidlist = array_column($communityArr, 'id');
  62. $case_num = MaterialCase::where([['community_id', 'in', $comidlist], ['del', '=', 0], ['publish', '=', 1]])->count();
  63. $style_num = Decostyle::where([['root_id', '=', $token['root_org']], ['type', '=', 0]])->count();
  64. $w[] = ['path', 'like', $token['root_org'] . '-%'];
  65. $w[] = ['org_type', '=', 2];
  66. $orgs = Org::where($w)->column('id');
  67. $designer_num = Employee::where([['org_id', 'in', $orgs], ['root_id', '=', $token['root_org']], ['show', '=', 0], ['state', '=', '在职']])->count();
  68. $construction_num = Construction::where([['root_id', '=', $token['root_org']],['del','=',0],['status','=',1]])->count();
  69. $employee_id = $this->request->token['employee_id'];
  70. //查询设置可见人信息
  71. $special = BuildingSpecialEmp::where('root_id', $this->request->token['root_org'])->value('assign_employee');
  72. $assign_employee = !empty($special) ? explode(',', $special) : [];
  73. if (in_array($employee_id, $assign_employee)) {
  74. $communities_num = Building::where('root_id', '=', $token['root_org'])->count();
  75. } else {
  76. $communities_num = Building::where('root_id', '=', $token['root_org'])->where(function ($query) use ($employee_id) {
  77. $query->whereRaw("FIND_IN_SET(" . $employee_id . " , assign_employee)")
  78. ->whereOr('assign_employee', '=', NULL)
  79. ->whereOr('assign_employee', '=', '');
  80. })->where(function ($query) use ($employee_id) {
  81. $query->whereRaw("`from` = 0 or (`from` =1 and `org_id` =" . $this->request->token['org_id'] . ") or ( `from` = 1 and (FIND_IN_SET(" . $employee_id . " , assign_employee)))");
  82. })->count();
  83. }
  84. $evidence_num = MaterialEvidence::where([['del', '=', 0], ['root_id', '=', $token['root_org']], ['publish', '=', 1]])->count();
  85. // 活动数量统计
  86. $activity_num = Activity::where([['del', '=', 0], ['show', '=', 1], ['root_id', '=', $token['root_org']], ['end_date', '>=', date('Y-m-d')]])->count();
  87. /**----------------需要演示乐尚企业,展示数量进行调整,正式使用系统时删除此代码------------------------*/
  88. if($token['root_org'] == 1793) {
  89. $case_num = 2680;
  90. $evidence_num = 1652;
  91. $construction_num = 1286;
  92. }
  93. /*-----------------------------------------------------------------------------------------------------*/
  94. $data = ['case_num' => $case_num, 'style_num' => $style_num, 'designer_num' => $designer_num, 'construction_num' => $construction_num, 'communities_num' => $communities_num, 'evidence_num' => $evidence_num, 'activity_num' => $activity_num
  95. ];
  96. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
  97. }
  98. /**
  99. * 公司线上展厅列表
  100. */
  101. public function compvrshow_list()
  102. {
  103. $token = $this->request->token;
  104. $where[] = ['type', '=', 1];
  105. $where[] = ['root_id', '=', $token['root_org']];
  106. $list = CompanyVrshow::where($where)->select()->toArray();
  107. return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']);
  108. }
  109. }