public function authBeeCloud() { // return 'success'; $appId = Config::get('beeCloud.app_id'); $appSecret = Config::get('beeCloud.app_secret'); $jsonStr = file_get_contents("php://input"); $msg = json_decode($jsonStr, true); Log::info($msg); Log::info($msg['transactionId']); $info = OrderAuthInfo::where('transactionId', $msg['transactionId'])->first(); if (!isset($info)) { Log::info('无此数据'); return 'false'; } Log::info($info); //验证签名 $sign = md5($appId . $appSecret . $msg['timestamp']); if ($sign != $msg['sign']) { Log::info('签名有错'); return Response::json(array('errCode' => 21, 'message' => '验证码不正确')); } //订单号 if ($info->transactionId != $msg['transactionId']) { Log::info('订单号有错'); return Response::json(array('errCode' => 22, 'message' => '订单号')); } if ($msg['transactionType'] == "PAY") { $message_detail = $msg['messageDetail']; //订单金额 if ($info->transactionFee != $msg['transactionFee']) { Log::info('金额有错有错'); return Response::json(array('errCode' => 23, 'message' => '金额不不正确')); } if ($message_detail['total_fee'] != $info->transactionFee) { Log::info('messageDetail中金额有错'); return Response::json(array('errCode' => 24, 'message' => '金额不不正确')); } //判断是代办还是充值,有user_id为充值 if (isset($msg['optional']['user_id'])) { try { DB::transaction(function () use($info, $msg) { $cost_detail = new CostDetail(); $cost_detail->user_id = $msg['optional']['user_id']; $cost_detail->cost_id = $info->transactionId; $cost_detail->fee_type_id = FeeType::where('category', FeeType::get_recharge_code())->where('item', FeeType::get_recharge_subitem())->first()->id; $cost_detail->number = $info->transactionFee / 100; $cost_detail->save(); Log::info($info->transactionFee); Log::info($msg['optional']['user_id']); $result = BusinessController::recharge($info->transactionFee / 100, $msg['optional']['user_id']); if (!$result) { throw new Exception(); } }); } catch (\Exception $e) { Log::info($e->getMessage()); return 'false'; } $info->delete(); return 'success'; } else { $order = AgencyOrder::find($info->transactionId); if ($msg['channelType'] == 'WX') { $order->pay_trade_no = $message_detail['transaction_id']; //交易流水号 $order->pay_platform = 0; //支付平台 } else { $order->pay_trade_no = $message_detail['trade_no']; $order->pay_platform = 1; } $order->trade_status = 1; //已付款 $order->process_status = 1; //已受理 if (!$order->save()) { return 'false'; } $info->delete(); return 'success'; } } //退款逻辑 if ($msg['transactionType'] == "REFUND") { //退款 if ($info->transactionFee != $msg['transactionFee']) { Log::info('退款金额有错'); return Response::json(array('errCode' => 25, 'message' => '退款金额有错')); } //更改状态 $refund_id = $msg['optional']['refund_id']; $refund = RefundRecord::find($refund); $order = AgencyOrder::find($info->transactionId); try { DB::transaction(function () use($refund, $order) { $refund->status = 2; $refund->save(); $order->trade_status = 3; $order->process_status = 3; $order->save(); }); } catch (Exception $e) { Log::info($e->getMessage()); return 'false'; } $info->delete(); return 'success'; } }
/** * 插入随机数据 */ protected function create_cost_details($total = 300) { echo 'Creating cost_details...'; $fee_type = FeeType::where('category', '10')->first(); $users = User::all(); foreach ($users as $user) { for ($i = 0; $i < $total; ++$i) { $cost_detail = new CostDetail(); $cost_detail->user_id = $user->user_id; $cost_detail->fee_type_id = $fee_type->id; $cost_detail->number = rand(50, 100); $cost_detail->created_at = $this->get_random_datetime(); $cost_detail->save(); } } echo 'Done' . PHP_EOL; }