ShareController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. namespace App\Http\Controllers\Web\Share;
  3. use App\Http\Controllers\Web\WebBaseController;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Http\Request;
  6. use App\Services\Share\ShareService;
  7. class ShareController extends WebBaseController
  8. {
  9. protected $shareService;
  10. public function __construct(ShareService $shareService)
  11. {
  12. $this->shareService = $shareService;
  13. }
  14. public function index()
  15. {
  16. return view('app.share.index');
  17. }
  18. public function getSelectData()
  19. {
  20. $trade = DB::table('share_trade')->get();
  21. $result = [];
  22. foreach ($trade as $k => $v){
  23. $sub = DB::table('share_job')->where('trade',$v->id)->get()->toArray();
  24. $sub_opt = [];
  25. foreach($sub as $key => $val){
  26. $item = [
  27. 'value' => $val->id,
  28. 'label' => $val->name
  29. ];
  30. array_push($sub_opt,$item);
  31. }
  32. $item = [
  33. 'value' => $v->id,
  34. 'label' => $v->name,
  35. 'sub' => $sub_opt
  36. ];
  37. array_push($result,$item);
  38. }
  39. return json_encode($result);
  40. }
  41. public function getShareHallData(Request $request)
  42. {
  43. $type = intval($request->input('type'));
  44. $trade = intval($request->input('trade'));
  45. $job = intval($request->input('job'));
  46. //$page = intval($request->input('page',10));
  47. $where = [
  48. ['id','>=',1],
  49. ['status', '>', 0]
  50. ];
  51. if($type > 0){
  52. $where[] = ['role','=',$type];
  53. }
  54. if($trade > 0){
  55. $where[] = ['trade','=',$trade];
  56. }
  57. if($job > 0){
  58. $where[] = ['pro','=',$job];
  59. }
  60. $list = $this->shareService->list($where,10);
  61. //$list = DB::table('share')->where($where)->paginate(10);
  62. $result = [
  63. 'total' => $list->total(),
  64. 'data' => []
  65. ];
  66. if($list->total() > 0){
  67. $trade = DB::table('share_trade')->pluck('name', 'id');
  68. $job = DB::table('share_job')->pluck('name', 'id');
  69. foreach($list as $k => $v){
  70. if($v->utype == 1){
  71. $info = DB::table('companys')->where('id',$v->uid)->first();
  72. }else{
  73. $info = DB::table('member_infos')->where('uid',$v->uid)->first();
  74. }
  75. $item = [];
  76. $item['name'] = $v->utype == 1 ? $info->companyname : substr($info->realname,0,3) . ($info->sex == 1 ? '先生' : '女士');
  77. $item['utype'] = $v->utype == 1 ? "企业" : "个人" ;
  78. $item['role'] = $v->role == 1 ? "供应" : "需求";
  79. switch($v->type){
  80. case 1:
  81. $item['type'] = '小时工';
  82. break;
  83. case 2:
  84. $item['type'] = '劳务派遣';
  85. break;
  86. case 3:
  87. $item['type'] = '委托招聘';
  88. break;
  89. case 4:
  90. $item['type'] = '服务外包';
  91. break;
  92. case 5:
  93. $item['type'] = '其它';
  94. break;
  95. }
  96. $item['trade'] = $trade[$v->trade];
  97. $item['job'] = $job[$v->pro];
  98. $item['area'] = $v->area;
  99. $item['time'] = $v->time;
  100. $item['salary'] = $v->salary;
  101. $item['number'] = stripos($v->number,'人') ? $v->number : $v->number . '人';
  102. $item['remark'] = $v->remark;
  103. $item['contact'] = [
  104. 'name' => $item['name'],
  105. 'email' => $info->email,
  106. 'phone' => $v->utype == 1 ? $info->mobile : $info->phone
  107. ];
  108. array_push($result['data'],$item);
  109. }
  110. }
  111. return json_encode($result);
  112. }
  113. public function my(){
  114. return view('app.share.my');
  115. }
  116. public function getMyData()
  117. {
  118. $user = $this->getLoginUser();
  119. $list = $this->shareService->list(['uid'=>$user->id],10);
  120. $result = [
  121. 'total' => $list->total(),
  122. 'data' => []
  123. ];
  124. if($list->total() > 0){
  125. $trade = DB::table('share_trade')->pluck('name', 'id');
  126. $job = DB::table('share_job')->pluck('name', 'id');
  127. foreach($list as $k => $v){
  128. if($v->utype == 1){
  129. $info = DB::table('companys')->where('id',$v->uid)->first();
  130. }else{
  131. $info = DB::table('member_infos')->where('uid',$v->uid)->first();
  132. }
  133. $item = [];
  134. $item['name'] = $v->utype == 1 ? $info->companyname : substr($info->realname,0,3) . ($info->sex == 1 ? '先生' : '女士');
  135. $item['utype'] = $v->utype == 1 ? "企业" : "个人" ;
  136. $item['role'] = $v->role == 1 ? "供应" : "需求";
  137. switch($v->type){
  138. case 1:
  139. $item['type'] = '小时工';
  140. break;
  141. case 2:
  142. $item['type'] = '劳务派遣';
  143. break;
  144. case 3:
  145. $item['type'] = '委托招聘';
  146. break;
  147. case 4:
  148. $item['type'] = '服务外包';
  149. break;
  150. case 5:
  151. $item['type'] = '其它';
  152. break;
  153. }
  154. $item['trade'] = $trade[$v->trade];
  155. $item['job'] = $job[$v->pro];
  156. $item['area'] = $v->area;
  157. $item['time'] = $v->time;
  158. $item['salary'] = $v->salary;
  159. $item['number'] = stripos($v->number,'人') ? $v->number : $v->number . '人';
  160. $item['remark'] = $v->remark;
  161. $item['status'] = $v->status;
  162. $item['id'] = $v->id;
  163. $item['contact'] = [
  164. 'name' => $item['name'],
  165. 'email' => $info->email,
  166. 'phone' => $v->utype == 1 ? $info->mobile : $info->phone
  167. ];
  168. array_push($result['data'],$item);
  169. }
  170. }
  171. return json_encode($result);
  172. }
  173. public function update(Request $request)
  174. {
  175. $id = $request->input('id',0);
  176. return view('app.share.update',['id'=>$id]);
  177. }
  178. public function getMyInfo(Request $request)
  179. {
  180. $user = $this->getLoginUser();
  181. $id = $request->input('id');
  182. if($id){
  183. //TODO 登录及权限检测
  184. $info = \App\Models\Share::where('id',$id)->where('uid',$user->id)->first();
  185. if(!$info){
  186. return response()->json(['status' => '0', 'msg' => '找不到对应的修改记录']);
  187. }
  188. $info->role = (string)$info->role;
  189. $info->type = explode(',',$info->type);
  190. $info->status = (string)$info->status;
  191. return response()->json(['status' => '1', 'msg' => '信息查询成功', 'data' => $info]);
  192. }else{
  193. return response()->json(['status' => '1', 'msg' => '信息查询成功','data' => null]);
  194. }
  195. }
  196. public function save(Request $request){
  197. $data = $request->only('type','trade','pro','area','time','salary','number','remark','status','role','id');
  198. //判断用户登录状态
  199. $user = $this->getLoginUser();
  200. $data['utype'] = $user->utype;
  201. $data['uid'] = $user->id;
  202. if(!array_key_exists('role',$data) || !$data['role']){
  203. return response()->json(['status' => '0', 'msg' => '请指定信息角色']);
  204. }
  205. if(!array_key_exists('type',$data) || !$data['type']){
  206. return response()->json(['status' => '0', 'msg' => '共享方式不能为空']);
  207. }else{
  208. $data['type'] = implode(',',$data['type']);
  209. }
  210. if(!array_key_exists('trade',$data) || !$data['trade']){
  211. return response()->json(['status' => '0', 'msg' => '请选择行业']);
  212. }
  213. if(!array_key_exists('pro',$data) || !$data['pro']){
  214. return response()->json(['status' => '0', 'msg' => '请选择工种']);
  215. }
  216. if(!array_key_exists('area',$data) || !$data['area']){
  217. return response()->json(['status' => '0', 'msg' => '请选择工种']);
  218. }
  219. if(!array_key_exists('salary',$data) || !$data['salary']){
  220. return response()->json(['status' => '0', 'msg' => '请填写薪酬']);
  221. }
  222. if(!array_key_exists('number',$data) || !$data['number']){
  223. return response()->json(['status' => '0', 'msg' => '请填写人员数量']);
  224. }
  225. if(array_key_exists('id',$data) || $data['id']){
  226. $id = $data['id'];
  227. unset($data['id']);
  228. }else{
  229. $id = 0;
  230. }
  231. if($id){
  232. $affected = \App\Models\Share::where('uid',$data['uid'])->where('id',$id)->update($data);
  233. if($affected){
  234. return response()->json(['status' => '1', 'msg' => '信息修改成功']);
  235. }else{
  236. return response()->json(['status' => '1', 'msg' => '信息修改失败']);
  237. }
  238. }else{
  239. if(\App\Models\Share::insert($data)){
  240. return response()->json(['status' => '1', 'msg' => '信息提交成功,我们将尽快为您审核、匹配']);
  241. }else{
  242. return response()->json(['status' => '0', 'msg' => '信息提交失败']);
  243. }
  244. }
  245. }
  246. public function delete(Request $request){
  247. $user = $this->getLoginUser();
  248. $id = $request->input('id');
  249. if(!$id){
  250. return response()->json(['status' => '0', 'msg' => '请指定修改记录']);
  251. }
  252. $info = \App\Models\Share::where('id',$id)->where('uid',$user->id)->first();
  253. if(!$info){
  254. return response()->json(['status' => '0', 'msg' => '找不到记录']);
  255. }
  256. $info->delete();
  257. return response()->json(['status' => '1', 'msg' => '删除成功']);
  258. }
  259. }