Exemple #1
0
 /**
  * 展示列表 type-1用户 2-商户
  * @param $type
  * @return array
  */
 public function show($type, $user_id)
 {
     $user = UserBase::find($user_id);
     return $this->formatUsers($user ? [$user] : []);
     $data = [];
     $user_result = UserBase::where('user_id', $user_id)->first();
     $user_black_rt = UserBlackWater::whereIn('user_id', $user_id)->first();
     $data['user_id'] = $user_id;
     $data['user_cellphone'] = $user_result->user_cellphone;
     $data['user_name'] = $user_result->user_name;
     $data['invite_code'] = $user_result->invite_code;
     $user_financial = UserFinancial::where('user_id', $user_id)->first();
     $data['water_count'] = $user_financial ? $user_financial->water_count : 0;
     $data['black_water'] = $user_black_rt ? $user_black_rt->black_water : 0;
     $data['price'] = $user_financial ? $user_financial->price : 0;
     $data['send_water'] = $user_financial ? $user_financial->send_water : 0;
     $data['public_count'] = $user_financial ? $user_financial->public_count : 0;
     $data['giving'] = $user_financial ? $user_financial->giving : 0;
     switch ($type) {
         case 1:
             $user_image = UserImage::where('user_id', $user_id)->head()->first();
             $data['image_url'] = $user_image ? $user_image->path() : '';
             $user_third_party = UserThirdParty::where('user_id', $user_id)->get();
             $data['wei_xin'] = '';
             $data['qq'] = '';
             foreach ($user_third_party as $user_third_party_v) {
                 if ($user_third_party_v->type == 1) {
                     $data['wei_xin'] = $user_third_party_v->user_other_id;
                 } else {
                     $data['qq'] = $user_third_party_v->user_other_id;
                 }
             }
             return $data;
         case 2:
             $user_image = UserImage::where('user_id', $user_id)->get();
             $images = [];
             if (!empty($user_image)) {
                 foreach ($user_image as $user_image_val) {
                     $images[$user_image_val->id] = $user_image_val->path();
                 }
             }
             return $data;
     }
 }
Exemple #2
0
 public function update($user_id, $type, Request $request)
 {
     $user = UserBase::find($user_id);
     if (!$user) {
         return $this->returnAddJs('用户不存在');
     }
     $user_name = $request->get('user_name');
     if (!$user_name) {
         return $this->returnAddJs('用户名不能为空');
     }
     if ($type == 2) {
         //商家编辑
         $water_count = $request->get('water_count');
         if (!$water_count) {
             return $this->returnAddJs('请输入亲水值!');
         }
         $send_water = $request->get('send_water');
         if (!$send_water) {
             return $this->returnAddJs('请输入护水值!');
         }
         $image_url_real1 = $request->file('image_url_real1');
         if (!$image_url_real1->isValid()) {
             return $this->returnAddJs('营业执照无效');
         }
         if (strpos($image_url_real1->getMimeType(), 'image/') === false) {
             return $this->returnAddJs('营业执照格式不正确');
         }
         $image_url_real1_w = $this->updateFile($image_url_real1);
         if (!$image_url_real1_w) {
             return $this->returnAddJs('营业执照上传失败,请重新上传!');
         }
         $image_url_real2 = $request->file('image_url_real2');
         if ($image_url_real2) {
             if (!$image_url_real2->isValid()) {
                 return $this->returnAddJs('店铺实景1无效');
             }
             if (strpos($image_url_real2->getMimeType(), 'image/') === false) {
                 return $this->returnAddJs('店铺实景1格式不正确');
             }
             $image_url_real2_w = $this->updateFile($image_url_real2);
             if (!$image_url_real2) {
                 return $this->returnAddJs('店铺实景1上传失败,请重新上传!');
             }
         }
         $image_url_real3 = $request->file('image_url_real3');
         if ($image_url_real3) {
             if (!$image_url_real3->isValid()) {
                 return $this->returnAddJs('店铺实景2无效');
             }
             if (strpos($image_url_real3->getMimeType(), 'image/') === false) {
                 return $this->returnAddJs('店铺实景2格式不正确');
             }
             $image_url_real3_w = $this->updateFile($image_url_real3);
             if (!$image_url_real3_w) {
                 return $this->returnAddJs('店铺实景2上传失败,请重新上传!');
             }
         }
     }
     $image = $request->file('image');
     if (!$image->isValid()) {
         return $this->returnAddJs('图片无效');
     }
     if (strpos($image->getMimeType(), 'image/') === false) {
         return $this->returnAddJs('图片格式不正确');
     }
     $image_w = $this->updateFile($image);
     if (!$image_w) {
         return $this->returnAddJs('图片上传失败,请重新上传!');
     }
     $user->user_name = $user_name;
     $user->save();
     $user_image = UserImage::where('user_id', $user_id)->where('type', 1)->first();
     if (!$user_image) {
         $user_image_model = new UserImage();
         $user_image_model->user_id = $user_id;
         $user_image_model->image_url = $image_w;
         $user_image_model->type = 1;
         $user_image_model->is_completion = 0;
         $user_image_model->save();
     } else {
         $user_image->image_url = $image_w;
         $user_image->save();
     }
     if ($type == 2) {
         $user_desc = $request->get('user_desc', '');
         $user_f = UserFinancial::where('user_id', $user_id)->first();
         if (!$user_f) {
             $user_f = new UserFinancial();
             $user_f->user_id = $user_id;
         }
         $user_f->water_count = $water_count;
         $user_f->send_water = $send_water;
         $user_f->save();
         $user_c = UserCompanyExtend::where('user_id', $user_id)->first();
         if (!$user_c) {
             $user_c = new UserCompanyExtend();
             $user_c->user_id = $user_id;
         }
         $user_c->user_desc = $user_desc;
         $user_c->save();
         $user_image = UserImage::where('user_id', $user_id)->where('type', 2)->first();
         if (!$user_image) {
             $user_image_model = new UserImage();
             $user_image_model->user_id = $user_id;
             $user_image_model->image_url = $image_url_real1_w;
             $user_image_model->type = 2;
             $user_image_model->is_completion = 0;
             $user_image_model->save();
         } else {
             $user_image->image_url = $image_url_real1_w;
             $user_image->save();
         }
         if ($image_url_real2_w) {
             $user_image = UserImage::where('user_id', $user_id)->where('type', 3)->first();
             if (!$user_image) {
                 $user_image_model = new UserImage();
                 $user_image_model->user_id = $user_id;
                 $user_image_model->image_url = $image_url_real2_w;
                 $user_image_model->type = 3;
                 $user_image_model->is_completion = 0;
                 $user_image_model->save();
             } else {
                 $user_image->image_url = $image_url_real2_w;
                 $user_image->save();
             }
         }
         if ($image_url_real3_w) {
             $user_image = UserImage::where('user_id', $user_id)->where('type', 3)->first();
             if (!$user_image) {
                 $user_image_model = new UserImage();
                 $user_image_model->user_id = $user_id;
                 $user_image_model->image_url = $image_url_real3_w;
                 $user_image_model->type = 3;
                 $user_image_model->is_completion = 0;
                 $user_image_model->save();
             } else {
                 $user_image->image_url = $image_url_real3_w;
                 $user_image->save();
             }
         }
     }
     return $this->returnAddJs('编辑成功!');
 }