PurchaseOrder.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 $guarded = [];
  9. protected $table = "purchase_order"; //指定表
  10. const CREATED_AT = 'crt_time';
  11. const UPDATED_AT = 'upd_time';
  12. protected $dateFormat = 'U';
  13. const STATE_ZERO = 0;//未确认
  14. const STATE_ONE = 1;//已确认
  15. const prefix = 'CG';
  16. public static $name = [
  17. self::STATE_ZERO => '未确认',
  18. self::STATE_ONE => '已确认',
  19. ];
  20. const Order_type_one = 1;//普通采购
  21. const Order_type_two = 2;//代发采购
  22. const Order_type_three = 3;//采购施工(安装费)
  23. public static $order_type = [
  24. self::Order_type_one => '普通采购',
  25. self::Order_type_two => '代发采购',
  26. self::Order_type_three => '采购施工(安装费)'
  27. ];
  28. public static $user = [];
  29. public static $search = [];
  30. public static $is_search = false;
  31. public function __construct(array $attributes = [])
  32. {
  33. if(! empty($attributes['userData'])) {
  34. self::$user = $attributes['userData'];
  35. self::$search = $attributes['search'] ?? [];
  36. self::$is_search = true;
  37. }
  38. parent::__construct($attributes);
  39. }
  40. protected static function boot(){
  41. parent::boot();
  42. if(self::$is_search){
  43. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  44. }
  45. }
  46. }