CompanyImgService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2018/11/13
  6. * Time: 17:44
  7. */
  8. namespace App\Services\Company;
  9. use App\Repositories\CompanyImgRepository;
  10. use App\Repositories\CompanyRepository;
  11. use App\Repositories\MemberLogRepository;
  12. use App\Services\Common\TaskService;
  13. use http\Env\Response;
  14. class CompanyImgService
  15. {
  16. protected $companyImgRepository;
  17. protected $companyRepository;
  18. protected $taskService;
  19. protected $memberLogRepository;
  20. /**
  21. * CompanyImgService constructor.
  22. * @param $companyImgRepository
  23. * @param $companyRepository
  24. * @param $taskService
  25. * @param $memberLogRepository
  26. */
  27. public function __construct(CompanyImgRepository $companyImgRepository, MemberLogRepository $memberLogRepository, CompanyRepository $companyRepository, TaskService $taskService)
  28. {
  29. $this->companyImgRepository = $companyImgRepository;
  30. $this->companyRepository = $companyRepository;
  31. $this->taskService = $taskService;
  32. $this->memberLogRepository = $memberLogRepository;
  33. }
  34. public function list($id)
  35. {
  36. return $this->companyImgRepository->list($id);
  37. }
  38. /**
  39. * 企业风采
  40. * @param $id
  41. * @return \Illuminate\Http\JsonResponse|mixed
  42. */
  43. public function companyImg($id)
  44. {
  45. if (!$id) {
  46. return response()->json(['status'=>0, 'msg'=>'参数错误!']);
  47. }
  48. $res = $this->companyImgRepository->getImgInfo($id);
  49. $html = view('app.company.ajax.ajax_remark_img', ['res'=>$res])->render();
  50. return response()->json(['status'=>1, 'msg'=>'', 'data'=>$html]);
  51. }
  52. /**
  53. * @param $request
  54. * @param $user
  55. * @return \Illuminate\Http\JsonResponse
  56. * @throws \ErrorException
  57. * @throws \Prettus\Validator\Exceptions\ValidatorException
  58. */
  59. public function saveImg($images, $user)
  60. {
  61. $count = $this->companyImgRepository->imgCount();
  62. if ($count >8) {
  63. return response()->json(['status'=>0, 'msg'=>'上传图片已达上限','data'=>'']);
  64. }
  65. $data = [];
  66. $data['image'] = $images;
  67. $data['company_id'] = $user->id;
  68. $data['audit'] = 0;
  69. $subsite_id = $this->companyRepository->getCompanyColumn($user->id, ['subsite_id']);
  70. $data['subsite_id'] = $subsite_id['subsite_id'];
  71. if (false == $res = $this->companyImgRepository->store($data)) {
  72. return response()->json(['status'=>0,'msg'=>'保存失败!']);
  73. }
  74. $dotask = $this->taskService->doTask('20');
  75. $this->memberLogRepository->createLog($user, 1004, []);
  76. if ($dotask['code']) {
  77. return response()->json(['status'=>1, 'msg'=>'保存成功', 'imgId'=>$res->id,'data'=>$dotask['data']['points'],'path'=>upload_asset($images)]);
  78. } else {
  79. return response()->json(['status'=>1, 'msg'=>'保存成功', 'imgId'=>$res->id,'data'=>'','path'=>upload_asset($images)]);
  80. }
  81. }
  82. public function saveRemark($request,$user)
  83. {
  84. $where['id'] = $request->id;
  85. $where['company_id'] = $user->id;
  86. $data['title'] = $request->remark;
  87. if (!$this->companyImgRepository->saveRemark($data, $where)) {
  88. return response()->json(['status'=>0, 'msg'=>'保存备注失败!']);
  89. }
  90. return response()->json(['status'=>1, 'msg'=>'保存备注成功!']);
  91. }
  92. public function delImg($id,$user)
  93. {
  94. if (!$id) {
  95. return response()->json(['status'=>0, 'msg'=>'参数错误!']);
  96. }
  97. if (!$this->companyImgRepository->delImg($id,$user->id)) {
  98. return response()->json(['status'=>0, 'msg'=>'删除失败!']);
  99. }
  100. if(!$this->memberLogRepository->createLog($user,1022,$id)){
  101. throw new \Exception("日志记录失败!");
  102. }
  103. return response()->json(['status'=>1, 'msg'=>'删除成功!']);
  104. }
  105. }