CoursePromoter.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace addons\Course\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. use Exception;
  7. /**
  8. * This is the model class for table "qimall_addons_course_promoter".
  9. *
  10. * @property int $id
  11. * @property int $mall_id
  12. * @property int $user_id
  13. * @property int $status 活动状态,1:启用,0:禁用,-1删除
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class CoursePromoter extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_course_promoter}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'user_id'], 'required'],
  33. [['mall_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => 'Mall ID',
  44. 'user_id' => 'User ID',
  45. 'status' => '活动状态,1:启用,0:禁用,-1删除',
  46. 'created_at' => 'Created At',
  47. 'updated_at' => 'Updated At',
  48. ];
  49. }
  50. public static function setData(array $params)
  51. {
  52. try {
  53. if(!empty($params['id'])){
  54. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  55. if (empty($model)) throw new \Exception('服务不存在或已删除');
  56. }else{
  57. $model = new self();
  58. $model->loadDefaultValues();
  59. }
  60. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  61. if (!$model->save()) throw new Exception($model->getErrorMessage());
  62. return $model;
  63. } catch (\Exception $e) {
  64. self::$static_error = $e->getMessage();
  65. return false;
  66. }
  67. }
  68. }