Exemple #1
0
 /**
  * 亲水圈活动详情
  * @param $params
  * @param $user_id
  * @return array
  */
 public function circleDetail($params, $user_id)
 {
     if (!$params->get('circleID')) {
         return ['status' => false, 'message' => '活动ID不能为空!', 'info' => []];
     }
     /** @var $activity \App\Model\Activity */
     $activity = new Activity();
     $activity_result = $activity->where('activity_id', $params->get('circleID'))->StatusOk()->first();
     if (empty($activity_result)) {
         return ['status' => false, 'message' => '活动不存在!', 'info' => []];
     }
     $activity_comment = new ActivityComment();
     $data['active_id'] = $params->get('circleID');
     $data['video_url'] = ActivityImage::getImages($params->get('circleID'), ActivityImage::TYPE_IMAGE_IS_GIF);
     $data['title'] = $activity_result->title;
     $data['content'] = $activity_result->desc;
     $data['address'] = $activity_result->address;
     $data['create_time'] = (string) $activity_result->created_at;
     $data['is_focus'] = UserFocus::userIsFocus($params->get('circleID'), $user_id);
     $data['support_count'] = $activity_result->focus_count;
     $data['comment_count'] = $activity_comment->where('activity_id', $params->get('circleID'))->count();
     $data['focus_count'] = (new UserFocus())->where('activity_id', $params->get('circleID'))->count();
     $activity_comment_result = $activity_comment->where('activity_id', $params->get('circleID'))->orderBy('created_at', 'desc')->limit(2)->get();
     if (!empty($activity_comment_result)) {
         $user_ids = [];
         foreach ($activity_comment_result as $activity_comment_result_v) {
             array_push($user_ids, $activity_comment_result_v->user_id);
         }
         $user_base = new UserBase();
         $user_base_result = $user_base->whereIn('user_id', $user_ids)->get();
         $user_image = new UserImage();
         $user_image_result = $user_image->whereIn('user_id', $user_ids)->get();
         $user_image_list = [];
         foreach ($user_image_result as $user_image_result_v) {
             $user_image_list[$user_image_result_v->user_id] = $user_image_result_v->path();
         }
         $user_list = [];
         foreach ($user_base_result as $user_base_result_v) {
             $user_list[$user_base_result_v->user_id] = ['id' => $user_base_result_v->user_id, 'name' => $user_base_result_v->user_name, 'image_url' => isset($user_image_list[$user_base_result_v->user_id]) ? $user_image_list[$user_base_result_v->user_id] : ActivityImage::defaultImage()];
         }
         foreach ($activity_comment_result as $activity_comment_result_v_v) {
             if (isset($user_list[$activity_comment_result_v_v->user_id])) {
                 $data['comment_list'][] = ['comment_id' => $activity_comment_result_v_v->id, 'comment_name' => $user_list[$activity_comment_result_v_v->user_id]['name'], 'comment_image_url' => $user_list[$activity_comment_result_v_v->user_id]['image_url'], 'comment_date' => (string) $activity_comment_result_v_v->created_at, 'comment_detail' => $activity_comment_result_v_v->content];
             }
         }
     }
     return ['status' => true, 'message' => '获取成功!', 'info' => $data];
 }
Exemple #2
0
 /**
  * 为商户设置新图片
  * @param $user_id
  * @param $business_allow_image_path
  * @param $business_image_path
  * @param $business_image2_path
  * @return array
  */
 public function setBusinessNewImage($user_id, $business_allow_image_path, $business_image_path, $business_image2_path)
 {
     if (!empty($business_allow_image_path)) {
         $user_image_model_o = new UserImage();
         $user_image_model_o->user_id = $user_id;
         $user_image_model_o->type = UserImage::TYPE_BUSINESS;
         $user_image_model_o->image_url = $business_allow_image_path;
         $user_image_model_o->save();
         unset($user_image_model_o);
     }
     if (!empty($business_image_path)) {
         $user_image_model_t = new UserImage();
         $user_image_model_t->user_id = $user_id;
         $user_image_model_t->type = UserImage::TYPE_SHOP;
         $user_image_model_t->image_url = $business_image_path;
         $user_image_model_t->save();
         unset($user_image_model_t);
     }
     if (!empty($business_image2_path)) {
         $user_image_model_f = new UserImage();
         $user_image_model_f->user_id = $user_id;
         $user_image_model_f->type = UserImage::TYPE_SHOP;
         $user_image_model_f->image_url = $business_image2_path;
         $user_image_model_f->save();
         unset($user_image_model_f);
     }
     $data = [];
     $data['business_id'] = $user_id;
     $user_image_model = new UserImage();
     $result = $user_image_model->where('user_id', $user_id)->get();
     foreach ($result as $value) {
         if ($value['type'] == UserImage::TYPE_BUSINESS) {
             $data['business_allowImage'] = $value->path();
         }
         if ($value['type'] == UserImage::TYPE_SHOP) {
             if (empty($data['business_image'])) {
                 $data['business_image'] = $value->path();
             } else {
                 $data['business_image2'] = $value->path();
             }
         }
     }
     return ['status' => true, 'message' => 'success', 'info' => $data];
 }
Exemple #3
0
 /**
  * 第三方平台注册
  * @param $params
  * @return array
  */
 public function otherRegister($params)
 {
     if (!$params->get('open_id')) {
         return ['status' => false, 'message' => '用户唯一标识不能为空!'];
     }
     if (!$params->get('type')) {
         return ['status' => false, 'message' => '登入来源标识不能为空!'];
     }
     $user_third_parth = new UserThirdParty();
     $rt = $user_third_parth->where('user_other_id', $params->get('open_id'))->where('type', $params->get('type'))->first();
     $user_base = new UserBase();
     $user_image = new UserImage();
     //如果没注册过
     if (empty($rt) && in_array($params->get('type'), [UserThirdParty::TX_QQ, UserThirdParty::WEI_XIN])) {
         $user_base->invite_code = time() . mt_rand(100, 999);
         if ($params->get('nick_name')) {
             $user_base->user_name = $params->get('nick_name');
         }
         $user_base->save();
         if ($user_base->user_id) {
             $user_third_parth->user_other_id = $params->get('open_id');
             $user_third_parth->type = $params->get('type');
             $user_third_parth->user_id = $user_base->user_id;
             $user_third_parth->save();
             $image = $user_image->where('user_id', $user_base->user_id)->head()->first();
             if (empty($image)) {
                 $user_image->image_url = $params->get('head_img') ?: UserImage::defaultImage();
                 $user_image->user_id = $user_base->user_id;
                 $user_image->is_completion = UserImage::IS_COMPLETION_TRUE;
                 $user_image->type = UserImage::TYPE_HEAD;
                 $user_image->save();
             } else {
                 $user_image->where('user_id', $user_base->user_id)->where('type', UserImage::TYPE_HEAD)->update(['image_url' => $params->get('head_img') ?: UserImage::defaultImage()]);
             }
             if (UserFinancial::getInitialize() > 0) {
                 $user_financial = new UserFinancial();
                 $user_financial->user_id = $user_base->user_id;
                 $user_financial->water_count = UserFinancial::getInitialize();
                 $user_financial->save();
             }
         } else {
             return ['status' => false, 'message' => '系统一个人去旅行了,请稍后重试!'];
         }
         $user = $user_base->where('user_id', $user_base->user_id)->IsOpen()->first()->toArray();
         if ($params->get('head_img')) {
             $user['user_head'] = $params->get('head_img');
         } else {
             $user['user_head'] = UserImage::defaultImage();
         }
         $user['token'] = TokenService::tokenEncode($user_base->user_id);
         UserLoginLog::insert_login_log($user_base->user_id);
         return $this->outputFormat(true, 'success', $this->formatUser($user));
     }
     //如果已经注册过
     $user = $user_base->where('user_id', $rt->user_id)->IsOpen()->first()->toArray();
     $image = $user_image->where('user_id', $rt->user_id)->head()->first();
     if ($image) {
         $user['user_head'] = $image->path();
     } else {
         $user['user_head'] = UserImage::defaultImage();
     }
     $user['token'] = TokenService::tokenEncode($rt->user_id);
     UserLoginLog::insert_login_log($rt->user_id);
     return $this->outputFormat(true, 'success', $this->formatUser($user));
 }
Exemple #4
0
 /**
  * 水地图列表
  * @param $params
  * @return array
  */
 public function mapList($params)
 {
     if ($params->get('longitude') && $params->get('latitude')) {
         //            $squares = $this->returnSquarePoint($params->get('longitude'), $params->get('latitude'), $params->get('radius') ?: null);
         //            $result = UserCompanyExtend::where('user_company_lat', '>', '0')
         //                ->where('user_company_lat', '>=', $squares['right-bottom']['lat'])
         //                ->where('user_company_lat', '<=', $squares['left-top']['lat'])
         //                ->where('user_company_lng', '>=', $squares['left-top']['lng'])
         //                ->where('user_company_lng', '<=', $squares['right-bottom']['lng'])
         //                ->get();
         $user_company_extend = new UserCompanyExtend();
         $result = $user_company_extend->get();
         if (empty($result)) {
             return ['status' => true, 'message' => '获取成功!', 'info' => []];
         }
         $user_ids = [];
         foreach ($result as $result_val) {
             $user_ids[] = $result_val->user_id;
         }
         $user_images_result = UserImage::whereIn('user_id', $user_ids)->Head()->get();
         $images = [];
         if (!empty($user_images_result)) {
             foreach ($user_images_result as $user_images_result_val) {
                 $images[$user_images_result_val->user_id] = $user_images_result_val->path();
             }
         }
         $user_financial_result = UserFinancial::whereIn('user_id', $user_ids)->get();
         $financial = [];
         if (!empty($user_financial_result)) {
             foreach ($user_financial_result as $user_financial_result_val) {
                 $financial[$user_financial_result_val->user_id] = $user_financial_result_val->water_count;
             }
         }
         $data = [];
         foreach ($result as $result_value) {
             $data[] = ['store_id' => $result_value->user_id, 'store_name' => $result_value->user_company_name, 'image_url' => isset($images[$result_value->user_id]) ? $images[$result_value->user_id] : '', 'left_num' => isset($financial[$result_value->user_id]) ? $financial[$result_value->user_id] : 0, 'latitude' => $result_value->user_company_lat, 'longitude' => $result_value->user_company_lng, 'distance' => $this->getDistance($params->get('latitude'), $params->get('longitude'), $result_value->user_company_lat, $result_value->user_company_lng)];
         }
         return ['status' => true, 'msg' => 'success', 'info' => $data];
     } else {
         return ['status' => false, 'message' => '缺少经纬度参数!', 'info' => []];
     }
 }
Exemple #5
0
 /**
  * 接受手机号 验证码 分享批次-邀请码
  * @param $params
  * @return array
  */
 public function shareGet($params)
 {
     $code = $params->get('code');
     $e = explode('-', $code);
     if (count($e) == 2) {
         $user_share_log = new UserShareLog();
         $user_share_log_tr = $user_share_log->where('share_time', $e[0])->first();
         if (empty($user_share_log_tr)) {
             return ['status' => false, 'message' => '非法参数', 'code' => 1, 'info' => []];
         }
         if ($user_share_log_tr->status == UserShareLog::SHARE_NO) {
             return ['status' => false, 'message' => '分享已经结束', 'code' => 2, 'info' => []];
         }
         $rt = $this->checkVerify($params->get('cellphone'), $params->get('verify'));
         if (!$rt['status']) {
             return ['status' => false, 'code' => 3, 'message' => $rt['message'], 'userInfo' => []];
         }
         //注册成为用户
         $user_base = new UserBase();
         $user_base_rt = $user_base->where('user_cellphone', $params->get('cellphone'))->first();
         if (empty($user_base_rt)) {
             $user_id = $user_base->user_id;
             $password = mt_rand(100000, 999999);
             $user_base->user_cellphone = $params->get('cellphone');
             $user_base->password = $this->encryptPassword($password);
             $user_base->user_name = !empty($user_name) ? $user_name : '';
             $user_base->invite_code = crc32(md5($params->get('cellphone')));
             if ($user_base->save()) {
                 //发送短信提示
                 $user_verify = new UserVerify();
                 $content = '感谢你注册水想世界,您的APP登入密码为' . $password . ',请尽快登入之后修改密码噢~';
                 $user_verify->getSendMsgUrl($params->get('cellphone'), $content);
                 //建立图片
                 $user_image = new UserImage();
                 $user_image->user_id = $user_base->user_id;
                 $user_image->image_url = UserImage::defaultImage();
                 $user_image->type = UserImage::TYPE_HEAD;
                 $user_image->save();
                 //绑定关系
                 $user_relationship = new UserRelationship();
                 $user_relationship_rt = $user_relationship->where('user_id', $user_share_log_tr->user_id)->where('guest_id', $user_base->user_id)->first();
                 if (!empty($user_relationship_rt)) {
                     $user_relationship->user_id = $user_share_log_tr->user_id;
                     $user_relationship->guest_id = $user_base->user_id;
                     $user_relationship->save();
                 }
             }
         } else {
             $user_id = $user_base_rt->user_id;
         }
         $user_share_receive_log = new UserShareReceiveLog();
         $s = $user_share_receive_log->where('share_id', $user_share_log_tr->id)->where('share_receive_user_id', $user_id)->first();
         if (!empty($s)) {
             return ['status' => false, 'code' => 4, 'message' => '您已经领取过', 'info' => ['water_count' => $s->share_water_count]];
         }
         if (!empty($user_id)) {
             //开始分享
             $water = 0;
             $share_count = 0;
             $share_status = 1;
             switch ($user_share_log_tr->share_count) {
                 case 0:
                     $water = ceil($user_share_log_tr->share_water_count / 3);
                     $share_count = 1;
                     break;
                 case 1:
                     $water = ceil(($user_share_log_tr->share_water_count - $user_share_log_tr->share_receive) / 2);
                     $share_count = 2;
                     break;
                 case 2:
                     $water = $user_share_log_tr->share_water_count - $user_share_log_tr->share_receive;
                     $share_count = 3;
                     $share_status = 0;
                     break;
             }
             //放入用户账户
             $user_financial = new UserFinancial();
             $user_f_rt = $user_financial->where('user_id', $user_id)->first();
             if (empty($user_f_rt)) {
                 $user_financial->user_id = $user_id;
                 $user_financial->water_count = $water;
                 $user_financial->save();
             } else {
                 $user_financial->where('user_id', $user_id)->update(['water_count' => $user_f_rt->water_count + $water]);
             }
             $user_share_log->where('id', $user_share_log_tr->id)->update(['share_count' => $share_count, 'status' => $share_status, 'share_receive' => $user_share_log_tr->share_receive + $water]);
             //建立领取记录
             $user_send_water = new UserSendWater();
             $user_send_water->user_id = $user_share_log_tr->user_id;
             $user_send_water->water_count = $water;
             $user_send_water->accept_user_id = $user_id;
             $user_send_water->overdue_date = time();
             $user_send_water->share_type = UserSendWater::SHARE_TYPE_WEIXIN;
             $user_send_water->status = UserSendWater::STATUS_IS_TRUE;
             $user_send_water->save();
             //记录每期领取的人
             $user_share_receive_log->share_id = $user_share_log_tr->id;
             $user_share_receive_log->share_receive_user_id = $user_id;
             $user_share_receive_log->share_water_count = $water;
             $user_share_receive_log->save();
             return ['status' => true, 'message' => '领取成功', 'info' => ['water_count' => $water]];
         } else {
             return ['status' => false, 'code' => 5, 'message' => '系统一个人旅行去了,请重试!', 'info' => []];
         }
     } else {
         return ['status' => false, 'code' => 1, 'message' => '非法参数', 'info' => []];
     }
 }
Exemple #6
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('编辑成功!');
 }