Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Users::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'directalliancecount' => $this->directalliancecount, 'allalliancecount' => $this->allalliancecount, 'corns' => $this->corns, 'money' => $this->money, 'envelope' => $this->envelope, 'cornsforgrab' => $this->cornsforgrab, 'alliancerewards' => $this->alliancerewards, 'gender' => $this->gender, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'friendcount' => $this->friendcount, 'concerncount' => $this->concerncount, 'isdraw' => $this->isdraw]);
     $query->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'pwd', $this->pwd])->andFilterWhere(['like', 'authKey', $this->authKey])->andFilterWhere(['like', 'fatherid', $this->fatherid])->andFilterWhere(['like', 'nickname', $this->nickname])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'area', $this->area])->andFilterWhere(['like', 'job', $this->job])->andFilterWhere(['like', 'hobby', $this->hobby])->andFilterWhere(['like', 'signature', $this->signature])->andFilterWhere(['like', 'channel', $this->channel])->andFilterWhere(['like', 'platform', $this->platform]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 public function actionDelete()
 {
     $data = Yii::$app->request->post();
     if (isset($data['myphone']) && isset($data['concernphone'])) {
         $u1 = Users::find()->where(['phone' => $data['myphone']])->one();
         $u2 = Users::find()->where(['phone' => $data['concernphone']])->one();
         if (!Concerns::findAll(['myid' => $u1['id'], 'concernid' => $u2['id']])) {
             return array('flag' => 1, 'msg' => 'is already not concern!');
         }
         Concerns::deleteAll('myid = :myid and concernid = :concernid', [':myid' => $u1['id'], ':concernid' => $u2['id']]);
         $u2->concerncount--;
         $u2->save();
         return array('flag' => 1, 'msg' => 'delete concern success!');
     } else {
         return array('flag' => 0, 'msg' => 'arg not enough!');
     }
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 6
0
 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!');
     }
 }
 /**
  * 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!');
     }
 }
Ejemplo n.º 8
0
 /**
  * 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.');
     }
 }
Ejemplo n.º 9
0
 public function actionSetchannel()
 {
     $data = Yii::$app->request->post();
     $user = Users::find()->where(['phone' => $data['phone']])->one();
     if ($user) {
         if ($user . updateChannel($data['channel'])) {
             return array('flag' => 1, 'msg' => 'update user channel success');
         } else {
             return array('flag' => 0, 'msg' => 'update user channel fail');
         }
     } else {
         return array('flag' => 0, 'msg' => 'can not find the user');
     }
 }
Ejemplo n.º 10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFrom()
 {
     return $this->hasOne(Users::className(), ['id' => 'fromid']);
 }
 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!');
 }
Ejemplo n.º 12
0
 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;
     }
 }
Ejemplo n.º 13
0
 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!');
     }
 }
Ejemplo n.º 14
0
 public function actionReply()
 {
     $data = Yii::$app->request->post();
     //$user=new Users();
     $fromphone = Users::find()->select('id')->where(['phone' => $data['fphone']])->one();
     //var_dump($fromphone);
     $model = new Tbreplys();
     if ($data['tphone'] == '') {
         $model->toid = 0;
     } else {
         $tophone = Users::find()->select('id')->where(['phone' => $data['tphone']])->one();
         //var_dump($tophone);
         $model->toid = $tophone['id'];
     }
     // 		$to=Messages::findOne(['id'=>$data['msgid']]);
     // 		if($fromphone['id']!=$to['id']){
     // 			$model3=new Notify();
     // 			$model3->from=$fromphone['id'];
     // 			$model3->to=$to['userid'];
     // 			//$model3->kind='评论';
     // 			$model3->kind=$data['content'];
     // 			$model3->created_at=time();
     // 			$model3->msg_id=$data['msgid'];
     // 			if(!$model3->save()){
     // 				echo json_encode ( array (
     // 						'flag' => 0,
     // 						'msg' => 'Reply failed!'
     // 				));
     // 				return;
     // 			}
     // 		}
     $model->fromid = $fromphone['id'];
     $model->tbmessageid = $data['tbmessageid'];
     $model->content = $data['content'];
     $model->isread = 0;
     $model->created_at = time();
     //var_dump($model);
     $tbmessage = $this->findModel($data['tbmessageid']);
     $connection = Yii::$app->db;
     $transaction = $connection->beginTransaction();
     try {
         if (!$model->save()) {
             throw new Exception("dsfgsdfg");
         }
         $tbmessage->replycount++;
         if (!$tbmessage->save()) {
             throw new Exception("asdfgsdfg");
         }
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollBack();
         //var_dump("133435465");
         //Yii::$app->log->logger->
         return array('flag' => 0, 'msg' => 'Reply fail!');
     }
     return array('flag' => 1, 'msg' => 'Reply success!');
 }
Ejemplo n.º 15
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMy()
 {
     return $this->hasOne(Users::className(), ['id' => 'myid']);
 }
Ejemplo n.º 16
0
 public function actionReply()
 {
     $data = Yii::$app->request->post();
     //$user=new Users();
     $fromphone = Users::find()->select('id')->where(['phone' => $data['fphone']])->one();
     //var_dump($fromphone);
     $model = new Replys();
     if ($data['tphone'] == '') {
         $model->toid = 0;
     } else {
         $tophone = Users::find()->select('id')->where(['phone' => $data['tphone']])->one();
         //var_dump($tophone);
         $model->toid = $tophone['id'];
     }
     // 		$to=Messages::findOne(['id'=>$data['msgid']]);
     // 		if($fromphone['id']!=$to['id']){
     // 			$model3=new Notify();
     // 			$model3->from=$fromphone['id'];
     // 			$model3->to=$to['userid'];
     // 			//$model3->kind='评论';
     // 			$model3->kind=$data['content'];
     // 			$model3->created_at=time();
     // 			$model3->msg_id=$data['msgid'];
     // 			if(!$model3->save()){
     // 				echo json_encode ( array (
     // 						'flag' => 0,
     // 						'msg' => 'Reply failed!'
     // 				));
     // 				return;
     // 			}
     // 		}
     $model->fromid = $fromphone['id'];
     $model->messageid = $data['messageid'];
     $model->content = $data['content'];
     $model->isread = 0;
     $model->created_at = time();
     //var_dump($model);
     if ($model->save()) {
         return array('flag' => 1, 'msg' => 'Reply success!');
     } else {
         return array('flag' => 0, 'msg' => 'Reply failed!');
     }
 }
Ejemplo n.º 17
0
 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!');
 }
Ejemplo n.º 18
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(Users::className(), ['id' => 'userid']);
 }
Ejemplo n.º 19
0
 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!');
     }
 }