PurchaseOrder.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const range_function = 'purchaseRange';
  32. public function __construct(array $attributes = [])
  33. {
  34. if(! empty($attributes['userData'])) {
  35. self::$user = $attributes['userData'];
  36. self::$search = $attributes['search'] ?? [];
  37. self::$user['range_function'] = self::range_function;
  38. self::$is_search = true;
  39. }
  40. parent::__construct($attributes);
  41. }
  42. protected static function boot(){
  43. parent::boot();
  44. if(self::$is_search){
  45. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  46. }
  47. }
  48. }