예제 #1
0
 public function addTruckUser(Request $request)
 {
     $token = $request->get('_token');
     if ($token != '') {
         try {
             // data about truc
             $nametruck = date('dmY');
             $from = $request->get('from');
             $to = $request->get('to');
             $description = $request->get('description');
             $unit = $request->get('unit');
             $created_at = date('Y-m-d H:i:s');
             $address_detail_from = $request->get('address_detail_from');
             $phone_number_from = $request->get('phone_number_from');
             $email_from = $request->get('email_from');
             $email_to = $request->get('email_to');
             $address_detail_to = $request->get('address_detail_to');
             $phone_number_to = $request->get('phone_number_to');
             $data = array('nametruck' => 'X' . $nametruck, 'from_place' => $from, 'to_place' => $to, 'unit' => $unit, 'description' => $description, 'created_at' => $created_at, 'address_detail_to' => $address_detail_to, 'phone_to' => $phone_number_to, 'email_to' => $email_to, 'addresst_detail_from' => $address_detail_from, 'phone_from' => $phone_number_from, 'email_from' => $email_from);
             $id_truck = Truck::getInstance()->insert($data);
             // data for user
             $id_user = Session::get('user')->id;
             $input = array('user_id' => $id_user, 'custome_id' => $id_truck, 'type' => 'truck', 'status' => 'enable', 'created_at' => date('Y-m-d h:i:s'));
             $id_relation = Relation::getInstance()->insert($input);
             if ($id_relation) {
                 return response()->json(array('message' => 'Lưu dữ liệu thành công!', 'error' => 0));
             } else {
                 return response()->json(array('message' => 'Lưu dữ liệu không thành công!', 'error' => 1));
             }
         } catch (\Exception $e) {
             return response()->json(array('message' => 'Lưu dữ liệu không thành công!' . $e->getMessage(), 'error' => 1));
         }
     }
 }
예제 #2
0
 /**
  * Find by my ID and my friends.
  *
  * @param $id
  * @return $this
  */
 public function meAndMyFriends($id)
 {
     $modelClass = $this->modelClass;
     $statusTableName = $modelClass::tableName();
     $relationTableName = Relation::tableName();
     $userTableName = User::tableName();
     return $this->innerJoin(Relation::tableName(), $relationTableName . '.following_id = ' . $statusTableName . '.author_id OR ' . $relationTableName . '.follower_id = ' . $statusTableName . '.author_id')->innerJoin(User::tableName(), $relationTableName . '.following_id = ' . $userTableName . '.id OR ' . $relationTableName . '.follower_id = ' . $userTableName . '.id')->andWhere([User::tableName() . '.id' => $id])->orderBy($statusTableName . '.created_at DESC');
 }
예제 #3
0
 public function actionInsert()
 {
     if (Yii::$app->request->post()) {
         $msg = "";
         $request = Yii::$app->request;
         $emailId = $request->post('emailid');
         $userId = $request->post('userid');
         $result = Relation::find()->where(['user_id' => $userId, 'email_id' => $emailId])->one();
         if ($result == null) {
             $model = new Relation();
             $model->user_id = $userId;
             $model->email_id = $emailId;
             $model->save();
             $msg = "成功分发";
         } else {
             $msg = "分发失败,可能已经分发过了";
         }
         echo $msg;
     }
 }
예제 #4
0
 public function addRelation(Relation $relation)
 {
     if ($relation->getSource() !== $this) {
         throw new \Exception('Must be the source of the relation');
     }
     if (!$relation->isValid()) {
         throw new \Exception("Invalid relation {$relation} between {$relation->getSource()} and {$relation->getTarget()}");
     }
     $this->relations[] = $relation;
     $relation->onAdd();
 }
예제 #5
0
 public function addProductUser(Request $request)
 {
     $token = $request->get('_token');
     if ($token != '') {
         try {
             // data about truc
             $productName = date('dmY');
             $from = $request->get('from');
             $to = $request->get('to');
             $product_type = $request->get('product_type');
             $unit = $request->get('unit');
             $description = $request->get('description');
             $address_detail_from = $request->get('address_detail_from');
             $phone_number_from = $request->get('phone_number_from');
             $email_from = $request->get('email_from');
             $email_to = $request->get('email_to');
             $address_detail_to = $request->get('address_detail_to');
             $phone_number_to = $request->get('phone_number_to');
             $created_at = date('Y-m-d H:i:s');
             $data = array('product_name' => 'P' . $productName, 'comefrom' => $from, 'cometo' => $to, 'product_type' => $product_type, 'unit' => $unit, 'description' => $description, 'created_at' => $created_at, 'address_detail_to' => $address_detail_to, 'phone_to' => $phone_number_to, 'email_to' => $email_to, 'addresst_detail_from' => $address_detail_from, 'phone_from' => $phone_number_from, 'email_from' => $email_from);
             $id_product = Product::getInstance()->insert($data);
             // data for user
             $id_user = Session::get('user')->id;
             $input = array('user_id' => $id_user, 'custome_id' => $id_product, 'type' => 'product', 'status' => 'enable', 'created_at' => date('Y-m-d h:i:s'));
             //                    $input_price = array(
             //                        'price_sum' => $price_sum,
             //                        'foreign_key'       => $id_product
             //                    );
             //                    $id_price = Price::getInstance()->insert($input_price);
             $id_relation = Relation::getInstance()->insert($input);
             if ($id_relation) {
                 return response()->json(array('message' => 'Lưu dữ liệu thành công!', 'error' => 0));
             } else {
                 return response()->json(array('message' => 'Lưu dữ liệu không thành công!', 'error' => 1));
             }
         } catch (\Exception $e) {
             return response()->json(array('message' => 'Lưu dữ liệu không thành công!' . $e->getMessage(), 'error' => 1));
         }
     }
 }
예제 #6
0
파일: User.php 프로젝트: artpro676/twitter
 /**
  * Remove friend.
  *
  * @param $id Int
  * @return bool
  * @throws NotFoundHttpException
  */
 public function rmFriend($id)
 {
     if ($following = self::findIdentity($id)) {
         return $relation = Relation::find()->where('follower_id = :user_id AND following_id = :friend_id')->orWhere('follower_id = :friend_id AND following_id = :user_id')->params([':friend_id' => $following->id, ':user_id' => $this->id])->one()->delete();
     } else {
         throw new NotFoundHttpException();
     }
 }
예제 #7
0
 public function getRel()
 {
     return $this->hasMany(Relation::className(), ['user_id' => 'id']);
 }