123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- <?php
- namespace App\Http\Controllers\Web\Share;
- use App\Http\Controllers\Web\WebBaseController;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Http\Request;
- use App\Services\Share\ShareService;
- class ShareController extends WebBaseController
- {
- protected $shareService;
- public function __construct(ShareService $shareService)
- {
- $this->shareService = $shareService;
- }
- public function index()
- {
- return view('app.share.index');
- }
- public function getSelectData()
- {
- $trade = DB::table('share_trade')->get();
- $result = [];
- foreach ($trade as $k => $v){
- $sub = DB::table('share_job')->where('trade',$v->id)->get()->toArray();
- $sub_opt = [];
- foreach($sub as $key => $val){
- $item = [
- 'value' => $val->id,
- 'label' => $val->name
- ];
- array_push($sub_opt,$item);
- }
- $item = [
- 'value' => $v->id,
- 'label' => $v->name,
- 'sub' => $sub_opt
- ];
- array_push($result,$item);
- }
- return json_encode($result);
- }
- public function getShareHallData(Request $request)
- {
- $type = intval($request->input('type'));
- $trade = intval($request->input('trade'));
- $job = intval($request->input('job'));
- //$page = intval($request->input('page',10));
- $where = [
- ['id','>=',1],
- ['status', '>', 0]
- ];
- if($type > 0){
- $where[] = ['role','=',$type];
- }
- if($trade > 0){
- $where[] = ['trade','=',$trade];
- }
- if($job > 0){
- $where[] = ['pro','=',$job];
- }
- $list = $this->shareService->list($where,10);
- //$list = DB::table('share')->where($where)->paginate(10);
- $result = [
- 'total' => $list->total(),
- 'data' => []
- ];
- if($list->total() > 0){
- $trade = DB::table('share_trade')->pluck('name', 'id');
- $job = DB::table('share_job')->pluck('name', 'id');
- foreach($list as $k => $v){
- if($v->utype == 1){
- $info = DB::table('companys')->where('id',$v->uid)->first();
- }else{
- $info = DB::table('member_infos')->where('uid',$v->uid)->first();
- }
- $item = [];
- $item['name'] = $v->utype == 1 ? $info->companyname : substr($info->realname,0,3) . ($info->sex == 1 ? '先生' : '女士');
- $item['utype'] = $v->utype == 1 ? "企业" : "个人" ;
- $item['role'] = $v->role == 1 ? "供应" : "需求";
- switch($v->type){
- case 1:
- $item['type'] = '小时工';
- break;
- case 2:
- $item['type'] = '劳务派遣';
- break;
- case 3:
- $item['type'] = '委托招聘';
- break;
- case 4:
- $item['type'] = '服务外包';
- break;
- case 5:
- $item['type'] = '其它';
- break;
- }
- $item['trade'] = $trade[$v->trade];
- $item['job'] = $job[$v->pro];
- $item['area'] = $v->area;
- $item['time'] = $v->time;
- $item['salary'] = $v->salary;
- $item['number'] = stripos($v->number,'人') ? $v->number : $v->number . '人';
- $item['remark'] = $v->remark;
- $item['contact'] = [
- 'name' => $item['name'],
- 'email' => $info->email,
- 'phone' => $v->utype == 1 ? $info->mobile : $info->phone
- ];
- array_push($result['data'],$item);
- }
- }
- return json_encode($result);
- }
- public function my(){
- return view('app.share.my');
- }
- public function getMyData()
- {
- $user = $this->getLoginUser();
- $list = $this->shareService->list(['uid'=>$user->id],10);
- $result = [
- 'total' => $list->total(),
- 'data' => []
- ];
- if($list->total() > 0){
- $trade = DB::table('share_trade')->pluck('name', 'id');
- $job = DB::table('share_job')->pluck('name', 'id');
- foreach($list as $k => $v){
- if($v->utype == 1){
- $info = DB::table('companys')->where('id',$v->uid)->first();
- }else{
- $info = DB::table('member_infos')->where('uid',$v->uid)->first();
- }
- $item = [];
- $item['name'] = $v->utype == 1 ? $info->companyname : substr($info->realname,0,3) . ($info->sex == 1 ? '先生' : '女士');
- $item['utype'] = $v->utype == 1 ? "企业" : "个人" ;
- $item['role'] = $v->role == 1 ? "供应" : "需求";
- switch($v->type){
- case 1:
- $item['type'] = '小时工';
- break;
- case 2:
- $item['type'] = '劳务派遣';
- break;
- case 3:
- $item['type'] = '委托招聘';
- break;
- case 4:
- $item['type'] = '服务外包';
- break;
- case 5:
- $item['type'] = '其它';
- break;
- }
- $item['trade'] = $trade[$v->trade];
- $item['job'] = $job[$v->pro];
- $item['area'] = $v->area;
- $item['time'] = $v->time;
- $item['salary'] = $v->salary;
- $item['number'] = stripos($v->number,'人') ? $v->number : $v->number . '人';
- $item['remark'] = $v->remark;
- $item['status'] = $v->status;
- $item['id'] = $v->id;
- $item['contact'] = [
- 'name' => $item['name'],
- 'email' => $info->email,
- 'phone' => $v->utype == 1 ? $info->mobile : $info->phone
- ];
- array_push($result['data'],$item);
- }
- }
- return json_encode($result);
- }
- public function update(Request $request)
- {
- $id = $request->input('id',0);
- return view('app.share.update',['id'=>$id]);
- }
- public function getMyInfo(Request $request)
- {
- $user = $this->getLoginUser();
- $id = $request->input('id');
- if($id){
- //TODO 登录及权限检测
- $info = \App\Models\Share::where('id',$id)->where('uid',$user->id)->first();
- if(!$info){
- return response()->json(['status' => '0', 'msg' => '找不到对应的修改记录']);
- }
- $info->role = (string)$info->role;
- $info->type = explode(',',$info->type);
- $info->status = (string)$info->status;
- return response()->json(['status' => '1', 'msg' => '信息查询成功', 'data' => $info]);
- }else{
- return response()->json(['status' => '1', 'msg' => '信息查询成功','data' => null]);
- }
- }
- public function save(Request $request){
- $data = $request->only('type','trade','pro','area','time','salary','number','remark','status','role','id');
- //判断用户登录状态
- $user = $this->getLoginUser();
- $data['utype'] = $user->utype;
- $data['uid'] = $user->id;
- if(!array_key_exists('role',$data) || !$data['role']){
- return response()->json(['status' => '0', 'msg' => '请指定信息角色']);
- }
- if(!array_key_exists('type',$data) || !$data['type']){
- return response()->json(['status' => '0', 'msg' => '共享方式不能为空']);
- }else{
- $data['type'] = implode(',',$data['type']);
- }
- if(!array_key_exists('trade',$data) || !$data['trade']){
- return response()->json(['status' => '0', 'msg' => '请选择行业']);
- }
- if(!array_key_exists('pro',$data) || !$data['pro']){
- return response()->json(['status' => '0', 'msg' => '请选择工种']);
- }
- if(!array_key_exists('area',$data) || !$data['area']){
- return response()->json(['status' => '0', 'msg' => '请选择工种']);
- }
- if(!array_key_exists('salary',$data) || !$data['salary']){
- return response()->json(['status' => '0', 'msg' => '请填写薪酬']);
- }
- if(!array_key_exists('number',$data) || !$data['number']){
- return response()->json(['status' => '0', 'msg' => '请填写人员数量']);
- }
- if(array_key_exists('id',$data) || $data['id']){
- $id = $data['id'];
- unset($data['id']);
- }else{
- $id = 0;
- }
- if($id){
- $affected = \App\Models\Share::where('uid',$data['uid'])->where('id',$id)->update($data);
- if($affected){
- return response()->json(['status' => '1', 'msg' => '信息修改成功']);
- }else{
- return response()->json(['status' => '1', 'msg' => '信息修改失败']);
- }
- }else{
- if(\App\Models\Share::insert($data)){
- return response()->json(['status' => '1', 'msg' => '信息提交成功,我们将尽快为您审核、匹配']);
- }else{
- return response()->json(['status' => '0', 'msg' => '信息提交失败']);
- }
- }
- }
- public function delete(Request $request){
- $user = $this->getLoginUser();
- $id = $request->input('id');
- if(!$id){
- return response()->json(['status' => '0', 'msg' => '请指定修改记录']);
- }
- $info = \App\Models\Share::where('id',$id)->where('uid',$user->id)->first();
- if(!$info){
- return response()->json(['status' => '0', 'msg' => '找不到记录']);
- }
- $info->delete();
- return response()->json(['status' => '1', 'msg' => '删除成功']);
- }
- }
|