This commit is contained in:
Hankin 2026-04-27 14:19:00 +08:00
parent 2d3e878e11
commit e7f77af788

View File

@ -231,7 +231,8 @@ class EarningController extends Controller
//商家服务id //商家服务id
$service_ids = CommunityActivity::where('merchant_id', $request->account_id) $service_ids = CommunityActivity::where('merchant_id', $request->account_id)
->where('class', 'many')->pluck('id') ->where('class', 'many')->pluck('id')
->toArray();; ->toArray();
;
foreach ($earnings as $earning) { foreach ($earnings as $earning) {
if ($earning->m_user_id) { if ($earning->m_user_id) {
$user = MerchantUser::find($earning->m_user_id); $user = MerchantUser::find($earning->m_user_id);
@ -409,8 +410,10 @@ class EarningController extends Controller
if ($value['ratio'] > 1) { if ($value['ratio'] > 1) {
return $this->failure('分成利润不能大于1'); return $this->failure('分成利润不能大于1');
} }
if (!isset($value['first_sharer']) || !isset($value['last_sharer']) || !isset($value['other_sharer'])) throw new Exception("缺少分成人员比例参数"); if (!isset($value['first_sharer']) || !isset($value['last_sharer']) || !isset($value['other_sharer']))
if ($value['first_sharer'] + $value['last_sharer'] + $value['other_sharer'] != 1) return $this->failure("分成人员比例必须100%"); throw new Exception("缺少分成人员比例参数");
if ($value['first_sharer'] + $value['last_sharer'] + $value['other_sharer'] != 1)
return $this->failure("分成人员比例必须100%");
$result = MEarningRules::where('m_id', $merchant_id) $result = MEarningRules::where('m_id', $merchant_id)
->where('type_id', 0) ->where('type_id', 0)
->where('name', $key) ->where('name', $key)
@ -547,12 +550,14 @@ class EarningController extends Controller
try { try {
$m_id = $request->account_id; $m_id = $request->account_id;
$title = $request->input('title'); $title = $request->input('title');
if (empty($title)) return $this->failure("操作失败,请输入规则名称"); if (empty($title))
return $this->failure("操作失败,请输入规则名称");
$amount = $request->input('amount', 0); $amount = $request->input('amount', 0);
$ratio = $request->input('ratio', 1); $ratio = $request->input('ratio', 1);
$forzen_time = $request->input('forzen_time', 0); $forzen_time = $request->input('forzen_time', 0);
$grade = MEarningGrade::where('m_id', $m_id)->where('amount', $amount)->first(); $grade = MEarningGrade::where('m_id', $m_id)->where('amount', $amount)->first();
if ($grade) return $this->failure("操作失败,已设置同价位的规则"); if ($grade)
return $this->failure("操作失败,已设置同价位的规则");
$grade = MEarningGrade::create(['m_id' => $m_id, 'title' => $title, 'amount' => $amount, 'ratio' => $ratio, 'forzen_time' => $forzen_time]); $grade = MEarningGrade::create(['m_id' => $m_id, 'title' => $title, 'amount' => $amount, 'ratio' => $ratio, 'forzen_time' => $forzen_time]);
return $this->success('ok', $grade); return $this->success('ok', $grade);
} catch (Exception $e) { } catch (Exception $e) {
@ -572,13 +577,15 @@ class EarningController extends Controller
try { try {
$m_id = $request->account_id; $m_id = $request->account_id;
$grade = MEarningGrade::where('m_id', $m_id)->where('id', $grade_id)->first(); $grade = MEarningGrade::where('m_id', $m_id)->where('id', $grade_id)->first();
if (empty($grade)) return $this->failure("操作失败,该收益规则不能存在"); if (empty($grade))
return $this->failure("操作失败,该收益规则不能存在");
if ($request->title && $request->title != $grade->title) { if ($request->title && $request->title != $grade->title) {
$grade->title = $request->title; $grade->title = $request->title;
} }
if ($request->has('amount') && $request->amount != $grade->amount) { if ($request->has('amount') && $request->amount != $grade->amount) {
$own_grade = MEarningGrade::where('m_id', $m_id)->where('amount', $request->amount)->where('id', '<>', $grade->id)->first(); $own_grade = MEarningGrade::where('m_id', $m_id)->where('amount', $request->amount)->where('id', '<>', $grade->id)->first();
if ($own_grade) return $this->failure("操作失败,已设置同价位的规则"); if ($own_grade)
return $this->failure("操作失败,已设置同价位的规则");
$grade->amount = $request->amount; $grade->amount = $request->amount;
} }
if ($request->has('ratio') && $request->ratio != $grade->ratio) { if ($request->has('ratio') && $request->ratio != $grade->ratio) {
@ -605,7 +612,8 @@ class EarningController extends Controller
try { try {
$m_id = $request->account_id; $m_id = $request->account_id;
$grade = MEarningGrade::where('m_id', $m_id)->where('id', $grade_id)->first(); $grade = MEarningGrade::where('m_id', $m_id)->where('id', $grade_id)->first();
if (empty($grade)) return $this->failure("操作失败,该收益规则不能存在"); if (empty($grade))
return $this->failure("操作失败,该收益规则不能存在");
return $this->success('ok', $grade); return $this->success('ok', $grade);
} catch (Exception $e) { } catch (Exception $e) {
$this->getError($e); $this->getError($e);
@ -624,7 +632,8 @@ class EarningController extends Controller
try { try {
$m_id = $request->account_id; $m_id = $request->account_id;
$grade = MEarningGrade::where('m_id', $m_id)->where('id', $grade_id)->first(); $grade = MEarningGrade::where('m_id', $m_id)->where('id', $grade_id)->first();
if (empty($grade)) return $this->failure("操作失败,该收益规则不能存在"); if (empty($grade))
return $this->failure("操作失败,该收益规则不能存在");
$result = $grade->delete(); $result = $grade->delete();
return $this->success('ok', $result); return $this->success('ok', $result);
} catch (Exception $e) { } catch (Exception $e) {
@ -714,7 +723,8 @@ class EarningController extends Controller
$MEarningTransfers->bank_code = $request->bank_code; $MEarningTransfers->bank_code = $request->bank_code;
if ($request->bank_name || $request->bank_code) { if ($request->bank_name || $request->bank_code) {
$bank = DB::table('banks')->where('name', $request->bank_name)->where('code', $request->bank_code)->first(); $bank = DB::table('banks')->where('name', $request->bank_name)->where('code', $request->bank_code)->first();
if (!$bank) return $this->failure('暂不支持该银行'); if (!$bank)
return $this->failure('暂不支持该银行');
} }
$MEarningTransfers->in_use = $status ? 0 : 1; $MEarningTransfers->in_use = $status ? 0 : 1;
$MEarningTransfers->save(); $MEarningTransfers->save();
@ -748,7 +758,8 @@ class EarningController extends Controller
} }
if ($request->bank_name || $request->bank_code) { if ($request->bank_name || $request->bank_code) {
$bank = DB::table('banks')->where('name', $request->bank_name)->where('code', $request->bank_code)->first(); $bank = DB::table('banks')->where('name', $request->bank_name)->where('code', $request->bank_code)->first();
if (!$bank) return $this->failure('暂不支持该银行'); if (!$bank)
return $this->failure('暂不支持该银行');
} }
$MEarningTransfers->way = $request->way ?? $MEarningTransfers->way; $MEarningTransfers->way = $request->way ?? $MEarningTransfers->way;
$MEarningTransfers->m_id = $merchant_id ?? $MEarningTransfers->merchant_id; $MEarningTransfers->m_id = $merchant_id ?? $MEarningTransfers->merchant_id;
@ -1092,7 +1103,8 @@ class EarningController extends Controller
* @param Request $request * @param Request $request
* @return JsonResponse|BinaryFileResponse * @return JsonResponse|BinaryFileResponse
*/ */
public function OrderEarningExport(Request $request){ public function OrderEarningExport(Request $request)
{
try { try {
$start_time = $request->start_time; $start_time = $request->start_time;
$end_time = $request->end_time; $end_time = $request->end_time;
@ -1163,7 +1175,8 @@ class EarningController extends Controller
} }
// 过滤掉emoji表情 // 过滤掉emoji表情
function filterEmoji($str){ function filterEmoji($str)
{
$str = preg_replace_callback('/./u', function (array $match) { $str = preg_replace_callback('/./u', function (array $match) {
return strlen($match[0]) >= 4 ? '' : $match[0]; return strlen($match[0]) >= 4 ? '' : $match[0];
}, $str); }, $str);
@ -1218,7 +1231,8 @@ class EarningController extends Controller
$trade_no = \CommonUtilsService::getTradeNO(); $trade_no = \CommonUtilsService::getTradeNO();
if ($cash_out_type == 'wechat') { //微信提现 if ($cash_out_type == 'wechat') { //微信提现
//判断是否绑定微信 //判断是否绑定微信
if (empty($openid)) return $this->failure('绑定微信账号失败'); if (empty($openid))
return $this->failure('绑定微信账号失败');
//绑定完成 提现 //绑定完成 提现
$desc = "<$anchor_name>提现-微信"; $desc = "<$anchor_name>提现-微信";
// $wechat = new WechatService($this->sms); // $wechat = new WechatService($this->sms);
@ -1395,6 +1409,10 @@ class EarningController extends Controller
} else { } else {
$value->bankName = null; $value->bankName = null;
} }
$appId = config("wechat.service_payment.app_id");
$mchId = config("wechat.payment.mch_id");
$value->appId = $appId;
$value->mchId = $mchId;
} }
return $this->success('ok', $result); return $this->success('ok', $result);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -1423,9 +1441,15 @@ class EarningController extends Controller
->join('tourist_orders', 'm_earnings.m_order_id', '=', 'tourist_orders.id') ->join('tourist_orders', 'm_earnings.m_order_id', '=', 'tourist_orders.id')
// ->select('tourist_orders.*') // ->select('tourist_orders.*')
->select([ ->select([
'tourist_orders.id', 'tourist_orders.name', 'tourist_orders.mobile', 'tourist_orders.price', 'tourist_orders.id',
'tourist_orders.type', 'tourist_orders.type_id', 'tourist_orders.account_id', 'tourist_orders.name',
'tourist_orders.merchant_id', 'tourist_orders.created_at' 'tourist_orders.mobile',
'tourist_orders.price',
'tourist_orders.type',
'tourist_orders.type_id',
'tourist_orders.account_id',
'tourist_orders.merchant_id',
'tourist_orders.created_at'
]) ])
->where('m_earnings.m_user_id', 0) ->where('m_earnings.m_user_id', 0)
->where('m_earnings.m_id', $merchant_id) ->where('m_earnings.m_id', $merchant_id)
@ -1624,20 +1648,28 @@ class EarningController extends Controller
$merchant_id = $request->account_id; $merchant_id = $request->account_id;
$merchant = MerchantAccount::find($merchant_id); $merchant = MerchantAccount::find($merchant_id);
$anchor = Anchor::where('m_id', $merchant_id)->first(); $anchor = Anchor::where('m_id', $merchant_id)->first();
if (!$merchant) return $this->failure('账户信息有误,请重新登录'); if (!$merchant)
if(empty($merchant->poundage)) throw new \Exception('商家提现手续费异常.商家id='.$merchant_id); return $this->failure('账户信息有误,请重新登录');
if (empty($merchant->poundage))
throw new \Exception('商家提现手续费异常.商家id=' . $merchant_id);
//用户当前提现账号 //用户当前提现账号
$transfer = MEarningTransfers::where('id', $request->transfer_id)->first(); $transfer = MEarningTransfers::where('id', $request->transfer_id)->first();
if (!$transfer) return $this->failure('提现账户数据有误'); if (!$transfer)
if($transfer->m_id != $merchant_id || $transfer->m_user_id != 0) throw new \Exception('商家提现数据有误.商家id='.$merchant_id.' transfer_id='.$transfer->id); return $this->failure('提现账户数据有误');
if ($transfer->m_id != $merchant_id || $transfer->m_user_id != 0)
throw new \Exception('商家提现数据有误.商家id=' . $merchant_id . ' transfer_id=' . $transfer->id);
//提现多少钱 //提现多少钱
$cashout_num = $request->cashout_num; $cashout_num = $request->cashout_num;
if (!is_numeric($cashout_num) || $cashout_num <= 0) return $this->failure('请输入正确的提现金额'); if (!is_numeric($cashout_num) || $cashout_num <= 0)
if ($cashout_num < 1) return $this->failure('单笔提现最低金额为1元'); return $this->failure('请输入正确的提现金额');
if ($cashout_num < 1)
return $this->failure('单笔提现最低金额为1元');
$account = MEarningAccount::where('m_id', $merchant_id)->where('m_user_id', 0)->first(); $account = MEarningAccount::where('m_id', $merchant_id)->where('m_user_id', 0)->first();
if(!$account) return $this->failure('你暂无提现额度'); if (!$account)
return $this->failure('你暂无提现额度');
//查询余额足够? //查询余额足够?
if ($account->balance < $cashout_num) return $this->failure('提现金额不能大于可以提现的总金额!'); if ($account->balance < $cashout_num)
return $this->failure('提现金额不能大于可以提现的总金额!');
$trade_no = \CommonUtilsService::getTradeNO(); $trade_no = \CommonUtilsService::getTradeNO();
// $poundage = Redis::get('withdrawal_poundage') ?? 2; //提现手续费百分比 // $poundage = Redis::get('withdrawal_poundage') ?? 2; //提现手续费百分比
$poundage = $merchant->poundage; $poundage = $merchant->poundage;
@ -1684,7 +1716,8 @@ class EarningController extends Controller
]; ];
SendTemplateMsg::dispatch($data)->onQueue('template_message'); SendTemplateMsg::dispatch($data)->onQueue('template_message');
$openid = $merchant->openid; $openid = $merchant->openid;
if (empty($openid)) $openid = $anchor->openid; if (empty($openid))
$openid = $anchor->openid;
$data['touser'] = $openid; $data['touser'] = $openid;
$data['template_id'] = 'OwXPF2dKEjPQUoGyzH944ATsJ6SgxpZ8kzB-KVVxanY'; $data['template_id'] = 'OwXPF2dKEjPQUoGyzH944ATsJ6SgxpZ8kzB-KVVxanY';
$data['url'] = ''; $data['url'] = '';
@ -1714,7 +1747,8 @@ class EarningController extends Controller
{ {
$m_id = $request->account_id; $m_id = $request->account_id;
$admin_id = $request->merchant_admin_id; $admin_id = $request->merchant_admin_id;
if ($admin_id) return $this->failure('管理员没有权限'); if ($admin_id)
return $this->failure('管理员没有权限');
$jump_url = urlencode(env('APP_URL') . '/h5/#/bindWeChatPage'); $jump_url = urlencode(env('APP_URL') . '/h5/#/bindWeChatPage');
$share_url = env('APP_URL') . '/api/official/live/wechat/oauth?merchant_id=' . $m_id . '&url=' . $jump_url . '&auth_state=0'; $share_url = env('APP_URL') . '/api/official/live/wechat/oauth?merchant_id=' . $m_id . '&url=' . $jump_url . '&auth_state=0';
$share_qrcode = $this->getPreviewQrcode($share_url); $share_qrcode = $this->getPreviewQrcode($share_url);
@ -1792,30 +1826,40 @@ class EarningController extends Controller
} }
//商户转账给商户或用户 //商户转账给商户或用户
public function transferAccounts(Request $request){ public function transferAccounts(Request $request)
{
try { try {
if($request->merchant_admin_id) return $this->failure('暂不支持管理员发起转账'); if ($request->merchant_admin_id)
return $this->failure('暂不支持管理员发起转账');
$mobile = trim($request->mobile); $mobile = trim($request->mobile);
$name = trim($request->name); $name = trim($request->name);
$amount = $request->amount; $amount = $request->amount;
$remark = trim($request->remark) ?? null; $remark = trim($request->remark) ?? null;
if(!$mobile || !$name) return $this->failure('请完善手机号码或名字'); if (!$mobile || !$name)
if(!is_numeric($amount) || $amount <= 0) return $this->failure('请输入正确的转账金额'); return $this->failure('请完善手机号码或名字');
if(empty($remark)) return $this->failure('请填写转账原因'); if (!is_numeric($amount) || $amount <= 0)
return $this->failure('请输入正确的转账金额');
if (empty($remark))
return $this->failure('请填写转账原因');
//输入手机号和姓名,根据手机号优先转给商家,未找到对应用户/商家,转账失败 //输入手机号和姓名,根据手机号优先转给商家,未找到对应用户/商家,转账失败
$transfer_object = MerchantAccount::with('anchorV2')->whereHas('anchorV2')->where('mobile', $mobile)->first(); $transfer_object = MerchantAccount::with('anchorV2')->whereHas('anchorV2')->where('mobile', $mobile)->first();
if (!$transfer_object) { if (!$transfer_object) {
$transfer_object = MerchantUser::where('mobile', $mobile)->first(); $transfer_object = MerchantUser::where('mobile', $mobile)->first();
} else { } else {
if($transfer_object->id == $request->account_id) return $this->failure('无法转账给自己'); if ($transfer_object->id == $request->account_id)
if($transfer_object->anchorV2->mobile != $transfer_object->mobile) throw new \Exception('接收转账商家账号异常,号码:'.$request->mobile); return $this->failure('无法转账给自己');
if ($transfer_object->anchorV2->mobile != $transfer_object->mobile)
throw new \Exception('接收转账商家账号异常,号码:' . $request->mobile);
} }
if(!$transfer_object) return $this->failure('未查询到需要转账的用户,请确认后重新发起转账'); if (!$transfer_object)
return $this->failure('未查询到需要转账的用户,请确认后重新发起转账');
//当前商家收益账号 //当前商家收益账号
$account = MerchantAccount::find($request->account_id); $account = MerchantAccount::find($request->account_id);
$m_earning_account = $account->getMEarningAccount(); $m_earning_account = $account->getMEarningAccount();
if($m_earning_account->balance <= 0) return $this->failure('余额不足'); if ($m_earning_account->balance <= 0)
if($amount > $m_earning_account->balance) return $this->failure('余额不足,最多转'.$m_earning_account->balance.'元'); return $this->failure('余额不足');
if ($amount > $m_earning_account->balance)
return $this->failure('余额不足,最多转' . $m_earning_account->balance . '元');
DB::beginTransaction(); DB::beginTransaction();
$m_earning_account->decrement('balance', $amount); $m_earning_account->decrement('balance', $amount);
$m_earning_account->decrement('total_value', $amount); $m_earning_account->decrement('total_value', $amount);
@ -1848,7 +1892,8 @@ class EarningController extends Controller
$order->merchant_id = null; $order->merchant_id = null;
$order->account_id = $transfer_object->id; $order->account_id = $transfer_object->id;
} }
if($result === false) throw new \Exception('增加收益记录异常,号码:'.$request->mobile); if ($result === false)
throw new \Exception('增加收益记录异常,号码:' . $request->mobile);
$order->save(); $order->save();
//增加转账记录 //增加转账记录
$insert2 = ['m_id' => $request->account_id, 'amount' => $amount, 'mobile' => $mobile, 'm_earning_id' => $result->id, 'name' => $name, 'remark' => $remark, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')]; $insert2 = ['m_id' => $request->account_id, 'amount' => $amount, 'mobile' => $mobile, 'm_earning_id' => $result->id, 'name' => $name, 'remark' => $remark, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')];
@ -1864,7 +1909,8 @@ class EarningController extends Controller
} }
//转账记录 //转账记录
public function merchantTransferLog(Request $request){ public function merchantTransferLog(Request $request)
{
try { try {
$keyword = trim($request->keyword); $keyword = trim($request->keyword);
$logs = MerchantTransferLog::where('m_id', $request->account_id); $logs = MerchantTransferLog::where('m_id', $request->account_id);
@ -1883,7 +1929,8 @@ class EarningController extends Controller
} }
} }
//下载转账 //下载转账
public function merchantTransferExport(Request $request){ public function merchantTransferExport(Request $request)
{
try { try {
$start_time = $request->start_time; $start_time = $request->start_time;
$end_time = $request->end_time; $end_time = $request->end_time;