AddonsCourseRelays.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_relays}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城id
  10. * @property int $user_id 用户id
  11. * @property int $course_id 课程id
  12. * @property int $relay_type 转发方式,1:微信好友,2:微信朋友圈
  13. * @property int $status 状态 0禁用,1启用,-1是删除
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class AddonsCourseRelays extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_course_relays}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'user_id', 'course_id', 'relay_type', 'status', 'created_at', 'updated_at'], 'integer'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => '商城id',
  43. 'user_id' => '用户id',
  44. 'course_id' => '课程id',
  45. 'relay_type' => '转发方式,1:微信好友,2:微信朋友圈',
  46. 'status' => '状态 0禁用,1启用,-1是删除',
  47. 'created_at' => 'Created At',
  48. 'updated_at' => 'Updated At',
  49. ];
  50. }
  51. public static function setData($data)
  52. {
  53. $course_info = AddonsCourse::getOne([['id' => $data['course_id'], 'mall_id' => $data['mall_id'], 'status' => StatusEnum::ENABLED]]);
  54. if (empty($course_info)) {
  55. return "false";
  56. }
  57. $course_info->shares += 1;
  58. $course_info->relay_times += 1;
  59. $course_info->save();
  60. $model = new self();
  61. $model->load($data, '');
  62. $model->status = StatusEnum::ENABLED;
  63. if (!$model->save()) {
  64. self::$static_error = '保存数据失败:' . $model->getErrorMessage();
  65. return false;
  66. }
  67. return true;
  68. }
  69. }