SalesOrder.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 Order_type_one = 1;//安装件
  13. const Order_type_two = 2;//快递件
  14. public static $order_type = [
  15. self::Order_type_one => '安装件',
  16. self::Order_type_two => '快递件',
  17. ];
  18. const Model_type_one = 1; // 线下订单合同
  19. const Model_type_two = 2; // 分社订货合同
  20. const Model_type_three = 3; // 二手车精品加装合同
  21. public static $model_type = [
  22. self::Model_type_one,
  23. self::Model_type_two,
  24. self::Model_type_three
  25. ];
  26. const State_zero = 0;//未锁定
  27. const State_one = 1;//锁定
  28. public static $state = [
  29. self::State_zero => '未锁定',
  30. self::State_one => '锁定',
  31. ];
  32. public static $prefix = [
  33. self::Model_type_one => 'T9XS.',
  34. self::Model_type_two => 'T9SO.',
  35. self::Model_type_three => 'T9XS.'
  36. ];
  37. public static $user = [];
  38. public static $is_search = false;
  39. public function __construct(array $attributes = [])
  40. {
  41. if(! empty($attributes['userData'])) {
  42. self::$user = $attributes['userData'];
  43. self::$is_search = true;
  44. }
  45. parent::__construct($attributes);
  46. }
  47. protected static function boot(){
  48. parent::boot();
  49. if(self::$is_search){
  50. static::addGlobalScope(new DepartmentScope(self::$user));
  51. }
  52. }
  53. }