CloudStockGiftPlan.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace addons\CloudStock\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "{{%addons_cloud_stock_upgrade_bag".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城id
  11. * @property string $name 升级礼包名称
  12. * @property int $goods_id 升级商品id
  13. * @property string $give_goods_num 赠送商品数量
  14. * @property string $give_goods_id 赠送商品id
  15. * @property string $gift_condition_level 赠送条件
  16. * @property int $status 状态[-1:删除;0:禁用;1启用]
  17. * @property int $created_at
  18. * @property int $updated_at
  19. * @property string $level_reward
  20. */
  21. class CloudStockGiftPlan extends BaseActiveRecord
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addons_cloud_stock_gift_plan}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['mall_id'], 'required'],
  37. [['mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  38. [['goods_id', 'give_goods_id','give_goods_num','gift_condition_level'], 'string'],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'mall_id' => '商城id',
  49. 'goods_id' => '升级商品id',
  50. 'give_goods_num' => '赠送商品数量',
  51. 'give_goods_id' => '赠送商品id',
  52. 'gift_condition_level' => 'gift_condition_level',
  53. 'status' => '状态[-1:删除;0:禁用;1启用]',
  54. 'created_at' => 'Created At',
  55. 'updated_at' => 'Updated At',
  56. ];
  57. }
  58. public static function setData(array $params)
  59. {
  60. try {
  61. if(!empty($params['id'])){
  62. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]);
  63. if (empty($model)) throw new \Exception('服务不存在或已删除');
  64. }else{
  65. $model = new self();
  66. $model->loadDefaultValues();
  67. }
  68. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  69. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  70. return $model;
  71. } catch (\Exception $e) {
  72. self::$static_error = $e->getMessage();
  73. return false;
  74. }
  75. }
  76. }