| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace addons\CloudStock\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\goods\Goods;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_cloud_stock_increase_by_platform_log}}".
- *
- * @property int $id 自增id
- * @property int $mall_id 商城id
- * @property int $goods_id 商品id
- * @property int $changes_type 库存变动类型;100向上级补货;101上级给自己配货;102退货退库存;103系统添加;104平台补货赠送;105购买礼包赠送;
- * @property int $stock_log_id 库存变动表qimall_addons_cloud_stock_goods_stock_log的id
- * @property int $user_id 增加库存代理商用户id
- * @property int $order_id 订单id
- * @property int $order_type order类型,1:会员购买订单,2:补货订单;
- * @property int $num 增加数量
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class CloudStockIncreaseByPlatformLog extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_cloud_stock_increase_by_platform_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'goods_id', 'changes_type', 'user_id', 'num'], 'required'],
- [['mall_id', 'goods_id', 'changes_type', 'user_id', 'order_id','num', 'status', 'created_at', 'updated_at','order_type'], 'integer'],
- [['fill_unit_price'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '自增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;
- }
- }
|