123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wuzhenke
- * Date: 2018/11/13
- * Time: 17:44
- */
- namespace App\Services\Company;
- use App\Repositories\CompanyImgRepository;
- use App\Repositories\CompanyRepository;
- use App\Repositories\MemberLogRepository;
- use App\Services\Common\TaskService;
- use http\Env\Response;
- class CompanyImgService
- {
- protected $companyImgRepository;
- protected $companyRepository;
- protected $taskService;
- protected $memberLogRepository;
- /**
- * CompanyImgService constructor.
- * @param $companyImgRepository
- * @param $companyRepository
- * @param $taskService
- * @param $memberLogRepository
- */
- public function __construct(CompanyImgRepository $companyImgRepository, MemberLogRepository $memberLogRepository, CompanyRepository $companyRepository, TaskService $taskService)
- {
- $this->companyImgRepository = $companyImgRepository;
- $this->companyRepository = $companyRepository;
- $this->taskService = $taskService;
- $this->memberLogRepository = $memberLogRepository;
- }
- public function list($id)
- {
- return $this->companyImgRepository->list($id);
- }
- /**
- * 企业风采
- * @param $id
- * @return \Illuminate\Http\JsonResponse|mixed
- */
- public function companyImg($id)
- {
- if (!$id) {
- return response()->json(['status'=>0, 'msg'=>'参数错误!']);
- }
- $res = $this->companyImgRepository->getImgInfo($id);
- $html = view('app.company.ajax.ajax_remark_img', ['res'=>$res])->render();
- return response()->json(['status'=>1, 'msg'=>'', 'data'=>$html]);
- }
- /**
- * @param $request
- * @param $user
- * @return \Illuminate\Http\JsonResponse
- * @throws \ErrorException
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function saveImg($images, $user)
- {
- $count = $this->companyImgRepository->imgCount();
- if ($count >8) {
- return response()->json(['status'=>0, 'msg'=>'上传图片已达上限','data'=>'']);
- }
- $data = [];
- $data['image'] = $images;
- $data['company_id'] = $user->id;
- $data['audit'] = 0;
- $subsite_id = $this->companyRepository->getCompanyColumn($user->id, ['subsite_id']);
- $data['subsite_id'] = $subsite_id['subsite_id'];
- if (false == $res = $this->companyImgRepository->store($data)) {
- return response()->json(['status'=>0,'msg'=>'保存失败!']);
- }
- $dotask = $this->taskService->doTask('20');
- $this->memberLogRepository->createLog($user, 1004, []);
- if ($dotask['code']) {
- return response()->json(['status'=>1, 'msg'=>'保存成功', 'imgId'=>$res->id,'data'=>$dotask['data']['points'],'path'=>upload_asset($images)]);
- } else {
- return response()->json(['status'=>1, 'msg'=>'保存成功', 'imgId'=>$res->id,'data'=>'','path'=>upload_asset($images)]);
- }
- }
- public function saveRemark($request,$user)
- {
- $where['id'] = $request->id;
- $where['company_id'] = $user->id;
- $data['title'] = $request->remark;
- if (!$this->companyImgRepository->saveRemark($data, $where)) {
- return response()->json(['status'=>0, 'msg'=>'保存备注失败!']);
- }
- return response()->json(['status'=>1, 'msg'=>'保存备注成功!']);
- }
- public function delImg($id,$user)
- {
- if (!$id) {
- return response()->json(['status'=>0, 'msg'=>'参数错误!']);
- }
- if (!$this->companyImgRepository->delImg($id,$user->id)) {
- return response()->json(['status'=>0, 'msg'=>'删除失败!']);
- }
- if(!$this->memberLogRepository->createLog($user,1022,$id)){
- throw new \Exception("日志记录失败!");
- }
- return response()->json(['status'=>1, 'msg'=>'删除成功!']);
- }
- }
|