PurchaseOrder.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\DepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class PurchaseOrder extends Model
  6. {
  7. protected $fillable = ['userData'];
  8. protected $table = "purchase_order"; //指定表
  9. const CREATED_AT = 'crt_time';
  10. const UPDATED_AT = 'upd_time';
  11. protected $dateFormat = 'U';
  12. const STATE_ZERO = 0;//未确认
  13. const STATE_ONE = 1;//已确认
  14. const prefix = 'CG';
  15. public static $name = [
  16. self::STATE_ZERO => '未确认',
  17. self::STATE_ONE => '已确认',
  18. ];
  19. const Order_type_one = 1;//普通采购
  20. const Order_type_two = 2;//代发采购
  21. const Order_type_three = 3;//采购施工(安装费)
  22. public static $order_type = [
  23. self::Order_type_one => '普通采购',
  24. self::Order_type_two => '代发采购',
  25. self::Order_type_three => '采购施工(安装费)'
  26. ];
  27. public static $user = [];
  28. public static $is_search = false;
  29. public function __construct(array $attributes = [])
  30. {
  31. if(! empty($attributes['userData'])) {
  32. self::$user = $attributes['userData'];
  33. self::$is_search = true;
  34. }
  35. parent::__construct($attributes);
  36. }
  37. protected static function boot(){
  38. parent::boot();
  39. if(self::$is_search){
  40. static::addGlobalScope(new DepartmentScope(self::$user));
  41. }
  42. }
  43. }