Example #1
0
  public function getDeliverinfo (Request $request)
  {
    $order_code = $request->input('order_code');

    if (empty($order_code)) {

      return $this->failResponse('empty');

    }

    $info = DeliverInfo::where('order_code', '=', $order_code)->first();

    if (empty($info->id)) {

      return $this->failResponse('not_found');

    }

    $order = Order::where('code', '=', $order_code)->first();

    $result = [
    
      'deliver_code' => $info->code,

      'company' => $info->company,

      'plate_number' => $order->plate_number
    
    ];

    return $this->successResponse('result', $result);

  }
 public function postDeliver(Request $request)
 {
     $validator = Validator::make($request->input(), ['plate_number' => 'required', 'company' => 'required', 'deliver_code' => 'required']);
     if ($validator->fails()) {
         $failed = $validator->failed();
         return $this->failResponse($failed);
     }
     $plate_number = $request->input('plate_number');
     $company = $request->input('company');
     $deliver_code = $request->input('deliver_code');
     $order_code = $request->input('order_code');
     $operator_id = Session::get('admin')->id;
     $deliver = DeliverInfo::where('order_code', '=', $order_code)->first();
     $order = Order::where('code', '=', $order_code)->first();
     /*
      * 如果未创建
      */
     if (empty($deliver->id)) {
         $result = DeliverInfo::create(['company' => $company, 'code' => $deliver_code, 'order_code' => $order_code, 'operator_id' => $operator_id, 'active' => 1]);
         if (!empty($result->id)) {
             if (!empty($order->id)) {
                 $order->status = 2;
                 $order->plate_number = $plate_number;
                 $order->save();
                 $user = User::find($order->uid);
                 $boun = Boun::where('uid', '=', $user->id)->where('type', '=', 0)->where('active', '=', 1)->first();
                 $post_data = ['order_code' => $order->code, 'deliver_code' => $result->code, 'company' => $result->company, 'recommend' => !empty($boun->code) ? $boun->code : '您还没有优惠码', 'user' => $user->name, 'url' => "www.sf-express.com"];
                 $smsRes = event(new TriggerSms($user->mobile, 'deliver', $post_data));
                 $mailRes = event(new TriggerEmail($user->email, 'deliver', $post_data));
                 return $this->successResponse('res', ['deliver' => $result, 'order' => $order, 'sms' => $smsRes, 'mailRes' => $mailRes]);
             } else {
                 return $this->failResponse('order_not_found');
             }
         } else {
             return $this->failResponse('failed');
         }
     } else {
         $deliver->code = $deliver_code;
         $deliver->company = $company;
         $deliver->save();
         $order->plate_number = $plate_number;
         $order->save();
         return $this->successResponse('res', ['deliver' => $deliver, 'order' => $order]);
     }
 }