Dispatch.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\common\models\goods;
  3. use app\common\models\BaseModel;
  4. use app\common\observers\dispatchObserver\DispatchObserver;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Contracts\Validation\Validator;
  7. /**
  8. * Created by PhpStorm.
  9. * Author: 芸众商城 www.yunzshop.com
  10. * Date: 2017/2/22
  11. * Time: 下午5:54
  12. */
  13. class Dispatch extends BaseModel
  14. {
  15. public $table = 'yz_dispatch';
  16. public $attributes = [
  17. 'display_order' => 0,
  18. 'first_weight' => 1000,
  19. 'first_weight_price' => 0,
  20. 'another_weight' => 1000,
  21. 'another_weight_price' => 0,
  22. 'first_piece' => 1,
  23. 'first_piece_price' => 0,
  24. 'another_piece' => 1,
  25. 'another_piece_price' => 0,
  26. ];
  27. /**
  28. * 不可填充字段.
  29. *
  30. * @var array
  31. */
  32. protected $guarded = ['deleted_at'];
  33. /**
  34. * 自定义显示错误信息
  35. * @return array
  36. */
  37. public static function getDispatchList()
  38. {
  39. $dispatchList = self::uniacid()->where(['enabled' => 1 , 'plugin_id' => 0 ])->Where('is_plugin', 0)
  40. ->get()->toArray();
  41. return $dispatchList;
  42. }
  43. public static function getDispatch()
  44. {
  45. $dispatchList = self::uniacid()
  46. ->select('id','dispatch_name')
  47. ->where('enabled', 1)
  48. ->Where('is_plugin', 0)
  49. ->get();
  50. return $dispatchList;
  51. }
  52. /**
  53. * 自定义字段名
  54. * 可使用
  55. * @return array
  56. */
  57. public function atributeNames()
  58. {
  59. return [
  60. 'uniacid' => '公众号id',
  61. 'dispatch_name' => '配送方式名称',
  62. 'display_order' => '排序',
  63. 'is_default' => '是否默认',
  64. 'enabled' => '是否显示',
  65. 'calculate_type' => '计算方式',
  66. 'first_weight' => '首重',
  67. 'first_weight_price' => '首费',
  68. 'another_weight' => '续重',
  69. 'another_weight_price' => '续费',
  70. 'first_piece' => '首件',
  71. 'first_piece_price' => '运费',
  72. 'another_piece' => '续件',
  73. 'another_piece_price' => '续费'
  74. ];
  75. }
  76. public function rules()
  77. {
  78. return [
  79. 'uniacid' => 'required',
  80. 'dispatch_name' => 'required|max:50',
  81. 'display_order' => '',
  82. 'is_default' => 'digits_between:0,1',
  83. 'enabled' => 'integer',
  84. 'calculate_type' => 'digits_between:0,1',
  85. 'first_weight' => 'required',
  86. 'first_weight_price' => 'required',
  87. 'another_weight' => 'required',
  88. 'another_weight_price' => 'required',
  89. 'first_piece' => 'required',
  90. 'first_piece_price' => 'required',
  91. 'another_piece' => 'required',
  92. 'another_piece_price' => 'required'
  93. ];
  94. }
  95. public static function boot()
  96. {
  97. parent::boot();
  98. static::observe(new DispatchObserver());
  99. }
  100. }