WorkBooksService.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Laravel框架 [ Laravel ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 Laravel研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: wesmiler <12345678@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services;
  12. use App\Models\MemberModel;
  13. use App\Models\WorkBooksModel;
  14. use App\Models\WorkModel;
  15. /**
  16. * 工作报名管理-服务类
  17. * @author wesmiler
  18. * @since 2020/11/11
  19. * Class WorkBooksService
  20. * @package App\Services
  21. */
  22. class WorkBooksService extends BaseService
  23. {
  24. /**
  25. * 构造函数
  26. * @author wesmiler
  27. * @since 2020/11/11
  28. * WorkBooksService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new WorkBooksModel();
  33. }
  34. /**
  35. * 获取列表
  36. * @return array
  37. * @since 2020/11/11
  38. * @author wesmiler
  39. */
  40. public function getList()
  41. {
  42. $params = request()->all();
  43. $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
  44. $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
  45. $dataList = $this->model::from('work_books as b')
  46. ->leftJoin('works as a', 'a.id', '=', 'b.aid')
  47. ->leftJoin('member as m', 'm.id', '=', 'b.user_id')
  48. ->where(function ($query) use ($params) {
  49. $query->where('b.mark', 1);
  50. $status = isset($params['status']) ? $params['status'] : 0;
  51. if ($status > 0) {
  52. $query->where('b.status', $status);
  53. } else {
  54. $query->whereIn('b.status', [1, 2, 3]);
  55. }
  56. })
  57. ->where(function ($query) use ($params) {
  58. $keyword = isset($params['keyword']) ? trim($params['keyword']) : '';
  59. if (!empty($keyword)) {
  60. $query->where('a.title', 'like', "%{$keyword}%")
  61. ->orWhere('b.realname','like',"%{$keyword}%")
  62. ->orWhere('m.nickname','like',"%{$keyword}%");
  63. }
  64. })
  65. ->select(['b.id', 'b.aid', 'a.title','b.reason', 'm.nickname', 'b.realname', 'b.phone', 'b.thumb', 'b.status', 'b.create_time', 'b.update_time', 'b.description'])
  66. ->orderBy('b.update_time', 'desc')
  67. ->paginate($pageSize);
  68. $dataList = $dataList ? $dataList->toArray() : [];
  69. if ($dataList) {
  70. foreach ($dataList['data'] as &$item) {
  71. $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : '';
  72. $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
  73. }
  74. unset($item);
  75. }
  76. return [
  77. 'code' => 0,
  78. 'success'=> true,
  79. 'msg' => '操作成功',
  80. 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
  81. 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
  82. ];
  83. }
  84. /**
  85. * 获取列表
  86. * @return array
  87. * @since 2020/11/11
  88. * @author wesmiler
  89. */
  90. public function getDataList($params)
  91. {
  92. $page = isset($params['pageSize']) ? intval($params['pageSize']) : PAGE;
  93. $pageSize = isset($params['pageSize']) ? intval($params['pageSize']) : PERPAGE;
  94. $userId = isset($params['user_id']) ? intval($params['user_id']) : 0;
  95. $dataList = $this->model::from('work_books as b')
  96. ->leftJoin('works as a', 'a.id', '=', 'b.aid')
  97. ->leftJoin('member as m', 'm.id', '=', 'b.user_id')
  98. ->where(['b.mark'=> 1,'b.user_id'=> $userId])
  99. ->whereIn('b.status',[1,2,3])
  100. ->select(['b.id', 'b.aid', 'a.title','a.num', 'm.nickname', 'b.realname', 'b.phone','b.thumb as image', 'a.thumb', 'b.status','b.reason', 'b.create_time', 'b.update_time', 'b.description'])
  101. ->orderBy('b.update_time', 'desc')
  102. ->paginate($pageSize);
  103. $dataList = $dataList ? $dataList->toArray() : [];
  104. if ($dataList) {
  105. foreach ($dataList['data'] as &$item) {
  106. $item['thumb'] = $item['thumb'] ? get_image_url($item['thumb']) : '';
  107. $item['image'] = $item['image'] ? get_image_url($item['image']) : '';
  108. $item['create_time'] = $item['create_time'] ? datetime($item['create_time'],'Y-m-d H:i:s') : '';
  109. $bookNum = WorkBooksModel::where(['aid'=> $item['aid'],'mark'=> 1,'status'=> 1])->count('user_id');
  110. $item['book_num'] = intval($bookNum);
  111. }
  112. unset($item);
  113. }
  114. return [
  115. 'code' => 0,
  116. 'success'=> true,
  117. 'msg' => '操作成功',
  118. 'count' => isset($dataList['total']) ? $dataList['total'] : 0,
  119. 'data' => isset($dataList['data']) ? $dataList['data'] : 0,
  120. ];
  121. }
  122. /**
  123. * 添加或编辑
  124. * @return array
  125. * @since 2020/11/11
  126. * @author wesmiler
  127. */
  128. public function edit()
  129. {
  130. $data = request()->all();
  131. $id = isset($data['id'])? $data['id'] : 0;
  132. $status = isset($data['status'])? $data['status'] : 0;
  133. if($id){
  134. $info = $this->model::where(['id'=> $id])->first();
  135. if($info && $info->status != 1 && $status == 1){
  136. $workInfo = WorkModel::where(['id'=> $info['aid'],'mark'=> 1,'status'=> 1])
  137. ->select(['id','title','num'])
  138. ->first();
  139. $bookNum = $this->model::where(['aid'=> $info['aid'], 'mark'=> 1,'status'=> 1])->count('id');
  140. if($workInfo && $workInfo->num <= $bookNum){
  141. return message('报名人数已满,无法审核通过', false);
  142. }
  143. }
  144. }
  145. $data['update_time'] = time();
  146. return parent::edit($data); // TODO: Change the autogenerated stub
  147. }
  148. /**
  149. * 报名
  150. * @parpam array $params 参数
  151. * @return array
  152. * @since 2020/11/11
  153. * @author wesmiler
  154. */
  155. public function books($params)
  156. {
  157. $userId = isset($params['user_id'])? $params['user_id'] : 0;
  158. $memberInfo = MemberModel::where(['id'=> $userId,'mark'=> 1,'status'=> 1])
  159. ->select(['id','nickname','openid'])
  160. ->first();
  161. if(!$memberInfo){
  162. return message('用户状态不可操作,请联系客服', false);
  163. }
  164. $aid = isset($params['id'])? intval($params['id']) : 0;
  165. $workInfo = WorkModel::where(['id'=> $aid,'mark'=> 1,'status'=> 1])
  166. ->select(['id','title','num'])
  167. ->first();
  168. if(!$workInfo){
  169. return message('该岗位不存在或已下架', false);
  170. }
  171. $bookNum = $this->model::where(['aid'=> $aid, 'mark'=> 1,'status'=> 1])->count('id');
  172. if($workInfo->num <= $bookNum){
  173. return message('报名人数已满', false);
  174. }
  175. // 是否报名过
  176. $info = $this->model::where(['aid'=> $aid,'user_id'=> $userId, 'mark'=> 1])
  177. ->first();
  178. if($info && $info->status==1){
  179. return message('该岗位您已经成功报名', false);
  180. }else if($info && $info->status==2){
  181. return message('该岗位您已经提交报名,请耐心等候审核', false);
  182. }
  183. if($info){
  184. $info->realname = isset($params['realname'])? trim($params['realname']) : '';
  185. $info->phone = isset($params['phone'])? trim($params['phone']) : '';
  186. $info->thumb = isset($params['thumb'])? trim($params['thumb']) : '';
  187. $info->description = isset($params['description'])? trim($params['description']) : '';
  188. $info->create_time = time();
  189. $info->update_time = time();
  190. $info->mark = 1;
  191. $info->status = 2;
  192. $info->reason = '';
  193. if($info->save()){
  194. return message('提交成功', true);
  195. }else{
  196. return message('提交失败', false);
  197. }
  198. }else{
  199. $data = [
  200. 'aid'=> $aid,
  201. 'user_id'=> $userId,
  202. 'realname'=> isset($params['realname'])? trim($params['realname']) : '',
  203. 'phone'=> isset($params['phone'])? trim($params['phone']) : '',
  204. 'thumb'=> isset($params['thumb'])? trim($params['thumb']) : '',
  205. 'description'=> isset($params['description'])? trim($params['description']) : '',
  206. 'create_time'=> time(),
  207. 'mark'=> 1,
  208. 'status'=> 2
  209. ];
  210. $data['update_time'] = time();
  211. return parent::edit($data); // TODO: Change the autogenerated stub
  212. }
  213. }
  214. }