示例#1
0
 public function submit_order()
 {
     if (!Session::has('violations')) {
         return Response::json(['errCode' => 2, 'message' => '请先查询并确认代办']);
     }
     $violations = Session::get('violations');
     $sign = Input::get('sign');
     if (!array_key_exists($sign, $violations)) {
         return Response::json(['errCode' => 3, 'message' => '参数错误']);
     }
     if ($violations[$sign]['info']['status'] != static::$AGENCY_STATUS_CONFIRMED) {
         return Response::json(['errCode' => 2, 'message' => '请先确认']);
     }
     $is_delivered = (int) Input::get('is_delivered');
     if ($is_delivered == 1) {
         $params = Input::all();
         $rules = ['recipient_name' => 'required', 'recipient_addr' => 'required', 'recipient_phone' => 'required|telephone'];
         $message = ['required' => '请输入:attribute', 'telephone' => ':attribute格式不正确'];
         $attributes = ['recipient_name' => '收件人姓名', 'recipient_addr' => '收件人地址', 'recipient_phone' => '收件人手机'];
         $validator = Validator::make($params, $rules, $message, $attributes);
         if ($validator->fails()) {
             return Response::json(['errCode' => 4, 'message' => $validator->messages()->first()]);
         }
     }
     $violation = $violations[$sign];
     try {
         DB::beginTransaction();
         $order_id = AgencyOrder::get_unique_id();
         $agency_order = new AgencyOrder();
         $agency_order->order_id = $order_id;
         $agency_order->user_id = Sentry::getUser()->user_id;
         $agency_order->agency_no = $violation['info']['count'];
         $agency_order->capital_sum = $violation['info']['total_fee'];
         $agency_order->car_type_no = $violation['info']['car_type_no'];
         $agency_order->car_plate_no = $violation['info']['car_plate_no'];
         $agency_order->car_engine_no = $violation['info']['car_engine_no'];
         $agency_order->car_frame_no = $violation['info']['car_frame_no'];
         $agency_order->service_charge_sum = $violation['info']['service_fee'] * $violation['info']['count'];
         $agency_order->late_fee_sum = 0.0;
         $agency_order->trade_status = 0;
         $agency_order->process_status = 0;
         if ($is_delivered == 1) {
             $agency_order->is_delivered = true;
             $agency_order->express_fee = $violation['info']['express_fee'];
             $agency_order->recipient_name = $params['recipient_name'];
             $agency_order->recipient_addr = $params['recipient_addr'];
             $agency_order->recipient_phone = $params['recipient_phone'];
         }
         $agency_order->save();
         foreach ($violation['results'] as $violation_result) {
             $violation_info = new TrafficViolationInfo();
             $violation_info->order_id = $order_id;
             $violation_info->req_car_frame_no = '';
             $violation_info->req_car_plate_no = $violation_result['hphm'];
             //车牌号码
             $violation_info->req_car_engine_no = $violation_result['fdjh'];
             //发动机号后六位
             $violation_info->car_type_no = $violation_result['hpzl'];
             //号牌种类
             $violation_info->rep_sequence_num = $violation_result['xh'];
             $violation_info->rep_event_time = $violation_result['wfsj'];
             //违法时间
             $violation_info->rep_event_city = $violation_result['wfcs'];
             //违法城市
             $violation_info->rep_event_addr = $violation_result['wfdz'];
             //违法地址
             $violation_info->rep_violation_behavior = $violation_result['wfxwzt'] . '[' . $violation_result['wfxw'] . ']';
             //违法行为
             $violation_info->rep_point_no = $violation_result['wfjfs'];
             //违法记分数
             $violation_info->rep_priciple_balance = $violation_result['fkje'];
             //罚款金额
             $violation_info->rep_service_charge = $violation['info']['service_fee'];
             $violation_info->save();
         }
         DB::commit();
     } catch (Exception $e) {
         DB::rollback();
         throw $e;
         return Response::json(['errCode' => 1, 'message' => '订单处理失败']);
     }
     unset($violations[$sign]);
     Session::put('violations', $violations);
     return Response::json(['errCode' => 0, 'message' => 'ok', 'order_id' => $order_id]);
 }
示例#2
0
 /**
  * 插入随机数据
  */
 protected function create_agency_orders($total = 200)
 {
     echo 'Creating agency_orders...';
     $users = User::all();
     for ($i = 0; $i < $total; ++$i) {
         $user = $users[rand(0, $users->count() - 1)];
         //DB::transaction(function() use ( $user ){
         $order_id = AgencyOrder::get_unique_id();
         $agency_order = new AgencyOrder();
         $agency_order->order_id = $order_id;
         $agency_order->user_id = $user->user_id;
         $agency_order->recipient_name = "cyrilzhao";
         $agency_order->recipient_phone = "13911111111";
         $agency_order->recipient_addr = "国王十字车站九又四分之三站台";
         $agency_order->pay_platform = rand(0, 1) ? '0' : '1';
         $agency_order->pay_time = $this->get_random_datetime();
         $agency_order->pay_trade_no = uniqid('ptn', true);
         $agency_order->car_plate_no = '粤A12N12';
         $agency_order->capital_sum = (double) (rand(500, 1000) / 10);
         $agency_order->late_fee_sum = (double) (rand(500, 1000) / 20);
         $agency_order->service_charge_sum = (double) (rand(500, 1000) / 10);
         if ($i % 5 == 0) {
             $agency_order->process_status = '4';
             // 已关闭
             $agency_order->trade_status = '3';
             // 已退款
         } else {
             if ($i % 5 == 1) {
                 $agency_order->process_status = '3';
                 // 已完成
                 $agency_order->trade_status = '1';
                 // 已付款
             } else {
                 if ($i % 5 == 2) {
                     $agency_order->process_status = '2';
                     // 办理中
                     $agency_order->trade_status = '1';
                     // 已付款
                 } else {
                     if ($i % 5 == 3) {
                         $agency_order->process_status = '1';
                         // 已受理
                         if (rand(0, 1)) {
                             $agency_order->trade_status = '1';
                             // 已付款
                         } else {
                             $agency_order->trade_status = '2';
                             // 申请退款
                         }
                     } else {
                         $agency_order->process_status = '0';
                         // 未受理
                         $agency_order->trade_status = '0';
                         // 等待付款
                     }
                 }
             }
         }
         $agency_order->car_type_no = '02';
         $agency_order->agency_no = rand(1, 3);
         if ($agency_order->save()) {
             for ($j = 0; $j < $agency_order->agency_no; ++$j) {
                 $traffic_info = new TrafficViolationInfo();
                 $traffic_info->order_id = $order_id;
                 $traffic_info->req_car_plate_no = '粤A12N12';
                 $traffic_info->req_car_engine_no = '123123';
                 $traffic_info->car_type_no = 'AAA';
                 $traffic_info->req_car_frame_no = '123123';
                 $traffic_info->rep_event_time = $this->get_random_datetime();
                 $traffic_info->rep_event_addr = '番禺区大学城';
                 $traffic_info->rep_violation_behavior = 'F**k a dog';
                 $traffic_info->save();
             }
         }
         //});
     }
     echo 'Done' . PHP_EOL;
 }