love_php/app/Http/Controllers/TestController.php
2026-04-02 09:20:51 +08:00

960 lines
36 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Exports\CommunityActivityExport;
use App\Exports\EvalOrdersExprt;
use App\Exports\MerchantEarningExport;
use App\Exports\NewUserExport;
use App\Exports\ReportFormExport;
use App\Exports\ReportQuarterExport;
use App\Exports\StatementExport;
use App\Exports\StatementExportV2;
use App\Exports\StatementExportV3;
use App\Exports\TestExport;
use App\Exports\UserCoinExport;
use App\Facades\CommonUtilsService;
use App\Facades\WechatService;
use App\Imports\MemberSeatImport;
use App\Http\Resources\CommunityActivitiesResource;
use App\Http\Response\ResponseJson;
use App\Jobs\CheckMEarningAccount;
use App\Jobs\MakeSurveyQrcode;
use App\Model\Server\CommunityActivitySeat;
use App\Models\Audit;
use App\Models\Coin;
use App\Models\CoinLog;
use App\Models\CoinWithdrawLog;
use App\Models\ConsultAccount;
use App\Models\Consultation;
use App\Models\ConsultationRecords;
use App\Models\Coupon;
use App\Models\Course\Course;
use App\Models\FellowingCard;
use App\Models\FellowingCardHistory;
use App\Models\IdentityAuthorization;
use App\Models\Live\Anchor;
use App\Models\Live\Viewer;
use App\Models\Message;
use App\Models\MessageLinkman;
use App\Models\Order;
use App\Models\ProfileCourtship;
use App\Models\ProfileMarriage;
use App\Models\ProfilePhoto;
use App\Models\Server\CommunityActivity;
use App\Models\Server\CommunityActivityMember;
use App\Models\Server\EvaluateQuestion;
use App\Models\Server\MEarning;
use App\Models\Server\MEarningAccount;
use App\Models\Server\MEarningwithdraws;
use App\Models\Server\MerchantAccount;
use App\Models\Server\MerchantEvaluate;
use App\Models\Server\MerchantTransferLog;
use App\Models\Server\MerchantUser;
use App\Models\Server\MerchantUserPhoto;
use App\Models\Server\MerchantUserProfile;
use App\Models\Server\MRefundOrder;
use App\Models\Server\SaasMemberLevel;
use App\Models\Server\SaasMemberVipGain;
use App\Models\TemplateMsgLog;
use App\Models\TouristOrder;
use App\Models\User;
use App\Models\Wechat;
use App\Services\IMService;
use App\Services\SaasVipService;
use App\Services\TestService;
use App\Utils\Http;
use App\Utils\Messenger;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\TextCard;
use GatewayClient\Gateway;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use App\Exports\ActiveUserExport;
use App\Exports\ProvinceUserExport;
class TestController extends Controller
{
use ResponseJson;
public function __construct()
{
if (config('app.env') == 'production') {
Gateway::$registerAddress = '192.168.1.204:1238';
} else {
Gateway::$registerAddress = '192.168.62.13:1238';
}
}
public function chat()
{
return view('test_chat');
}
public function chatBind(Request $request)
{
$client_id = $request->input('client_id');
$room_id = $request->input('room_id');
$user = ['id' => 2, 'name' => 'Hankin', 'client_id' => $client_id, 'time' => date('Y-m-d H:i:s')];
Gateway::bindUid($client_id, $user['id']);
Gateway::joinGroup($client_id, $room_id);
$uid_infos = Gateway::getUidListByGroup($room_id);
dd(array_keys($uid_infos));
return $this->success('ok', $user);
}
public function sendMessage(Request $request)
{
$uid = 1;
$name = 'Hankin';
$res = Gateway::getClientIdByUid($uid);
$content = $request->input('content');
$to_client_id = $request->input('to_client_id');
$room_id = $request->input('room_id');
$message = ['type' => 'say', 'from_client_id' => $res[0], 'from_client_name' => $name, 'content' => $content, 'time' => date('Y-m-d H:i:s')];
if ($to_client_id == 'all') {
Gateway::sendToGroup($room_id, json_encode($message));
} else {
}
return $this->success('ok');
}
public function updateViewerUser()
{
try {
DB::table('temp_viewers')->whereNotNull('mobile')->where(function ($sql) {
$sql->whereNull('user_id')->orWhere('user_id', 0)->orWhere('user_id', '');
})->orderBy('id', 'desc')->chunk(100, function ($viewers) {
foreach ($viewers as $viewer) {
$user_id = DB::table('users')->where("mobile", $viewer->mobile)->value('id');
if ($user_id) {
DB::table('temp_viewers')->where("id", $viewer->id)->update(['user_id' => $user_id]);
}
}
});
} catch (\Exception $e) {
$this->getError($e);
}
}
public function testCrmUsers()
{
$users = User::single()->approve()->pay()->fullinkUser();
$users = MerchantUser::whereHas('mpUser', function ($sql) {
$sql->single()->approve()->fullinkUser();
})->whereHas('orders', function ($sql) {
$sql->where('pay_status', '<>', 0)->where('price', '>', 0)->where('merchant_id', 491);
});
dd($users->count());
}
public function testTransfer(Request $request, $name)
{
try {
return $this->$name($request);
} catch (\Exception $e) {
$this->getError($e);
}
}
public function exportActivities(Request $request)
{
$communities = CommunityActivity::where('merchant_id', 491)->where('class', $request->class)->whereBetween("created_at", [20220101, 20230101])->orderby('id', 'asc')->get();
$activities = new CommunityActivitiesResource($communities);
return \Excel::download(new CommunityActivityExport($activities), '2022年活动.xlsx');
}
public function test($request)
{
$time = '2023-01-01 00:00';
dd(date('Y-m-d', strtotime($time)));
}
public function merchantEarningExport(Request $request)
{
// $orders = TouristOrder::with('anchor:m_id,name', 'refunds')->where('pay_status', 4)->where('price','>', 0)->where('pay_type', 'wechat')->whereBetween('created_at', [20220101, 20230101]);
// if ($request->input('is_love')) {
// $orders = $orders->whereIn('merchant_id', [491, 71]);
// }else {
// $orders = $orders->whereNotIn('merchant_id', [491, 71]);
// }
$orders = Order::where("pay_status", 'PAID')->where('price', '>', 0)->whereBetween('created_at', [20220101, 20230101])->get();
return \Excel::download(new MerchantEarningExport($orders), '2022会员收益.xlsx');
}
public function evalOrders()
{
$orders = TouristOrder::whereHas('merchant_evaluate', function ($sql) {
$sql->where('test_item_id', '<', 10000);
})->where('type', 'evaluate')->where('price', '>', 0)->get();
return \Excel::download(new EvalOrdersExprt($orders), '壹点灵订单.xlsx');
}
public function exportCityUsers(Request $request)
{
$city_arr = $request->input('city_arr');
$city_arr = explode(',', $city_arr);
$users = User::whereHas("profileCourtship", function ($sql) use ($city_arr) {
$sql->whereIn('city', $city_arr)->where('income', '>=', 5);
})->where('is_real_approved', 1)->with('userDetailQrcode')->where('type', 'single')->where('hidden_profile', 'NONE')->paginate();
// return \Excel::download(new CityUsersExport($users), $city_arr[0].'城市用户.xlsx');
return view('city_users', ['users' => $users, 'city_arr' => $city_arr]);
}
public function exportProvinceUsers(Request $request)
{
set_time_limit(0);
$province = $request->input('province');
$user_id = $request->user_id;
$users = User::whereHas("profileCourtship", function ($sql) use ($province) {
$sql->where('province', $province);
})->where('type', 'loveing')->where("id", ">", $user_id)->limit(2000)->get();
return \Excel::download(new ProvinceUserExport($users), '省份用户.xlsx');
}
public function testExport()
{
return \Excel::download(new TestExport(), 'test.xlsx');
}
public function saasUserProfile()
{
$ias = IdentityAuthorization::all();
foreach ($ias as $ia) {
$m_profile = MerchantUserProfile::where(['m_id' => $ia->m_id, 'user_id' => $ia->m_user_id])->first();
if (empty($m_profile)) {
$keys = [
'birthday',
'sex',
'state',
'belief',
'stature',
'weight',
'province',
'city',
'resident_province',
'resident_city',
'degree',
'industry',
'industry_sub',
'income',
'introduction',
'interest_hobby',
'mate_conditon',
'ideal_mate'
];
if (empty($ia->merchant_user->mpUser))
continue;
$profile = new MerchantUserProfile();
$profile->m_id = $ia->m_id;
$profile->user_id = $ia->m_user_id;
foreach ($keys as $key) {
if ($key == 'industry' || $key == 'industry_sub') {
$profile->$key = $ia->merchant_user->mpUser->$key;
continue;
}
$profile->$key = $ia->merchant_user->mpUser->sass_profileCourtship->$key;
}
DB::beginTransaction();
$profile->save();
$photos = ProfilePhoto::where('user_id', $ia->merchant_user->user_id)->select('user_id', 'photo', 'dateline')->get()->toArray();
foreach ($photos as &$photo) {
$photo['user_id'] = $ia->m_user_id;
$photo['m_id'] = $ia->m_id;
$photo['created_at'] = $photo['updated_at'] = date('Y-m-d H:i:s');
}
MerchantUserPhoto::insert($photos);
DB::commit();
}
}
}
public function exportUserCoin()
{
$coins = Coin::with('user')->where('remain_amount', '>', 0)->orderByDesc('remain_amount')->get();
$data = [];
foreach ($coins as $coin) {
$coin_value = CoinLog::where('type', 'RECSYSTEM')->where('user_id', $coin->user_id)->where('remark', 'like', '%邀请好友%')->sum('coin');
//减去提现的金额
$consume_coin = CoinWithdrawLog::where('user_id', $coin->user_id)->wherein('status', [0, 1])->wherein('is_hooked', [0, 1])->where('remark', '邀请好友')->sum('value');
$remain_coin = $coin_value - $consume_coin ?: 0;
$arr = [];
if ($remain_coin > 0) {
$arr['user_id'] = $coin->user_id;
$arr['name'] = $coin->user ? $coin->user->nickname : '';
$arr['amount'] = $remain_coin;
$data[] = $arr;
}
}
return \Excel::download(new UserCoinExport($data), '壹点灵订单.xlsx');
}
public function showReportForms(Request $request)
{
return view('report_forms');
}
public function makeReportForms(Request $request)
{
$start_date = $request->start_date;
if (empty($start_date))
return $this->failure("请选择开始日期");
return \Excel::download(new ReportFormExport($start_date), $start_date . '福恋报表.xlsx');
// return $this->success('ok', $file);
}
public function statementExport(Request $request)
{
$date = $request->date;
if (empty($date))
return $this->failure("请选择日期");
if ($request->pwd != "love_saas")
return $this->failure("密码错误");
return \Excel::download(new StatementExport($date), date('m', strtotime($date)) . "月福恋报表.xlsx");
}
public function statementExportV2(Request $request)
{
$date = $request->date;
if (empty($date))
return $this->failure("请选择日期");
if ($request->pwd != "love_saas")
return $this->failure("密码错误");
return \Excel::download(new StatementExportV2($date), date('m', strtotime($date)) . "月福恋报表.xlsx");
}
public function statementExportV3(Request $request)
{
$date = $request->date;
if (empty($date))
return $this->failure("请选择日期");
if ($request->pwd != "love_saas")
return $this->failure("密码错误");
return \Excel::download(new StatementExportV3($date), date('m', strtotime($date)) . "月福恋报表.xlsx");
}
public function statementLoveExport(Request $request)
{
$start_date = $request->start_date;
return \Excel::download(new StatementExport($start_date, "love"), date('m', strtotime($start_date)) . "月福恋产品报表.xlsx");
}
public function showStatementExport()
{
return view("statement");
}
/**
* 福恋报表-季度
* @param Request $request
*/
public function makeReportQuarter(Request $request)
{
$year = $request->year;
if (empty($year))
return $this->failure("请选择年份");
return \Excel::download(new ReportQuarterExport($year . '0101'), $year . '年福恋报表.xlsx');
}
public function getUrlqrcodes(Request $request)
{
$path = $request->input('path');
$path = "https://love.ufutx.com/api/official/live/wechat/FamilyAuth?merchant_id=44&url=https%3A%2F%2Flove.ufutx.com%2Fpu%2F%23%2FofflineSignIn%2F2115";
$url = parent::getUrlqrcode($path);
return $this->success('ok', $url);
}
public function sh5Toekn()
{
$id = request()->id;
$account = MerchantUser::where('id', $id)->first();
$token = $this->api_token($account);
return $this->success('ok', $token);
}
public function mpToken()
{
$user_id = request()->user_id;
$user = User::find($user_id);
$token = $user->createToken($user->id)->accessToken;
return $this->success('ok', $token);
}
//创建token
public function api_token($account)
{
$token = $account->api_token;
if ($token) {
try {
$result = decrypt($token);
} catch (\Exception $e) {
$token = encrypt($account->id . '-' . $account->mobile . '-' . time() . '-' . $account->email);
$account->api_token = $token;
$account->save();
}
$time = explode('-', $result)[2];
if (time() - $time > 604800) {
$token = encrypt($account->id . '-' . $account->mobile . '-' . time() . '-' . $account->email);
$account->api_token = $token;
$account->save();
}
} else {
$token = encrypt($account->id . '-' . $account->mobile . '-' . time() . '-' . $account->email);
$account->api_token = $token;
$account->save();
}
return $token;
}
/**
* 注销用户
*/
public function writeOffUser(Request $request)
{
try {
$code = $request->input('code');
$redis_code = Cache::get('write_off_user_code');
if (empty($code) || $redis_code != $code)
return $this->failure("code失效");
$mobile = $request->mobile;
if (empty($mobile))
return $this->failure('请输入手机号');
$user = User::where('mobile', $mobile)->first();
if (empty($user))
return $this->failure("手机号已注销");
// $close_users = DB::table('close_users')->get();
// $close_wechats = DB::table('close_wechats')->get();
// $data = [
// 'user' => $user,
// 'user_wechat' => $user->wechat,
// 'user_wechat_getAttributes' => $user->wechat->getAttributes(),
// 'close_users' => $close_users,
// 'close_wechats' => $close_wechats,
// ];
DB::beginTransaction();
$data = $user->getAttributes();
$data['deleted_at'] = date("Y-m-d H:i:s");
DB::table('close_users')->insert($data);
if ($user->wechat) {
DB::table('close_wechats')->insert($user->wechat->getAttributes());
$user->wechat->forceDelete();
}
$user->forceDelete();
DB::commit();
return $this->success('ok');
} catch (\Exception $e) {
DB::rollBack();
$this->getError($e);
return $this->failure($e->getMessage());
}
}
/**
* 注销用户code
* @param Request $request
*/
public function writeOffUserCode(Request $request)
{
$code = Cache::get('write_off_user_code');
if (empty($code)) {
$code = uniqid() . time();
Cache::put('write_off_user_code', $code, 1);
}
return $this->success('ok', $code);
}
public function testChatMessages(Request $request)
{
$user_id = $request->user_id;
$send_user_id = $request->send_user_id;
$im_service = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET'));
$begintime = $request->input('start_time', CommonUtilsService::getMillisecond() - 72 * 36600 * 1000);
$endtime = $request->input('start_time', CommonUtilsService::getMillisecond());
$mine_messages = $im_service->querySessionMsg($user_id, $send_user_id, $begintime, $endtime);
return $this->success('ok', $mine_messages);
}
public function userByOpenid($openid)
{
return MerchantUser::where('openid', $openid)->first();
}
public function testOrderTransfer()
{
$count = 0;
$mine_share_count = 0;
$has_transfer_count = 0;
$no_user_count = 0;
$success_count = 0;
TouristOrder::where('type', 'community')->where('type_id', 2201)->where('pay_status', 4)->whereIn('goods', ["参会者票", "特邀嘉宾票", "VIP票"])->whereNotNull('from_openid')->chunk(100, function ($orders) use (&$count, &$mine_share_count, &$has_transfer_count, &$no_user_count, &$success_count) {
$count += count($orders);
foreach ($orders as $order) {
$user = $this->userByOpenid($order->from_openid);
if (empty($user) || empty($order->from_openid)) {
$no_user_count += 1;
continue;
}
if ($user->id == $order->account_id) {
$mine_share_count += 1;
continue;
}
//判断是否已经转账
$res = $this->isTransferOrder($order, $user);
if ($res) {
$has_transfer_count += 1;
continue;
}
// $this->transferOrder($order, $user);
$success_count += 1;
}
});
return $this->success('ok', compact('count', 'has_transfer_count', 'no_user_count', 'success_count'));
}
public function transferOrder($order, $user)
{
DB::beginTransaction();
//转账金额
$amount = number_format($order->price * 0.25, 2);
//修改商户账号
$m_earning_account = MEarningAccount::where('m_id', $order->merchant_id)->where('m_user_id', 0)->first();
$m_earning_account->decrement('balance', $amount);
$m_earning_account->decrement('total_value', $amount);
if ($m_earning_account->balance < 0)
throw new \Exception("商户账号余额不足");
//创建转账订单
$trade_no = CommonUtilsService::getTradeNO();
$remark = "订单" . $order->id . "分享收益增加额外25%";
$name = $user->nickname ?: "未知";
$mobile = $user->mobile ?: "未知";
$order = \App\Models\Server\TouristOrder::create([
'price' => $amount,
'pay_type' => 'wechat',
'type' => 'transfer',
'pay_status' => 4,
'trade_no' => $trade_no,
'withdrawal_radio' => 100,
'name' => $name,
'mobile' => $mobile,
'desc' => $remark,
'merchant_id' => $order->merchant_id,
'account_id' => $user->id,
]);
//修改用户收益
$earning = $user->addEarning($order->merchant_id, 'transfer', $amount, $order->id);
if ($earning === false)
throw new \Exception('增加订单转账收益记录异常,号码:' . $order->id);
//增加转账记录
$insert = ['m_id' => $order->merchant_id, 'amount' => $amount, 'mobile' => $mobile, 'm_earning_id' => $earning->id, 'name' => $name, 'remark' => $remark, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), 'recive_m_id' => 0, 'recive_m_user_id' => $user->id, 'nickname' => $user->nickname];
MerchantTransferLog::insert($insert);
DB::commit();
}
public function isTransferOrder($order, $user)
{
//判断订单在指定时间段是否有记录
// $res = MEarning::hasTransferOrder()->where(['m_id'=>$order->merchant_id, 'm_user_id'=>$user->id])->whereBetween('created_at',[$start_time, $end_time])->exists();
$res = MerchantTransferLog::where('remark', "订单" . $order->id . "分享收益增加额外25%")->exists();
return $res;
}
public function EarningAccountBan()
{
$account = MEarningAccount::where('is_banned', 1)->orderByDesc('id')->first();
CheckMEarningAccount::dispatch($account)->onQueue('love');
return $this->success('ok');
}
public function testPartnerPay()
{
$sub_mchid = "1626601973";
$total = 0.01;
$openid = "oPC_2vneOWpQbicNZQAUCxuwZ4mw";
$trade_no = CommonUtilsService::getTradeNo();
$notify_url = 'https://love.ufutx.com';
$desc = "测试订单";
$res = WechatService::partnerPay(1, $sub_mchid, $total, $openid, $trade_no, $notify_url, $desc);
return $this->success("ok", $res);
}
public function testPartnerPaid()
{
$trade_no = "1690453703882491";
$sub_mchid = "1626601973";
$res = WechatService::partnerOrderPaid($trade_no, $sub_mchid);
return $this->success('ok', $res);
}
public function addCoupon(Request $request)
{
try {
$link = $request->link; //'receiveCoupons';
$coupon_id = $request->coupon_id;
$jump_url = $request->jump_url ?: urlencode(env('APP_URL') . '/pu/#/' . $link . '/' . $coupon_id);
$url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $request->account_id . '&url=' . $jump_url;
$qr_code = Redis::get('s_coupons' . $coupon_id);
if (!$qr_code) {
$qr_code = $this->getPreviewQrcode($url);
Redis::setex('s_coupon' . $coupon_id, 60 * 60 * 24 * 30, $qr_code);
$qr_code = Redis::get('s_coupon' . $coupon_id);
}
return $this->success('ok', $qr_code);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息中,请稍后再试');
}
}
public function testEarningAccount(Request $request)
{
$accounts = MEarningAccount::where('m_id', $request->m_id);
if (is_numeric($request->m_user_id)) {
$accounts = $accounts->where('m_user_id', $request->m_user_id);
}
$accounts = $accounts->get();
foreach ($accounts as $account) {
CheckMEarningAccount::dispatch($account)->onQueue('love');
}
}
public function testRefundService()
{
$merchant_id = 491;
$orders = TouristOrder::whereIn('id', [21025, 20913, 20632])->where('merchant_id', $merchant_id)->get();
foreach ($orders as $order) {
DB::beginTransaction();
$refund_trade_no = $this->getRefundTradeNo();
$refund_price = $order->price;
//生成退款订单
MRefundOrder::create([
'm_id' => $merchant_id,
'admin_id' => 58859,
'm_user_id' => $order->account_id,
'type' => $order->type,
'trade_no' => $order->trade_no,
'refund_trade_no' => $refund_trade_no,
'total_fee' => $order->price,
'refund_fee' => $refund_price,
'is_hook' => 0,
'remark' => "未参加活动,已结算,系统全部退款",
]);
$m_earning_account = MEarningAccount::where('m_id', $merchant_id)->where('m_user_id', 0)->first();
//删除商家收益
$m_earning_account->decrement('balance', $order->price);
$m_earning_account->decrement('total_value', $order->price);
MEarning::where('m_id', $merchant_id)->where('m_user_id', 0)->where('m_order_id', $order->id)->delete();
//福恋转账分享用户
$this->transferUser($order, $merchant_id);
$order->update(['pay_status' => 3]);
//退款
$result = \WechatService::orderRefund($order->trade_no, $refund_trade_no, $order->price, $refund_price, $array = ['refund_desc' => '订单退款']);
if (is_array($result) && $result['status'] === true) {//退款成功
DB::commit();
} else {
DB::rollBack();
}
}
}
public function transferUser($order, $m_id)
{
$earnings = MEarning::where("m_id", $m_id)->where("m_user_id", '<>', 0)->where('m_order_id', $order->id)->get();
foreach ($earnings as $earning) {
$insert = ['m_id' => $m_id, 'recive_m_user_id' => $earning->m_user_id, 'amount' => $earning->value, 'mobile' => $order->mobile, 'm_earning_id' => $earning->id, 'name' => $order->name, "nickname" => $order->name, 'remark' => "订单退款,分享人收益不变", 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')];
MerchantTransferLog::insert($insert);
}
}
public function testCreateEval()
{
$questions = EvaluateQuestion::with("answer")->where('test_item_id', 10007)->get()->toArray();
dd(json_encode($questions, JSON_UNESCAPED_UNICODE));
// $this->createEval();
}
public function testMain()
{
try {
$test_key = request()->input('test_key');
if ($test_key != 'l2SjkKTORy5uYhfPVOtvVR51B15dKPZd') {
return 'error';
}
$action = request()->input('action');
return $this->$action();
} catch (\Exception $e) {
echo 'error:' . $e->getMessage();
}
}
public function addMessageLinkman()
{
$my_linkman = MessageLinkman::firstOrCreate(['user_id' => 3587, 'other_user_id' => 7622]);
$my_linkman->updated_at = date('Y-m-d H:i:s');
$my_linkman->save();
}
public function restoreAvatar()
{
$user_id = request()->input('user_id');
$user = User::find($user_id);
if (!$user) {
return 'no user';
}
$wechat = Wechat::where('user_id', $user_id)->first();
if (!$wechat) {
return 'no wechat';
}
$avatar = $wechat->avatar2 ?: $wechat->avatar;
if (!$avatar) {
return 'no avatar';
}
$uniqid = uniqid();
$path = storage_path("qrcode/{$uniqid}.png");
file_put_contents($path, file_get_contents($avatar));
$qrcode = $this->uploadFile($path);
unlink($path);
$user->photo = $qrcode;
$user->save();
dd($qrcode);
}
public function clearIsMarriageApproved()
{
$user_id = request()->input('user_id');
$user = User::query()->find($user_id);
if ($user) {
$user->is_marriage_approved = 0;
$user->save();
}
$profile = ProfileMarriage::query()->where('user_id', $user_id)->first();
if ($profile) {
$profile->desc = '';
$profile->certificates = null;
$profile->save();
}
Audit::query()->where('user_id', $user_id)->where('type', Audit::TYPE_MARRIAGE_APPROVE)->delete();
}
public function importActivityMember()
{
\Excel::import(new MemberSeatImport, storage_path('seats.xlsx'));
$members = CommunityActivitySeat::where('activity_id', 2446)->get();
Cache::put('activity:2446:members', $members, now()->addDays(7));
return $this->success('ok');
}
public function syncSurveyQrcode(Request $request)
{
$m_id = $request->input('m_id');
$survey_id = $request->input('survey_id');
MakeSurveyQrcode::dispatch($m_id, null, null, $survey_id)->onQueue('love');
}
public function exportActiveUsers()
{
set_time_limit(0);
$start_date = request()->start_date;
$end_date = request()->end_date;
$type = request()->type;
return \Excel::download(new ActiveUserExport($start_date, $end_date, $type), '活跃用户.xlsx');
}
public function exportNewUsers()
{
$rows = [];
$users = User::with("profileCourtship")->where("created_at", ">=", request()->start_time)->where("created_at", "<", request()->end_time)->where("type", "single")->where("hidden_profile", "NONE")->get();
foreach ($users as $user) {
$profile = $user->ProfileCourtship;
$arr = [];
$arr['user_id'] = $user->id;
$arr["province"] = $profile->province;
$arr["city"] = $profile->city;
$arr['sex'] = $user->sex;
$arr['degree'] = $profile->degree;
$arr['industry'] = $user->industry;
$arr['industry_sub'] = $user->industry_sub;
$arr['state'] = $profile->state;
$arr['income'] = $profile->income;
$arr['nickname'] = $user->nickname;
$arr['name'] = $user->name;
$arr['mobile'] = $user->mobile;
$arr['belief'] = $profile->belief;
$arr['age'] = CommonUtilsService::getAge($profile->birthday);
$rows[] = $arr;
}
return \Excel::download(new NewUserExport($rows), '新用户.xlsx');
}
public function sendBirthdayBlessing(): string
{
$user = User::find(request()->user_id);
$nickname = $user->nickName;
$mobile = $user->mobile;
$code = '生日提醒短信';
//如果今年已经发送过一次短信则不在发送
$this_year_initial_date = date('Y-01-01');
if (empty($mobile))
return false;
$result = Message::where('phone', $mobile)
->where('created_at', '>=', $this_year_initial_date)
->where('code', $code)
->count();
if ($result) {
return false;
}
$m = Message::create([
'phone' => $mobile,
'message' => '',
'confirmed' => 1,
'code' => $code,
'ip' => request() ? request()->ip() : '127.0.0.1',
]);
$url = '';
$wecharLink = \CommonUtilsService::getWecharLink('/pages/home/birthdayPresent');
$url = \CommonUtilsService::createShortUrl(env('APP_URL') . '/h5/#/jump_url?url=' . $wecharLink, $m->id);
$message = "亲爱的 $nickname 生日快乐! 福恋悄悄给你送了一个神秘的专属礼物哦,点击链接 $url 拆开你的礼物吧!";
$m->message = $message;
$m->save();
Messenger::sendSMS($mobile, $message);
return $url;
}
public function checkApproveBirthday()
{
User::with("profileCourtship")->where("type", "single")->where("is_real_approved", 1)->chunk(100, function ($users) {
foreach ($users as $user) {
$res = CommonUtilsService::checkCardBirhday($user->card_num);
if ($user->profileCourtship) {
$birthday = $user->profileCourtship->birthday;
} else {
$birthday = "";
}
if ($res["tdate"] != $birthday && $birthday) {
Log::info("bk id=" . $user->id . " " . $res["tdate"] . " " . $birthday);
}
}
});
}
// 设置福恋公众号菜单
public function settingOfficialMenu()
{
$menuJson = '{
"button": [
{
"type": "miniprogram",
"name": "找对象",
"url": "https://love.ufutx.com",
"appid": "wxc41491431733671e",
"pagepath": "pages/tabBar/welcome?from_platform=FL_88"
},
{
"name": "想脱单",
"sub_button": [
{
"type": "view",
"name": "综合服务",
"url": "https://love.ufutx.cn/api/official/live/wechat/FamilyAuth?merchant_id=491&url=https://love.ufutx.cn/pu/#/"
},
{
"type": "view",
"name": "结婚喜报",
"url": "https://love.ufutx.cn/s/74a"
},
{
"type": "view",
"name": "免费发帖",
"url": "https://love.ufutx.cn/h5/#/OntheWall?from_platform=FL_88"
}
]
},
{
"name": "关于",
"sub_button": [
{
"type": "view",
"name": "服务收益",
"url": "https://love.ufutx.cn/auth/saas/earning/account"
},
{
"type": "view",
"name": "服务管理",
"url": "https://love.ufutx.cn/api/official/merchat/auth/login"
},
{
"type": "view",
"name": "服务入驻",
"url": "https://love.ufutx.cn/s/74d"
},
{
"type": "view",
"name": "关于本号",
"url": "https://mp.weixin.qq.com/s/LJitBk0aShltTZHStPll2g"
}
]
}
]
}';
$token = request()->input("token");
if ($token != "love_setting_official_menu")
return $this->failure("秘钥错误");
$access_token = "";
$app = \WechatService::officialApp()->access_token;
$token = $app->getToken(true);
$access_token = $token['access_token'];
if (empty($access_token)) {
return $this->failure("缺少access_token");
}
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $access_token;
$result = Http::post($url, $menuJson);
dd($result);
}
public function getOfficialMenu()
{
$token = request()->input("token");
if ($token != "love_get_official_menu")
return $this->failure("秘钥错误");
$access_token = "";
$app = \WechatService::officialApp()->access_token;
$token = $app->getToken(true);
$access_token = $token['access_token'];
if (empty($access_token)) {
return $this->failure("缺少access_token");
}
$url = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=" . $access_token;
$result = Http::get($url);
return $this->success("ok", $result);
}
}