user()->toArray(); $broken_time = intval(sys_config('extract_time')); $search_time = time() - 86400 * $broken_time; //返佣 + $brokerage_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage']) ->where('add_time', '>', $search_time) ->where('pm', 1) ->sum('number'); //退款退的佣金 - $refund_commission = UserBill::where(['uid' => $info['uid'], 'category' => 'now_money', 'type' => 'brokerage']) ->where('add_time', '>', $search_time) ->where('pm', 0) ->sum('number'); $info['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2); if ($info['broken_commission'] < 0) $info['broken_commission'] = 0; $info['commissionCount'] = bcsub($info['brokerage_price'], $info['broken_commission'], 2); if ($info['commissionCount'] < 0) $info['commissionCount'] = 0; if ($info['uid'] != 10045){ UserLevel::setLevelComplete($info['uid']); } $info['is_enter'] = 0; if (UserEnter::where('uid', $info['uid'])->where('status', 0)->find()){ $info['is_enter'] = 1; }elseif (UserEnter::where('uid', $info['uid'])->where('status', 1)->find()){ $info['is_enter'] = 2; } return app('json')->success($info); } /** * 用户资金统计 * @param Request $request * @return mixed * @throws \think\Exception * @throws DataNotFoundException * @throws ModelNotFoundException * @throws \think\exception\DbException */ public function balance(Request $request) { $uid = $request->uid(); $user['now_money'] = User::getUserInfo($uid, 'now_money')['now_money'];//当前总资金 $user['recharge'] = UserBill::getRecharge($uid);//累计充值 $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($uid);//累计消费 return app('json')->successful($user); } /** * 个人中心 * @param Request $request * @return mixed */ public function user(Request $request) { $user = $request->user(); $user = $user->toArray(); $user['couponCount'] = StoreCouponUser::getUserValidCouponCount($user['uid']); $user['like'] = StoreProductRelation::getUserIdCollect($user['uid']); $user['orderStatusNum'] = StoreOrder::getOrderData($user['uid']); $user['notice'] = UserNotice::getNotice($user['uid']); // $user['brokerage'] = UserBill::getBrokerage($user['uid']);//获取总佣金 $user['recharge'] = UserBill::getRecharge($user['uid']);//累计充值 $user['orderStatusSum'] = StoreOrder::getOrderStatusSum($user['uid']);//累计消费 $user['extractTotalPrice'] = UserExtract::userExtractTotalPrice($user['uid']);//累计提现 $user['extractPrice'] = $user['brokerage_price'];//可提现 $user['statu'] = (int)sys_config('store_brokerage_statu'); $broken_time = intval(sys_config('extract_time')); $search_time = time() - 86400 * $broken_time; if (!$user['is_promoter'] && $user['statu'] == 2) { $price = StoreOrder::where(['paid' => 1, 'refund_status' => 0, 'uid' => $user['uid']])->sum('pay_price'); $status = is_brokerage_statu($price); if ($status) { User::where('uid', $user['uid'])->update(['is_promoter' => 1]); $user['is_promoter'] = 1; } else { $storeBrokeragePrice = sys_config('store_brokerage_price', 0); $user['promoter_price'] = bcsub($storeBrokeragePrice, $price, 2); } } //可提现佣金 //返佣 + $brokerage_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage']) ->where('add_time', '>', $search_time) ->where('pm', 1) ->sum('number'); //退款退的佣金 - $refund_commission = UserBill::where(['uid' => $user['uid'], 'category' => 'now_money', 'type' => 'brokerage']) ->where('add_time', '>', $search_time) ->where('pm', 0) ->sum('number'); $user['broken_commission'] = bcsub($brokerage_commission, $refund_commission, 2); if ($user['broken_commission'] < 0) $user['broken_commission'] = 0; $user['commissionCount'] = bcsub($user['brokerage_price'], $user['broken_commission'], 2); if ($user['commissionCount'] < 0) $user['commissionCount'] = 0; if (!sys_config('vip_open')) $user['vip'] = false; else { $vipId = UserLevel::getUserLevel($user['uid']); $user['vip'] = $vipId !== false ? true : false; if ($user['vip']) { $user['vip_id'] = $vipId; $user['vip_icon'] = UserLevel::getUserLevelInfo($vipId, 'icon'); $user['vip_name'] = UserLevel::getUserLevelInfo($vipId, 'name'); } } $user['yesterDay'] = UserBill::yesterdayCommissionSum($user['uid']); $user['recharge_switch'] = (int)sys_config('recharge_switch');//充值开关 $user['adminid'] = (boolean)\app\models\store\StoreService::orderServiceStatus($user['uid']); if ($user['phone'] && $user['user_type'] != 'h5') { $user['switchUserInfo'][] = $request->user(); if ($h5UserInfo = User::where('account', $user['phone'])->where('user_type', 'h5')->find()) { $user['switchUserInfo'][] = $h5UserInfo; } } else if ($user['phone'] && $user['user_type'] == 'h5') { if ($wechatUserInfo = User::where('phone', $user['phone'])->where('user_type', '<>', 'h5')->find()) { $user['switchUserInfo'][] = $wechatUserInfo; } $user['switchUserInfo'][] = $request->user(); } else if (!$user['phone']) { $user['switchUserInfo'][] = $request->user(); } return app('json')->successful($user); } /** * 地址 获取单个 * @param Request $request * @param $id * @return mixed * @throws DataNotFoundException * @throws ModelNotFoundException * @throws \think\exception\DbException */ public function address(Request $request, $id) { $addressInfo = []; if ($id && is_numeric($id) && UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) { $addressInfo = UserAddress::find($id)->toArray(); } return app('json')->successful($addressInfo); } /** * 地址列表 * @param Request $request * @param $page * @param $limit * @return mixed */ public function address_list(Request $request) { list($page, $limit) = UtilService::getMore([['page', 0], ['limit', 20]], $request, true); $list = UserAddress::getUserValidAddressList($request->uid(), $page, $limit, 'id,real_name,phone,province,city,district,detail,is_default'); return app('json')->successful($list); } /** * 设置默认地址 * * @param Request $request * @return mixed */ public function address_default_set(Request $request) { list($id) = UtilService::getMore([['id', 0]], $request, true); if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!'); if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) return app('json')->fail('地址不存在!'); $res = UserAddress::setDefaultAddress($id, $request->uid()); if (!$res) return app('json')->fail('地址不存在!'); else return app('json')->successful(); } /** * 获取默认地址 * @param Request $request * @return mixed */ public function address_default(Request $request) { $defaultAddress = UserAddress::getUserDefaultAddress($request->uid(), 'id,real_name,phone,province,city,district,detail,is_default'); if ($defaultAddress) { $defaultAddress = $defaultAddress->toArray(); return app('json')->successful('ok', $defaultAddress); } return app('json')->successful('empty', []); } /** * 修改 添加地址 * @param Request $request * @return mixed */ public function address_edit(Request $request) { $addressInfo = UtilService::postMore([ ['address', []], ['is_default', false], ['real_name', ''], ['post_code', ''], ['phone', ''], ['detail', ''], ['id', 0], ['type', 0] ], $request); if (!isset($addressInfo['address']['province'])) return app('json')->fail('收货地址格式错误!'); if (!isset($addressInfo['address']['city'])) return app('json')->fail('收货地址格式错误!'); if (!isset($addressInfo['address']['district'])) return app('json')->fail('收货地址格式错误!'); if (!isset($addressInfo['address']['city_id']) && $addressInfo['type'] == 0) { return app('json')->fail('收货地址格式错误!请重新选择!'); } else if ($addressInfo['type'] == 1) { $city = $addressInfo['address']['city']; $cityId = SystemCity::where('name', $city)->where('parent_id', '<>', 0)->value('city_id'); if ($cityId) { $addressInfo['address']['city_id'] = $cityId; } else { if (!($cityId = SystemCity::where('parent_id', '<>', 0)->where('name', 'like', "%$city%")->value('city_id'))) { return app('json')->fail('收货地址格式错误!修改后请重新导入!'); } $addressInfo['address']['city_id'] = $cityId; } } $addressInfo['province'] = $addressInfo['address']['province']; $addressInfo['city'] = $addressInfo['address']['city']; $addressInfo['city_id'] = $addressInfo['address']['city_id'] ?? 0; $addressInfo['district'] = $addressInfo['address']['district']; $addressInfo['is_default'] = (int)$addressInfo['is_default'] == true ? 1 : 0; $addressInfo['uid'] = $request->uid(); unset($addressInfo['address'], $addressInfo['type']); try { validate(AddressValidate::class)->check($addressInfo); } catch (ValidateException $e) { return app('json')->fail($e->getError()); } if ($addressInfo['id'] && UserAddress::be(['id' => $addressInfo['id'], 'uid' => $request->uid(), 'is_del' => 0])) { $id = $addressInfo['id']; unset($addressInfo['id']); if (UserAddress::edit($addressInfo, $id, 'id')) { if ($addressInfo['is_default']) UserAddress::setDefaultAddress($id, $request->uid()); return app('json')->successful(); } else return app('json')->fail('编辑收货地址失败!'); } else { $addressInfo['add_time'] = time(); if ($address = UserAddress::create($addressInfo)) { if ($addressInfo['is_default']) { UserAddress::setDefaultAddress($address->id, $request->uid()); } return app('json')->successful(['id' => $address->id]); } else { return app('json')->fail('添加收货地址失败!'); } } } /** * 删除地址 * * @param Request $request * @return mixed */ public function address_del(Request $request) { list($id) = UtilService::postMore([['id', 0]], $request, true); if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!'); if (!UserAddress::be(['is_del' => 0, 'id' => $id, 'uid' => $request->uid()])) return app('json')->fail('地址不存在!'); if (UserAddress::edit(['is_del' => '1'], $id, 'id')) return app('json')->successful(); else return app('json')->fail('删除地址失败!'); } /** * 获取收藏产品 * * @param Request $request * @return mixed */ public function collect_user(Request $request) { list($page, $limit) = UtilService::getMore([ ['page', 0], ['limit', 0] ], $request, true); if (!(int)$limit) return app('json')->successful([]); $productRelationList = StoreProductRelation::getUserCollectProduct($request->uid(), (int)$page, (int)$limit); return app('json')->successful($productRelationList); } /** * 添加收藏 * @param Request $request * @param $id * @param $category * @return mixed */ public function collect_add(Request $request) { list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true); if (!$id || !is_numeric($id)) return app('json')->fail('参数错误'); $res = StoreProductRelation::productRelation($id, $request->uid(), 'collect', $category); if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo()); else return app('json')->successful(); } /** * 取消收藏 * * @param Request $request * @return mixed */ public function collect_del(Request $request) { list($id, $category) = UtilService::postMore([['id', 0], ['category', 'product']], $request, true); if (!$id || !is_numeric($id)) return app('json')->fail('参数错误'); $res = StoreProductRelation::unProductRelation($id, $request->uid(), 'collect', $category); if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo()); else return app('json')->successful(); } /** * 批量收藏 * @param Request $request * @return mixed */ public function collect_all(Request $request) { $collectInfo = UtilService::postMore([ ['id', []], ['category', 'product'], ], $request); if (!count($collectInfo['id'])) return app('json')->fail('参数错误'); $productIdS = $collectInfo['id']; $res = StoreProductRelation::productRelationAll($productIdS, $request->uid(), 'collect', $collectInfo['category']); if (!$res) return app('json')->fail(StoreProductRelation::getErrorInfo()); else return app('json')->successful('收藏成功'); } /** * 添加点赞 * * @param Request $request * @return mixed */ // public function like_add(Request $request) // { // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true); // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误'); // $res = StoreProductRelation::productRelation($id,$request->uid(),'like',$category); // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo()); // else return app('json')->successful(); // } /** * 取消点赞 * * @param Request $request * @return mixed */ // public function like_del(Request $request) // { // list($id, $category) = UtilService::postMore([['id',0], ['category','product']], $request, true); // if(!$id || !is_numeric($id)) return app('json')->fail('参数错误'); // $res = StoreProductRelation::unProductRelation($id, $request->uid(),'like',$category); // if(!$res) return app('json')->fail(StoreProductRelation::getErrorInfo()); // else return app('json')->successful(); // } /** * 签到 配置 * @return mixed * @throws DataNotFoundException * @throws ModelNotFoundException * @throws \think\exception\DbException */ public function sign_config() { $signConfig = sys_data('sign_day_num') ?? []; return app('json')->successful($signConfig); } /** * 签到 列表 * @param Request $request * @param $page * @param $limit * @return mixed */ public function sign_list(Request $request) { list($page, $limit) = UtilService::getMore([ ['page', 0], ['limit', 0] ], $request, true); if (!$limit) return app('json')->successful([]); $signList = UserSign::getSignList($request->uid(), (int)$page, (int)$limit); if ($signList) $signList = $signList->toArray(); return app('json')->successful($signList); } /** * 签到 * @param Request $request * @return mixed */ public function sign_integral(Request $request) { $signed = UserSign::getIsSign($request->uid()); if ($signed) return app('json')->fail('已签到'); if (false !== ($integral = UserSign::sign($request->uid()))) return app('json')->successful('签到获得' . floatval($integral) . '积分', ['integral' => $integral]); return app('json')->fail(UserSign::getErrorInfo('签到失败')); } /** * 签到用户信息 * @param Request $request * @return mixed */ public function sign_user(Request $request) { list($sign, $integral, $all) = UtilService::postMore([ ['sign', 0], ['integral', 0], ['all', 0], ], $request, true); $user = $request->user(); //是否统计签到 if ($sign || $all) { $user['sum_sgin_day'] = UserSign::getSignSumDay($user['uid']); $user['is_day_sgin'] = UserSign::getIsSign($user['uid']); $user['is_YesterDay_sgin'] = UserSign::getIsSign($user['uid'], 'yesterday'); if (!$user['is_day_sgin'] && !$user['is_YesterDay_sgin']) { $user['sign_num'] = 0; } } //是否统计积分使用情况 if ($integral || $all) { $user['sum_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain'); $user['deduction_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'deduction', '', true) ?? 0; $user['today_integral'] = (int)UserBill::getRecordCount($user['uid'], 'integral', 'sign,system_add,gain', 'today'); } unset($user['pwd']); if (!$user['is_promoter']) { $user['is_promoter'] = (int)sys_config('store_brokerage_statu') == 2 ? true : false; } return app('json')->successful($user->hidden(['account', 'real_name', 'birthday', 'card_id', 'mark', 'partner_id', 'group_id', 'add_time', 'add_ip', 'phone', 'last_time', 'last_ip', 'spread_uid', 'spread_time', 'user_type', 'status', 'level', 'clean_time', 'addres'])->toArray()); } /** * 签到列表(年月) * * @param Request $request * @return mixed */ public function sign_month(Request $request) { list($page, $limit) = UtilService::getMore([ ['page', 0], ['limit', 0] ], $request, true); if (!$limit) return app('json')->successful([]); $userSignList = UserSign::getSignMonthList($request->uid(), (int)$page, (int)$limit); return app('json')->successful($userSignList); } /** * 获取活动状态 * @return mixed */ public function activity() { $data['is_bargin'] = StoreBargain::validBargain() ? true : false; $data['is_pink'] = StoreCombination::getPinkIsOpen() ? true : false; $data['is_seckill'] = StoreSeckill::getSeckillCount() ? true : false; return app('json')->successful($data); } /** * 用户修改信息 * @param Request $request * @return mixed */ public function edit(Request $request) { list($avatar, $nickname) = UtilService::postMore([ ['avatar', ''], ['nickname', ''], ], $request, true); if (User::editUser($avatar, $nickname, $request->uid())) return app('json')->successful('修改成功'); return app('json')->fail('修改失败'); } /** * 推广人排行 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws ModelNotFoundException * @throws \think\exception\DbException */ public function rank(Request $request) { $data = UtilService::getMore([ ['page', ''], ['limit', ''], ['type', ''] ], $request); $users = User::getRankList($data); return app('json')->success($users); } /** * 佣金排行 * @param Request $request * @return mixed */ public function brokerage_rank(Request $request) { $data = UtilService::getMore([ ['page', ''], ['limit'], ['type'] ], $request); return app('json')->success([ 'rank' => User::brokerageRank($data), 'position' => User::currentUserRank($data['type'], $request->user()['brokerage_price']) ]); } /** * 添加访问记录 * @param Request $request * @return mixed */ public function set_visit(Request $request) { $data = UtilService::postMore([ ['url', ''], ['stay_time', 0] ], $request); if ($data['url'] == '') return app('json')->fail('未获取页面路径'); $data['uid'] = $request->uid(); $data['ip'] = $request->ip(); $data['add_time'] = time(); $res = UserVisit::insert($data); if ($res) { return app('json')->success('添加访问记录成功'); } else { return app('json')->fail('添加访问记录失败'); } } /** * 静默绑定推广人 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function spread(Request $request) { $puid = $request->post('puid/d', 0); return app('json')->success(User::setSpread($puid, $request->uid())); } /** * * @param Request $request * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function dow_user(Request $request) { $data = UtilService::postMore([ 'phone', 'money', 'type', ]); if ($data['type'] == 1){ if (cache($request->uid())) return app('json')->fail('请勿频繁点击'); // if (empty($data['pas'])) return app('json')->fail('请填写支付密码'); // if ($request->user()['payment_pas'] != md5($data['pas'].'sxg')) return app('json')->fail('支付密码不正确'); if ($data['phone'] == $request->user()['account'] || $data['phone'] == $request->uid()) return app('json')->fail('不能给自己转账'); if (empty($data['phone']) or empty($data['money'])) return app('json')->fail('手机号,金额不能未空'); $user = User::where('account|uid', $data['phone'])->find(); if (!$user) return app('json')->fail('没有当前用户'); $userInfo = User::where('uid', $request->uid())->find(); if ($userInfo['now_money'] < $data['money']) return app('json')->fail('余额不足'); User::beginTrans(); $user['now_money'] += $data['money']; $userInfo['now_money'] -= $data['money']; try { $user->save(); $userInfo->save(); UserBill::expend('转账', $userInfo['uid'], 'now_money', 'sub_now_money', $data['money'], $userInfo['uid'], $userInfo['now_money'], '给用户'.$user['nickname'].'转账'.$data['money']); UserBill::income('收账', $user['uid'], 'now_money', 'add_now_money', $data['money'], $user['uid'], $user['now_money'], '用户'.$userInfo['nickname'].'给你转账'.$data['money']); cache($request->uid(), 1, 5); User::commitTrans(); return app('json')->success('成功'); } catch (\Exception $e) { User::rollbackTrans(); return app('json')->fail('失败'); } }elseif ($data['type'] == 2){ if (cache($request->uid())) return app('json')->fail('请勿频繁点击'); // if (empty($data['pas'])) return app('json')->fail('请填写支付密码'); // if ($request->user()['payment_pas'] != md5($data['pas'].'sxg')) return app('json')->fail('支付密码不正确'); if ($data['phone'] == $request->user()['account'] || $data['phone'] == $request->uid()) return app('json')->fail('不能给自己转账'); if (empty($data['phone']) or empty($data['money'])) return app('json')->fail('手机号,金额不能未空'); $user = User::where('account|uid', $data['phone'])->find(); if (!$user) return app('json')->fail('没有当前用户'); $userInfo = User::where('uid', $request->uid())->find(); if ($userInfo['business_integral'] < $data['money']) return app('json')->fail('积分不足'); User::beginTrans(); $user['business_integral'] += $data['money']; $userInfo['business_integral'] -= $data['money']; try { $user->save(); $userInfo->save(); UserBill::expend('转账', $userInfo['uid'], 'business_integral', 'sub_business_integral', $data['money'], $userInfo['uid'], $userInfo['now_money'], '给用户'.$user['nickname'].'转商家积分'.$data['money']); UserBill::income('收账', $user['uid'], 'business_integral', 'add_business_integral', $data['money'], $user['uid'], $user['now_money'], '用户'.$userInfo['nickname'].'给你转商家积分'.$data['money']); cache($request->uid(), 1, 5); User::commitTrans(); return app('json')->success('成功'); } catch (\Exception $e) { User::rollbackTrans(); return app('json')->fail('失败'); } } return app('json')->fail('参数传入错误'); } /** * 团队下级人数和流水 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function dow(Request $request) { $user = User::select(); $userId = get_downline_dow($user, $request->uid()); $data = [ 'count' => 0, 'user_list' => [], 'user_price' => 0, 'week_price' => 0 ]; $week = date('w'); if (count($userId) > 0){ $count = count($userId); $userList = User::where('uid', 'in', $userId) ->field('uid,nickname,avatar,add_time,spread_uid,phone') ->select(); foreach ($userList as &$item){ $item['zt'] = 0; $item['phone'] = substr_replace($item['phone'], '****', 3, 4); if ($item['spread_uid'] == $request->uid()) $item['zt'] = 1; $item['price'] = ManyOrder::where('uid', $item['uid'])->where('status', 1)->sum('price');//返回额度 $item['cy_price'] = ManyOrder::where('uid', $item['uid'])->where('status', 0)->where('is_return', 0)->sum('price'); // 参与中金额 $item['dfh_price'] = ManyOrder::where('uid', $item['uid'])->where('status', 0)->where('is_return', 1)->sum('price'); // 待返回金额 $item['ztr_price'] = ManyOrder::where('uid', $item['uid'])->sum('price'); // 总投注额度 $item['order_price'] = StoreOrder::where('uid', $item['uid'])->where('paid', 1)->sum('pay_price'); } $userPrice = ManyOrder::where('uid', 'in', $userId)->where('status', 1)->sum('price'); $weekPrice = ManyOrder::where('uid', 'in', $userId)->whereBetweenTime('create_time', strtotime(date('Y-m-d',strtotime( '+'. 1-$week .' days' ))), strtotime(date('Y-m-d',strtotime( '+'. 7-$week .' days' ))))->sum('price'); $data = [ 'count' => $count, 'user_price' => $userPrice, 'week_price' => $weekPrice, 'user_list' => $userList ]; } return app('json')->success($data); } /** * 消息通知 * @param Request $request * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function notice(Request $request) { $data = UtilService::getMore([ 'type', 'page', 'limit' ]); if ($data['type']){ $list = UserNotice::where('type', $data['type'])->where('uid', $request->uid())->order('id DESC')->page($data['page'], $data['limit'])->select();//系统消息 $list = empty($list)?[]:$list->toArray(); foreach ($list as &$item) { $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']); } return app('json')->success($list); }else{ $list['xt'] = UserNotice::where('type', 1)->where('uid', $request->uid())->order('id DESC')->find();//系统消息 if ($list['xt']) $list['xt']['add_time'] = date('Y-m-d H:i:s', $list['xt']['add_time']); $list['xx'] = UserNotice::where('type', 2)->where('uid', $request->uid())->order('id DESC')->find();//新增下线 if ($list['xx'])$list['xx']['add_time'] = date('Y-m-d H:i:s', $list['xx']['add_time']); $list['yj'] = UserNotice::where('type', 3)->where('uid', $request->uid())->order('id DESC')->find();//佣金通知 if ($list['yj'])$list['yj']['add_time'] = date('Y-m-d H:i:s', $list['yj']['add_time']); $list['fh'] = UserNotice::where('type', 4)->where('uid', $request->uid())->order('id DESC')->find();//发货通知 if ($list['fh'])$list['fh']['add_time'] = date('Y-m-d H:i:s', $list['fh']['add_time']); $list['dg'] = UserNotice::where('type', 5)->where('uid', $request->uid())->order('id DESC')->find();//打怪通知 if ($list['dg'])$list['dg']['add_time'] = date('Y-m-d H:i:s', $list['dg']['add_time']); return app('json')->success($list); } } public function read(Request $request) { $data = UtilService::getMore([ 'id', ]); $notice = UserNotice::where('id', $data['id'])->find(); if (!$notice) return app('json')->fail('消息不存在'); $notice['status'] = 1; $notice->save(); $notice = empty($notice)?[]:$notice->toArray(); return app('json')->success($notice); } /** * 会员紧缩 * @return void * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function tighten() { $user = User::select(); foreach ($user as $item) { $time = time() - $item['add_time']; if ($time > (86400*30)){ $many_order = ManyOrder::where('uid', $item['uid'])->whereBetweenTime('create_time', strtotime('-30 day'), time())->count(); if ($many_order == 0){ User::where('spread_uid', $item['uid'])->update(['spread_uid' => $item['spread_uid']]); User::where('uid', $item['uid'])->delete(); WechatUser::where('uid', $item['uid'])->delete(); } } } return app('json')->success('成功'); } /** * @param Request $request * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function turn(Request $request) { $data = UtilService::postMore([ ['price', 0], ['uid', 0] ]); if ($data['price'] <= 0) return app('json')->fail('请输入转账额度'); if ($data['uid'] <= 0) return app('json')->fail('请输入转账人手机号或者编号'); $id = $request->uid(); $user = User::where('uid', $id)->find(); // 转账人 $user_e = User::where('uid|phone', $data['uid'])->find(); // 收转人 if ($user['purple_integral'] < $data['price']) return app('json')->fail('转账积分不足'); if (!$user_e) return app('json')->fail('转账用户不存在'); $userList = User::select()->toArray(); $top = getParent($user['spread_uid'], $userList); $lower = get_downline_dow($userList, $user['uid']); $spread = array_merge($top, $lower); if (!in_array($user_e['uid'],$spread)) return app('json')->fail('该用户不是你的同一条线'); try { Db::startTrans(); User::where('uid', $user['uid'])->dec('purple_integral', $data['price'])->update(); User::where('uid', $user_e['uid'])->inc('white_integral', $data['price'])->update(); UserBill::expend('转账阳光积分', $user['uid'], 'purple_integral', 'turn_purple_integral', $data['price'], $user_e['uid'], $user['purple_integral']-$data['price'], '转账给用户'.$user_e['account'].'阳光积分'); UserBill::income('接收红积分', $user_e['uid'], 'white_integral', 'jies_purple_integral', $data['price'], $user['uid'], $user_e['white_integral']+$data['price'], '接收用户'.$user['account'].'阳光积分转为红积分'); Db::commit(); return app('json')->success('转账成功'); } catch (\Exception $e) { Db::rollback(); return app('json')->success('操作失败'); } } }