public function actionGetinfobyphonearray() { $data = Yii::$app->request->post(); if (!(isset($data['phones']) && isset($data['phone']))) { return array('flag' => 0, 'msg' => 'no enough arg!'); } $user = Users::findOne(['phone' => $data['phone']]); $people = (new \yii\db\Query())->select(['users.id', 'users.thumb', 'users.phone', 'users.nickname', 'if(isnull(friends.friendid),0,1) as isfriend'])->from('users')->join('LEFT JOIN', 'friends', 'friends.myid = users.id and friends.friendid = ' . $user['id'])->where('users.phone in (' . join($data['phones'], ',') . ')')->all(); $map = array(); foreach ($people as $t) { $map[$t['phone']] = $t; } $ret = array(); foreach ($data['phones'] as $phone) { if (isset($map[$phone])) { $map[$phone]['isregisted'] = 1; $ret[] = $map[$phone]; } else { $t = array(); $t['phone'] = $phone; $t['isregisted'] = 0; $ret[] = $t; } } return $ret; }
public function actionWin() { $data = Yii::$app->request->post(); if (!isset($data['phone'])) { return array('flag' => 0, 'msg' => 'no enough arg!'); } //(new \yii\db\Query ())->createCommand(); $connection = Yii::$app->db; $user = Users::findOne(['phone' => $data['phone']]); //$query->andFilterWhere(['grabcornrecords.userid' => $user->id]); //$connection->queryBuilder->buildUnion($unions, $params) //$cmd=$connection->createCommand('SELECT if(isnull(grabcornrecords.id),0,0) as tbk, `grabcorns`.`id` AS `flag`, `grabcornrecords`.`id`, `grabcornrecords`.`grabcornid` AS `grabid`, `grabcornrecords`.`userid`, `grabcornrecords`.`type`, `grabcornrecords`.`created_at`, `grabcornrecords`.`isgotback`, `grabcorns`.`isgot`, `grabcorns`.`picture`, `grabcorns`.`title`, `grabcorns`.`version`, `grabcorns`.`date`, `grabcorns`.`needed`, `grabcorns`.`end_at`, `grabcorns`.`islotteried`, `grabcorns`.`winnernumber`, `users`.`nickname`, `users`.`phone`, `users`.`thumb` FROM `grabcornrecords` INNER JOIN `grabcorns` ON grabcornrecords.grabcornid = grabcorns.id INNER JOIN `users` ON grabcornrecords.userid = users.id and winnerrecordid = grabcornrecords.id WHERE `grabcornrecords`.`userid`=:userid UNION ALL SELECT if(isnull(grabcommodityrecords.id),1,1) as tbk, `grabcommodityrecords`.`id` AS `flag`, `grabcommodityrecords`.`id`, `grabcommodityrecords`.`grabcommodityid` AS `grabid`, `grabcommodityrecords`.`userid`, `grabcommodityrecords`.`type`, `grabcommodityrecords`.`created_at`, `grabcommodityrecords`.`isgotback`, `grabcommodities`.`isgot`, `grabcommodities`.`picture`, `grabcommodities`.`title`, `grabcommodities`.`version`, `grabcommodities`.`date`, `grabcommodities`.`needed`, `grabcommodities`.`end_at`, `grabcommodities`.`islotteried`, `grabcommodities`.`winnernumber`, `users`.`nickname`, `users`.`phone`, `users`.`thumb` FROM `grabcommodityrecords` INNER JOIN `grabcommodities` ON grabcommodityrecords.grabcommodityid = grabcommodities.id and winnerrecordid = grabcommodityrecords.id INNER JOIN `users` ON grabcommodityrecords.userid = :userid',[':userid'=>$user->id]); //$query=$cmd->query(); $query = (new \yii\db\Query())->select('*, id as version')->from('activities')->where('userid=:userid', [':userid' => $user->id])->orderBy('end_at desc'); //->orderBy('created_at des'); //var_dump($query); $dataProvider = new ActiveDataProvider(['query' => $query]); //$this->load($params); //$value = 0; if (!empty($data)) { if (isset($data['phone'])) { } } return $dataProvider; }
public function actionList() { $data = Yii::$app->request->post(); if (!isset($data['phone'])) { return array('flag' => 0, 'msg' => 'arg not enough!'); } $user = Users::findOne(['phone' => $data['phone']]); if (!$user) { return array('flag' => 0, 'msg' => 'get fail!'); } $query = (new \yii\db\Query())->select('users.*')->from('concerns')->orderBy('concerns.created_at desc')->join('INNER JOIN', 'users', 'concerns.concernid = users.id')->where(['myid' => $user->id]); $dataProvider = new ActiveDataProvider(['query' => $query]); return $dataProvider; }
public function setFather($fid) { //$result=$this->find()->select()->join('INNER JOIN','users u1',['u1.phone'=>$fatherphone])->join('LEFT JOIN','users u2','u3.phone = u1.fatherid')->join('Left JOIN','users u3','u3.phone = u2.fatherid')->one(); $f = Users::findOne(['id' => $fid]); // if($f['status']!=2){ // return true; // } $result = (new \yii\db\Query())->select('u1.id as f, u2.id as gf ,u3.id as ggf')->from('users u1')->where('u1.id=:id', [':id' => $fid])->join('LEFT JOIN', 'users u2', 'u2.id = u1.fatherid')->join('Left JOIN', 'users u3', 'u3.id = u2.fatherid')->one(); // var_dump($result); // return true; if ($result) { $this->fatherid = strval($fid); Users::updateAllCounters(['directalliancecount' => 1, 'allalliancecount' => 1], ['id' => $result['f']]); Users::updateAllCounters(['allalliancecount' => 1], ['id' => $result['gf']]); Users::updateAllCounters(['allalliancecount' => 1], ['id' => $result['ggf']]); return true; } else { return false; } }
public function search($data, $type) { if (!(isset($data) && isset($data['phone']) && isset($type))) { return array('flag' => 0, 'msg' => 'no enough arg!'); } $user = Users::findOne(['phone' => $data['phone']]); $query = (new \yii\db\Query())->select(['users.phone', 'users.nickname', 'users.thumb', 'users.signature', 'users.concerncount', 'if(isnull(concerns.id),0,1) as isconcerned'])->from('users'); switch ($type) { case 1: $query = $query->orderBy('users.concerncount desc')->join('LEFT JOIN', 'concerns', 'concerns.concernid = users.id and concerns.myid = :id', [':id' => $user->id]); break; case 2: $query = $query->orderBy('concerns.created_at desc')->join('INNER JOIN', 'concerns', 'concerns.concernid = users.id and concerns.myid = :id', [':id' => $user->id]); break; case 3: $query = $query->orderBy('concerns.created_at desc')->join('INNER JOIN', 'concerns c', 'c.concernid = :id and c.myid = users.id', [':id' => $user->id])->join('LEFT JOIN', 'concerns', 'concerns.concernid = users.id and concerns.myid = :id', [':id' => $user->id]); break; } $dataProvider = new ActiveDataProvider(['query' => $query]); return $dataProvider; }
public function actionList() { $data = Yii::$app->request->post(); $query = (new \yii\db\Query())->select('grabcommodityrecords.*,grabcommodities.picture,grabcommodities.title,grabcommodities.id as version,grabcommodities.date,grabcommodities.needed,grabcommodities.end_at,grabcommodities.winnernumber,grabcommodities.islotteried,g2.count as winnercount,users.phone,users.nickname,users.thumb')->from('grabcommodityrecords')->orderBy('grabcommodityrecords.created_at desc')->join('INNER JOIN', 'grabcommodities', 'grabcommodityrecords.grabcommodityid = grabcommodities.id')->join('LEFT JOIN', 'grabcommodityrecords g2', 'grabcommodities.winnerrecordid = g2.id')->join('LEFT JOIN', 'users', 'g2.userid = users.id'); $dataProvider = new ActiveDataProvider(['query' => $query]); //$this->load($params); //$value = 0; if (!empty($data)) { if (isset($data['phone'])) { $user = Users::findOne(['phone' => $data['phone']]); $query->andFilterWhere(['grabcommodityrecords.userid' => $user->id]); } // if(isset($data['hobbyid'])){ // $query->andFilterWhere(['hobbyid' => $data['hobbyid']]); // } // if(isset($data['content'])){ // $query->andFilterWhere(['like', 'content',$data['content']]); // } } return $dataProvider; }
public function actionDelete() { $data = Yii::$app->request->post(); if (empty($data['phone']) || empty('usertocardid')) { return array('flag' => 0, 'msg' => 'no enough arg!'); } $user = Users::findOne(['phone' => $data['phone']]); if (!$user) { return array('flag' => 0, 'msg' => 'user not exist!'); } $model = Usertocards::findOne(['id' => $data['usertocardid']]); if (!$model) { return array('flag' => 0, 'msg' => 'usertocard not exist!'); } if ($model['userid'] != $user['id']) { return array('flag' => 0, 'msg' => 'not the owner!'); } if ($model->delete()) { return array('flag' => 1, 'msg' => 'delete success!'); } else { return array('flag' => 0, 'msg' => 'delete failure!'); } }
public function actionDelete() { $data = Yii::$app->request->post(); $id = $data['messageid']; $msg = new Messages(); $user = Users::findOne(['phone' => $data['phone']]); $msg = Messages::find()->where(['id' => $id])->one(); if ($msg == null) { return array('flag' => 0, 'msg' => 'Message do not exist!'); } if ($user['id'] != $msg['userid']) { return array('flag' => 0, 'msg' => 'you do not own the message!'); } if ($msg->delete()) { return array('flag' => 1, 'msg' => 'Delete success!'); } else { return array('flag' => 0, 'msg' => 'Delete failed!'); } }
/** * Deletes an existing Applyjobs model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete() { $data = Yii::$app->request->post(); if (!isset($data['phone']) || !isset($data['recommendationcommentid'])) { return array('flag' => 0, 'msg' => 'no enough arg!'); } $user = Users::findOne(['phone' => $data['phone']]); $recommendation = $this->findModel($data['recommendationcommentid']); if (!$recommendation || !$user) { return array('flag' => 0, 'msg' => 'delete job applying fail!'); } if ($recommendation->userid == $user->id) { if ($recommendation->delete()) { return array('flag' => 1, 'msg' => 'delete recommendation success!'); } else { return array('flag' => 0, 'msg' => 'delete recommendation fail!'); } } else { return array('flag' => 0, 'msg' => 'have no authority!'); } }
/** * Finds the Users model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Users the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Users::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionGetback() { $data = Yii::$app->request->post(); if (!(isset($data['phone']) && isset($data['grabcornid']))) { return array('flag' => 0, 'msg' => 'no enough arg!'); } //Users::findOne(['phone'=>$data['phone']]) $grabcorn = Grabcorns::findOne(['id' => $data['grabcornid']]); if (!$grabcorn) { return array('flag' => 0, 'msg' => 'activity not exist!'); } $user = Users::findOne(['phone' => $data['phone']]); if (!$user) { return array('flag' => 0, 'msg' => 'find user fail!'); } // if($grabcorn->winneruserid !=$user->id){ // return array ( // 'flag' => 0, // 'msg' => 'you are not the winner!' // ); // } // if($grabcorn->isgot !=0){ // return array ( // 'flag' => 0, // 'msg' => 'you has got the corn!' // ); // } $back = 0; $back = (new \yii\db\Query())->select('SUM(grabcornrecords.count) as back')->from('grabcornrecords')->where('grabcornrecords.userid = :userid and grabcornrecords.grabcornid = :id and grabcornrecords.isgotback=0', [':id' => $data['grabcornid'], ':userid' => $user->id])->one(); $back = $back['back']; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); $updategrab = 0; try { $updategrab = $connection->createCommand('update grabcornrecords g1 set g1.isgotback=1 where g1.grabcornid = :id and g1.userid = :userid', [':id' => $data['grabcornid'], ':userid' => $user->id])->execute(); $updateuser = $connection->createCommand('update users u1 set u1.money = u1.money + :back where u1.id=:id', [':id' => $user->id, ':back' => intval($back * 0.9)])->execute(); if (!$updateuser) { throw new Exception("Value must be 1 or below"); } $trade = new Traderecords(); $trade->userid = $user['id']; $trade->type = 4; $trade->description = '自己人联盟提前保本'; $trade->cardid = 0; $trade->count = intval($back * 0.9); $trade->ishandled = 0; $trade->created_at = time(); if (!$trade->save()) { throw new Exception("Value must be 1 or below"); } // ... executing other SQL statements ... $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); //var_dump($e->getMessage()); //Yii::$app->log->logger-> return array('flag' => 0, 'msg' => 'get corn fail!'); } return array('flag' => 1, 'msg' => 'get corn success!'); }
public function actionChangetocorns() { $data = Yii::$app->request->post(); if (!(isset($data['phone']) && isset($data['grabcommodityid']))) { return array('flag' => 0, 'msg' => 'no enough arg!'); } //Users::findOne(['phone'=>$data['phone']]) $grabcommodity = Grabcorns::findOne(['id' => $data['grabcommodityid']]); if (!$grabcommodity) { return array('flag' => 0, 'msg' => 'activity not exist!'); } $user = Users::findOne(['phone' => $data['phone']]); if (!$user) { return array('flag' => 0, 'msg' => 'find user fail!'); } if ($grabcommodity->winneruserid != $user->id) { return array('flag' => 0, 'msg' => 'you are not the winner!'); } if ($grabcommodity->isgot != 0) { return array('flag' => 0, 'msg' => 'you has got the corn!'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); $updategrab = 0; try { //$worth = intval($grabcommodity->worth * 0.9); $updategrab = $connection->createCommand('update grabcommodities g1,users u1 set g1.isgot=1,u1.corns=u1.corns+g1.worth where g1.id=:id and u1.id = g1.winneruserid', [':id' => $data['grabcommodityid']])->execute(); if (!$updategrab) { throw new Exception("Value must be 1 or below"); } // ... executing other SQL statements ... $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); //var_dump($e->getMessage()); //Yii::$app->log->logger-> return array('err' => $e, 'flag' => 0, 'msg' => 'get grabcommodity fail!'); } return array('c' => $updategrab, 'flag' => 1, 'msg' => 'get grabcommodity success!'); }
public function actionDelete() { $data = Yii::$app->request->post(); if (!isset($data['phone']) || !isset($data['tbotherid'])) { return array('flag' => 0, 'msg' => 'no enough arg!'); } $user = Users::findOne(['phone' => $data['phone']]); $model = $this->findModel($data['tbotherid']); if (!$model || !$user) { return array('flag' => 0, 'msg' => 'delete fail!'); } if ($model->userid == $user->id) { if ($model->delete()) { return array('flag' => 1, 'msg' => 'delete success!'); } else { return array('flag' => 0, 'msg' => 'delete fail!'); } } else { return array('flag' => 0, 'msg' => 'have no authority!'); } }
public function actionLogout() { //Yii::$app->user->logout (); $data = Yii::$app->request->post(); $model = new Users(); $info = $model->findOne(['phone' => $data['phone']]); if ($info) { return array('flag' => 1, 'username' => $info->id, 'msg' => 'Logout success!'); } else { return array('flag' => 0, 'msg' => 'Logout failed!'); } }