12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace App\Models;
- use Carbon\Carbon;
- class Order extends BaseModel
- {
- public static function createOrderNumber()
- {
- $times = 10;
- $str = substr(Carbon::now()->format('Ymdhis'), 2);
- do {
- $str = $str . mt_rand(10000, 99999);
- $res = self::where('order_number', $str)->first();
- if(!$res) break;
- $times = $times - 1;
- } while($times);
- return $str;
- }
- public function user()
- {
- return $this->belongsTo('App\Models\User', 'user_id');
- }
- public function workPoint()
- {
- return $this->belongsTo('App\Models\WorkPoint', 'work_point_id');
- }
- public function getOrderStatus(Project $project, $user, $is_draft)
- {
- if($is_draft) {
- return Option::get('orders', 'status', 'checking');
- }
- if($project->isTopLevel($user)) {
- return Option::get('orders', 'status', 'pass');
- }
- return Option::get('orders', 'status', 'checking');
- }
- }
|