0

パートナーからのオファーのコレクションを希望しているクライアントがいますが、変更を承認する必要があります。パートナーからの変更の履歴を保持する最良の方法は何ですか?

だからここにそれがどのように機能するかがあります

{
partner_id: {here}
offer1:
offer2:
offer3:
date:
status:
}

オファーが変更されたかどうかを確認する方法が必要です (ただし、1 つだけ戻る)。変更された場合は、挿入して過去のものを status:history として作成します。

次のステータスのみが存在する必要があります。

履歴
保留中
承認済み

しかし、彼らが新しいオファーを挿入しているが、承認済みのオファーがある場合は、承認されるまで承認されたままにする必要があります。

これどうやってするの?これが私が考えた方法です:

    <?php

    function checkoffers($data)
    {
    $this->data = $data;

    $collection = $this->db->partner_offers;
    if($this->data["_id"] != null)
    {
      $cursor = $collection->insert(RUN INSERT ARRAY)
    }
    else
    {
      $cursor = $collection->find(array("_id"=>new MongoId($this->data["_id"])));

      if ($cursor->count() > 0)
        {
            $test = array();
            while( $cursor->hasNext() ) {   
                $test[] = ($cursor->getNext());
            }


                     foreach($test as $offers)
                     {
                      check to see if offer matches the past offer. if not then run new function and insert.
}


                 }


    }

?>
4

1 に答える 1

0

1 つのアプローチは、オファーごとにドキュメントを使用してスキーマを整理することです。

{
    partner_id: 123,
    offer: 'Even better than the last one',
    date: ISODate("2012-08-28T10:00"),
    status: 'pending'
}
{
    partner_id: 123,
    offer: 'The best of the best',
    date: ISODate("2012-08-28T09:00"),
    status: 'approved'
}
{
    partner_id: 123,
    offer: 'An offer you cannot refuse',
    date: ISODate("2012-08-28T08:00"),
    status: 'approved'
}

次に、最新の承認済みまたは保留中のオファーをステータスと日付で並べ替えて簡単に見つけることができます。

> db.partner.find({partner_id:123, status:'approved'}).sort({date:-1}).limit(1)

{
    "_id" : ObjectId("503c6c8be16d4a06b6f0da17"),
    "partner_id" : 123,
    "offer" : "The best of the best",
    "date" : ISODate("2012-08-28T09:00:00Z"),
    "status" : "approved"
}
于 2012-08-28T07:02:07.433 に答える