You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.2 KiB

  1. <?php
  2. namespace backend\modules\shop\models\ars;
  3. use Yii;
  4. use yii\behaviors\TimestampBehavior;
  5. /**
  6. * This is the model class for table "ats_delivery".
  7. *
  8. * @property int $id
  9. * @property int $order_id 订单id
  10. * @property string $shipping_name 货流名称
  11. * @property string $shipping_id 运货单位
  12. * @property string $invoice_sn 运单号
  13. * @property int $type 类型
  14. * @property string $goods 商品
  15. * @property int $status 状态
  16. * @property string $decription 描述
  17. * @property int $updated_at 更新时间
  18. * @property int $created_at 创建时间
  19. */
  20. class Delivery extends \yii\db\ActiveRecord
  21. {
  22. const TYPE_SHIPMENT_ALL = 1;
  23. const TYPE_SHIPMENT_PORTION = 2;
  24. public $deliveryGoods;
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public static function tableName()
  29. {
  30. return 'ats_delivery';
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['order_id', 'type', 'status'], 'integer'],
  39. [['shipping_id'], 'required'],
  40. [['goods', 'decription'], 'string'],
  41. [['shipping_name'], 'string', 'max' => 50],
  42. [['shipping_id'], 'string', 'max' => 10],
  43. [['invoice_sn'], 'string', 'max' => 255],
  44. ];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function attributeLabels()
  50. {
  51. return [
  52. 'id' => 'id',
  53. 'order_id' => '订单id',
  54. 'shipping_name' => '货流名称',
  55. 'shipping_id' => '运货单位',
  56. 'invoice_sn' => '运单号',
  57. 'type' => '类型',
  58. 'goods' => '商品',
  59. 'status' => '状态',
  60. 'decription' => '描述',
  61. 'updated_at' => '更新时间',
  62. 'created_at' => '创建时间',
  63. ];
  64. }
  65. /**
  66. * @author linyao
  67. * @email 602604991@qq.com
  68. * @created Nov 8, 2019
  69. *
  70. * 行为存储创建时间和更新时间
  71. */
  72. public function behaviors()
  73. {
  74. return [
  75. [
  76. 'class' => TimestampBehavior::className(),
  77. 'createdAtAttribute' => 'created_at',
  78. 'updatedAtAttribute' => 'updated_at',
  79. 'value' => function() {
  80. return time();
  81. },
  82. ],
  83. ];
  84. }
  85. /**
  86. * @param $column
  87. * @param null $value
  88. * @return bool
  89. * 获取各状态数组
  90. */
  91. public static function dropDown($column, $value = null)
  92. {
  93. $dropDownList = [
  94. 'type' => [
  95. self::TYPE_SHIPMENT_ALL => '全部发货',
  96. self::TYPE_SHIPMENT_PORTION => '部分发货',
  97. ],
  98. ];
  99. //根据具体值显示对应的值
  100. if ($value !== null)
  101. return array_key_exists($column, $dropDownList) ? $dropDownList[$column][$value] : false;
  102. //返回关联数组,用户下拉的filter实现
  103. else
  104. return array_key_exists($column, $dropDownList) ? $dropDownList[$column] : false;
  105. }
  106. public function beforeSave($insert)
  107. {
  108. if ($insert) {
  109. $this->shipping_name = Yii::$app->params['logistics'][$this->shipping_id];
  110. }
  111. return parent::beforeSave($insert); // TODO: Change the autogenerated stub
  112. }
  113. }