Exemplo n.º 1
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]);
         }
     }
 }
Exemplo n.º 2
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'];
         }
     }
 }
Exemplo n.º 3
0
 /**
  * 亲水列表
  * @param $params
  * @param $user_id
  * @return array
  */
 public function bagList($params, $user_id)
 {
     $page = $params->get('page') ?: 1;
     $count = $params->get('count') ?: 10;
     $user_send_water = new UserSendWater();
     $result = [];
     $send_water = 0;
     if ($params->get('status')) {
         switch ($params->get('status')) {
             case 0:
                 $result = $user_send_water->where('accept_user_id', $user_id)->where('status', UserSendWater::STATUS_IS_FALSE)->where('overdue_date', '>=', time())->skip(($page - 1) * $count)->take($count)->get()->toArray();
                 $send_water = $user_send_water->where('accept_user_id', $user_id)->where('status', UserSendWater::STATUS_IS_FALSE)->count();
                 break;
             case 1:
                 $result = $user_send_water->where('accept_user_id', $user_id)->where('status', UserSendWater::STATUS_IS_TRUE)->where('overdue_date', '>=', time())->skip(($page - 1) * $count)->take($count)->get()->toArray();
                 $send_water = $user_send_water->where('accept_user_id', $user_id)->where('status', UserSendWater::STATUS_IS_FALSE)->count();
                 break;
             case 2:
                 $result = $user_send_water->where('accept_user_id', $user_id)->whereBetween('status', [0, 2])->where('overdue_date', '<', time())->skip(($page - 1) * $count)->take($count)->get()->toArray();
                 $send_water = $user_send_water->where('status', UserSendWater::STATUS_IS_FALSE)->count();
                 break;
         }
     } else {
         $result = $user_send_water->where('accept_user_id', $user_id)->skip(($page - 1) * $count)->take($count)->get()->toArray();
         $send_water = $user_send_water->where('accept_user_id', $user_id)->count();
     }
     $next_page = ($page - 1) * $count >= $send_water ? $page : $page + 1;
     $pager = ['page' => $page, 'count' => $count, 'total' => $send_water, 'next' => $next_page];
     if (empty($result)) {
         return ['status' => true, 'message' => 'success', 'info' => [], 'pager' => $pager];
     }
     $user_ids = [];
     foreach ($result as $value) {
         $user_ids[] = $value['user_id'];
     }
     $user_result = UserBase::whereIn('user_id', array_unique($user_ids))->get()->toArray();
     $user_list = [];
     foreach ($user_result as $user_result_val) {
         $user_list[$user_result_val['user_id']] = $user_result_val['user_name'] ?: '匿名';
     }
     $list = [];
     foreach ($result as $value) {
         $list[] = ['bag_id' => $value['id'], 'water_num' => $value['water_count'], 'from_id' => $value['user_id'], 'from_name' => $user_list[$value['user_id']], 'create_time' => $value['created_at'], 'get_time' => $value['updated_at'], 'status' => $value['status']];
     }
     return ['status' => true, 'message' => 'success', 'info' => $list, 'pager' => $pager];
 }
Exemplo n.º 4
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' => []];
     }
 }