createOutTradeNo($site_id); $pay_detail = $default_site_id . '_' . $site_id; $pay->addPay($default_site_id, $out_trade_no, $pay_type, $order_name, $pay_detail, $pay_money, '', 'DividemoneyOrderPayNotify', '', ''); $notify_url = addon_url("pay/pay/notify/paytype/" . $pay_type . '/app_type/' . $app_type . '/site_id/' . $default_site_id); $return_url = addon_url("pay/pay/payreturn", ['out_trade_no' => $out_trade_no, 'app_type' => $app_type]); $data['site_id'] = $default_site_id; $data['out_trade_no'] = $out_trade_no; $data['pay_money'] = $pay_money; $data['app_type'] = $app_type; $data['pay_body'] = $order_name; $data['notify_url'] = $notify_url; $data['return_url'] = $return_url; $data['pay_type'] = $pay_type; $data["member_id"] = $site_id; $data["is_matched"] = 0; $data["hb_fq_num"] = 0; $res = event('Pay', $data, true); $res['data']['out_trade_no'] = $out_trade_no; return $res; } /*** * 商家主动支付佣金回调 * @param $data * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function OrderPay($data) { if (isset($data['payInfo'])) { $payInfo = $data['payInfo']; list($p_site_id, $site_id) = explode('_', $payInfo['pay_detail']); $startTime = mktime(0, 0, 0, date('m'), date('d') - 15, date('Y')); $failWhere = [ ['site_id', '=', $site_id], ['is_order_account_locking', '=', 0], ['states', 'in', [0, 2, 3]], ['create_time', '<', $startTime] ]; $res = Db::name('dividemoney_bill')->where($failWhere) ->group('account') ->field('sum(amount) as amount,ag_site_id,channel_type,account') ->select(); if ($res->toArray()) { $log = []; foreach ($res as $item) { $log[] = [ 'site_id' => $site_id, 'agent_site_id' => $item['ag_site_id'], 'commission_money' => $item['amount'], 'channel_type' => $item['channel_type'], 'account' => $item['account'], 'create_time' => time(), 'update_time' => time(), 'remarks' => '商家主动结算佣金', ]; } $user_model = new User(); $update = [ 'states' => 1, 'refuse' => '商户主动结算', 'is_order_account_locking' => 1, 'sub_code' => '', ]; model('website_commission')->addList($log); model('dividemoney_bill')->update($update, $failWhere); $cron = new Cron(); $cron->addCron(1, 1, '解除货款结算限制', 'SecureCronOrderDividemoney', time(), $site_id); cache('alipayTradeBatchquery' . $site_id, null); cache('is_pay_error' . $site_id, null); $user_info = $user_model->userInfo('shop'); if (empty($user_info)) { $user_info = model('site')->getInfo(['site_id' => $site_id], 'site_id as uid,username'); } $user_model->addUserLog($user_info['uid'] ?: $site_id, $user_info['username'] ?: $site_id, $site_id, "商户主动支付服务佣金{$payInfo['pay_money']}元", []); //添加日志 return $this->success('结算成功'); } else { return $this->success('结算成功'); } } return $this->error('无效订单'); } /*** * 充值 * @param $pay_money * @param $member_id * @param $site_id * @return void */ public function rechargeOrderCreate($pay_money, $member_id, $site_id = 1) { return $this->success('未使用'); } /** * 生成订单编号 * @param array $site_id */ public function createOrderNo($site_id, $member_id = 0) { $time_str = date('YmdHi'); $max_no = Cache::get($site_id . "_" . $member_id . "_" . $time_str); if (!isset($max_no) || empty($max_no)) { $max_no = 1; } else { $max_no = $max_no + 1; } $order_no = $time_str . $member_id . sprintf("%03d", $max_no); Cache::set($site_id . "_" . $member_id . "_" . $time_str, $max_no); return $order_no; } }