|
@@ -21,10 +21,13 @@ use App\Http\Utils\Meituan\MeituanLianmengUtil;
|
|
|
use App\Http\Utils\Pdd\DuoDuoKeUtil;
|
|
|
use App\Http\Utils\WechatAccountUtil;
|
|
|
use App\Models\CategoryModel;
|
|
|
+use App\Models\UserCashModel;
|
|
|
use App\Models\UserFinanceModel;
|
|
|
use App\Models\UserModel;
|
|
|
use App\Models\UserOrderCommissionModel;
|
|
|
use App\Models\UserOrderModel;
|
|
|
+use App\Models\WechatAccountModel;
|
|
|
+use EasyWeChat\Factory;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class CronLogic extends BaseLogic
|
|
@@ -456,6 +459,7 @@ class CronLogic extends BaseLogic
|
|
|
->where("order_commission",">",0)
|
|
|
->where("user_id","<>",0)
|
|
|
->where("order_complete_notify_status",0)
|
|
|
+ ->where("created_at","<",$endTime)
|
|
|
->chunk(100,function ($orderCommissions){
|
|
|
foreach ($orderCommissions as $orderCommission){
|
|
|
try{
|
|
@@ -511,4 +515,146 @@ class CronLogic extends BaseLogic
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理提现打款逻辑
|
|
|
+ */
|
|
|
+ public static function transferFinanceLogic()
|
|
|
+ {
|
|
|
+ $account = WechatAccountModel::query()
|
|
|
+ ->where("wechat_app_code","fanbuting")
|
|
|
+ ->first();
|
|
|
+ $config = [
|
|
|
+ "app_id"=>$account["wechat_app_id"],
|
|
|
+ "mch_id"=>$account["account_mch_id"],
|
|
|
+ "key"=>$account["account_key"],
|
|
|
+ "cert_path"=>$account["account_cert_path"],
|
|
|
+ "key_path"=>$account["account_key_path"]
|
|
|
+ ];
|
|
|
+ $app = Factory::payment($config);
|
|
|
+ //获取已审核且未打款的提现记录
|
|
|
+ $cashLogs = UserCashModel::query()
|
|
|
+ ->where("check_status",2)
|
|
|
+ ->where("cash_status",0)
|
|
|
+ ->get();
|
|
|
+ if(!$cashLogs){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ //将打款记录修改为执行中
|
|
|
+ $logIds = [];
|
|
|
+ foreach ($cashLogs as $cashLog){
|
|
|
+ $logIds[] = $cashLog["id"];
|
|
|
+ }
|
|
|
+ WechatAccountModel::query()
|
|
|
+ ->whereIn("id",$logIds)
|
|
|
+ ->update(
|
|
|
+ [
|
|
|
+ "cash_status"=>1
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ foreach ($cashLogs as $cashLog){
|
|
|
+ //1.获取用户的openId
|
|
|
+ $user = UserModel::query()->find($cashLog["user_id"]);
|
|
|
+ if($user){
|
|
|
+ $res = $app->transfer->toBalance(
|
|
|
+ [
|
|
|
+ "partner_trade_no"=>$cashLog["cash_order_number"],
|
|
|
+ "openid"=>$user["user_open_id"],
|
|
|
+ "check_name"=>"NO_CHECK",//不校验姓名
|
|
|
+ "re_user_name"=>"",//真实姓名
|
|
|
+ "amount"=>$cashLog["cash_money"],
|
|
|
+ "desc"=>"用户提现"
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ //判断是否支付成功
|
|
|
+ if($res["return_code"]=="SUCCESS" && $res["result_code"]=="SUCCESS"){
|
|
|
+ UserCashModel::query()
|
|
|
+ ->where("id",$cashLog["id"])
|
|
|
+ ->update(
|
|
|
+ [
|
|
|
+ "cash_status"=>2,
|
|
|
+ "upstream_response"=>json_encode($res),
|
|
|
+ "cash_receive_at"=>date("Y-m-d H:i:s")
|
|
|
+ ]
|
|
|
+ );
|
|
|
+
|
|
|
+ }else{
|
|
|
+ //打款失败
|
|
|
+ UserCashModel::query()
|
|
|
+ ->where("id",$cashLog["id"])
|
|
|
+ ->update(
|
|
|
+ [
|
|
|
+ "cash_status"=>3,
|
|
|
+ "upstream_response"=>json_encode($res)
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 打款失败退款逻辑
|
|
|
+ */
|
|
|
+ public static function callbackCashLogic()
|
|
|
+ {
|
|
|
+ //获取已审核且未打款的提现记录
|
|
|
+ $cashLogs = UserCashModel::query()
|
|
|
+ ->where("callback_status",0)
|
|
|
+ ->where(function ($query){
|
|
|
+ $query->where("check_status",3)
|
|
|
+ ->orWhere("cash_status",3);
|
|
|
+ })
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ if(!$cashLogs){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($cashLogs as $cashLog){
|
|
|
+ DB::beginTransaction();
|
|
|
+ //获取用户
|
|
|
+ $user = UserModel::query()->lock(true)->find($cashLog["user_id"]);
|
|
|
+ //1.用户金额增加
|
|
|
+ $userRes = UserModel::query()
|
|
|
+ ->where("id",$user["user_id"])
|
|
|
+ ->increment("user_balance",$cashLog["cash_money"]);
|
|
|
+ if(!$userRes){
|
|
|
+ DB::rollBack();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //2.添加流水记录
|
|
|
+ $financeRes = UserFinanceModel::query()->insert(
|
|
|
+ [
|
|
|
+ "user_id"=>$cashLog["user_id"],
|
|
|
+ "user_before_balance"=>$user["user_balance"],
|
|
|
+ "user_after_balance"=>$user["user_balance"]+$cashLog["cash_money"],
|
|
|
+ "finance_balance"=>$cashLog["cash_money"],
|
|
|
+ "finance_remark"=>"提现失败退回,原提现记录ID为:".$cashLog["id"],
|
|
|
+ "finance_type"=>1,
|
|
|
+ "finance_number"=>BaseUtil::getOrderNumber(),
|
|
|
+ "created_at"=>date("Y-m-d H:i:s"),
|
|
|
+ "updated_at"=>date("Y-m-d H:i:s"),
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ if(!$financeRes){
|
|
|
+ DB::rollBack();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //3.修改提现记录为退款成功
|
|
|
+ $cashRes = UserCashModel::query()
|
|
|
+ ->where("id",$cashLog["id"])
|
|
|
+ ->update([
|
|
|
+ "callback_status"=>1
|
|
|
+ ]);
|
|
|
+ if(!$cashRes){
|
|
|
+ DB::rollBack();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|