AddonsCourseActivity.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace addons\Course\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_course_activity}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property string $course_id 活动关联的课程id,多个用逗号连接
  11. * @property int $good_id 活动关联的商品id,只能是一个商品
  12. * @property int $course_number 活动关联的课程个数
  13. * @property int $select_number 活动关联的课程中任选课程的个数
  14. * @property string $name 活动名称
  15. * @property string|null $banners 活动轮播图,多个图片地址用逗号隔开
  16. * @property int $status 活动状态,1:启用,0:禁用,-1删除
  17. * @property int $created_at
  18. * @property int $updated_at
  19. * @property string $logo 活动封面logo图片
  20. */
  21. class AddonsCourseActivity extends \common\models\base\BaseActiveRecord
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addons_course_activity}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['mall_id'], 'required'],
  37. [['mall_id', 'goods_id', 'course_number', 'select_number', 'status', 'created_at', 'updated_at'], 'integer'],
  38. [['course_id', 'banners', 'logo'], 'string'],
  39. [['name'], 'string', 'max' => 50],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'mall_id' => 'Mall ID',
  50. 'course_id' => '活动关联的课程id,多个用逗号连接',
  51. 'goods_id' => '活动关联的商品id,只能是一个商品',
  52. 'course_number' => '活动关联的课程个数',
  53. 'select_number' => '活动关联的课程中任选课程的个数',
  54. 'name' => '活动名称',
  55. 'banners' => '活动轮播图,多个图片地址用逗号隔开',
  56. 'status' => '活动状态,1:启用,0:禁用,-1删除',
  57. 'created_at' => 'Created At',
  58. 'updated_at' => 'Updated At',
  59. 'logo' => '活动封面logo图片保存地址',
  60. ];
  61. }
  62. public static function setData(array $params)
  63. {
  64. try {
  65. if(!empty($params['id'])){
  66. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  67. if (empty($model)) throw new \Exception('服务不存在或已删除');
  68. }else{
  69. $model = new self();
  70. $model->loadDefaultValues();
  71. }
  72. if(!empty($params['banners'])) $params['banners'] = json_encode($params['banners']);
  73. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  74. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  75. return $model;
  76. } catch (\Exception $e) {
  77. self::$static_error = $e->getMessage();
  78. return false;
  79. }
  80. }
  81. }