CloudStockPriceDifferenceGiftPackage.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "qimall_addons_cloud_stock_price_difference_gift_package".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城id
  11. * @property string $name 礼包名称
  12. * @property int $pic_type 0:默认;1:自定义
  13. * @property string $pic 礼包主图
  14. * @property int $level 升级等级权重
  15. * @property float $price 礼包金额
  16. * @property string|null $goods_id
  17. * @property string|null $recommend_reward 推荐奖励设置
  18. * @property int $status 状态[-1:删除;0:禁用;1启用]
  19. * @property int $created_at
  20. * @property int $updated_at
  21. * @property int $is_range 是否走极差:1:是;0:否
  22. * @property int $is_achievement_user 是否走极差:1:是;0:否
  23. * @property int $not_get_price_difference 开启后若代理商获得推荐奖励,则不会同时得到差价奖 1:开启;0:关闭
  24. * @property int $not_distribute_payment_for_goods 开启后若推荐奖发放到货款者后不再发出 1:开启;0:关闭
  25. */
  26. class CloudStockPriceDifferenceGiftPackage extends BaseActiveRecord
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%addons_cloud_stock_price_difference_gift_package}}';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['mall_id', 'name', 'level', 'price'], 'required'],
  42. [['mall_id', 'pic_type', 'level', 'status', 'created_at', 'updated_at', 'is_range', 'is_achievement_user',
  43. 'not_get_price_difference', 'not_distribute_payment_for_goods'], 'integer'],
  44. [['price'], 'number'],
  45. [['goods_id', 'recommend_reward'], 'string'],
  46. [['name', 'pic'], 'string', 'max' => 255],
  47. ];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'mall_id' => 'Mall ID',
  57. 'name' => 'Name',
  58. 'pic_type' => 'Pic Type',
  59. 'pic' => 'Pic',
  60. 'level' => 'Level',
  61. 'price' => 'Price',
  62. 'goods_id' => 'Goods ID',
  63. 'recommend_reward' => 'Recommend Reward',
  64. 'status' => 'Status',
  65. 'created_at' => 'Created At',
  66. 'updated_at' => 'Updated At',
  67. 'is_range' => 'is_range',
  68. 'is_achievement_user' => 'is_achievement_user',
  69. 'not_get_price_difference' => 'not_get_price_difference',
  70. 'not_distribute_payment_for_goods' => 'not_distribute_payment_for_goods',
  71. ];
  72. }
  73. public static function setData(array $params)
  74. {
  75. try {
  76. if (!empty($params['id'])) {
  77. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  78. if (empty($model)) throw new \Exception('服务不存在或已删除');
  79. $obj = self::findOne(['mall_id' => $params['mall_id'], 'level' => $params['level'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  80. if (!empty($obj) && $obj->id != $params['id']) {
  81. throw new \Exception('该等级已有礼包');
  82. }
  83. } else {
  84. $model = self::findOne(['mall_id' => $params['mall_id'], 'level' => $params['level'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  85. if (!empty($model)) {
  86. throw new \Exception('该等级已有礼包');
  87. }
  88. $model = new self();
  89. $model->loadDefaultValues();
  90. }
  91. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  92. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  93. return $model;
  94. } catch (\Exception $e) {
  95. self::$static_error = $e->getMessage();
  96. return false;
  97. }
  98. }
  99. }