ApiController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace App\Http\Controllers\Web\Share;
  3. use App\Http\Controllers\Web\WebBaseController;
  4. use Illuminate\Support\Facades\Auth;
  5. use App\Repositories\PmsRepository;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Http\Request;
  8. class ApiController extends WebBaseController
  9. {
  10. protected $user;
  11. protected $pmsRepository;
  12. public function __construct(PmsRepository $pmsRepository)
  13. {
  14. header('Access-Control-Allow-Origin:*');
  15. header('Access-Control-Allow-Methods:GET,POST,PUT,DELETE');
  16. header('Access-Control-Allow-Headers:Origin, Content-Type, Cookie, Accept');
  17. header('Access-Control-Allow-Credentials:true');
  18. $this->pmsRepository = $pmsRepository;
  19. }
  20. public function getUser()
  21. {
  22. $res['isLogin'] = 1;
  23. $res['status'] = 1;
  24. $res['user'] = [
  25. 'name' => '郑明炜',
  26. 'pmsNum' => 5
  27. ];
  28. return json_encode($res);
  29. $user = parent::getLoginUser();
  30. $res = [];
  31. if(!$user){
  32. $res['isLogin'] = 0;
  33. $res['status'] = 1;
  34. $res['user'] = null;
  35. }else{
  36. $condition4 = [
  37. 'msgtouid' => $user->id,
  38. 'utype' => $user->utype,
  39. 'new'=>1,
  40. ];
  41. $pms = $this->pmsRepository->getPmsCount($condition4);
  42. switch ($user->utype){
  43. case '1':
  44. $name = $user->companyname;
  45. break;
  46. case '2':
  47. $memberService=app('App\Services\Person\MemberService');
  48. $name = $memberService->getName();
  49. break;
  50. }
  51. $res['isLogin'] = 1;
  52. $res['status'] = 1;
  53. $res['user'] = [
  54. 'name' => $name,
  55. 'pmsNum' => $pms
  56. ];
  57. }
  58. return json_encode($res);
  59. }
  60. public function getSelectData()
  61. {
  62. $trade = DB::table('share_trade')->get();
  63. $result = [];
  64. foreach ($trade as $k => $v){
  65. $sub = DB::table('share_job')->where('trade',$v->id)->get()->toArray();
  66. $sub_opt = [];
  67. foreach($sub as $key => $val){
  68. $item = [
  69. 'value' => $val->id,
  70. 'label' => $val->name
  71. ];
  72. array_push($sub_opt,$item);
  73. }
  74. $item = [
  75. 'value' => $v->id,
  76. 'label' => $v->name,
  77. 'sub' => $sub_opt
  78. ];
  79. array_push($result,$item);
  80. }
  81. return json_encode($result);
  82. }
  83. public function getShareHallData(Request $request)
  84. {
  85. $type = intval($request->input('type'));
  86. $trade = intval($request->input('trade'));
  87. $job = intval($request->input('job'));
  88. $page = intval($request->input('page'));
  89. $where = [
  90. ['id','>=',1]
  91. ];
  92. if($type > 0){
  93. $where[] = ['role','=',$type];
  94. }
  95. if($trade > 0){
  96. $where[] = ['trade','=',$trade];
  97. }
  98. if($job > 0){
  99. $where[] = ['pro','=',$job];
  100. }
  101. $list = DB::table('share')->where($where)->paginate(10);
  102. $result = [
  103. 'total' => $list->total(),
  104. 'data' => []
  105. ];
  106. if($list->total() > 0){
  107. $trade = DB::table('share_trade')->pluck('name', 'id');
  108. $job = DB::table('share_job')->pluck('name', 'id');
  109. foreach($list as $k => $v){
  110. if($v->utype == 1){
  111. $info = DB::table('member_infos')->where('uid',$v->uid)->first();
  112. }else{
  113. $info = DB::table('companys')->where('id',$v->uid)->first();
  114. }
  115. $item = [];
  116. $item['name'] = $v->utype == 1 ? substr($info->realname,0,3) . ($info->sex == 1 ? '先生' : '女士') : $info->companyname;
  117. $item['utype'] = $v->utype == 1 ? "个人" : "企业";
  118. $item['role'] = $v->role == 1 ? "供应" : "需求";
  119. switch($v->type){
  120. case 1:
  121. $item['type'] = '小时工';
  122. break;
  123. case 2:
  124. $item['type'] = '劳务派遣';
  125. break;
  126. case 3:
  127. $item['type'] = '委托招聘';
  128. break;
  129. case 4:
  130. $item['type'] = '服务外包';
  131. break;
  132. case 5:
  133. $item['type'] = '其它';
  134. break;
  135. }
  136. $item['trade'] = $trade[$v->trade];
  137. $item['job'] = $job[$v->pro];
  138. $item['area'] = $v->area;
  139. $item['time'] = $v->time;
  140. $item['salary'] = $v->salary;
  141. $item['number'] = stripos($v->number,'人') ? $v->number : $v->number . '人';
  142. $item['remark'] = $v->remark;
  143. $item['contact'] = [
  144. 'name' => $item['name'],
  145. 'email' => $info->email,
  146. 'phone' => $info->mobile
  147. ];
  148. array_push($result['data'],$item);
  149. }
  150. }
  151. return json_encode($result);
  152. }
  153. public function getMyData()
  154. {
  155. $list = DB::table('share')->where('uid',59412)->get();
  156. $user = parent::getLoginUser();
  157. }
  158. }