ReservationServiceUser.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace addons\ReservationService\common\models;
  3. use addons\Store\common\models\Store;
  4. use common\enums\StatusEnum;
  5. use common\models\user\User;
  6. use Yii;
  7. /**
  8. * This is the model class for table "{{%addons_reservation_service_user}}".
  9. *
  10. * @property int $id ID
  11. * @property int $mall_id 商城ID
  12. * @property int $user_id 用户ID
  13. * @property int $level 等级
  14. * @property string $idcard 身份证
  15. * @property string $idcard_front 身份证正面
  16. * @property string $idcard_back 身份证反面
  17. * @property string $address 地址
  18. * @property string $longitude 经度
  19. * @property string $latitude 纬度
  20. * @property string $name 姓名
  21. * @property string $mobile 手机号
  22. * @property float $commission 佣金
  23. * @property float $service_rating 佣金
  24. * @property string $qualification_certificate 资格证书
  25. * @property int $status 状态;1正常,0禁用,-1删除
  26. * @property int $check_status 审核状态:0:待审核;1:已通过;2:未通过
  27. * @property string $check_remark 审核备注
  28. * @property string $avatar 审核备注
  29. * @property string $desc 审核备注
  30. * @property int $created_at 创建时间
  31. * @property int $updated_at 更新时间
  32. * @property int $store_id 更新时间
  33. * @property int $store_status 更新时间
  34. * @property int $gender 性别,0保密,1男,2女
  35. * @property int $age 年龄
  36. * @property int $is_working 更新时间
  37. * @property int $order_num 更新时间
  38. * @property int $store_order_num 更新时间
  39. * @property float $store_lng 佣金
  40. * @property float $store_lat 佣金
  41. * @property float $store_service_rating 门店技师的服务评分
  42. * @property string $province 省
  43. * @property string $city 市
  44. * @property string $district 区
  45. */
  46. class ReservationServiceUser extends \common\models\base\BaseActiveRecord
  47. {
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public static function tableName()
  52. {
  53. return '{{%addons_reservation_service_user}}';
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function rules()
  59. {
  60. return [
  61. [['mall_id', 'user_id', 'level', 'status', 'check_status', 'created_at', 'updated_at', 'store_id', 'store_status',
  62. 'gender', 'age', 'is_working', 'order_num', 'store_order_num'], 'integer'],
  63. [['user_id'], 'required'],
  64. [['idcard'], 'string', 'max' => 32],
  65. [['idcard_front', 'idcard_back', 'address', 'check_remark'], 'string', 'max' => 255],
  66. [['longitude', 'latitude'], 'string', 'max' => 64],
  67. [['name'], 'string', 'max' => 100],
  68. [['mobile'], 'string', 'max' => 16],
  69. [['desc'], 'string', 'max' => 500],
  70. [['avatar','province','city','district'], 'string', 'max' => 255],
  71. [['commission', 'service_rating', 'store_lng', 'store_lat','store_service_rating'],'number'],
  72. [['qualification_certificate'], 'string'],
  73. ];
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function attributeLabels()
  79. {
  80. return [
  81. 'id' => 'ID',
  82. 'mall_id' => '商城ID',
  83. 'user_id' => '用户ID',
  84. 'level' => '等级',
  85. 'idcard' => '身份证',
  86. 'idcard_front' => '身份证正面',
  87. 'idcard_back' => '身份证反面',
  88. 'address' => '地址',
  89. 'longitude' => '经度',
  90. 'latitude' => '纬度',
  91. 'name' => '姓名',
  92. 'mobile' => '手机号',
  93. 'qualification_certificate' => '资格证书',
  94. 'status' => '状态;1正常,0禁用,-1删除',
  95. 'check_status' => '审核状态:0:待审核;1:已通过;2:未通过',
  96. 'check_remark' => '审核备注',
  97. 'commission' => '佣金',
  98. 'created_at' => '创建时间',
  99. 'updated_at' => '更新时间',
  100. ];
  101. }
  102. public function getUser()
  103. {
  104. return $this->hasOne(User::class, ['id' => 'user_id']);
  105. }
  106. public function getLevel()
  107. {
  108. return $this->hasOne(ReservationServiceLevel::class, ['level' => 'level'])->where(['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  109. }
  110. public function getStore()
  111. {
  112. return $this->hasOne(Store::class, ['id' => 'store_id']);
  113. }
  114. public static function getDataOne($params = [], $select = '*', $orderBy = 'id desc')
  115. {
  116. return self::find()->where($params)->select($select)->orderBy($orderBy)->asArray()->one();
  117. }
  118. public static function getDataAll($params = [], $select = '*', $orderBy = 'id desc')
  119. {
  120. return self::find()->where($params)->select($select)->orderBy($orderBy)->indexBy('id')->asArray()->all();
  121. }
  122. /**
  123. * @Description: 保存数据
  124. * @Author: zsan
  125. * @DateTime 2023-10-09 10:39:20
  126. * @param array $params
  127. * @return self|bool
  128. */
  129. public static function setData(array $params)
  130. {
  131. try {
  132. if (!empty($params['id'])) {
  133. $model = self::findOne(['and', ['id' => $params['id'], 'mall_id' => $params['mall_id']], ['<>', 'status', StatusEnum::DELETE]]);
  134. if (empty($model)) throw new \Exception('技师不存在或已删除');
  135. } else {
  136. $model = self::findOne(['user_id' => $params['user_id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  137. if (empty($model)) {
  138. $model = new self();
  139. $model->loadDefaultValues();
  140. $model->mall_id = $params['mall_id'];
  141. }
  142. }
  143. if (!$model->load($params, '') || !$model->save()) {
  144. throw new \Exception($model->getErrorMessage());
  145. }
  146. return $model;
  147. } catch (\Exception $e) {
  148. self::$static_error = $e->getMessage();
  149. return false;
  150. }
  151. }
  152. }