CloudStockTwoIncreaseDetail.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace addons\CloudStockTwo\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use common\models\goods\Goods;
  6. use common\models\user\User;
  7. use Yii;
  8. /**
  9. * This is the model class for table "{{%addons_cloud_stock_increase_detail}}".
  10. *
  11. * @property int $id 自增id
  12. * @property int $mall_id 商城id
  13. * @property int $goods_id 商品id
  14. * @property int $changes_type 库存变动类型;100向上级补货;101上级给自己配货;102退货退库存;103系统添加;104平台补货赠送;105购买礼包赠送;
  15. * @property int $stock_log_id 库存变动表qimall_addons_cloud_stock_goods_stock_log的id
  16. * @property int $user_id 增加库存代理商用户id
  17. * @property int $order_id 订单id
  18. * @property int $order_type order类型,1:会员购买订单,2:补货订单;
  19. * @property int $num 增加数量
  20. * @property int $status 状态[-1:删除;0:禁用;1启用]
  21. * @property int $created_at
  22. * @property int $updated_at
  23. */
  24. class CloudStockTwoIncreaseDetail extends BaseActiveRecord
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public static function tableName()
  30. {
  31. return '{{%addons_cloud_stock_two_increase_detail}}';
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['mall_id', 'goods_id', 'changes_type', 'stock_log_id', 'user_id', 'num'], 'required'],
  40. [['mall_id', 'goods_id', 'changes_type', 'stock_log_id', 'user_id', 'order_id', 'order_type', 'num', 'status', 'created_at', 'updated_at'], 'integer'],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => '自增id',
  50. 'mall_id' => '商城id',
  51. 'goods_id' => '商品id',
  52. 'changes_type' => '库存变动类型;100向上级补货;101上级给自己配货;102退货退库存;103系统添加;104平台补货赠送;105购买礼包赠送;',
  53. 'stock_log_id' => '库存变动表qimall_addons_cloud_stock_goods_stock_log的id',
  54. 'user_id' => '增加库存代理商用户id',
  55. 'order_id' => '订单id',
  56. 'order_type' => 'order类型,1:会员购买订单,2:补货订单;',
  57. 'num' => '增加数量',
  58. 'status' => '状态[-1:删除;0:禁用;1启用]',
  59. 'created_at' => 'Created At',
  60. 'updated_at' => 'Updated At',
  61. ];
  62. }
  63. public function getUser()
  64. {
  65. return $this->hasOne(User::class, ['id' => 'user_id'])->select(['id','mobile','nickname','avatar_url']);
  66. }
  67. public function getGoods()
  68. {
  69. return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select(['id', 'goods_name', 'cover_pic']);
  70. }
  71. public static function setData(array $data)
  72. {
  73. if (!empty($data['id'])) {
  74. $model = self::findOne(['status' => StatusEnum::ENABLED, 'id' => $data['id']]);
  75. } else {
  76. $model = new self();
  77. $model->loadDefaultValues();
  78. }
  79. foreach ($data as $key => $val) {
  80. $model->$key = $val;
  81. }
  82. // dd($model);
  83. if (!$model->save()) {
  84. self::$static_error = '保存数据失败:' . $model->getErrorMessage();
  85. return false;
  86. }
  87. return $model;
  88. }
  89. }