'trim'], [['mobile_phone'], 'match', 'pattern' => '/^[1][34578][0-9]{9}$/'], ]; } public function attributeLabels() { return [ 'mobile_phone' => '手机号', 'real_name' => '姓名', 'gender' => '性别', 'is_view' => '鞋码', ]; } /** * 会员注册 */ public function modify_user() { if (!$this->validate()) { return $this->getModelError(); } $user = User::findOne(['id' => $this->user_id]); if (!empty($user->mobile_phone) && !empty($user->is_view)) { return [ 'code' => 0, 'msg' => '已填写', ]; } $t = \Yii::$app->db->beginTransaction(); try { $user->real_name = $this->real_name; $user->mobile_phone = $this->mobile_phone; $user->gender = $this->gender; $user->is_view = $this->is_view; if (!$user->save()) { $t->rollBack(); return $this->getModelError($user); } $t->commit(); return [ 'code' => 0, 'msg' => '绑定成功', ]; } catch (\Exception $e) { $t->rollBack(); return [ 'code' => 1, 'msg' => '绑定失败', ]; } } }