PolicyService.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. namespace App\Services\Content;
  3. use App\Models\Feature;
  4. use App\Models\membersProject;
  5. use App\Models\PolicyCategory;
  6. use App\Repositories\CategoryRepository;
  7. use App\Repositories\PolicyCategoryRepository;
  8. use App\Repositories\PolicyPropertyReoository;
  9. use App\Repositories\PolicyRepository;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\DB;
  12. class PolicyService
  13. {
  14. protected $policyCategoryRepository;
  15. protected $policyRepository;
  16. protected $policyPropertyReoository;
  17. protected $CategoryRepository;
  18. public function __construct(PolicyCategoryRepository $policyCategoryRepository,PolicyRepository $policyRepository,PolicyPropertyReoository $policyPropertyReoository,CategoryRepository $CategoryRepository)
  19. {
  20. $this->policyCategoryRepository = $policyCategoryRepository;
  21. $this->policyRepository = $policyRepository;
  22. $this->policyPropertyReoository = $policyPropertyReoository;
  23. $this->CategoryRepository = $CategoryRepository;
  24. }
  25. public function getPolicyInfo($id,$fairjob = 0)
  26. {
  27. $where = array(
  28. 'id' => $id,
  29. 'is_display'=>'1',
  30. );
  31. $policy_info = $this->policyRepository->firstWhere($where);
  32. if (empty($policy_info)){
  33. return $policy_info;
  34. }
  35. if ($policy_info) {
  36. $property = $this->policyPropertyReoository->getProperty(['id'=>$policy_info->focos]);
  37. $policy_info->property = '';
  38. if ($property) {
  39. $policy_info->property = $property->categoryname;
  40. }
  41. }
  42. //获取相同分类下的所有新闻列表
  43. $lists = $this->policy_list('', $policy_info->type_id);
  44. $pre_info = array();
  45. $nex_info = array();
  46. $policy_info->prev = 0;
  47. $policy_info->next = 0;
  48. $info_key = -1;
  49. if ($lists->toArray()) {
  50. foreach ($lists as $k => $v) {
  51. if ($v->id==$id) {
  52. $info_key = $k;
  53. }
  54. }
  55. }
  56. $prev = $info_key>-1 && !empty($lists[$info_key-1]) ? $lists[$info_key-1] : 0;
  57. if ($prev) {
  58. $policy_info->prev = 1;
  59. $policy_info->prev_title = $prev->origin_title;
  60. if($fairjob){
  61. $policy_info->prev_url = route('jobfair.new.show', ['id'=>$prev->id]);
  62. }else{
  63. $policy_info->prev_url = route('policy.show', ['id'=>$prev->id]);
  64. }
  65. }
  66. $next = $info_key>-1 && !empty($lists[$info_key+1]) ? $lists[$info_key+1] : 0;
  67. if ($next) {
  68. $policy_info->next = 1;
  69. $policy_info->next_title = $next->origin_title;
  70. if($fairjob){
  71. $policy_info->next_url = route('jobfair.new.show', ['id'=>$next->id]);
  72. }else{
  73. $policy_info->next_url = route('policy.show', ['id'=>$next->id]);
  74. }
  75. }
  76. return $policy_info;
  77. }
  78. public function policy_list($key = '', $id = '', $page = '')
  79. {
  80. $where = array();
  81. $map = array();
  82. $where[] = array('is_display','=','1');
  83. $map[] = array('is_display','=','1');
  84. if ($key) {
  85. $where[] = array('title','like','%'.$key.'%');
  86. $map[] = array('title','like','%'.$key.'%');
  87. }
  88. if ($id) {
  89. $category=PolicyCategory::where(array('id'=>$id))->first();
  90. if($category->parent_id==0){
  91. $where[] = array('parentid','=',$id);
  92. }else{
  93. $where[] = array('type_id','=',$id);
  94. }
  95. $list=$this->policyRepository->getPolicys($where, $page);
  96. } else {
  97. $or_map = $map;
  98. $or_map[] = array('type_id','=','9');
  99. $map[] = array('parentid','=','1');
  100. $list=$this->policyRepository->getAllPolicys($map, $or_map, $page);
  101. }
  102. if ($list->toArray()) {
  103. foreach ($list as $k => $v) {
  104. $list[$k]->origin_title = $v->title;
  105. $style= '';
  106. if ($v->tit_color) {
  107. $style .='color:'.$v->tit_color.';';
  108. }
  109. if ($v->tit_b=='1') {
  110. $style .='font-weight:bold;';
  111. }
  112. if ($style) {
  113. $list[$k]->title = '<span style='.$style.'>'.$v->title.'</span>';
  114. }
  115. }
  116. }
  117. return $list;
  118. }
  119. public function getChildCategorys($id)
  120. {
  121. $where = array();
  122. $where['parent_id'] = $id;
  123. $list=$this->policyCategoryRepository->getChildCategorys($where);
  124. return $list;
  125. }
  126. //获取指定属性的新闻资讯
  127. public function getFocosPolicys($property_id, $limit = '5')
  128. {
  129. return $this->policyRepository->getFocosPolicys($property_id, $limit);
  130. }
  131. public function incrementData($where, $num, $filed)
  132. {
  133. return $this->policyRepository->incrementData($where, $num, $filed);
  134. }
  135. //获取人才类型
  136. public function getRCCategory(){
  137. return $this->CategoryRepository->getCategoryByAlias(['alias'=>'RC_category']);
  138. }
  139. public function getRcInfosByIndex(){
  140. $where[] = ['is_display','=','1'];
  141. return Feature::where($where)->orderBy('id', 'desc')->get();
  142. }
  143. public function getRcInfos($request){
  144. $page = 10;
  145. $where[] = ['is_display','=','1'];
  146. if($request->personal){
  147. $where[] = ['personal','=',$request->personal];
  148. }
  149. return Feature::where($where)->orderBy('id', 'desc')->paginate($page, ['*']);
  150. }
  151. public function getTsrcInfos($request){
  152. $page = 10;
  153. $where[] = ['is_display','=','1'];
  154. $where[] = ['parentid','<>','0'];
  155. $where[] = ['type_id','<>','0'];
  156. if($request->parentid){
  157. $where[] = ['parentid','=',$request->parentid];
  158. }
  159. if($request->type_id){
  160. $where[] = ['type_id','=',$request->type_id];
  161. }
  162. return Feature::where($where)->orderBy('id', 'desc')->paginate($page, ['*']);
  163. }
  164. public function getProInfos($request,$uid){
  165. $page = 10;
  166. $where[] = ['uid','=',$uid];
  167. return membersProject::where($where)->orderBy('created_at', 'desc')->paginate($page, ['*']);
  168. }
  169. public function getProInfo($request){
  170. $where[] = ['id','=',$request['id']];
  171. return membersProject::where($where)->first();
  172. }
  173. public function updateProject($data, $user){
  174. DB::beginTransaction();
  175. try {
  176. $data['uid']=$user->id;
  177. $data['project_audit']=0;
  178. if (empty($data['id'])==true) {
  179. membersProject::create($data);
  180. } else {
  181. membersProject::where(['id'=>$data['id']])->update($data);
  182. }
  183. DB::commit();
  184. return ['code'=>1,'info'=>$data];
  185. } catch (\Exception $e) {
  186. DB::rollback();
  187. return ['code'=>0,'info'=>$e->getMessage()];
  188. }
  189. }
  190. public function delProject($request){
  191. DB::beginTransaction();
  192. try {
  193. membersProject::where(['id'=>$request['id']])->delete();
  194. DB::commit();
  195. return ['code'=>1,'info'=>"删除成功"];
  196. } catch (\Exception $e) {
  197. DB::rollback();
  198. return ['code'=>0,'info'=>$e->getMessage()];
  199. }
  200. }
  201. }