HappinessMoveGoods.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace addons\Happiness\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\goods\Goods;
  5. use common\models\goods\GoodsAttr;
  6. use Yii;
  7. /**
  8. * This is the model class for table "qimall_addons_happiness_move_goods".
  9. *
  10. * @property int $id
  11. * @property int $goods_id 商品ID
  12. * @property int $move_id 调货单ID
  13. * @property int $attr_id 规格ID
  14. * @property int $num 调货数量
  15. * @property int $mall_id 商城ID
  16. * @property int $created_at
  17. * @property int $updated_at
  18. * @property int $status
  19. */
  20. class HappinessMoveGoods extends \common\models\base\BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return 'qimall_addons_happiness_move_goods';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['goods_id', 'move_id', 'attr_id', 'num', 'mall_id', 'created_at', 'updated_at', 'status'], 'integer'],
  36. [['total_price'], 'number']
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'goods_id' => 'Goods ID',
  47. 'move_id' => 'Move ID',
  48. 'attr_id' => 'Attr ID',
  49. 'num' => 'Num',
  50. 'total_price' => 'Total Price',
  51. 'mall_id' => 'Mall ID',
  52. 'created_at' => 'Created At',
  53. 'updated_at' => 'Updated At',
  54. 'status' => 'Status',
  55. ];
  56. }
  57. public function getAttr()
  58. {
  59. return $this->hasOne(GoodsAttr::class, ['id' => 'attr_id']);
  60. }
  61. public function getGoods()
  62. {
  63. return $this->hasOne(Goods::class, ['id' => 'goods_id']);
  64. }
  65. public static function setData($params)
  66. {
  67. try {
  68. if(isset($params['id']) && !empty($params['id']))
  69. $model = self::findOne($params['id']);
  70. else {
  71. $model = new self();
  72. $model->loadDefaultValues();
  73. }
  74. if (!$model->load($params, '') || !$model->save()) {
  75. throw new \Exception($model->getErrorMessage());
  76. }
  77. return $model;
  78. } catch (\Exception $e) {
  79. self::$static_error = $e->getMessage();
  80. return false;
  81. }
  82. }
  83. }