public function actionDelete() { $data = Yii::$app->request->post(); if (isset($data['myphone']) && isset($data['friendphone'])) { $u1 = Users::find()->where(['phone' => $data['myphone']])->one(); $u2 = Users::find()->where(['phone' => $data['friendphone']])->one(); if (!Friends::findAll(['myid' => $u1['id'], 'friendid' => $u2['id']]) && !Friends::findAll(['myid' => $u2['id'], 'friendid' => $u1['id']])) { return array('flag' => 0, 'msg' => 'is already not friend!'); } Friends::deleteAll('myid = :myid and friendid = :friendid or myid = :friendid and friendid = :myid', [':myid' => $u1['id'], ':friendid' => $u2['id']]); $easeclient = new Easeapi('YXA6halokJDEEeWMRgvYONLZPQ', 'YXA6pswnZbss8mj351XE3oxuRYm6cek', '13022660999', 'allpeopleleague', 'file'); $result = json_decode($easeclient->curl('/users/' . $u1->id . '/contacts/users/' . $u2->id, '', 'DELETE'), true); return array('flag' => 1, 'msg' => 'delete friend success!'); } else { return array('flag' => 0, 'msg' => 'arg not enough!'); } }
public function actionChangepwd() { $data = Yii::$app->request->post(); $model = Users::findone(['phone' => $data['phone']]); $model['pwd'] = md5($data['pwd']); if ($model->save()) { $easeclient = new Easeapi('YXA6halokJDEEeWMRgvYONLZPQ', 'YXA6pswnZbss8mj351XE3oxuRYm6cek', '13022660999', 'allpeopleleague', 'file'); $result = $easeclient->curl('/users/' . $model['id'] . '/password', array('newpassword' => $data['pwd']), 'PUT'); $status = $result['status']; $result = json_decode($result['result'], true); if ($status != 200) { //$model->delete(); return array('error' => $result, 'flag' => 0, 'msg' => 'Signup fail!'); } return array('flag' => 1, 'msg' => 'Modify success!'); } else { return array('flag' => 0, 'msg' => 'Modify fail!'); } }