Inheritance: extends Illuminate\Database\Eloquent\Model
Beispiel #1
0
 public function update($id)
 {
     $order = Store\Order::findOrFail($id);
     if ($order->status !== 'paid') {
         return error_popup("order status {$order->status} is invalid.");
     }
     $order->unguard();
     $order->update(Request::input('order'));
     $order->save();
     return ['message' => "order {$id} updated"];
 }
Beispiel #2
0
 private function userCart()
 {
     if (Auth::check()) {
         return Store\Order::cart(Auth::user());
     } else {
         return new Store\Order();
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $orders = Store\Order::where("status", "=", "shipped")->where("tracking_code", "!=", "")->orderBy('updated_at')->get();
     $count = count($orders);
     if (!$count) {
         return;
     }
     $this->info("found {$count} orders.");
     Slack::send("Checking order tracking status ({$count} orders)...");
     $statuses = [];
     $i = 0;
     foreach ($orders as $o) {
         $i++;
         try {
             if (!strlen(trim($o->tracking_code)) || strpos($o->tracking_code, "EJ") !== 0) {
                 continue;
             }
             if (!$o->shipped_at) {
                 $o->shipped_at = time();
                 $o->save();
             }
             $response = file_get_contents("https://trackings.post.japanpost.jp/services/srv/search/direct?searchKind=S004&locale=en&reqCodeNo1={$o->tracking_code}");
             preg_match_all("/\\<td rowspan=\"2\" class=\"w_150\"\\>([^\\<]*)\\<\\/td\\>/", $response, $status);
             if (!count($status[1])) {
                 if (!$o->last_tracking_state) {
                     $days_until_warning = 4;
                     if (time() - $o->shipped_at->timestamp > 3600 * 24 * $days_until_warning) {
                         Slack::send("WARNING: <https://store.ppy.sh/store/admin/{$o->order_id}|Order #{$o->order_id}> has no tracking after {$days_until_warning} days!");
                     }
                 }
                 continue;
             }
             $lastStatus = end($status[1]);
             $statuses[$lastStatus][] = $o;
             $this->info("#{$i}: Order #{$o->order_id} (https://store.ppy.sh/store/invoice/{$o->order_id})\t{$o->address->country_code}\tshipped {$o->shipped_at}\t{$lastStatus}");
             if (!$o->last_tracking_state) {
                 mail($o->user->user_email, "Your osu!store order is on its way!", "Hi {$o->user->username},\n\n\tThanks again for your osu!store order!\n\n\tWe have just shipped your order out from Japan! You can follow the progress of it at https://store.ppy.sh/store/invoice/{$o->order_id}.\n\n\tIf you have any questions, don't hesitate to reply to this email.\n\n\tRegards,\n\tThe osu!store team", "From: \"osu!store team\" <*****@*****.**>");
             }
             if ($lastStatus != $o->last_tracking_state) {
                 switch ($lastStatus) {
                     case "Final delivery":
                     case "P.O.Box Delivery":
                         Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> has been delivered!");
                         $o->status = "delivered";
                         break;
                     case "Retention":
                     case "Absence. Attempted delivery.":
                         mail($o->user->user_email, "IMPORTANT: Your osu!store order is pending delivery", "Hi {$o->user->username},\n\n\tWe have been tracking your order and noticed that it is currently in the state of \"{$lastStatus}\".\n\n\tThis means it has likely reached your local post office, but you weren't around to collect the package. Please check your letterbox for any notices of missed packages, and if there is no sign of such a notice please contact or visit your local post office and enquire using your tracking number ({$o->tracking_code}) to ensure you receive your order successfully. If no action is taken in 7 days, they are likely to return the package to us, so it is very important that you follow up on this.\n\n\tYou can check the current tracking status here: https://store.ppy.sh/store/invoice/{$o->order_id}.\n\n\tIf you have any questions, don't hesitate to reply to this email.\n\n\tRegards,\n\tThe osu!store team", "From: \"osu!store team\" <*****@*****.**>");
                         Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> is being held at the destination post office. Contacting user ({$o->user->user_email}).");
                         break;
                     default:
                         if ($o->last_tracking_state) {
                             Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> has changed status from \"{$o->last_tracking_state}\" to \"{$lastStatus}\"");
                         } else {
                             Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> is now being tracked with an initial state of \"{$lastStatus}\"");
                         }
                 }
                 $o->last_tracking_state = $lastStatus;
                 $o->save();
             }
         } catch (\Exception $e) {
             //slack could throw errors here if their servers are dead.
         }
     }
     $fields = [];
     foreach ($statuses as $k => $v) {
         $orderstring = "";
         foreach ($v as $o) {
             $orderstring .= "<https://store.ppy.sh/store/invoice/{$o->order_id}|{$o->order_id}({$o->address->country_code})> ";
         }
         $fields[] = ['title' => $k, 'value' => $orderstring];
     }
     Slack::attach(['color' => 'good', 'fields' => $fields])->send('Tracking Results are in:');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $orders = Store\Order::where('status', '=', 'shipped')->where('tracking_code', '!=', '')->orderBy('updated_at')->get();
     $count = count($orders);
     if (!$count) {
         return;
     }
     $this->info("found {$count} orders.");
     Slack::send("Checking order tracking status ({$count} orders)...");
     $globalStatuses = [];
     $i = 0;
     foreach ($orders as $o) {
         ++$i;
         try {
             $trackingCodes = $o->trackingCodes();
             if (!count($trackingCodes)) {
                 continue;
             }
             if (!$o->shipped_at) {
                 $o->shipped_at = time();
                 $o->save();
             }
             $orderStatuses = [];
             $retainedCodes = [];
             $deliveredCodes = [];
             //a single order may have multiple tracking numbers
             foreach ($trackingCodes as $code) {
                 $code = trim($code);
                 $response = file_get_contents("https://trackings.post.japanpost.jp/services/srv/search/direct?searchKind=S004&locale=en&reqCodeNo1={$code}");
                 preg_match_all("/\\<td rowspan=\"2\" class=\"w_150\"\\>([^\\<]*)\\<\\/td\\>/", $response, $status);
                 if (!count($status[1])) {
                     if (!$o->last_tracking_state) {
                         $days_until_warning = 4;
                         if (time() - $o->shipped_at->timestamp > 3600 * 24 * $days_until_warning) {
                             Slack::send("WARNING: <https://store.ppy.sh/admin/store/orders/{$o->order_id}|Order #{$o->order_id}> has no tracking after {$days_until_warning} days!");
                         }
                     }
                     continue;
                 }
                 $thisStatus = end($status[1]);
                 switch ($thisStatus) {
                     case 'Final delivery':
                     case 'P.O.Box Delivery':
                         array_push($deliveredCodes, $code);
                         break;
                     case 'Retention':
                     case 'Absence. Attempted delivery.':
                         array_push($retainedCodes, $code);
                         break;
                 }
                 array_push($orderStatuses, $thisStatus);
             }
             $lastStatus = implode(' / ', $orderStatuses);
             $globalStatuses[$lastStatus][] = $o;
             if (strlen($lastStatus) === 0 || $lastStatus === $o->last_tracking_state) {
                 continue;
             }
             //no change in tracking state since our last check.
             $this->info("#{$i}: Order #{$o->order_id} (https://store.ppy.sh/store/invoice/{$o->order_id})\t{$o->address->country_code}\tshipped {$o->shipped_at}\t{$lastStatus}");
             foreach ($retainedCodes as $code) {
                 mail($o->user->user_email, 'IMPORTANT: Your osu!store order is pending delivery', "Hi {$o->user->username},\n\nWe have been tracking your order and noticed that it is currently in the state of \"{$thisStatus}\".\n\nThis means it has likely reached your local post office, but you weren't around to collect the package. Please check your letterbox for any notices of missed packages, and if there is no sign of such a notice please contact or visit your local post office and enquire using your tracking number ({$code}) to ensure you receive your order successfully. If no action is taken in 7 days, they are likely to return the package to us, so it is very important that you follow up on this.\n\nYou can check the current tracking status here: https://store.ppy.sh/store/invoice/{$o->order_id}.\n\nIf you have any questions, don't hesitate to reply to this email.\n\nRegards,\nThe osu!store team", 'From: "osu!store team" <*****@*****.**>');
                 Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> is being held at the destination post office. Contacting user ({$o->user->user_email}).");
             }
             if (count($deliveredCodes) === count($trackingCodes)) {
                 Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> has been delivered!");
                 $o->status = 'delivered';
             }
             if (!$o->last_tracking_state) {
                 //first status update should sent out an email to the user.
                 Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> is now being tracked with an initial state of \"{$lastStatus}\"");
                 mail($o->user->user_email, 'Your osu!store order is on its way!', "Hi {$o->user->username},\n\nThanks again for your osu!store order!\n\nWe have just shipped your order out from Japan! You can follow the progress of it at https://store.ppy.sh/store/invoice/{$o->order_id}.\n\nIf you have any questions, don't hesitate to reply to this email.\n\nRegards,\nThe osu!store team", 'From: "osu!store team" <*****@*****.**>');
             } else {
                 Slack::send("<https://store.ppy.sh/store/invoice/{$o->order_id}|Order #{$o->order_id}> has changed status from \"{$o->last_tracking_state}\" to \"{$lastStatus}\"");
             }
             $o->last_tracking_state = $lastStatus;
             $o->save();
         } catch (\Exception $e) {
             //slack could throw errors here if their servers are dead.
         }
     }
     $fields = [];
     foreach ($globalStatuses as $k => $v) {
         $orderstring = '';
         foreach ($v as $o) {
             $orderstring .= "<https://store.ppy.sh/store/invoice/{$o->order_id}|{$o->order_id}({$o->address->country_code})> ";
         }
         $fields[] = ['title' => $k, 'value' => $orderstring];
     }
     Slack::attach(['color' => 'good', 'fields' => $fields])->send('Tracking Results are in:');
 }