'自增id', 'mall_id' => '商城id', 'goods_id' => '商品id', 'changes_type' => '库存变动类型;100向上级补货;101上级给自己配货;102退货退库存;103系统添加;104平台补货赠送;105购买礼包赠送;', 'user_id' => '增加库存代理商用户id', 'order_id' => '订单id', 'num' => '增加数量', 'fill_unit_price' => '补货单价', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public function getUser() { return $this->hasOne(User::class, ['id' => 'user_id'])->select(['id','mobile','nickname','avatar_url']); } public function getGoods() { return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select(['id', 'goods_name', 'cover_pic']); } public static function setData(array $data) { if (!empty($data['id'])) { $model = self::findOne(['status' => StatusEnum::ENABLED, 'id' => $data['id']]); } else { $model = new self(); $model->loadDefaultValues(); } if (!$model->load($data, '')) throw new \Exception($model->getErrorMessage()); if (!$model->save()) { self::$static_error = '保存数据失败:' . $model->getErrorMessage(); return false; } return $model; } }