| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- // +----------------------------------------------------------------------
- // | Laravel框架 [ Laravel ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 Laravel研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: wesmiler <12345678@qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services;
- use App\Models\MemberModel;
- use App\Models\WorkBooksModel;
- use App\Models\WorkModel;
- /**
- * 工作报名管理-服务类
- * @author wesmiler
- * @since 2020/11/11
- * Class WorkBooksService
- * @package App\Services
- */
- class WorkBooksService extends BaseService
- {
- /**
- * 构造函数
- * @author wesmiler
- * @since 2020/11/11
- * WorkBooksService constructor.
- */
- public function __construct()
- {
- $this->model = new WorkBooksModel();
- }
- /**
- * 获取列表
- * @return array
- * @since 2020/11/11
- * @author wesmiler
- */
- public function getList()
- {
- $params = request()->all();
- $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
- $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
- $dataList = $this->model::from('work_books as b')
- ->leftJoin('works as a', 'a.id', '=', 'b.aid')
- ->leftJoin('member as m', 'm.id', '=', 'b.user_id')
- ->where(function ($query) use ($params) {
- $query->where('b.mark', 1);
- $status = isset($params['status']) ? $params['status'] : 0;
- if ($status > 0) {
- $query->where('b.status', $status);
- } else {
- $query->whereIn('b.status', [1, 2, 3]);
- }
- })
- ->where(function ($query) use ($params) {
- $keyword = isset($params['keyword']) ? trim($params['keyword']) : '';
- if (!empty($keyword)) {
- $query->where('a.title', 'like', "%{$keyword}%")
- ->orWhere('b.realname','like',"%{$keyword}%")
- ->orWhere('m.nickname','like',"%{$keyword}%");
- }
- })
- ->select(['b.id', 'b.aid', 'a.title', 'm.nickname', 'b.realname', 'b.phone', 'b.thumb', 'b.status', 'b.create_time', 'b.update_time', 'b.description'])
- ->orderBy('b.update_time', 'desc')
- ->paginate($pageSize);
- $dataList = $dataList ? $dataList->toArray() : [];
- if ($dataList) {
- foreach ($dataList['data'] as &$item) {
- $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : '';
- $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
- }
- unset($item);
- }
- return [
- 'code' => 0,
- 'success'=> true,
- 'msg' => '操作成功',
- 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
- 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
- ];
- }
- /**
- * 获取列表
- * @return array
- * @since 2020/11/11
- * @author wesmiler
- */
- public function getDataList($params)
- {
- $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
- $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
- $userId = isset($params['user_id']) ? intval($params['user_id']) : 0;
- $dataList = $this->model::from('work_books as b')
- ->leftJoin('works as a', 'a.id', '=', 'b.aid')
- ->leftJoin('member as m', 'm.id', '=', 'b.user_id')
- ->where(['b.mark'=> 1,'b.user_id'=> $userId])
- ->whereIn('b.status',[1,2,3])
- ->select(['b.id', 'b.aid', 'a.title','a.num', 'm.nickname', 'b.realname', 'b.phone', 'b.thumb', 'b.status','b.reason', 'b.create_time', 'b.update_time', 'b.description'])
- ->orderBy('b.update_time', 'desc')
- ->paginate($pageSize);
- $dataList = $dataList ? $dataList->toArray() : [];
- if ($dataList) {
- foreach ($dataList['data'] as &$item) {
- $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : '';
- $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
- $bookNum = WorkBooksModel::where(['aid'=> $item['aid'],'mark'=> 1,'status'=> 1])->count('user_id');
- $item['book_num'] = intval($bookNum);
- }
- unset($item);
- }
- return [
- 'code' => 0,
- 'success'=> true,
- 'msg' => '操作成功',
- 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
- 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
- ];
- }
- /**
- * 添加或编辑
- * @return array
- * @since 2020/11/11
- * @author wesmiler
- */
- public function edit()
- {
- $data = request()->all();
- $id = isset($data['id'])? $data['id'] : 0;
- $status = isset($data['status'])? $data['status'] : 0;
- if($id){
- $info = $this->model::where(['id'=> $id])->first();
- if($info && $info->status != 1 && $status == 1){
- $workInfo = WorkModel::where(['id'=> $info['aid'],'mark'=> 1,'status'=> 1])
- ->select(['id','title','num'])
- ->first();
- $bookNum = $this->model::where(['aid'=> $info['aid'], 'mark'=> 1,'status'=> 1])->count('id');
- if($workInfo && $workInfo->num <= $bookNum){
- return message('报名人数已满,无法审核通过', false);
- }
- }
- }
- $data['update_time'] = time();
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- /**
- * 报名
- * @parpam array $params 参数
- * @return array
- * @since 2020/11/11
- * @author wesmiler
- */
- public function books($params)
- {
- $userId = isset($params['user_id'])? $params['user_id'] : 0;
- $memberInfo = MemberModel::where(['id'=> $userId,'mark'=> 1,'status'=> 1])
- ->select(['id','nickname','openid'])
- ->first();
- if(!$memberInfo){
- return message('用户状态不可操作,请联系客服', false);
- }
- $aid = isset($params['id'])? intval($params['id']) : 0;
- $workInfo = WorkModel::where(['id'=> $aid,'mark'=> 1,'status'=> 1])
- ->select(['id','title','num'])
- ->first();
- if(!$workInfo){
- return message('该岗位不存在或已下架', false);
- }
- $bookNum = $this->model::where(['aid'=> $aid, 'mark'=> 1,'status'=> 1])->count('id');
- if($workInfo->num <= $bookNum){
- return message('报名人数已满', false);
- }
- // 是否报名过
- $info = $this->model::where(['aid'=> $aid,'user_id'=> $userId, 'mark'=> 1])
- ->first();
- if($info && $info->status==1){
- return message('该岗位您已经成功报名', false);
- }else if($info && $info->status==2){
- return message('该岗位您已经提交报名,请耐心等候审核', false);
- }
- if($info){
- $info->realname = isset($params['realname'])? trim($params['realname']) : '';
- $info->phone = isset($params['phone'])? trim($params['phone']) : '';
- $info->thumb = isset($params['thumb'])? trim($params['thumb']) : '';
- $info->description = isset($params['description'])? trim($params['description']) : '';
- $info->create_time = time();
- $info->update_time = time();
- $info->mark = 1;
- $info->status = 2;
- $info->reason = '';
- if($info->save()){
- return message('提交成功', true);
- }else{
- return message('提交失败', false);
- }
- }else{
- $data = [
- 'aid'=> $aid,
- 'user_id'=> $userId,
- 'realname'=> isset($params['realname'])? trim($params['realname']) : '',
- 'phone'=> isset($params['phone'])? trim($params['phone']) : '',
- 'thumb'=> isset($params['thumb'])? trim($params['thumb']) : '',
- 'description'=> isset($params['description'])? trim($params['description']) : '',
- 'create_time'=> time(),
- 'mark'=> 1,
- 'status'=> 2
- ];
- $data['update_time'] = time();
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- }
- }
|