repository = $repository; $this->source = $this->request->header('source'); $this->merId = $this->request->header('merId'); } /** * 创建环信账户 * @return mixed */ public function hxim_create() { $uid = $this->request->uid(); try { $im = new Im(); $user = Db::name('user')->where('uid', $uid)->field('im_uuid,im_userid as im_user_id,im,uid,nickname,im_password as im_pass')->find(); if (isset($user['im_uuid']) && $user['im_user_id']) { return app('json')->success($user); } $im_user_id = 'user' . $user['uid']; $data = []; $data['im_pass'] = mt_rand(100000, 999999); $data['im_user_id'] = $im_user_id; // 获取用户是否存在 $imUser = $im->getImUser('user' . $uid); if (isset($imUser['activated']) && $imUser['activated'] == true) { $data['im_uuid'] = $imUser['uuid']; } else { $data['im_uuid'] = $im->createImUser($im_user_id, $user['nickname'], $data['im_pass']); } Db::name('User')->where(['uid' => $uid])->update([ 'im' => 1, 'im_uuid' => $data['im_uuid'], 'im_userid' => $im_user_id, 'im_password' => $data['im_pass'] ]); return app('json')->success($data); } catch (\Exception $e) { Db::name('log')->insert(['data' => '注册异常' . $e->getFile() . $e->getMessage() . $e->getLine()]); } return app('json')->fail('注册失败'); } /** * @return mixed * @author xaboy * @day 2020/6/22 */ public function we_com() { $where2['mer_id'] = $this->merId; $user = Db::name('enterprise')->field('we_com,we_com_url')->where($where2)->find(); return app('json')->success($user); } public function spread_image() { $type = $this->request->param('type'); $res = $type == 'routine' ? $this->repository->routineSpreadImage($this->request->userInfo()) : $this->repository->wxSpreadImage($this->request->userInfo()); return app('json')->success($res); } /** * @return mixed * 分享每日海报 */ public function share_day() { /** * 1242 * 2208 */ $user = $this->request->userInfo(); $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg'; $siteUrl = systemConfig('site_url'); $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);//二维码链接 $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name, $user['avatar']); if (is_string($imageInfo)) throw new ValidateException('二维码生成失败'); $filename = 'https://88yx.xyz/qqh/uploads/20211101074257444.jpg'; $qrcode = $imageInfo['dir']; dump($qrcode); $config = array( 'image' => array( array( 'url' => $qrcode,//二维码资源 'stream' => 0, 'left' => 533, 'top' => 1941, 'right' => 0, 'bottom' => 0, 'width' => 184, 'height' => 182, 'opacity' => 100 ) ), 'background' => $filename ); $data = setSharePoster($config, 'routine/spread/poster'); dump($data); return app('json')->success($data); } public function spread_info() { $user = $this->request->userInfo(); $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage']); $data = [ 'lock_brokerage' => $user->lock_brokerage, 'one_level_count' => $user->one_level_count, 'two_level_count' => $user->two_level_count, 'spread_total' => $user->spread_total, 'yesterday_brokerage' => $user->yesterday_brokerage, 'total_extract' => $user->total_extract, 'total_brokerage' => $user->total_brokerage, 'brokerage_price' => $user->brokerage_price, 'member_brokerage_price' => $user->member_brokerage_price, 'now_money' => $user->now_money, 'broken_day' => (int)systemConfig('lock_brokerage_timer') ]; return app('json')->success($data); } public function spread_info_yhc() { $user = $this->request->userInfo(); if ($this->source == 'yhc' && $this->merId) { $where['mer_id'] = $this->merId; $where['uid'] = $user->uid; $enterprise_user = Db::name('enterprise_user')->where($where)->find(); if ($enterprise_user) { $data['current_balance'] = set_price_rtrim($enterprise_user['commission']);//收益余额 $data['unsettled_balance'] = 0;//未结算 $extract_price = Db::name('user_extract')->where($where)->whereIn('status', [0, 1])->sum('extract_price'); $data['withdrawn_balance'] = set_price_rtrim($extract_price); //已提现 $data['total_balance'] = set_price_rtrim($enterprise_user['commission'] + $data['withdrawn_balance']);//总收益=收益余额+已提现 $data['identity'] = $enterprise_user['identity']; $data['level'] = $enterprise_user['level']; $data['partnership'] = $enterprise_user['partnership']; $data['green_integral'] = $enterprise_user['green_integral']; $data['green_integral_is'] = $enterprise_user['green_integral_is']; $data['operate'] = $enterprise_user['operate']; $data['operate_icon'] = ''; $data['operate_text'] = ''; $member_settings = merchantConfig($this->merId, 'member_settings'); if ($data['operate'] == 101) { $data['operate_icon'] = $member_settings['yy_one_img']; $data['operate_text'] = $member_settings['yy_one_text']; } if ($data['operate'] == 102) { $data['operate_icon'] = $member_settings['yy_two_img']; $data['operate_text'] = $member_settings['yy_two_text']; } $data['nickname'] = $user->nickname; $data['avatar'] = $enterprise_user['avatar']; $arr = $this->jisuan_fans($user->uid); $data['fans_num'] = count($arr);//粉丝总数 $yanglao = 0; $offLinewhere = ['mer_id' => $this->merId, 'uid' => $user->uid, 'commission_type' => '5', 'type_shop' => 0]; $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number'); $yanglao += $offLine1; $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number'); $yanglao += $offLine2; $data['ylj'] = set_price_rtrim($yanglao); $data['yhc_withdrawal_money'] = merchantConfig($this->merId, 'yhc_withdrawal_money'); $data['uid'] = $enterprise_user['uid']; if ($enterprise_user['identity'] > 100) { $data['identity_data'] = Db::name('enterprise_performance_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['identity'])->find(); if (!$data['identity_data']) { $data['identity_data'] = null; $data['identity'] = '100'; } } else { $data['identity_data'] = null; } $data['level_data'] = Db::name('enterprise_agent_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['level'])->find(); return app('json')->success($data); } } return app('json')->fail('用户不存在'); } /** * @param UserBillRepository $billRepository * @return mixed * @author xaboy * @day 2020/6/22 */ public function bill(UserBillRepository $billRepository) { [$page, $limit] = $this->getPage(); $where = [ // 'now_money' => $this->request->param('type', 0), 'status' => $this->request->param('status'), ]; if ($this->request->param('is_red') == true) { $where['is_red_brokerage'] = 1; } return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit)); } /** * @param UserBillRepository $billRepository * @return mixed * @author xaboy * @day 2020/6/22 */ public function brokerage_list(UserBillRepository $billRepository) { [$page, $limit] = $this->getPage(); return app('json')->success($billRepository->userList([ 'category' => 'brokerage', ], $this->request->uid(), $page, $limit)); } /** * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author xaboy * @day 2020/6/22 */ public function spread_order() { [$page, $limit] = $this->getPage(); return app('json')->success($this->repository->subOrder($this->request->uid(), $page, $limit)); } /** * TODO * @return mixed * @author Qinii * @day 2020-06-18 */ public function binding() { $data = $this->request->params(['phone', 'sms_code']); if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确'); $user = $this->repository->accountByUser($data['phone']); if ($user) { $data = ['phone' => $data['phone']]; } else { $data = ['account' => $data['phone'], 'phone' => $data['phone']]; } $this->repository->update($this->request->uid(), $data); return app('json')->success('绑定成功'); } /** * TODO * @return mixed * @author Qinii * @day 2020-06-18 */ public function binding_verify() { $data = $this->request->params(['user_id', 'captcha']); $data['phone'] = \think\facade\Db::name("user")->where(["uid" => $data['user_id']])->value("phone"); $data['sms_code'] = $data['captcha']; if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确'); return app('json')->success('验证成功'); } public function checkSmsCode($phone, $code) { $sms_key = 'api.auth.sms.' . $phone; if (!$cache_code = Cache::get($sms_key)) return false; if ($code != $cache_code) return false; Cache::delete($sms_key); return true; } /** * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author xaboy * @day 2020/6/22 */ public function spread_list() { [$level, $sort, $nickname] = $this->request->params(['level', 'sort', 'keyword'], true); $uid = $this->request->uid(); [$page, $limit] = $this->getPage(); return app('json')->success($level == 2 ? $this->repository->getTwoLevelList($uid, $nickname, $sort, $page, $limit) : $this->repository->getOneLevelList($uid, $nickname, $sort, $page, $limit)); } /** * @return mixed * @author xaboy * @day 2020/6/22 */ public function spread_top() { [$page, $limit] = $this->getPage(); $type = $this->request->param('type', 0); return app('json')->success($type == 1 ? $this->repository->spreadMonthTop($page, $limit) : $this->repository->spreadWeekTop($page, $limit)); } /** * @return mixed * @author xaboy * @day 2020/6/22 */ public function brokerage_top() { [$page, $limit] = $this->getPage(); $type = $this->request->param('type', 0); return app('json')->success($type == 1 ? $this->repository->brokerageMonthTop($page, $limit) : $this->repository->brokerageWeekTop($page, $limit)); } public function history(UserVisitRepository $repository) { $uid = $this->request->uid(); [$page, $limit] = $this->getPage(); return app('json')->success($repository->getHistory($uid, $page, $limit)); } public function deleteHistory($id, UserVisitRepository $repository) { $uid = $this->request->uid(); if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid])) return app('json')->fail('数据不存在'); $repository->delete($id); return app('json')->success('删除成功'); } public function account() { $user = $this->request->userInfo(); if (!$user->phone) return app('json')->fail('请绑定手机号'); return app('json')->success($this->repository->selfUserList($user->phone)); } public function switchUser() { $uid = (int)$this->request->param('uid'); if (!$uid) return app('json')->fail('用户不存在'); $userInfo = $this->request->userInfo(); if (!$userInfo->phone) return app('json')->fail('请绑定手机号'); $user = $this->repository->switchUser($userInfo, $uid); $tokenInfo = $this->repository->createToken($user); $this->repository->loginAfter($user); return app('json')->success($this->repository->returnToken($user, $tokenInfo)); } /** * 签到 获取积分 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function sub_signin() { $member_id = $this->request->uid(); if (!$member_id) return app('json')->fail('用户不存在'); $res = $this->repository->sub_signin($member_id); return app('json')->success($res); } /** * 获取用户签到记录 * data1 开始时间 * data2 结束时间 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function get_signin() { $member_id = $this->request->uid(); if (!$member_id) return app('json')->fail('用户不存在'); $where = []; $data1 = input('data1'); $data2 = input('data2'); if ($data1 && $data2) { $where["data1"] = $data1; $where["data2"] = $data2; } $res = $this->repository->get_signin($member_id, $where); return app('json')->success($res); } /** * 提交实名认证 * * @return void */ public function add_certification() { $member_id = $this->request->uid(); $type = input("type", 0); if ($type == 1) { $data = $this->repository->get_cer(["uid" => $member_id]); return app('json')->success($data); } if (!$member_id) return app('json')->fail('用户不存在'); $params = $this->request->params([ 'user_name', 'mobile', 'user_card', 'card_positive', 'card_reverse', ]); $params['create_time'] = time(); $params['uid'] = $member_id; $baidu = new Ocr(); $image = file_get_contents($params['card_positive']); $idCardSide = "front"; $result = $baidu->idcard($image, $idCardSide); $real_user_name = $result['words_result']['姓名']['words'] ?? ''; $real_user_card = $result['words_result']['公民身份号码']['words'] ?? ''; if ($real_user_name != $params['user_name']) { return app('json')->fail('姓名或身份证号输入有误~'); } if ($real_user_card != $params['user_card']) { return app('json')->fail('姓名或身份证号输入有误~'); } if ($result['image_status'] == "normal" && $result['idcard_number_type'] == 1) { $params['status'] = 1; $res = $this->repository->add_cer($params, $member_id); if ($res) { return app('json')->success($res); } else { return app('json')->fail('认证失败'); } } else { return app('json')->fail('认证失败,请重新认证'); } } /** * 申请代理 * name:公司名称 * identity:身份 * license:营业执照 */ public function apply_agent() { $name = input("name", ""); $identity = input("identity", 1); $license = input("license", ""); $province_id = input("province_id", ""); $city_id = input("city_id", ""); $area_id = input("area_id", ""); $street_id = input("street_id", ""); $spread_account = input("spread_account", ""); $member_id = $this->request->uid(); if ($identity != 6 && (!$name || !$identity || !$license)) { return app('json')->fail('请检查参数'); } if ($identity == 6 && (!$name || !$identity)) { return app('json')->fail('请检查参数'); } $data = [ "name" => $name, "identity" => $identity, "license" => $license, "user_id" => $member_id, "province_id" => $province_id, "city_id" => $city_id, "area_id" => $area_id, "street_id" => $street_id, 'spread_account' => $spread_account, "add_time" => time(), "update_time" => time() ]; $res = $this->repository->agent($data); if ($res['code'] == 400) { return app('json')->fail($res['msg']); } return app('json')->success("申请成功", $res); } /*查询是否有已申请或者审核中的代理信息*/ public function isAgent() { $uid = $this->request->uid(); $data = $this->repository->isAgent($uid); return app("json")->success($data); } /*查询是否有审核成功的未支付或支付失败的订单*/ public function AgentPayDetail() { $uid = $this->request->uid(); if (!$uid) { return app('json')->fail('请检查参数'); } $where = ['status' => 1, 'pay_status' => ['0', '2'], 'user_id' => $uid]; $data = $this->repository->getAgentPayDetail($where); return app('json')->success("成功", $data); } /** * 获取信息 全民营销首页 * @return mixed */ public function get_agent_info() { $member_id = $this->request->uid(); $res = $this->repository->get_agent_info($member_id); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 推广统计 * search 搜索 * @return mixed */ public function get_extension_info() { $search = input("search", ""); $where = $this->request->params(["identity"]); $member_id = $this->request->uid(); $res = $this->repository->get_extension_info($member_id, $search, $where); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 收益统计 * type 搜索 * @return mixed */ public function get_profit_info() { $where = $this->request->params([ 'commission_type', 'date_on', 'date_off', 'order' ]); $member_id = $this->request->uid(); $res = $this->repository->get_profit_info($member_id, $where); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 订单统计 * search 搜索 * @return mixed */ public function get_tuiguang_order() { $member_id = $this->request->uid(); $res = $this->repository->get_tuiguang_order($member_id); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /* * 攒金明细统计 * */ public function get_commission_all() { $uid = $this->request->uid(); $where['date_on'] = 1; $where['date_off'] = 0; // $where['commission_type'] = ''; $date = $this->request->params(['date']);//"today","yesterday","week","month","year" $where['order'] = $date['date']; $res = $this->repository->get_profit_info($uid, $where); return app('json')->success($res); } /* * 攒金明细列表 * */ public function get_commission_list() { $uid = $this->request->uid(); [$where['page'], $where['limit']] = $this->getPage(); $data = $this->request->params(['type', 'date']);//"today","yesterday","week","month","year" $where['type'] = $data['type'];//0线上;1线下 $where['order'] = $data['date'];//"today","yesterday","week","month","year" $res = $this->repository->get_tuiguang_list($uid, $where); return app('json')->success($res); } /* * 越攒越多佣金 * */ public function get_com_list() { $uid = $this->request->uid(); [$where['page'], $where['limit']] = $this->getPage(); $data = $this->request->params(['date']);//"today","yesterday","week","month","year" $where['order'] = $data['date'];//"today","yesterday","week","month","year" $res = $this->repository->get_com_list($uid, $where); return app('json')->success($res); } /* * 越攒越多统计 * */ public function get_com_all() { $uid = $this->request->uid(); $data = $this->request->params(['date']);//"today","yesterday","week","month","year" $where['order'] = $data['date'];//"today","yesterday","week","month","year" $res = $this->repository->get_com_all($uid, $where); return app('json')->success($res); } /** * 养老金详情 * @return mixed */ public function get_yanglao() { $member_id = $this->request->uid(); $res = $this->repository->get_yanglao($member_id); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 养老金明细 */ public function yanglaolog() { $member_id = $this->request->uid(); [$page, $limit] = $this->getPage(); $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "type_shop" => 0]; if ($this->source == 'yhc' && $this->merId) { $where['mer_id'] = $this->merId; } $month = $this->request->param('month', '');//年月搜索 $status = $this->request->param('status', 1); //1-全部 2-已结算 3-未结算 4-已取消 if ($status == 2) { $where['status'] = 1; } else if ($status == 3) { // $where['gzc']=0; $where['status'] = 0; } else if ($status == 4) { $where['status'] = -1; } $source = $this->request->param('source', -1); if ($source > -1) { $where['source'] = $source; } $res = $this->repository->yanglaolog($where, $page, $limit, $month); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /*养老金详情*/ public function YangLaoDetail($id) { $member_id = $this->request->uid(); $data = $this->request->params([ 'type', ]); $where = ["uid" => $member_id, "type" => "commission", "commission_type" => $data['type'], 'bill_id' => $id]; $res = $this->repository->yanglaoDetail($where); return app('json')->success($res); } /** * 消费明细 * @return mixed */ public function tripartite() { $member_id = $this->request->uid(); $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "tripartite" => ["<>", 0]]; $res = $this->repository->yanglaolog($where); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 提现明细 * @return mixed */ public function withdrawal() { $member_id = $this->request->uid(); $data = $this->request->params([ 'type', ]); $where = ["uid" => $member_id, "type" => $data['type'] ? $data['type'] : 2]; if ($this->source == 'yhc') { $where['mer_id'] = $this->merId; } $res = $this->repository->withdrawal_user($where); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 提现详情 * @return mixed * @author cabbage * @day 2020/10/31 */ public function withdrawalDetail() { $member_id = $this->request->uid(); $extract_id = input("extract_id", 0); return app('json')->success($this->repository->withdrawalDetail($extract_id, $member_id)); } /* * 修改个人信息*/ public function updateUser() { $data = $this->request->params([ 'nickname', 'avatar', 'sex', 'birthday', 'addres', 'mark' ]); $uid = $this->request->uid(); $res = ''; if ($this->source == 'yhc') { $res = Db::name('enterprise_user')->where('mer_id', $this->merId)->where('uid', $uid)->update(['avatar' => $data['avatar']]); unset($data['avatar']); } $data = $this->repository->updateUser($uid, $data); if ($data || $res) { return app("json")->success("修改成功", $data); } return app("json")->fail("未做任何修改"); } /*积分记录*/ public function socreList() { [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); $data = $this->repository->socreList($uid, $page, $limit); return app("json")->success($data); } function jisuan_fans($uid) { $where22['node_uid'] = $uid; $where22['mer_id'] = $this->merId; $arr = $this->jisuantuandui($where22); $where['puid'] = $uid; $where['mer_id'] = $this->merId; $direct_fans = Db::name('enterprise_user')->where($where)->column('uid');//直属粉丝数量 $result = array_unique(array_merge($arr, $direct_fans)); return $result; } function jisuantuandui($where, $data = []) { $enterprise_user_team = DB::name('enterprise_user')->where($where)->column('uid'); $arr = array_merge($data, $enterprise_user_team); foreach ($enterprise_user_team as $v) { $where['node_uid'] = $v; $arr = $this->jisuantuandui($where, $arr); } return $arr; } /** * 一壶茶-团队列表 */ public function team_list() { $uid = $this->request->uid(); $where['puid'] = $uid; $where['mer_id'] = $this->merId; $data['direct_fans_num'] = Db::name('enterprise_user')->where($where)->count();//直属粉丝数量 $arr = $this->jisuan_fans($uid); $data['fans_num'] = count($arr);//粉丝总数 [$page, $limit] = $this->getPage(); $where2['eu.mer_id'] = $this->merId; $type = $this->request->param('type', 0); $enterprise_user_team = DB::name('enterprise_user') ->alias('eu') ->join('user u', 'eu.uid=u.uid') ->where($where2) ->when($type < 1 || $type == 2, function ($q) use ($arr) { $q->whereIn('eu.uid', $arr); }) ->when($type == 1, function ($q) use ($uid) { $q->whereIn('eu.puid', $uid); }) ->when($type == 2, function ($q) use ($uid) { $q->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]); }) ->field('eu.uid,u.nickname,u.phone,eu.avatar,eu.create_time,eu.identity,eu.level,eu.partnership') ->order('eu.enterprise_user_id desc') ->paginate($limit) ->each(function ($item) { $item['phone'] = substr_replace($item['phone'], '****', 3, 4); return $item; }); $data['team_list'] = $enterprise_user_team; $data['effective_fans_num'] = DB::name('enterprise_user') ->alias('eu') ->join('user u', 'eu.uid=u.uid') ->where($where2) ->whereIn('eu.uid', $arr) ->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]) ->count();//有效粉丝数量 return app("json")->success($data); } public function team_details() { $uid = $this->request->param('uid', 0); $where2['eu.uid'] = $uid; $where2['eu.mer_id'] = $this->merId; $enterprise_user_team = DB::name('enterprise_user') ->alias('eu') ->join('user u', 'eu.uid=u.uid') ->where($where2) ->field('eu.uid,u.nickname,u.phone,u.avatar,eu.create_time,eu.identity,eu.level,eu.partnership,eu.puid') ->find();; if ($enterprise_user_team) { $enterprise_user_team['phone'] = substr_replace($enterprise_user_team['phone'], '****', 3, 4); $enterprise_user_team['p_nickname'] = ''; $enterprise_user_team['p_phone'] = ''; $yanglao = 0; $offLinewhere = ['mer_id' => $this->merId, 'uid' => $uid, 'commission_type' => '5', 'type_shop' => 0]; $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number'); $yanglao += $offLine1; $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number'); $yanglao += $offLine2; $enterprise_user_team['ylj'] = set_price_rtrim($yanglao); if ($enterprise_user_team['puid'] > 0) { $user = Db::name('user')->where('uid', $enterprise_user_team['puid'])->find(); if ($user) { $enterprise_user_team['p_nickname'] = $user['nickname']; $enterprise_user_team['p_phone'] = substr_replace($user['phone'], '****', 3, 4); } } } return app("json")->success($enterprise_user_team); } /** * 率积分明细 */ public function green_integral_list() { $pm = $this->request->param('pm', 1); [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); $where['uid'] = $uid; $where['mer_id'] = $this->merId; if ($pm == 1) { $pm_arr = [1, 3]; } else { $pm_arr = [2, 4]; } $data = DB::name('enterprise_user_score')->where($where)->whereIn('pm', $pm_arr)->field('id,mark,reward_socre,pm,create_time,order_id')->page($page, $limit)->order("id desc")->select()->each(function ($v) { if ($v['pm'] == 3 || $v['pm'] == 1) { $v['pm'] = 1; } else { $v['pm'] = 2; } return $v; }); return app("json")->success($data); } public function user_invite_profit_list() { $uid = $this->request->uid(); [$page, $limit] = $this->getPage(); $commission_type = $this->request->param('commission_type', 0); if ($commission_type) { $where['commission_type'] = $commission_type; } $month = $this->request->param('month', '') ?: date('Y-m'); $startMonth = date('Y-m-01 00:00:00', strtotime($month)); $endMonth = date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))); $data['yanglao_clear_all'] = Db::name('user_bill') ->where('uid', $uid) ->whereBetween('create_time', [$startMonth, $endMonth]) ->where('commission_type', 5) ->where('pm', 1) ->where('status', 1) ->sum('number'); $data['yanglao_nclear_all'] = Db::name('user_bill') ->where('uid', $uid) ->whereBetween('create_time', [$startMonth, $endMonth]) ->where('commission_type', 5) ->where('pm', 1) ->where('status', 0) ->sum('number'); $data['yanglao_yugu_all'] = $data['yanglao_clear_all'] + $data['yanglao_nclear_all']; $where['uid'] = $uid; $data['totel_money'] = Db::name('user_bill')->where($where) ->whereNotIn('commission_type', [5, 7, 17, 19]) ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) { $query->whereBetween('create_time', [$startMonth, $endMonth]); }, function ($query) use ($where, $month, $startMonth, $endMonth) { $query->where('commission_type', '<>', 5) ->whereBetween('create_time', [$startMonth, $endMonth]); }) ->sum('number'); $pageInfo = Db::name('user_bill') ->where($where) ->whereNotIn('commission_type', [5, 7, 17, 19]) ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) { $query->whereBetween('create_time', [$startMonth, $endMonth]); }, function ($query) use ($where, $month, $startMonth, $endMonth) { $query->where('commission_type', '<>', 5) ->whereBetween('create_time', [$startMonth, $endMonth]); }) ->order('bill_id desc') ->paginate($limit); $data_arr = []; foreach ($pageInfo->items() as $k => $v) { $v['money'] = set_price_rtrim($v['number']); $v['order_money'] = set_price_rtrim(0); $v['commission_rate'] = set_price_rtrim(0); $order = Db::name('store_order')->where('order_sn', $v['order_sn'])->find(); if (!empty($order)) { $v['order_money'] = set_price_rtrim($order['total_price']); $v['commission_rate'] = set_price_rtrim(bcdiv($v['money'], $v['order_money'], 2)); } if ($v['status'] == 0) { // $v['create_time'] = '--'; } if ($v['status'] == 1) { // $v['create_time'] = $v['take_time']; } $data_arr[] = $v; } $data['pageInfo']['current_page'] = $pageInfo->currentPage(); $data['pageInfo']['data'] = $data_arr; $data['pageInfo']['last_page'] = $pageInfo->lastPage(); return app("json")->success($data); } /*导航转链-用于用户下单绑定*/ public function changeLink() { $uid = $this->request->uid(); if (!$uid) { return app("json")->error("请登录"); } $data = $data = $this->request->params([ 'url', 'name' ]); $data['url'] = urldecode($data['url']); $data['name'] = urldecode($data['name']); if (in_array($data['name'], ['京东', '苏宁易购', '饿了么', '唯品会', '拼多多'])) { if ($data['name'] == '京东') { $url = app()->make(Jd::class)->linkChange($data['url'], $uid); } if ($data['name'] == '拼多多') { $url = app()->make(TaoKe::class)->changeLink($data['url'], $uid); } if ($data['name'] == '唯品会') { $url = app()->make(Vip::class)->changeLink($data['url'], $uid); } if ($data['name'] == '苏宁易购') { $url = $data['url']; //$url = app()->make(Su::class)->changeLink($data['url'],$uid); } if ($data['name'] == '饿了么') {//获取饿了么官方活动链接 //如果用户没有拉取relation_id, $where = ['uid' => $uid, 'type' => 5]; $isRelation = UserThirdModel::where($where)->find(); if ($isRelation) { $result = DaTaoKe::activityChangeLink('20150318020002597', $uid); if ($result['code'] == 0) { return \app('json')->fail("获取饿了么链接出错", $result['raw']); } $url = $result['link']; } else {//如果还没有获取用户的relation_id还需要拉淘宝授权 $state = "{$uid}_h5"; $url = \app()->make(TaoBao::class)->getAuthUrl($state); } } } return app("json")->success($url); } /*获取协议*/ public function xieyi() { $data = $this->request->params([ 'type' ]); $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($data['type']); return app("json")->success($data); } /** * 支付宝获取授权 * @return mixed * @author php迷途小书童 * @created 2021/1/16 17:03 */ public function alipayAuthorization(UserRepository $userRepository) { $authorization_code = $this->request->param('code'); $type = $this->request->param('type', 'h5'); $paramStr = $userRepository->getTokenByCode($authorization_code, false, $type); return app("json")->success($paramStr); } /** * 微信获取授权 * @return mixed * @author php迷途小书童 * @created 2021/1/16 19:08 */ public function wechatAuthorization() { $request = $this->request; $wxConfig = [ "appid" => "wx66f5f8def2b755da", "appsecret" => "891572d83222105a635cf9f502363ff8" ]; $oauth = WechatService::create()->getApplication()->oauth; // dump($oauth); $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent())); try { $wechatInfo = $oauth->user()->getOriginal(); } catch (\Exception $e) { return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]); } if (!isset($wechatInfo['nickname'])) { return app('json')->fail('授权失败[002]'); } return app("json")->success($wechatInfo); } /** * 更新绑定微信支付宝账号 * type=1 微信 2 支付宝 * openid openid */ public function updateAccount(UserRepository $userRepository) { $type = $this->request->param('type'); $openid = $this->request->param('openid');//前端传的是unionid $nickname = $this->request->param('nickname'); $avater = $this->request->param('avater'); $alinfo = $this->request->param('alinfo'); $uid = $this->request->uid(); $user = $this->request->userInfo(); if (!$type) { return app("json")->fail("失败"); } makeLock()->lock(); try { if ($type == 1) { $data = ["wechat_user_id" => $openid]; $unionId = $openid; $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid'); if ($check) throw new \Exception("此微信号已被绑定"); } else { $alinfo = json_decode($alinfo, true); if (!$alinfo) throw new \Exception("参数异常"); $data = ["ali_user_id" => $alinfo["userId"]]; $unionId = $alinfo["userId"]; $check = Db::name("user")->where("ali_user_id", $unionId)->find(); if ($check) throw new \Exception("此支付宝号已被绑定"); $paramStr = $userRepository->getTokenByCode($alinfo["authCode"], true); // \think\facade\Db::name('log')->insert(['data'=>'支付宝授权信息'.json_encode($paramStr)]); $nickname = empty($paramStr["nick_name"]) ? "al" . $alinfo["userId"] : $paramStr["nick_name"]; $avater = empty($paramStr["avatar"]) ? "http://app.bjtdba.com/uploads/def/20201118/5984361a2e00f5407776bcd6eaaae1ce.png" : $paramStr["avatar"]; } $data2 = [ "type" => $type, "uid" => $uid, "nickname" => $nickname, "avater" => $avater, ]; $result = $this->repository->updateUser($uid, $data, $data2); if (!$result) throw new \Exception("修改失败"); $userRepository = app()->make(UserRepository::class); $userInfo = $userRepository->getOne(['uid' => $uid]); //绑定线下充值金额 $unionUsersRepository = app()->make(UnionUsersRepository::class); $orderMerchantRepository = app()->make(OrderMerchantRepository::class); $notBind = $unionUsersRepository->getAllNotBind($unionId); if ($notBind) { $orderMerchantRepository->doBindUser($userInfo, $type); } } catch (\Throwable $e) { makeLock()->unlock(); return app("json")->fail("失败" . $e->getMessage()); } makeLock()->unlock(); return app("json")->success("修改成功", $data); } /** * 获取账号绑定信息 * @return mixed */ public function getAccount() { $uid = $this->request->uid(); // $data = $this->repository->getUser($uid, "wechat_user_id,ali_user_id"); $data = $this->repository->getAccount($uid); if ($data) { return app("json")->success("查询成功", $data); } return app("json")->fail("未绑定"); } /* * 养老金统计 * */ public function get_yanglao_statistics() { $uid = $this->request->uid(); //线下数量 // 查询未结算 $gzc_order_list = Db::name('gzc_logs')->where('uid', $uid)->column('out_trade_no'); $onlineYanglaoUserBill = Db::name('user_bill')->where('commission_type', 5)->whereNotIn('order_sn',$gzc_order_list)->where('status', 0)->where('uid', $uid)->sum('number'); $onlineYanglaoGzc = Db::name('gzc_logs')->where('success', 0)->where('uid', $uid)->sum('pension'); $clearYanglao = Db::name('gzc_logs')->where('success', 1)->where('uid', $uid)->sum('pension'); $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find(); $res = GzcApiRequest::checkAmount($userInfo); $gzc = $res['extendData']['amount'] * 0.01; // PCPC-中信公证处 $data['all_gzc'] = set_price_rtrim(sprintf("%01.2f", $gzc)); // 总养老金 $data['all_yanglao'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao + $gzc); // 一壶茶平台养老金 $data['all_yanglao_yhc'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao); // 未结算养老金=预估养老金,不能包含进入公证处未成功的记录(这部分是已结算的) $data['all_yanglao_yugu'] = set_price_rtrim(round($onlineYanglaoUserBill, 2)); // 已结算养老金 已入账 $data['all_yanglao_clear'] = set_price_rtrim(round($onlineYanglaoGzc+$clearYanglao, 2)); // 已入账养老金 $data['all_yanglao_in'] = set_price_rtrim(round($clearYanglao, 2)); // 一壶茶平台未入账养老金 $data['all_yanglao_nclear'] = set_price_rtrim(round($onlineYanglaoGzc + $onlineYanglaoUserBill, 2)); // 待发起 $data['all_yanglao_wait'] = set_price_rtrim(round($onlineYanglaoGzc, 2)); return app("json")->success("查询成功", $data); } public function num($data, $field) { $sum = 0; foreach ($data as $item) { $sum += $item[$field]; } return $sum; } //志愿者升级 public function changeVolunteer() { $uid = $this->request->uid(); //志愿者条件 $volunteer_achievement = systemConfig("volunteer_achievement");//volunteer_achievement:用户本人满足养老金要求可升级为志愿者 $volunteer_class = new Volunteer(); $volunteer = $volunteer_class->volunteer($uid); if ($volunteer['self_yanglao'] < $volunteer_achievement) { $data['grade'] = 0; $data['self_yanglao'] = $volunteer['self_yanglao']; $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者 return app('json')->success($data); } $volunteer_class->grade($uid, 1, $volunteer); return app('json')->success('申请成功'); } public function GZC($uid) { $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); $orderId = $OrderMerchantRepository->getNewOrderId('IN10'); $OrderGzcRepository = app()->make(OrderGzcRepository::class); $where = [ 'uid' => $uid, 'pm' => 1, 'status' => 1, 'type' => 'commission' ]; $user_data = \think\facade\Db::name('user')->where('uid', $uid)->find(); $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']]; $user_data['real_name'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_name'); $user_data['account'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('mobile'); $user_data['card_id'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_card'); Db::name('user_bill')->where($where)->select()->each(function ($item) use ($uid, $orderId, $OrderGzcRepository, $user_data, $certification) { $is_implement = 1; if ($item['source'] == 0) { $order_data = \think\facade\Db::name('store_order')->where('order_sn', $item['order_sn'])->value('uid'); if ($order_data['uid'] == $item['uid']) { $is_implement = 0; } else { $is_implement = 1; } } else { $order_data = \think\facade\Db::name('order_merchant')->where('out_trade_no', $item['order_sn'])->value('uid'); if ($order_data['uid'] == $item['uid']) { $is_implement = 0; } else { $is_implement = 1; } } if ($is_implement == 1) { $online = ['uid' => $uid, 'pay_type' => '1', 'order_sn' => $item['order_sn'], 'order_id' => $item['link_id']]; $create = [ 'uid' => $online['uid'], 'platform_no' => $orderId, 'account_type' => $online['pay_type'] == 1 ? 3 : 2, 'user_name' => $certification['user_name'], 'mobile' => $certification['mobile'], 'user_card' => $certification['user_card'], 'pension' => $item['number'], 'order_type' => 2, 'out_trade_no' => $online['order_sn'] ]; $OrderGzcRepository->create($create); } }); } //20220712版签到 public function new_sign() { return app('json')->fail('不允许签到'); $uid = $this->request->uid();//签到用户 $user = Db::name('user')->where('uid', $uid)->field("spread_uid,first_sign")->find();//上级用户 //前6天积分 $score = [ 2,//1 4,//2 6,//3 10,//4 14,//5 20//6 ]; //7-30天积分 $scoreS = 3; //额外积分 $scoreExtra = [ 7 => 38, 14 => 68, 21 => 128, 30 => 188 ]; $today_signintime = strtotime(date('Y-m-d', time())); $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find(); if (!empty($today_signin_info)) { return app('json')->fail('今天已经签到过了'); } else { //查询昨天是否已经签到了 $yes_signintime = strtotime(date('Y-m-d')) - 86400; $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find(); $has_qian = 1; if (!empty($yes_signin_info)) { $has_qian = $yes_signin_info['continuity_day'] + 1; $has_qian = $has_qian > 30 ? 1 : $has_qian; } if ($has_qian <= 6) { $get_score = $score[$has_qian - 1]; } else { $get_score = $scoreS; if (isset($scoreExtra[$has_qian])) { $get_score = $scoreS + $scoreExtra[$has_qian]; } } $userRepository = app()->make(UserRepository::class); $userRepository->sign_add($uid, $get_score, 1, '签到赠送积分', $has_qian, $today_signintime, ''); //首次签到 if ($user['first_sign'] == 0) { Db::name('user')->where('uid', $uid)->update(['first_sign' => 1]); } elseif ($user['first_sign'] == 1 && $has_qian == 1) { Db::name('user')->where('uid', $uid)->update(['first_sign' => 2]); } //非首次签到,第一天,断签 //好友连续签到3天 奖励50 //好友连续签到14天 奖励100 //好友联系签到30天 奖励300 if ($user['first_sign'] < 2) { if ($has_qian == 3) { $userRepository->sign_add($user['spread_uid'], 50, 1, '好友签到赠送积分', '', $today_signintime, ''); } elseif ($has_qian == 14) { $userRepository->sign_add($user['spread_uid'], 100, 1, '好友签到赠送积分', '', $today_signintime, ''); } elseif ($has_qian == 30) { $userRepository->sign_add($user['spread_uid'], 300, 1, '好友签到赠送积分', '', $today_signintime, ''); Db::name('user')->where('uid', $uid)->update(['first_sign' => 3]); } } return app('json')->success('签到成功', ['score' => $get_score]); } } public function new_sign_info() { $uid = $this->request->uid(); //查询今天是否已经签到 $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find(); //查询昨天是否已经签到了 $yes_signintime = strtotime(date('Y-m-d')) - 86400; $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find(); $data = [ 'today' => 0, 'day' => 0 ]; if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day']; if ($yes_signin_info['continuity_day'] >= 30) $data['day'] = 0; if ($today_signin_info) { $data['today'] = 1; $data['day'] = $data['day'] + 1; } return app('json')->success($data); } /** * 积分列表 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function sign_list() { [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); $month = $this->request->param('month', '') ?: date('Y-m'); $status = $this->request->param('status'); $pm = $this->request->param('pm'); $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month))); $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month)))); $count = Db::name('user_sign_score') ->whereBetween('addtime', [$startMonth, $endMonth]) ->when(isset($status) && $status !== '', function ($query) use ($status) { $query->where('status', $status); }) ->when(isset($pm) && $pm !== '', function ($query) use ($pm) { $query->where('pm', $pm); }) ->where('uid', $uid)->count(); $list = Db::name('user_sign_score') ->whereBetween('addtime', [$startMonth, $endMonth]) ->where('uid', $uid) ->when(isset($status) && $status !== '', function ($query) use ($status) { $query->where('status', $status); }) ->when(isset($pm) && $pm !== '', function ($query) use ($pm) { $query->where('pm', $pm); }) ->page($page, $limit)->order('id DESC')->select()->each(function ($item) { $item['signin_time'] = date('Y-m-d', $item['signin_time']); $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']); if (!empty($item['order_id'])) { //线上订单 if ($item['order_type'] == 'store_order' || $item['order_type'] == 'store_order_beishengtang') { $item['order_sn'] = Db::name("store_order")->where("order_id", $item['order_id'])->value("order_sn"); } elseif ($item['order_type'] == 'order_merchant') { $item['order_sn'] = Db::name("order_merchant")->where("id", $item['order_id'])->value("out_trade_no"); } elseif ($item['order_type'] == 'extract') { $item['order_sn'] = Db::name("user_extract")->where("extract_id", $item['order_id'])->value("order_sn"); } else { $item['order_sn'] = ''; } } else { $item['order_sn'] = ''; } return $item; }); $data['list'] = $list; $data['count'] = $count; return app('json')->success($data); } public function getAmountFromGzc() { $uid = $this->request->uid(); $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find(); $res = GzcApiRequest::checkAmount($userInfo); return app('json')->success(['amount' => sprintf("%01.2f", $res['extendData']['amount'] * 0.01)]); } public function check_user_annual_fee() { //INSERT INTO rrx_user_pension_account (uid) SELECT uid FROM rrx_user; //UPDATE `renrenxiang`.`rrx_user_pension_account` SET `start_time` = '2023-04-07 00:00:00', `end_time` = '2024-04-07 23:59:59', `status` = 1, `give` = 1 WHERE `id` > 0; $uid = $this->request->uid(); $check = Db::name("user_pension_account")->where("uid", $uid)->find(); $data = [ "status" => 3,//0:未交年费,1:年费到期。2:未实名认证,3:正常 ]; // //未交年费 // if (!$check || $check["status"] == 0) { // $data["status"] = 0; // return app('json')->success($data); // } // //到期时间小于当前时间。年费到期 // if (strtotime($check['end_time']) < time()){ // $data["status"] = 1; // return app('json')->success($data); // } // $data["start_time"] = $check['start_time']; // $data["end_time"] = $check['end_time']; // // //检查实名认证 // $checkCertification = Db::name("user_certification") -> where("uid",$uid) -> find(); // if (!$checkCertification){ // $data["status"] = 2; // return app('json')->success($data); // } return app('json')->success($data); } /** * * @remarks 创建年费订单 * @author 小菜菜 * @created 2023/04/10 14:37 */ public function create_annual_order() { $uid = $this->request->uid(); $type = $this->request->param('type', 1); $OrderMerchantRepository = app()->make(OrderMerchantRepository::class); if ($type == 1) $price = "12.00"; elseif ($type == 2) $price = systemConfig('offline_a'); elseif ($type == 3) $price = systemConfig('offline_b'); elseif ($type == 4) $price = systemConfig('offline_c'); else return app('json')->fail("参数错误"); $check = Db::name("user_pension_account")->where("uid", $uid)->find(); //到期时间小于当前时间。年费到期 if (strtotime($check['end_time']) > time() && $check['status'] == 1) { return app('json')->fail("账户已开通,不可重复开通账户"); } $insertData = [ 'pay_price' => $price, 'status' => 0, 'order_no' => $OrderMerchantRepository->getNewOrderId("mt"), 'uid' => $uid, 'type' => $type, ]; $order_id = Db::name('user_pension_account_order')->insertGetId($insertData); try { return app('json')->success(['order_id' => $order_id]); } catch (\Exception $e) { return app('json')->status('error', $e->getMessage(), ['order_id' => $order_id]); } } /** * @remarks 会员支付 * @author Tang * @created 2021/8/27 9:18 */ public function pay_user_annual() { try { $oid = r::param('oid', ''); $code = r::param('code', ''); $payType = r::param('type', '');//wx.ALI if ($oid == '') return app('json')->fail("请检查参数是否正确"); $groupOrder = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find(); if (!$groupOrder) return app('json')->fail('订单不存在或已支付'); $access = new Access(); $res = $access->pay_huifu($payType, $code, $groupOrder, "年费", env('APP_URL') . "/api/hf_notify/pay_user_annual"); Db::name('log')->insert(['data' => '汇付用户年费支付---' . json_encode($res)]); Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]); return app('json')->success($res); } catch (\Exception $exception) { return app('json')->fail(); } } /** * @remarks 会员支付 线下 * @author Tang * @created 2021/8/27 9:18 */ public function pay_user_annual_offline() { try { $oid = r::param('oid', ''); $payType = r::param('type', '');//WX.ALI $pay_user_id = r::param('pay_user_id', '');//如果是微信。传open_id 如果是支付宝。传user_id if ($oid == '') return app('json')->fail("请检查参数是否正确"); if ($pay_user_id == '') return app('json')->fail("请检查参数是否正确"); $order = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find(); if (!$order) return app('json')->fail('订单不存在或已支付'); if ($order['type'] == 1) { $title = "开通账户"; } elseif ($order['type'] == 2) { $title = "大礼包1"; } elseif ($order['type'] == 3) { $title = "大礼包2"; } elseif ($order['type'] == 4) { $title = "大礼包3"; } else { return app('json')->fail('订单异常'); } if ($order['type'] > 1) { //本人给养老金10% $ylj = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的养老金 $commission = 0; //上级给佣金10% $order_user = Db::name("user")->where("uid", $order["uid"])->field("spread_uid")->find(); //推广员id $spread_uid = $order_user["spread_uid"]; if (!empty($spread_uid)) { $commission = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的佣金 } $pt = sprintf("%01.2f", 12 + $ylj + $commission); $merchant_money = sprintf("%01.2f", $order['pay_price'] - $pt); } else { $pt = "12.00"; $merchant_money = "0.00"; } if ($payType == 'WX') { $pay_wx = systemConfig('pay_wx'); //微信 if ($pay_wx == 3) { $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 3)->value('member_id'); $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871'; $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0'; } else { $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 2)->value('member_id'); $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f'; $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419'; } $type = '2'; $pay_channel = 'wx_pub'; $expend = [ 'open_id' => $pay_user_id ]; } elseif ($payType == 'ALI') { $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 1)->value('member_id'); $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f'; $type = '1'; $pay_channel = 'alipay_pub'; $expend = [ 'buyer_id' => $pay_user_id ]; $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9'; } if ($merchant_money == '0.00') { $div_members = [ [ 'member_id' => 0, 'amount' => $pt, 'fee_flag' => 'Y' ] ]; } else { $div_members = [ [ 'member_id' => $member_id, 'amount' => $merchant_money, 'fee_flag' => 'Y' ], [ 'member_id' => 0, 'amount' => $pt, 'fee_flag' => 'N' ] ]; } $params = [ 'order_no' => $order['order_no'] . '_' . rand(000, 999), 'app_id' => $app_id, 'pay_channel' => $pay_channel, 'pay_amt' => (string)$order['pay_price'], 'goods_title' => "储蓄保", 'goods_desc' => $title, 'device_info' => [ 'device_ip' => app('request')->ip() // 'device_ip'=>'115.171.134.68' ], 'expend' => json_encode($expend), 'div_members' => json_encode($div_members), 'fee_mode' => 'I', 'notify_url' => env('APP_URL') . "/api/jsapiPay/notify/HF_pay_user_annual" ]; $res = $this->Payment_create_traits($params, $type, $key); if (!empty($res['error_code'])) { return app('json')->fail($res['return_msg']); } else { Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]); return app('json')->success($res); } } catch (\Exception $exception) { Db::name('log')->insert(['data' => '大礼包支付error:' . $exception->getFile() . ':' . $exception->getLine() . '【' . $exception->getMessage() . '】']); return app('json')->fail(); } } public function red_log() { $uid = $this->request->uid(); [$page, $limit] = $this->getPage(); $user_rich_log = Db::name('user_rich_log')->where('uid', $uid)->field('uid,red,pm,time,mark')->page($page, $limit)->order('id DESC')->select()->each(function ($item) { $item['create_time'] = date('Y-m-d H:i:s', $item['time']); $item['red'] = set_price_rtrim($item['red']); return $item; }); return app('json')->success($user_rich_log); } public function apply_bang_fu() { $uid = $this->request->uid(); $check = Db::name('user_rich')->where('uid', $uid)->find(); if ($check['type'] < 3) { return app('json')->fail("不满足申请条件"); } $check = Db::name('user_bangfu')->where('uid', $uid)->value('status'); if ($check == 0) { return app('json')->fail("审核中"); } if ($check == 1) { return app('json')->fail("已是帮扶中心"); } if ($check == 2) { return app('json')->fail("审核被拒绝"); } $bang_fu_number = systemConfig("bang_fu_number"); //检测用户是否满足条件 $number = $this->getNumber($uid, $bang_fu_number) - 1;//满足条件人数 减去自己 //条件 if ($number >= $bang_fu_number) { // echo '满足'; Db::name('user_bangfu')->insert([ 'uid' => $uid, 'time' => time(), 'status' => 0 ]); return app('json')->success("提交申请成功"); } return app('json')->fail("不满足申请条件"); // echo '不满足'; } //获得满足 1+5 的下级数量 public function getNumber($uid, $bang_fu_number): int { $number = 0; $getUid = Db::name('user')->where('level_id', $uid)->field('uid')->select(); $count = count($getUid); if ($count >= 5) { $number = 1; foreach ($getUid as $value) { $number += $this->getNumber($value['uid'], $bang_fu_number); if ($number >= $bang_fu_number) { break; } } } return $number; } /** * 积分明细 * @return mixed */ public function score_info() { $uid = $this->request->uid();; $data['score'] = decimal2(Db::name('user_sign_score') ->where('uid', $uid) ->where('status', 1) ->where('pm', 1) ->sum('reward_socre'));; $data['no_clear_score'] = decimal2(Db::name('user_sign_score') ->where('uid', $uid) ->where('status', -1) ->where('pm', 1) ->sum('reward_socre')); $data['lose_score'] = decimal2(Db::name('user_sign_score') ->where('uid', $uid) ->where('pm', 2) ->sum('reward_socre')); $data['clear_score'] = $score = decimal2($data['score'] - $data['lose_score']); $data['score'] = $data['clear_score'] + $data['no_clear_score'] + $data['lose_score']; $data['score'] = decimal2($data['score']); Db::name('user')->where('uid', $uid)->update([ 'score' => $score ]); //clear_score 可用积分,score 积分总数 lose_score 已使用积分 no_clear_score 未结算积分 return app('json')->success($data); } /** * 新版我的团队 */ public function get_team_list() { $data = []; [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); $type = intval($this->request->param('type')); //查询团队列表 $userRepository = app()->make(UserRepository::class); $chilid_userids = $userRepository->getSpreadUidBreak($uid); $data['fans_count'] = count($chilid_userids); $direct_uid_list = Db::name('user')->where('spread_uid', $uid)->where('is_del', 0)->column('uid'); $data['direct_count'] = count($direct_uid_list); $valid_uid_list = Db::name('store_order') ->whereIn('uid', $chilid_userids) ->where('paid', 1) ->group('uid') ->column('uid'); $data['valid_count'] = count($valid_uid_list); $data['count'] = Db::name('user') ->whereIn('uid', $chilid_userids) ->count(); $data['list'] = Db::name('user') ->field('uid,phone,nickname,user_group,create_time,avatar as picture') ->page($page, $limit) ->whereIn('uid', $chilid_userids) ->when($type == 1, function ($query) use ($direct_uid_list) { return $query->whereIn('uid', $direct_uid_list); }) ->when($type == 2, function ($query) use ($valid_uid_list) { return $query->whereIn('uid', $valid_uid_list); }) ->order('uid DESC') ->select() ->toArray(); foreach ($data['list'] as &$user) { $user ['phone'] = substr_replace($user['phone'], '****', 3, 4); } return app('json')->success($data); } /** * 我的粉丝详情 */ public function get_team_info() { $uid = $this->request->param('uid', ''); if (!$uid) return app('json')->fail("uid不正确"); $userRepository = app()->make(UserRepository::class); $chilid_userids = $userRepository->getSpreadUidBreak($this->request->uid()); if (!in_array($uid, $chilid_userids)) return app('json')->fail("该用户不在所属团队内"); $data = Db::name('user') ->field('uid,phone,nickname,spread_uid,user_group,create_time,manage_address') ->where('uid', $uid) ->find(); $data['regimental_commander_count'] = Db::name('user') ->where('spread_uid', $uid) ->where('user_group', 2) ->count(); $data['clear_order_amount'] = Db::name('store_order') ->where('uid', $uid) ->where('is_settlement', 1) ->sum('pay_price'); $data['mybuy_order_amount'] = Db::name('store_order') ->where('uid', $uid) ->where('paid', 1) ->sum('pay_price'); $spread_user = Db::name('user') ->field('nickname as spread_nickname,phone as spread_phone') ->where('uid', $data['spread_uid']) ->find(); $spread_user ['spread_phone'] = substr_replace($spread_user['spread_phone'], '****', 3, 4); $spread_user ['spread_nick_name'] = $spread_user['spread_nickname'] ?? ''; $data ['phone'] = substr_replace($data['phone'], '****', 3, 4); $data = array_merge($data, $spread_user); if (in_array($data['user_group'], [5, 6])) { $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $data['manage_address'])->cache('code:' . $data['manage_address'], 7200)->column('name'); $data['area_name'] = join($data['area_name']); $data['area_bonus_money'] = Db::name('user_bill') ->where('uid', $uid) ->sum('number'); } unset($data['manage_address']); if (in_array($data['user_group'], [4])) { $merchant = Db::name('merchant')->where('uid', $uid)->field('mer_id,mer_name')->find(); $data['mer_id'] = $merchant['mer_id'] ?? 0; $data['mer_name'] = $merchant['mer_name'] ?? ''; } return app('json')->success($data); } /** * 我的佣金 */ public function get_brokerage_info() { $uid = $this->request->uid(); $data['brokerage_price'] = Db::name('user')->where('uid', $uid)->value('brokerage_price'); $data['sum_amount'] = Db::name('user_bill') ->where('uid', $uid) ->where('commission_type', '<>', 5) ->where('pm', 1) ->sum('number'); $data['no_clear_amount'] = Db::name('user_bill') ->where('uid', $uid) ->where('commission_type', '<>', 5) ->where('pm', 1) ->where('status', 0) ->sum('number'); $data['withdraw_amount'] = Db::name('user_extract') ->where('uid', $uid) ->whereIn('status', [0, 1]) ->sum('extract_price'); return app('json')->success($data); } public function get_token_by_phone(UserRepository $repository){ $user = $repository->accountByUser($this->request->param('phone')); $tokenInfo = $repository->createToken($user); return app('json')->success($repository->returnToken($user, $tokenInfo)); } }