AddonsCourseGroups.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_groups}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property string $gname 分组名称
  11. * @property int $sort 序号
  12. * @property string|null $cid 关联的课程id,多个课程 id 用逗号(英文)连接
  13. * @property string $logo 分组logo图片保存路径
  14. * @property int $status 状态 0禁用,1启用,-1是删除
  15. * @property int $created_at
  16. * @property int $updated_at
  17. */
  18. class AddonsCourseGroups extends \common\models\base\BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_course_groups}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['mall_id'], 'required'],
  34. [['mall_id', 'sort', 'status', 'created_at', 'updated_at'], 'integer'],
  35. [['cid'], 'string'],
  36. [['gname'], 'string', 'max' => 150],
  37. [['logo'], 'string', 'max' => 255],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => 'ID',
  47. 'mall_id' => 'Mall ID',
  48. 'gname' => '分组名称',
  49. 'sort' => '序号',
  50. 'cid' => '关联的课程id,多个课程 id 用逗号(英文)连接',
  51. 'logo' => '分组logo图片保存路径',
  52. 'status' => '状态 0禁用,1启用,-1是删除',
  53. 'created_at' => 'Created At',
  54. 'updated_at' => 'Updated At',
  55. ];
  56. }
  57. public static function setData(array $params)
  58. {
  59. try {
  60. if(!empty($params['id'])){
  61. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  62. if (empty($model)) throw new \Exception('服务不存在或已删除');
  63. }else{
  64. $model = new self();
  65. $model->loadDefaultValues();
  66. }
  67. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  68. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  69. return $model;
  70. } catch (\Exception $e) {
  71. self::$static_error = $e->getMessage();
  72. return false;
  73. }
  74. }
  75. }