コード例 #1
0
ファイル: BusinessService.php プロジェクト: xiongjiewu/shui
 /**
  * 商户暂停发送亲水包
  * @param $user_id
  * @return array
  */
 public function businessEnd($user_id)
 {
     $user_financial = new UserFinancial();
     $result = $user_financial->where('user_id', $user_id)->first();
     if (!empty($result)) {
         $bool = $user_financial->where('user_id', $user_id)->update(['giving' => UserFinancial::DEFAULT_GIVING]);
     } else {
         $user_financial->user_id = $user_id;
         $user_financial->giving = UserFinancial::DEFAULT_GIVING;
         $bool = $user_financial->save();
     }
     if ($bool) {
         return ['status' => true, 'message' => 'success', 'info' => []];
     } else {
         return ['status' => false, 'message' => '设置失败!', 'info' => []];
     }
 }
コード例 #2
0
ファイル: OrderService.php プロジェクト: xiongjiewu/shui
 /**
  * 确认订单
  * @param $params
  * @param $user_id
  * @return array
  */
 public function businessBankSure($params, $user_id)
 {
     $order_id = $params->get('business_orderID');
     if (empty($order_id)) {
         return ['status' => false, 'message' => '订单ID不能为空!', 'info' => []];
     }
     /** @var \App\Model\OrderLog */
     $order_log = new OrderLog();
     $result = $order_log->where('order_id', $order_id)->where('user_id', $user_id)->first();
     if ($result->status == OrderLog::STATUS_IS_TRUE) {
         return ['status' => false, 'message' => '请勿重复充值!', 'info' => []];
     }
     $user_financial = new UserFinancial();
     $user_financial_result = $user_financial->where('user_id', $user_id)->first();
     if (empty($user_financial_result)) {
         $user_financial->user_id = $user_id;
         $user_financial->water_count = $result->water_count;
         $user_financial->price = $result->price;
         $user_financial->save();
     } else {
         $user_financial->where('user_id', $user_id)->update(['water_count' => $user_financial_result->water_count + $result->water_count, 'price' => $user_financial_result->price + $result->price]);
     }
     $result = $order_log->where('order_id', $order_id)->update(['status' => OrderLog::STATUS_IS_TRUE]);
     if ($result) {
         return ['status' => true, 'message' => '提交成功!', 'info' => []];
     } else {
         return ['status' => false, 'message' => '提交失败!', 'info' => []];
     }
 }
コード例 #3
0
ファイル: UserService.php プロジェクト: xiongjiewu/shui
 /**
  * 第三方平台注册
  * @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));
 }
コード例 #4
0
ファイル: WaterService.php プロジェクト: xiongjiewu/shui
 /**
  * 水地图亲水包获取
  * @param $params
  * @param $user_id
  * @return Array
  */
 public function mapBag($params, $user_id)
 {
     $user_financial = new UserFinancial();
     $result = $user_financial->where('user_id', $params->get('storeId'))->first();
     if (empty($result)) {
         return ['status' => false, 'message' => '店铺ID不存在!', 'info' => []];
     }
     if ($result->giving == 0 || $result->water_count < $result->giving) {
         return ['status' => false, 'message' => '已经领取完了!', 'info' => []];
     }
     $start_now_time = Carbon::now()->format('Y-m-d') . ' 00:00:01';
     $end_now_time = Carbon::now()->format('Y-m-d') . ' 23:23:59';
     $get_show_water_log = new GetShopWaterLog();
     $is_giving = $get_show_water_log->where('user_id', $params->get('storeId'))->where('giving_user_id', $user_id)->whereBetween('created_at', [$start_now_time, $end_now_time])->first();
     if (!empty($is_giving)) {
         return ['status' => false, 'message' => '今天您已经领取过,请勿重复领取!', 'info' => []];
     }
     $bool = $user_financial->where('user_id', $params->get('storeId'))->update(['water_count' => $result->water_count - $result->giving, 'send_water' => $result->send_water + $result->giving]);
     if ($bool) {
         $my_result = $user_financial->where('user_id', $user_id)->first();
         if (!empty($my_result)) {
             $user_financial->where('user_id', $user_id)->update(['public_count' => $my_result->public_count + $result->giving]);
         } else {
             $user_financial->user_id = $user_id;
             $user_financial->public_count = $result->giving;
             $user_financial->save();
         }
         //给与推荐给我相关的人分享一半的值
         $user_relationship = new UserRelationship();
         $user_relationship_rt = $user_relationship->where('guest_id', $user_id)->first();
         $has_guest = false;
         if (!empty($user_relationship_rt) && $result->water_count - $result->giving - $result->giving * UserRelationship::getGuestRate() >= 0) {
             $has_guest = true;
             $be_guest_result = $user_financial->where('user_id', $params->get('storeId'))->first();
             $user_financial->where('user_id', $params->get('storeId'))->update(['water_count' => $result->water_count - $result->giving - $result->giving * UserRelationship::getGuestRate(), 'send_water' => $result->send_water + $result->giving + $result->giving * UserRelationship::getGuestRate()]);
             if (!empty($be_guest_result)) {
                 $be_guest_user = $user_financial->where('user_id', $user_relationship_rt->user_id)->first();
                 if (!empty($be_guest_user)) {
                     $user_financial->where('user_id', $user_relationship_rt->user_id)->update(['public_count' => $be_guest_user->public_count + $result->giving * UserRelationship::getGuestRate()]);
                 } else {
                     $user_financial->user_id = $user_relationship_rt->user_id;
                     $user_financial->public_count = $result->giving * UserRelationship::getGuestRate();
                     $user_financial->save();
                 }
                 $get_show_water_log = new GetShopWaterLog();
                 $get_show_water_log->user_id = $params->get('storeId');
                 $get_show_water_log->water_count = $result->giving * UserRelationship::getGuestRate();
                 $get_show_water_log->giving_user_id = $user_relationship_rt->user_id;
                 $get_show_water_log->type = GetShopWaterLog::GUEST_GET_TYPE;
                 $get_show_water_log->save();
                 unset($get_show_water_log);
             }
         }
         $guest_val = 0;
         if ($has_guest == true) {
             $guest_val = UserRelationship::getGuestRate();
         }
         //再扣除公益值
         if ($result->water_count - $result->giving - $result->giving * $guest_val - $result->giving * SystemHasWater::getRate() >= 0) {
             $user_financial->where('user_id', $params->get('storeId'))->update(['water_count' => $result->water_count - $result->giving - $result->giving * $guest_val - $result->giving * SystemHasWater::getRate(), 'send_water' => $result->send_water + $result->giving + $result->giving * $guest_val + $result->giving * SystemHasWater::getRate()]);
             $system_has_water = new SystemHasWater();
             $system_has_water->business_id = $params->get('storeId');
             $system_has_water->sys_water_count = $result->giving * SystemHasWater::getRate();
             $system_has_water->rate = SystemHasWater::getRate();
             $system_has_water->save();
             unset($system_has_water);
             $get_show_water_log = new GetShopWaterLog();
             $get_show_water_log->user_id = $params->get('storeId');
             $get_show_water_log->water_count = $result->giving * SystemHasWater::getRate();
             $get_show_water_log->type = GetShopWaterLog::SYS_GET_TYPE;
             $get_show_water_log->save();
             unset($get_show_water_log);
         }
         $get_show_water_log = new GetShopWaterLog();
         $get_show_water_log->user_id = $params->get('storeId');
         $get_show_water_log->water_count = $result->giving;
         $get_show_water_log->giving_user_id = $user_id;
         $get_show_water_log->type = GetShopWaterLog::USER_GET_TYPE;
         $get_show_water_log->save();
         unset($get_show_water_log);
         return ['status' => true, 'message' => '领取成功!', 'info' => ['water_count' => $result->giving]];
     }
     return ['status' => false, 'message' => '领取失败!', 'info' => []];
 }
コード例 #5
0
ファイル: ShareService.php プロジェクト: xiongjiewu/shui
 /**
  * 接受手机号 验证码 分享批次-邀请码
  * @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' => []];
     }
 }
コード例 #6
0
ファイル: UserController.php プロジェクト: xiongjiewu/shui
 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('编辑成功!');
 }