/**
  * 算快递费
  *
  * @param 	$user_id 	string
  * @return 	float
  */
 public static function getExpressFee($user_id = null)
 {
     if ($user_id) {
         $user = User::find($user_id);
     } else {
         $user = Sentry::getUser();
     }
     $fee_type = FeeType::where('user_type', $user->user_type)->where('category', FeeType::get_express_code())->where('item', FeeType::get_express_subitem($user->user_type))->first();
     $user_fee = UserFee::where('fee_type_id', $fee_type->id)->first();
     // 有特殊费用情况
     if (isset($user_fee) && $user_fee->fee_no != null) {
         return $user_fee->fee_no;
     }
     // 否则返回默认值
     return $fee_type->number;
 }
 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';
     }
 }
Exemple #3
0
 /**
  * 插入随机数据
  */
 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;
 }