CloudStockTwoDeductionDetail.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_deduction_detail}}".
  10. *
  11. * @property int $id 自增id
  12. * @property int $mall_id 商城id
  13. * @property int $goods_id 商品id
  14. * @property int $changes_type 库存变动类型;200会员买货;201给下级配货;202下级向自己补货;203自提货到线下;204系统扣减;
  15. * @property int $order_id 订单id
  16. * @property int $order_type order类型,1:会员购买订单,2:补货订单;
  17. * @property int $not_yet_num 剩余未扣库存数
  18. * @property int $num 扣库存数
  19. * @property int $stock_log_id qimall_addons_cloud_stock_goods_stock_log表的id
  20. * @property int $user_id 扣减代理商用户user_id;0为平台
  21. * @property int $status 状态[-1:删除;0:禁用;1启用]
  22. * @property int $created_at
  23. * @property int $updated_at
  24. */
  25. class CloudStockTwoDeductionDetail extends BaseActiveRecord
  26. {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function tableName()
  31. {
  32. return '{{%addons_cloud_stock_two_deduction_detail}}';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['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'],
  41. [['goods_id', 'changes_type', 'stock_log_id', 'user_id'], 'required'],
  42. [['remark'],'string'],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => '自增id',
  52. 'mall_id' => '商城id',
  53. 'goods_id' => '商品id',
  54. 'changes_type' => '库存变动类型;200会员买货;201给下级配货;202下级向自己补货;203自提货到线下;204系统扣减;',
  55. 'order_id' => '订单id',
  56. 'order_type' => 'order类型,1:会员购买订单,2:补货订单;',
  57. 'not_yet_num' => '剩余未扣库存数',
  58. 'num' => '扣库存数',
  59. 'stock_log_id' => 'qimall_addons_cloud_stock_goods_stock_log表的id',
  60. 'user_id' => '扣减代理商用户user_id;0为平台',
  61. 'status' => '状态[-1:删除;0:禁用;1启用]',
  62. 'created_at' => 'Created At',
  63. 'updated_at' => 'Updated At',
  64. 'is_sales' => 'Is Sales',
  65. 'company_id' => 'Company Id',
  66. 'remark' => '备注'
  67. ];
  68. }
  69. public function getUser()
  70. {
  71. return $this->hasOne(User::class, ['id' => 'user_id'])->select(['id','mobile','nickname','avatar_url']);
  72. }
  73. public function getGoods()
  74. {
  75. return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select(['id', 'goods_name', 'cover_pic']);
  76. }
  77. public static function setData(array $data)
  78. {
  79. if (!empty($data['id'])) {
  80. $model = self::findOne(['status' => StatusEnum::ENABLED, 'id' => $data['id']]);
  81. } else {
  82. $model = new self();
  83. $model->loadDefaultValues();
  84. }
  85. foreach ($data as $key => $val) {
  86. $model->$key = $val;
  87. }
  88. // dd($model);
  89. if (!$model->save()) {
  90. self::$static_error = '保存数据失败:' . $model->getErrorMessage();
  91. return false;
  92. }
  93. return $model;
  94. }
  95. }