Reference.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace common\models\backend;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_reference".
  8. *
  9. * @property int $id ID
  10. * @property string $name 推荐人名称
  11. * @property string $mobile 推荐人手机号码
  12. * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
  13. * @property int $created_at 创建时间
  14. * @property int $updated_at 上次更新数据时间
  15. */
  16. class Reference extends BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%reference}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['status', 'created_at', 'updated_at'], 'integer'],
  32. [['name'], 'string', 'max' => 255],
  33. [['mobile'], 'string', 'max' => 20],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'name' => '推荐人名称',
  44. 'mobile' => '推荐人手机号码',
  45. 'status' => '状态[-1:删除;0:禁用;1启用;]',
  46. 'created_at' => '创建时间',
  47. 'updated_at' => '上次更新数据时间',
  48. ];
  49. }
  50. public static function setData(array $params)
  51. {
  52. try {
  53. if (!empty($params['id'])) {
  54. $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  55. if (empty($model)) throw new \Exception('服务不存在或已删除');
  56. } else {
  57. $model = self::findOne(['mobile' => $params['mobile'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  58. if (empty($model)) {
  59. $model = new self();
  60. $model->loadDefaultValues();
  61. }
  62. }
  63. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  64. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  65. return $model;
  66. } catch (\Exception $e) {
  67. self::$static_error = $e->getMessage();
  68. return false;
  69. }
  70. }
  71. }