/**
  * @param $job
  * @param $data
  */
 public function fire($job, $data)
 {
     $job->delete();
     if (!empty($data['share_id'])) {
         $user_share_log = new UserShareLog();
         $user_share_log_rt = $user_share_log->where('id', $data['share_id'])->first();
         if ($user_share_log_rt->status == UserShareLog::SHARE_OK) {
             $user_share_log->where('id', $data['share_id'])->update(['status' => UserShareLog::SHARE_NO]);
             $user_ry = $user_share_log_rt->share_water_count - $user_share_log_rt->share_receive;
             $user_financial = new UserFinancial();
             $user_rt = $user_financial->where('user_id', $user_share_log_rt->user_id)->first();
             $user_financial->where('user_id', $user_share_log_rt->user_id)->update(['water_count' => $user_rt->water_count + $user_ry, 'send_water' => $user_rt->send_water - $user_ry]);
         }
     }
 }
示例#2
0
 /**
  * @param $job
  * @param $data
  */
 public function fire($job, $data)
 {
     $job->delete();
     if (!empty($data['send_id'])) {
         $user_send_water = new UserSendWater();
         $result = $user_send_water->where('id', $data['send_id'])->first();
         if (!empty($result) && $result->status == UserSendWater::STATUS_IS_FALSE) {
             $user_send_water->where('id', $data['send_id'])->update(['status' => UserSendWater::STATUS_IS_ACTIVE_FALSE]);
             $user_financial_result = UserFinancial::where('user_id', $result->user_id)->first();
             UserFinancial::where('user_id', $result->user_id)->update(['water_count' => $user_financial_result->water_count + $result->water_count, 'send_water' => $user_financial_result->send_water - $result->water_count]);
         }
     }
 }
示例#3
0
 /**
  * 回收分享的亲水值
  * Execute the console command.
  * @return mixed
  */
 public function fire()
 {
     $i = 0;
     while (true) {
         $user_share_water = new UserShareLog();
         $rt = $user_share_water->where('status', UserShareLog::SHARE_OK)->where('id', '>', $i)->orderBy('id', 'asc')->limit($this->limit)->get()->toArray();
         if (empty($rt)) {
             break;
         }
         foreach ($rt as $v) {
             if (strtotime($v['created_at']) - time() >= UserShareLog::getSystemTime()) {
                 $user_share_water->where('id', $v['id'])->update(['status' => UserShareLog::SHARE_NO]);
                 $user_ry = $v['share_water_count'] - $v['share_receive'];
                 if ($user_ry > 0) {
                     $user_financial = new UserFinancial();
                     $user_rt = $user_financial->where('user_id', $v['user_id'])->first();
                     $user_financial->where('user_id', $v['user_id'])->update(['water_count' => $user_rt->water_count + $user_ry, 'send_water' => $user_rt->send_water - $user_ry]);
                 }
             }
             $i = $v['id'];
         }
     }
 }
示例#4
0
 /**
  * 回收亲水值
  * Execute the console command.
  * @return mixed
  */
 public function fire()
 {
     $i = 0;
     while (true) {
         $user_send_water = new UserSendWater();
         $user_send_rt = $user_send_water->where('status', UserSendWater::STATUS_IS_FALSE)->where('id', '>', $i)->limit($this->limit)->orderBy('id', 'asc')->get()->toArray();
         if (empty($user_send_rt)) {
             break;
         }
         $user_financial = new UserFinancial();
         foreach ($user_send_rt as $user_send_rt_v) {
             //如果创建时间比现在超过48小时则算无效
             if (strtotime($user_send_rt_v['created_at']) - time() >= UserSendWater::getSystemTime()) {
                 $result = $user_send_water->where('id', $user_send_rt['id'])->first();
                 if (!empty($result) && $result->status == UserSendWater::STATUS_IS_FALSE) {
                     $user_send_water->where('id', $user_send_rt['id'])->update(['status' => UserSendWater::STATUS_IS_ACTIVE_FALSE]);
                     $user_financial_result = $user_financial->where('user_id', $result->user_id)->first();
                     $user_financial->where('user_id', $result->user_id)->update(['water_count' => $user_financial_result->water_count + $result->water_count, 'send_water' => $user_financial_result->send_water - $result->water_count]);
                 }
             }
             $i = $user_send_rt['id'];
         }
     }
 }
示例#5
0
 /**
  * 公益捐款
  * @param $params
  * @param $user_id
  * @return array
  */
 public function activeDonations($params, $user_id)
 {
     if (!$params->get('activeID')) {
         return ['status' => false, 'message' => '活动ID不能为空!', 'info' => []];
     }
     if (!$params->get('money')) {
         return ['status' => false, 'message' => '金额不能为空!', 'info' => []];
     }
     //金额转换亲水值
     $money_to_water = $params->get('money') * ActivityDonationsLog::getRate();
     $user_financial = new UserFinancial();
     $user_financial_result = $user_financial->where('user_id', $user_id)->first();
     if ($user_financial_result->water_count < $money_to_water) {
         return ['status' => false, 'message' => '你的亲水值不够!', 'info' => []];
     }
     $bool = $user_financial->where('user_id', $user_id)->update(['water_count' => $user_financial_result->water_count - $money_to_water, 'send_water' => $user_financial_result->send_water + $money_to_water]);
     if ($bool) {
         $activity_fundraising = new ActivityFundraising();
         $activity_fundraising_result = $activity_fundraising->where('activity_id', $params->get('activeID'))->first();
         $activity_fundraising->where('activity_id', $params->get('activeID'))->update(['fundraising_count' => $activity_fundraising_result->fundraising_count + 1, 'existing_price' => $activity_fundraising_result->existing_price + $params->get('money')]);
         //记录日志
         $activity_donations_log = new ActivityDonationsLog();
         $activity_donations_log->active_id = $params->get('activeID');
         $activity_donations_log->user_id = $user_id;
         $activity_donations_log->water_count = $money_to_water;
         $activity_donations_log->price = $params->get('money');
         $activity_donations_log->rate = ActivityDonationsLog::getRate();
         $activity_donations_log->save();
         return ['status' => true, 'message' => '捐款成功!', 'info' => []];
     }
     return ['status' => false, 'message' => '系统错误!', 'info' => []];
 }
示例#6
0
 /**
  * 商户暂停发送亲水包
  * @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' => []];
     }
 }
示例#7
0
 /**
  * 用户护水值
  * @param $user_id
  * @return array
  */
 public function donations($user_id)
 {
     $user_financial = new UserFinancial();
     $user_financial_result = $user_financial->where('user_id', $user_id)->first();
     $data['protect_number'] = 0;
     $data['water_price'] = 0;
     if (!empty($user_financial_result)) {
         $data['protect_number'] = $user_financial_result->water_count;
         $data['water_price'] = $user_financial_result->water_count / OrderLog::getRate();
     }
     return ['status' => true, 'message' => '反馈成功!', 'info' => $data];
 }
示例#8
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;
     }
 }
示例#9
0
 /**
  * 水银行信息
  * @param $user_id
  * @return array
  */
 public function bankInfo($user_id)
 {
     $data = [];
     $user_black_water = UserBlackWater::where('user_id', $user_id)->first();
     $data['water_num'] = empty($user_black_water) ? 0 : $user_black_water->black_water;
     $user_financial = new UserFinancial();
     $data['person_water'] = $user_financial->sum('water_count');
     $user_financial_result = $user_financial->where('user_id', $user_id)->first();
     $data['protect_num'] = $user_financial_result ? $user_financial_result->water_count : 0;
     $data['water_rank'] = UserRank::getUserRank($user_id);
     return ['status' => true, 'message' => 'success', 'info' => $data];
 }
示例#10
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' => []];
     }
 }
示例#11
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('编辑成功!');
 }