| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace addons\Course\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_course_relays}}".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $user_id 用户id
- * @property int $course_id 课程id
- * @property int $relay_type 转发方式,1:微信好友,2:微信朋友圈
- * @property int $status 状态 0禁用,1启用,-1是删除
- * @property int $created_at
- * @property int $updated_at
- */
- class AddonsCourseRelays extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_course_relays}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'course_id', 'relay_type', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'user_id' => '用户id',
- 'course_id' => '课程id',
- 'relay_type' => '转发方式,1:微信好友,2:微信朋友圈',
- 'status' => '状态 0禁用,1启用,-1是删除',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData($data)
- {
- $course_info = AddonsCourse::getOne([['id' => $data['course_id'], 'mall_id' => $data['mall_id'], 'status' => StatusEnum::ENABLED]]);
- if (empty($course_info)) {
- return "false";
- }
- $course_info->shares += 1;
- $course_info->relay_times += 1;
- $course_info->save();
- $model = new self();
- $model->load($data, '');
- $model->status = StatusEnum::ENABLED;
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return true;
- }
- }
|