public function yes_contract_put()
 {
     $this->check_token();
     $body = $this->get_request_data('contract');
     if ($this->check_body_fields($body, array('id'))) {
         $contract_id = $body['id'];
         $bid_id = M('contract')->where(array('id' => $contract_id))->getField('bid_id');
         if (empty($bid_id)) {
             $this->error('5009');
         }
         $info = M('member')->find($this->uid);
         //用户信息
         $_POST = array('id' => $bid_id, 'status' => 4);
         if (update_data('bid')) {
             $res = get_info('contract', array('bid_id' => $bid_id, 'status' => 1));
             message_log(0, $res['member_id'], '学生已同意协议。' . $res['title'], 'contract', $res['id'], 2);
             $m = query_sql('', "select member.nickname,bid.demand_member_id from bid left join member on  member.id=bid.service_member_id where bid.id=" . $bid_id);
             M('message')->addAll(array(array("from_member_id" => 0, "to_member_id" => $res['member_id'], 'content' => '学生已同意协议"' . $res['title'] . '"。', 'table' => 'contract', 'table_id' => $res['id'], 'add_time' => date('Y-m-d H:i:s'), 'role' => 2), array("from_member_id" => 0, "to_member_id" => $info['id'], 'content' => '你已同意' . $m[0]['nickname'] . '的协议"' . $res['title'] . '"。', 'table' => 'contract', 'table_id' => $res['id'], 'add_time' => date('Y-m-d H:i:s'), 'role' => 1)));
             $this->success();
         } else {
             // 5010 修改数据失败
             $this->error(5010);
         }
     } else {
         $this->error(1001);
     }
 }
function EnsureGLEntriesBalanceOpenCart($TransType, $TransTypeNo)
{
    /*Ensures general ledger entries balance for a given transaction */
    global $db;
    $result = DB_query("SELECT SUM(amount)\r\n\t\t\t\t\t\tFROM gltrans\r\n\t\t\t\t\t\tWHERE type = '" . $TransType . "'\r\n\t\t\t\t\t\tAND typeno = '" . $TransTypeNo . "'", $db);
    $myrow = DB_fetch_row($result);
    $Difference = $myrow[0];
    if (abs($Difference) != 0) {
        if (abs($Difference) > 0.1) {
            message_log(_('The general ledger entries created do not balance. See your system administrator'), 'error');
        } else {
            $result = DB_query("SELECT counterindex,\r\n\t\t\t\t\t\t\t\t\t\tMAX(amount)\r\n\t\t\t\t\t\t\t\tFROM gltrans\r\n\t\t\t\t\t\t\t\tWHERE type = '" . $TransType . "'\r\n\t\t\t\t\t\t\t\tAND typeno = '" . $TransTypeNo . "'\r\n\t\t\t\t\t\t\t\tGROUP BY counterindex", $db);
            $myrow = DB_fetch_array($result);
            $TransToAmend = $myrow['counterindex'];
            $result = DB_query("UPDATE gltrans SET amount = amount - " . $Difference . "\r\n\t\t\t\t\t\t\t\tWHERE counterindex = '" . $TransToAmend . "'", $db);
        }
    }
}