| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace addons\CloudStockTwo\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_deduction_detail}}".
- *
- * @property int $id 自增id
- * @property int $mall_id 商城id
- * @property int $goods_id 商品id
- * @property int $changes_type 库存变动类型;200会员买货;201给下级配货;202下级向自己补货;203自提货到线下;204系统扣减;
- * @property int $order_id 订单id
- * @property int $order_type order类型,1:会员购买订单,2:补货订单;
- * @property int $not_yet_num 剩余未扣库存数
- * @property int $num 扣库存数
- * @property int $stock_log_id qimall_addons_cloud_stock_goods_stock_log表的id
- * @property int $user_id 扣减代理商用户user_id;0为平台
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class CloudStockTwoDeductionDetail extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_cloud_stock_two_deduction_detail}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'goods_id', 'changes_type', 'order_id', 'order_type', 'not_yet_num', 'num', 'stock_log_id', 'user_id', 'status', 'created_at', 'updated_at','is_sales','company_id'], 'integer'],
- [['goods_id', 'changes_type', 'stock_log_id', 'user_id'], 'required'],
- [['remark'],'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '自增id',
- 'mall_id' => '商城id',
- 'goods_id' => '商品id',
- 'changes_type' => '库存变动类型;200会员买货;201给下级配货;202下级向自己补货;203自提货到线下;204系统扣减;',
- 'order_id' => '订单id',
- 'order_type' => 'order类型,1:会员购买订单,2:补货订单;',
- 'not_yet_num' => '剩余未扣库存数',
- 'num' => '扣库存数',
- 'stock_log_id' => 'qimall_addons_cloud_stock_goods_stock_log表的id',
- 'user_id' => '扣减代理商用户user_id;0为平台',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'is_sales' => 'Is Sales',
- 'company_id' => 'Company Id',
- 'remark' => '备注'
- ];
- }
- 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();
- }
- foreach ($data as $key => $val) {
- $model->$key = $val;
- }
- // dd($model);
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return $model;
- }
- }
|