SalesOrder.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\DepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class SalesOrder extends Model
  6. {
  7. protected $fillable = ['userData'];
  8. protected $table = "sales_order"; //指定表
  9. const CREATED_AT = 'crt_time';
  10. const UPDATED_AT = 'upd_time';
  11. protected $dateFormat = 'U';
  12. const Model_type_one = 1; // 线下订单合同
  13. const Model_type_two = 2; // 分社订货合同
  14. const Model_type_three = 3; // 二手车精品加装合同
  15. public static $model_type = [
  16. self::Model_type_one,
  17. self::Model_type_two,
  18. self::Model_type_three
  19. ];
  20. const State_zero = 0;//未锁定
  21. const State_one = 1;//锁定
  22. public static $state = [
  23. self::State_zero => '未锁定',
  24. self::State_one => '锁定',
  25. ];
  26. public static $prefix = [
  27. self::Model_type_one => 'T9XS.',
  28. self::Model_type_two => 'T9SO.',
  29. self::Model_type_three => 'T9XS.'
  30. ];
  31. public static $user = [];
  32. public static $is_search = false;
  33. public function __construct(array $attributes = [])
  34. {
  35. if(! empty($attributes['userData'])) {
  36. self::$user = $attributes['userData'];
  37. self::$is_search = true;
  38. }
  39. parent::__construct($attributes);
  40. }
  41. protected static function boot(){
  42. parent::boot();
  43. if(self::$is_search){
  44. static::addGlobalScope(new DepartmentScope(self::$user));
  45. }
  46. }
  47. }